Commit | Line | Data |
---|---|---|
ed4a8563 | 1 | /* vlimit.c 4.2 83/06/20 */ |
611c3c29 SL |
2 | |
3 | /* | |
4 | * (Almost) backwards compatible vlimit. | |
5 | */ | |
ed4a8563 | 6 | #include <sys/time.h> |
611c3c29 | 7 | #include <sys/resource.h> |
ed4a8563 | 8 | #include <errno.h> |
611c3c29 SL |
9 | |
10 | /* LIM_NORAISE is not emulated */ | |
11 | #define LIM_NORAISE 0 /* if <> 0, can't raise limits */ | |
12 | #define LIM_CPU 1 /* max secs cpu time */ | |
13 | #define LIM_FSIZE 2 /* max size of file created */ | |
14 | #define LIM_DATA 3 /* max growth of data space */ | |
15 | #define LIM_STACK 4 /* max growth of stack */ | |
16 | #define LIM_CORE 5 /* max size of ``core'' file */ | |
17 | #define LIM_MAXRSS 6 /* max desired data+stack core usage */ | |
18 | ||
19 | #define NLIMITS 6 | |
20 | ||
21 | vlimit(limit, value) | |
22 | int limit, value; | |
23 | { | |
24 | struct rlimit rlim; | |
25 | ||
26 | if (limit <= 0 || limit > NLIMITS) | |
27 | return (EINVAL); | |
28 | if (value == -1) { | |
29 | if (getrlimit(limit - 1, &rlim) < 0) | |
30 | return (-1); | |
31 | return (rlim.rlim_cur); | |
32 | } | |
33 | rlim.rlim_cur = value; | |
34 | rlim.rlim_max = RLIM_INFINITY; | |
35 | return (setrlimit(limit - 1, &rlim)); | |
36 | } |