From 82cb97d3e3ad6bf51dbd0decdb731ab947a13529 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Claes=20N=C3=A4st=C3=A9n?= Date: Thu, 24 Nov 2005 21:13:21 +1000 Subject: [PATCH] builtin ulimit checks Adds checks for RLIMIT_NPROC, RLIMIT_RSS and RLIMIT_MEMLOCK not available on all platforms. darcs-hash:20051124111321-cac88-606a61ca0f3baa69115be658a056f42a5a9318ad.gz --- builtin_ulimit.c | 24 +++++++++++++++++++----- configure.ac | 37 +++++++++++++++++++++++++++++++++++++ 2 files changed, 56 insertions(+), 5 deletions(-) diff --git a/builtin_ulimit.c b/builtin_ulimit.c index 03bbbeb74..dcd113e1a 100644 --- a/builtin_ulimit.c +++ b/builtin_ulimit.c @@ -55,14 +55,18 @@ const static struct resource_t resource_arr[] = RLIMIT_FSIZE, L"Maximum size of files created by the shell", L'f' } , +#if HAVE_RLIMIT_MEMLOCK { RLIMIT_MEMLOCK, L"Maximum size that may be locked into memory", L'l' } , +#endif +#if HAVE_RLIMIT_RSS { RLIMIT_RSS, L"Maximum resident set size", L'm' } , +#endif { RLIMIT_NOFILE, L"Maximum number of open file descriptors", L'n' } @@ -75,10 +79,12 @@ const static struct resource_t resource_arr[] = RLIMIT_CPU, L"Maximum amount of cpu time in seconds", L't' } , +#if HAVE_RLIMIT_NPROC { RLIMIT_NPROC, L"Maximum number of processes available to a single user", L'u' } , +#endif #if HAVE_RLIMIT_AS { RLIMIT_AS, L"Maximum amount of virtual memory available to the shell", L'v' @@ -96,8 +102,11 @@ const static struct resource_t resource_arr[] = */ static int get_multiplier( int what ) { - if( ( what == RLIMIT_NPROC ) || - ( what == RLIMIT_NOFILE ) || + + if( ( what == RLIMIT_NOFILE ) || +#if HAVE_RLIMIT_NPROC + ( what == RLIMIT_NPROC ) || +#endif ( what == RLIMIT_CPU ) ) { return 1; @@ -365,14 +374,17 @@ int builtin_ulimit( wchar_t ** argv ) case L'f': what=RLIMIT_FSIZE; break; - +#if HAVE_RLIMIT_MEMLOCK case L'l': what=RLIMIT_MEMLOCK; break; - +#endif + +#if HAVE_RLIMIT_RSS case L'm': what=RLIMIT_RSS; break; +#endif case L'n': what=RLIMIT_NOFILE; @@ -385,10 +397,12 @@ int builtin_ulimit( wchar_t ** argv ) case L't': what=RLIMIT_CPU; break; - + +#if HAVE_RLIMIT_NPROC case L'u': what=RLIMIT_NPROC; break; +#endif #if HAVE_RLIMIT_AS case L'v': diff --git a/configure.ac b/configure.ac index 7728238d4..10351a708 100644 --- a/configure.ac +++ b/configure.ac @@ -79,6 +79,43 @@ else AC_MSG_RESULT(no) fi +# Check for RLIMIT_MEMLOCK in sys/resource.h. +AC_MSG_CHECKING([for RLIMIT_MEMLOCK in sys/resource.h]) +AC_TRY_COMPILE([#include ], +[int tmp; tmp=RLIMIT_MEMLOCK;], have_rlimit_as=yes, have_rlimit_as=no) +if test "$have_rlimit_as" = yes; then + AC_MSG_RESULT(yes) + AC_DEFINE([HAVE_RLIMIT_MEMLOCK], [1], + [Define to 1 if HAVE_RLIMIT_MEMLOCK is defined in .]) +else + AC_MSG_RESULT(no) +fi + +# Check for RLIMIT_RSS in sys/resource.h. +AC_MSG_CHECKING([for RLIMIT_RSS in sys/resource.h]) +AC_TRY_COMPILE([#include ], +[int tmp; tmp=RLIMIT_RSS;], have_rlimit_as=yes, have_rlimit_as=no) +if test "$have_rlimit_as" = yes; then + AC_MSG_RESULT(yes) + AC_DEFINE([HAVE_RLIMIT_RSS], [1], + [Define to 1 if HAVE_RLIMIT_RSS is defined in .]) +else + AC_MSG_RESULT(no) +fi + +# Check for RLIMIT_NPROC in sys/resource.h. +AC_MSG_CHECKING([for RLIMIT_NPROC in sys/resource.h]) +AC_TRY_COMPILE([#include ], +[int tmp; tmp=RLIMIT_NPROC;], have_rlimit_as=yes, have_rlimit_as=no) +if test "$have_rlimit_as" = yes; then + AC_MSG_RESULT(yes) + AC_DEFINE([HAVE_RLIMIT_NPROC], [1], + [Define to 1 if HAVE_RLIMIT_NPROC is defined in .]) +else + AC_MSG_RESULT(no) +fi + + AC_CHECK_LIB(socket, connect) AC_CHECK_LIB(rt, nanosleep)