diff options
author | Rich Felker <dalias@aerifal.cx> | 2012-03-22 01:00:35 -0400 |
---|---|---|
committer | Rich Felker <dalias@aerifal.cx> | 2012-03-22 01:00:35 -0400 |
commit | 2e0c1fed36be1f1435de79bfc7cdc34824cb5614 (patch) | |
tree | b988e27bd916f6b78cbbb6bb5807e6caa51b59d2 | |
parent | 47db8903f61e20aba53adfc987dfb576d22a0b81 (diff) | |
download | musl-2e0c1fed36be1f1435de79bfc7cdc34824cb5614.tar.gz musl-2e0c1fed36be1f1435de79bfc7cdc34824cb5614.tar.xz musl-2e0c1fed36be1f1435de79bfc7cdc34824cb5614.zip |
sysconf support for dynamic limits (open files and processes)
-rw-r--r-- | src/conf/sysconf.c | 11 |
1 files changed, 9 insertions, 2 deletions
diff --git a/src/conf/sysconf.c b/src/conf/sysconf.c index 28232a77..5b6c14e5 100644 --- a/src/conf/sysconf.c +++ b/src/conf/sysconf.c @@ -1,18 +1,21 @@ #include <unistd.h> #include <limits.h> #include <errno.h> +#include <sys/resource.h> +#include "syscall.h" #define VER (-2) #define OFLOW (-3) +#define RLIM(x) (-32768|(RLIMIT_ ## x)) long sysconf(int name) { static const short values[] = { [_SC_ARG_MAX] = OFLOW, - [_SC_CHILD_MAX] = -1, + [_SC_CHILD_MAX] = RLIM(NPROC), [_SC_CLK_TCK] = 100, [_SC_NGROUPS_MAX] = 32, - [_SC_OPEN_MAX] = 1024, + [_SC_OPEN_MAX] = RLIM(NOFILE), [_SC_STREAM_MAX] = -1, [_SC_TZNAME_MAX] = TZNAME_MAX, [_SC_JOB_CONTROL] = 1, @@ -217,6 +220,10 @@ long sysconf(int name) } else if (values[name] == OFLOW) { if (name == _SC_ARG_MAX) return ARG_MAX; if (name == _SC_SEM_VALUE_MAX) return SEM_VALUE_MAX; + } else if (values[name] < 0) { + long lim[2]; + __syscall(SYS_getrlimit, values[name]&16383, lim); + return lim[0] < 0 ? LONG_MAX : lim[0]; } return values[name]; } |