blob: 1df733b565d0059e7c7b675f695ef06a704e349f (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
|
/* getrlimit Author: Erik van der Kouwe
* query resource consumtion limits 4 December 2009
*
* Based on these specifications:
* http://www.opengroup.org/onlinepubs/007908775/xsh/getdtablesize.html
* http://www.opengroup.org/onlinepubs/007908775/xsh/getrlimit.html
*/
#include <sys/cdefs.h>
#include "namespace.h"
#include <errno.h>
#include <limits.h>
#include <sys/resource.h>
#include <unistd.h>
int getrlimit(int resource, struct rlimit *rlp)
{
rlim_t limit;
switch (resource)
{
case RLIMIT_CPU:
case RLIMIT_FSIZE:
case RLIMIT_DATA:
case RLIMIT_STACK:
case RLIMIT_CORE:
case RLIMIT_RSS:
case RLIMIT_MEMLOCK:
case RLIMIT_SBSIZE:
case RLIMIT_AS:
/* case RLIMIT_VMEM: Same as RLIMIT_AS */
case RLIMIT_NTHR:
/* no limit enforced (however architectural limits
* may apply)
*/
limit = RLIM_INFINITY;
break;
case RLIMIT_NPROC:
limit = CHILD_MAX;
break;
case RLIMIT_NOFILE:
limit = OPEN_MAX;
break;
default:
errno = EINVAL;
return -1;
}
/* return limit */
rlp->rlim_cur = limit;
rlp->rlim_max = limit;
return 0;
}
|