]> mj.ucw.cz Git - libucw.git/blob - lib/perl/Ulimit/Ulimit.xs
Readding line of makefile lost in merge
[libucw.git] / lib / perl / Ulimit / Ulimit.xs
1 /*
2  * PerlXS module for managing process limits
3  *
4  * (c) 2003 Tomas Valla <tom@ucw.cz>
5  */
6
7 #include "EXTERN.h"
8 #include "perl.h"
9 #include "XSUB.h"
10
11 #include <sys/resource.h>
12 #include <unistd.h>
13
14
15 MODULE = UCW::Ulimit            PACKAGE = UCW::Ulimit
16
17 PROTOTYPES: ENABLED
18
19 int
20 setlimit(IN int resource, IN int soft, IN int hard)
21 CODE:
22         struct rlimit rl;
23         int r;
24
25         switch(resource) {
26         case 0:
27                 r = RLIMIT_CPU; break;
28         case 1:
29                 r = RLIMIT_FSIZE; break;
30         case 2:
31                 r = RLIMIT_DATA; break;
32         case 3:
33                 r = RLIMIT_STACK; break;
34         case 4:
35                 r = RLIMIT_CORE; break;
36         case 5:
37                 r = RLIMIT_RSS; break;
38         case 6:
39                 r = RLIMIT_NPROC; break;
40         case 7:
41                 r = RLIMIT_NOFILE; break;
42         case 8:
43                 r = RLIMIT_MEMLOCK; break;
44         case 9:
45                 r = RLIMIT_AS; break;
46         }
47         rl.rlim_cur = soft;
48         rl.rlim_max = hard;
49         RETVAL = setrlimit(r, &rl);
50 OUTPUT:
51         RETVAL
52
53
54 int
55 getlimit(IN int resource, OUT int soft, OUT int hard)
56 CODE:
57         struct rlimit rl;
58         int r;
59
60         switch(resource) {
61         case 0:
62                 r = RLIMIT_CPU; break;
63         case 1:
64                 r = RLIMIT_FSIZE; break;
65         case 2:
66                 r = RLIMIT_DATA; break;
67         case 3:
68                 r = RLIMIT_STACK; break;
69         case 4:
70                 r = RLIMIT_CORE; break;
71         case 5:
72                 r = RLIMIT_RSS; break;
73         case 6:
74                 r = RLIMIT_NPROC; break;
75         case 7:
76                 r = RLIMIT_NOFILE; break;
77         case 8:
78                 r = RLIMIT_MEMLOCK; break;
79         case 9:
80                 r = RLIMIT_AS; break;
81         }
82
83         RETVAL = getrlimit(r, &rl);
84         soft = rl.rlim_cur;
85         hard = rl.rlim_max;
86 OUTPUT:
87         RETVAL