From be6a44566a7085470b96bc41d371e37b5b12ff87 Mon Sep 17 00:00:00 2001 From: Elliott Hughes Date: Tue, 17 Feb 2015 09:55:58 -0800 Subject: [PATCH] Fix sysconf for _SC_CHILD_MAX and _SC_OPEN_MAX. Change-Id: I656f613166bd604f35b31e5ec042a5230c6b82b8 --- libc/bionic/sysconf.cpp | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/libc/bionic/sysconf.cpp b/libc/bionic/sysconf.cpp index 411c23ab0..c301b27b3 100644 --- a/libc/bionic/sysconf.cpp +++ b/libc/bionic/sysconf.cpp @@ -33,6 +33,7 @@ #include #include // For FOPEN_MAX. #include +#include #include #include #include @@ -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(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;