My C program will not open a file...

I thought it very strange when my program which I was testing chad errno report that my system had to many files open.

So I opened another file with kwrite thus demonstrating that there was something else wrong.
So I rebooted got the same error and wrote in a call to rlimit.
It gave me a message when I compiling saying that my struct rlimit contained no fields.

ext-reg-comp.c:397:58: error: request for member ‘rlim_cur’ in something not a structure or union

So I removed the access to rlim_cur and it compiled.
I ran it and got this message.


The amount you can have is 0
Me: Fatal: File '/home/me/bin/dwmt/globs_sorted_reg.txt' can not be opened.
Me: Errno reports: 'Too many open files'
Aborted

Due to the size of the code I suse pasted it.

http://susepaste.org/6496250


   do
   {
       errno = 0;
       globs_sorted_reg = open(glob_file_name, 0);
       if(globs_sorted_reg == -1)
       {
           switch(errno)
           {
           ...
           }
       }
  } while(errno == EINTR || errno == 0);

Have a look at that loop (at the beginning of build_exts() ). There’s no close() inside it anywhere.
So this will loop and open the same file over and over again.
Eventually it will run out of file descriptors of course.

So I opened another file with kwrite thus demonstrating that there was something else wrong.

There is a per-process limit of file descriptors. Your program exceeded its limit, but that doesn’t affect other programs.

So I rebooted got the same error and wrote in a call to rlimit.

It gave me a message when I compiling saying that my struct rlimit contained no fields.

ext-reg-comp.c:397:58: error: request for member ‘rlim_cur’ in something not a structure or union

So I removed the access to rlim_cur and it compiled.

Did you include <sys/resource.h> ? That’s where struct rlimit is defined.
And you get the message “The amount you can have is 0” because you print the return code of getrlimit() which is 0 for success.

Sorry, I saw now that you did include it.

But how did you access rlim_cur?
This should work:

ff = file_rlimit.rlim_cur;

According to the error message you did it wrong. Maybe you had “rlimit.rlim_cur”? :wink: