Fix sysconf for _SC_CHILD_MAX and _SC_OPEN_MAX.

Change-Id: I656f613166bd604f35b31e5ec042a5230c6b82b8
This commit is contained in:
Elliott Hughes 2015-02-17 09:55:58 -08:00
parent fb48c68221
commit be6a44566a

View File

@ -33,6 +33,7 @@
#include <pthread.h>
#include <stdio.h> // For FOPEN_MAX.
#include <sys/auxv.h>
#include <sys/resource.h>
#include <sys/sysconf.h>
#include <sys/sysinfo.h>
#include <time.h>
@ -50,6 +51,12 @@ static bool __sysconf_has_clock(clockid_t clock_id) {
return clock_getres(clock_id, NULL) == 0;
}
static long __sysconf_rlimit(int resource) {
rlimit rl;
getrlimit(resource, &rl);
return rl.rlim_cur;
}
long sysconf(int name) {
switch (name) {
case _SC_ARG_MAX: return ARG_MAX;
@ -57,13 +64,13 @@ long sysconf(int name) {
case _SC_BC_DIM_MAX: return _POSIX2_BC_DIM_MAX; // Minimum requirement.
case _SC_BC_SCALE_MAX: return _POSIX2_BC_SCALE_MAX; // Minimum requirement.
case _SC_BC_STRING_MAX: return _POSIX2_BC_STRING_MAX; // Minimum requirement.
case _SC_CHILD_MAX: return CHILD_MAX;
case _SC_CHILD_MAX: return __sysconf_rlimit(RLIMIT_NPROC);
case _SC_CLK_TCK: return static_cast<long>(getauxval(AT_CLKTCK));
case _SC_COLL_WEIGHTS_MAX: return _POSIX2_COLL_WEIGHTS_MAX; // Minimum requirement.
case _SC_EXPR_NEST_MAX: return _POSIX2_EXPR_NEST_MAX; // Minimum requirement.
case _SC_LINE_MAX: return _POSIX2_LINE_MAX; // Minimum requirement.
case _SC_NGROUPS_MAX: return NGROUPS_MAX;
case _SC_OPEN_MAX: return OPEN_MAX;
case _SC_OPEN_MAX: return __sysconf_rlimit(RLIMIT_NOFILE);
case _SC_PASS_MAX: return PASS_MAX;
case _SC_2_C_BIND: return _POSIX2_C_BIND;
case _SC_2_C_DEV: return _POSIX2_C_DEV;