1433d6423SLionel Sambuc /* getrlimit Author: Erik van der Kouwe 2433d6423SLionel Sambuc * query resource consumtion limits 4 December 2009 3433d6423SLionel Sambuc * 4433d6423SLionel Sambuc * Based on these specifications: 5433d6423SLionel Sambuc * http://www.opengroup.org/onlinepubs/007908775/xsh/getdtablesize.html 6433d6423SLionel Sambuc * http://www.opengroup.org/onlinepubs/007908775/xsh/getrlimit.html 7433d6423SLionel Sambuc */ 8433d6423SLionel Sambuc 9433d6423SLionel Sambuc #include <sys/cdefs.h> 10433d6423SLionel Sambuc #include "namespace.h" 11433d6423SLionel Sambuc 12433d6423SLionel Sambuc #include <errno.h> 13433d6423SLionel Sambuc #include <limits.h> 14433d6423SLionel Sambuc #include <sys/resource.h> 15433d6423SLionel Sambuc #include <unistd.h> 16433d6423SLionel Sambuc getrlimit(int resource,struct rlimit * rlp)17433d6423SLionel Sambucint getrlimit(int resource, struct rlimit *rlp) 18433d6423SLionel Sambuc { 19433d6423SLionel Sambuc rlim_t limit; 20433d6423SLionel Sambuc 21433d6423SLionel Sambuc switch (resource) 22433d6423SLionel Sambuc { 23433d6423SLionel Sambuc case RLIMIT_CPU: 24433d6423SLionel Sambuc case RLIMIT_FSIZE: 25433d6423SLionel Sambuc case RLIMIT_DATA: 26433d6423SLionel Sambuc case RLIMIT_STACK: 27433d6423SLionel Sambuc case RLIMIT_CORE: 28433d6423SLionel Sambuc case RLIMIT_RSS: 29433d6423SLionel Sambuc case RLIMIT_MEMLOCK: 30433d6423SLionel Sambuc case RLIMIT_SBSIZE: 31433d6423SLionel Sambuc case RLIMIT_AS: 32433d6423SLionel Sambuc /* case RLIMIT_VMEM: Same as RLIMIT_AS */ 33433d6423SLionel Sambuc case RLIMIT_NTHR: 34433d6423SLionel Sambuc /* no limit enforced (however architectural limits 35433d6423SLionel Sambuc * may apply) 36433d6423SLionel Sambuc */ 37433d6423SLionel Sambuc limit = RLIM_INFINITY; 38433d6423SLionel Sambuc break; 39433d6423SLionel Sambuc 40*d2532d3dSDavid van Moolenbroek case RLIMIT_NPROC: 41*d2532d3dSDavid van Moolenbroek limit = CHILD_MAX; 42*d2532d3dSDavid van Moolenbroek break; 43*d2532d3dSDavid van Moolenbroek 44433d6423SLionel Sambuc case RLIMIT_NOFILE: 45433d6423SLionel Sambuc limit = OPEN_MAX; 46433d6423SLionel Sambuc break; 47433d6423SLionel Sambuc 48433d6423SLionel Sambuc default: 49433d6423SLionel Sambuc errno = EINVAL; 50433d6423SLionel Sambuc return -1; 51433d6423SLionel Sambuc } 52433d6423SLionel Sambuc 53433d6423SLionel Sambuc /* return limit */ 54433d6423SLionel Sambuc rlp->rlim_cur = limit; 55433d6423SLionel Sambuc rlp->rlim_max = limit; 56433d6423SLionel Sambuc return 0; 57433d6423SLionel Sambuc } 58433d6423SLionel Sambuc 59