>Hi all,
>
> Is it safe to call setrlimit(RLIMIT_NOFILE, ..) from a library?
> The code does
>        if (getrlimit(RLIMIT_NOFILE, &rl) == 0) {
>                rl.rlim_cur = rl.rlim_max;
>                (void) setrlimit(RLIMIT_NOFILE, &rl);
>        }

No.  Libraries should not have side effects like this.

> The library needs some file descriptors for its internal use
> and increasing the soft limit on file descriptors up to the hard limit
> will make it unlikely that an application using the library runs out
> of file descriptors for its own use. This seems safe to do to me
> as we are only increasing the limit.

But it is not.  Some code fails or starts to perform poorly when
confronted with large fd limits.

Secondly, it's not thread safe; if this happens in one thread and the
application modifies the limit in its own thread, weird things can happen.

> But, I am not sure if this is kosher since there does not seem to be
> any use of setrlimit(2) in ON libraries excepting in
> libdtrace (lib/libdtrace/common/dt_open.c).

Which is a special case because it's a special purpose library (not
used by programs, not exporting interfaces)

If your library cannot get the descriptors it needs, it must fail.

This is how it's dealt with everywhere else and there does not seem
to be a case for an exception (think of all the name lookup library
routines which cache fds)

Casper
_______________________________________________
opensolaris-code mailing list
[email protected]
http://mail.opensolaris.org/mailman/listinfo/opensolaris-code

Reply via email to