1 | n/a | |
---|
2 | n/a | #include "Python.h" |
---|
3 | n/a | #include <sys/resource.h> |
---|
4 | n/a | #include <sys/time.h> |
---|
5 | n/a | #include <string.h> |
---|
6 | n/a | #include <errno.h> |
---|
7 | n/a | /* for sysconf */ |
---|
8 | n/a | #if defined(HAVE_UNISTD_H) |
---|
9 | n/a | #include <unistd.h> |
---|
10 | n/a | #endif |
---|
11 | n/a | |
---|
12 | n/a | /* On some systems, these aren't in any header file. |
---|
13 | n/a | On others they are, with inconsistent prototypes. |
---|
14 | n/a | We declare the (default) return type, to shut up gcc -Wall; |
---|
15 | n/a | but we can't declare the prototype, to avoid errors |
---|
16 | n/a | when the header files declare it different. |
---|
17 | n/a | Worse, on some Linuxes, getpagesize() returns a size_t... */ |
---|
18 | n/a | |
---|
19 | n/a | #define doubletime(TV) ((double)(TV).tv_sec + (TV).tv_usec * 0.000001) |
---|
20 | n/a | |
---|
21 | n/a | PyDoc_STRVAR(struct_rusage__doc__, |
---|
22 | n/a | "struct_rusage: Result from getrusage.\n\n" |
---|
23 | n/a | "This object may be accessed either as a tuple of\n" |
---|
24 | n/a | " (utime,stime,maxrss,ixrss,idrss,isrss,minflt,majflt,\n" |
---|
25 | n/a | " nswap,inblock,oublock,msgsnd,msgrcv,nsignals,nvcsw,nivcsw)\n" |
---|
26 | n/a | "or via the attributes ru_utime, ru_stime, ru_maxrss, and so on."); |
---|
27 | n/a | |
---|
28 | n/a | static PyStructSequence_Field struct_rusage_fields[] = { |
---|
29 | n/a | {"ru_utime", "user time used"}, |
---|
30 | n/a | {"ru_stime", "system time used"}, |
---|
31 | n/a | {"ru_maxrss", "max. resident set size"}, |
---|
32 | n/a | {"ru_ixrss", "shared memory size"}, |
---|
33 | n/a | {"ru_idrss", "unshared data size"}, |
---|
34 | n/a | {"ru_isrss", "unshared stack size"}, |
---|
35 | n/a | {"ru_minflt", "page faults not requiring I/O"}, |
---|
36 | n/a | {"ru_majflt", "page faults requiring I/O"}, |
---|
37 | n/a | {"ru_nswap", "number of swap outs"}, |
---|
38 | n/a | {"ru_inblock", "block input operations"}, |
---|
39 | n/a | {"ru_oublock", "block output operations"}, |
---|
40 | n/a | {"ru_msgsnd", "IPC messages sent"}, |
---|
41 | n/a | {"ru_msgrcv", "IPC messages received"}, |
---|
42 | n/a | {"ru_nsignals", "signals received"}, |
---|
43 | n/a | {"ru_nvcsw", "voluntary context switches"}, |
---|
44 | n/a | {"ru_nivcsw", "involuntary context switches"}, |
---|
45 | n/a | {0} |
---|
46 | n/a | }; |
---|
47 | n/a | |
---|
48 | n/a | static PyStructSequence_Desc struct_rusage_desc = { |
---|
49 | n/a | "resource.struct_rusage", /* name */ |
---|
50 | n/a | struct_rusage__doc__, /* doc */ |
---|
51 | n/a | struct_rusage_fields, /* fields */ |
---|
52 | n/a | 16 /* n_in_sequence */ |
---|
53 | n/a | }; |
---|
54 | n/a | |
---|
55 | n/a | static int initialized; |
---|
56 | n/a | static PyTypeObject StructRUsageType; |
---|
57 | n/a | |
---|
58 | n/a | static PyObject * |
---|
59 | n/a | resource_getrusage(PyObject *self, PyObject *args) |
---|
60 | n/a | { |
---|
61 | n/a | int who; |
---|
62 | n/a | struct rusage ru; |
---|
63 | n/a | PyObject *result; |
---|
64 | n/a | |
---|
65 | n/a | if (!PyArg_ParseTuple(args, "i:getrusage", &who)) |
---|
66 | n/a | return NULL; |
---|
67 | n/a | |
---|
68 | n/a | if (getrusage(who, &ru) == -1) { |
---|
69 | n/a | if (errno == EINVAL) { |
---|
70 | n/a | PyErr_SetString(PyExc_ValueError, |
---|
71 | n/a | "invalid who parameter"); |
---|
72 | n/a | return NULL; |
---|
73 | n/a | } |
---|
74 | n/a | PyErr_SetFromErrno(PyExc_OSError); |
---|
75 | n/a | return NULL; |
---|
76 | n/a | } |
---|
77 | n/a | |
---|
78 | n/a | result = PyStructSequence_New(&StructRUsageType); |
---|
79 | n/a | if (!result) |
---|
80 | n/a | return NULL; |
---|
81 | n/a | |
---|
82 | n/a | PyStructSequence_SET_ITEM(result, 0, |
---|
83 | n/a | PyFloat_FromDouble(doubletime(ru.ru_utime))); |
---|
84 | n/a | PyStructSequence_SET_ITEM(result, 1, |
---|
85 | n/a | PyFloat_FromDouble(doubletime(ru.ru_stime))); |
---|
86 | n/a | PyStructSequence_SET_ITEM(result, 2, PyLong_FromLong(ru.ru_maxrss)); |
---|
87 | n/a | PyStructSequence_SET_ITEM(result, 3, PyLong_FromLong(ru.ru_ixrss)); |
---|
88 | n/a | PyStructSequence_SET_ITEM(result, 4, PyLong_FromLong(ru.ru_idrss)); |
---|
89 | n/a | PyStructSequence_SET_ITEM(result, 5, PyLong_FromLong(ru.ru_isrss)); |
---|
90 | n/a | PyStructSequence_SET_ITEM(result, 6, PyLong_FromLong(ru.ru_minflt)); |
---|
91 | n/a | PyStructSequence_SET_ITEM(result, 7, PyLong_FromLong(ru.ru_majflt)); |
---|
92 | n/a | PyStructSequence_SET_ITEM(result, 8, PyLong_FromLong(ru.ru_nswap)); |
---|
93 | n/a | PyStructSequence_SET_ITEM(result, 9, PyLong_FromLong(ru.ru_inblock)); |
---|
94 | n/a | PyStructSequence_SET_ITEM(result, 10, PyLong_FromLong(ru.ru_oublock)); |
---|
95 | n/a | PyStructSequence_SET_ITEM(result, 11, PyLong_FromLong(ru.ru_msgsnd)); |
---|
96 | n/a | PyStructSequence_SET_ITEM(result, 12, PyLong_FromLong(ru.ru_msgrcv)); |
---|
97 | n/a | PyStructSequence_SET_ITEM(result, 13, PyLong_FromLong(ru.ru_nsignals)); |
---|
98 | n/a | PyStructSequence_SET_ITEM(result, 14, PyLong_FromLong(ru.ru_nvcsw)); |
---|
99 | n/a | PyStructSequence_SET_ITEM(result, 15, PyLong_FromLong(ru.ru_nivcsw)); |
---|
100 | n/a | |
---|
101 | n/a | if (PyErr_Occurred()) { |
---|
102 | n/a | Py_DECREF(result); |
---|
103 | n/a | return NULL; |
---|
104 | n/a | } |
---|
105 | n/a | |
---|
106 | n/a | return result; |
---|
107 | n/a | } |
---|
108 | n/a | |
---|
109 | n/a | static int |
---|
110 | n/a | py2rlimit(PyObject *limits, struct rlimit *rl_out) |
---|
111 | n/a | { |
---|
112 | n/a | PyObject *curobj, *maxobj; |
---|
113 | n/a | limits = PySequence_Tuple(limits); |
---|
114 | n/a | if (!limits) |
---|
115 | n/a | /* Here limits is a borrowed reference */ |
---|
116 | n/a | return -1; |
---|
117 | n/a | |
---|
118 | n/a | if (PyTuple_GET_SIZE(limits) != 2) { |
---|
119 | n/a | PyErr_SetString(PyExc_ValueError, |
---|
120 | n/a | "expected a tuple of 2 integers"); |
---|
121 | n/a | goto error; |
---|
122 | n/a | } |
---|
123 | n/a | curobj = PyTuple_GET_ITEM(limits, 0); |
---|
124 | n/a | maxobj = PyTuple_GET_ITEM(limits, 1); |
---|
125 | n/a | #if !defined(HAVE_LARGEFILE_SUPPORT) |
---|
126 | n/a | rl_out->rlim_cur = PyLong_AsLong(curobj); |
---|
127 | n/a | if (rl_out->rlim_cur == (rlim_t)-1 && PyErr_Occurred()) |
---|
128 | n/a | goto error; |
---|
129 | n/a | rl_out->rlim_max = PyLong_AsLong(maxobj); |
---|
130 | n/a | if (rl_out->rlim_max == (rlim_t)-1 && PyErr_Occurred()) |
---|
131 | n/a | goto error; |
---|
132 | n/a | #else |
---|
133 | n/a | /* The limits are probably bigger than a long */ |
---|
134 | n/a | rl_out->rlim_cur = PyLong_AsLongLong(curobj); |
---|
135 | n/a | if (rl_out->rlim_cur == (rlim_t)-1 && PyErr_Occurred()) |
---|
136 | n/a | goto error; |
---|
137 | n/a | rl_out->rlim_max = PyLong_AsLongLong(maxobj); |
---|
138 | n/a | if (rl_out->rlim_max == (rlim_t)-1 && PyErr_Occurred()) |
---|
139 | n/a | goto error; |
---|
140 | n/a | #endif |
---|
141 | n/a | |
---|
142 | n/a | Py_DECREF(limits); |
---|
143 | n/a | rl_out->rlim_cur = rl_out->rlim_cur & RLIM_INFINITY; |
---|
144 | n/a | rl_out->rlim_max = rl_out->rlim_max & RLIM_INFINITY; |
---|
145 | n/a | return 0; |
---|
146 | n/a | |
---|
147 | n/a | error: |
---|
148 | n/a | Py_DECREF(limits); |
---|
149 | n/a | return -1; |
---|
150 | n/a | } |
---|
151 | n/a | |
---|
152 | n/a | static PyObject* |
---|
153 | n/a | rlimit2py(struct rlimit rl) |
---|
154 | n/a | { |
---|
155 | n/a | if (sizeof(rl.rlim_cur) > sizeof(long)) { |
---|
156 | n/a | return Py_BuildValue("LL", |
---|
157 | n/a | (long long) rl.rlim_cur, |
---|
158 | n/a | (long long) rl.rlim_max); |
---|
159 | n/a | } |
---|
160 | n/a | return Py_BuildValue("ll", (long) rl.rlim_cur, (long) rl.rlim_max); |
---|
161 | n/a | } |
---|
162 | n/a | |
---|
163 | n/a | static PyObject * |
---|
164 | n/a | resource_getrlimit(PyObject *self, PyObject *args) |
---|
165 | n/a | { |
---|
166 | n/a | struct rlimit rl; |
---|
167 | n/a | int resource; |
---|
168 | n/a | |
---|
169 | n/a | if (!PyArg_ParseTuple(args, "i:getrlimit", &resource)) |
---|
170 | n/a | return NULL; |
---|
171 | n/a | |
---|
172 | n/a | if (resource < 0 || resource >= RLIM_NLIMITS) { |
---|
173 | n/a | PyErr_SetString(PyExc_ValueError, |
---|
174 | n/a | "invalid resource specified"); |
---|
175 | n/a | return NULL; |
---|
176 | n/a | } |
---|
177 | n/a | |
---|
178 | n/a | if (getrlimit(resource, &rl) == -1) { |
---|
179 | n/a | PyErr_SetFromErrno(PyExc_OSError); |
---|
180 | n/a | return NULL; |
---|
181 | n/a | } |
---|
182 | n/a | return rlimit2py(rl); |
---|
183 | n/a | } |
---|
184 | n/a | |
---|
185 | n/a | static PyObject * |
---|
186 | n/a | resource_setrlimit(PyObject *self, PyObject *args) |
---|
187 | n/a | { |
---|
188 | n/a | struct rlimit rl; |
---|
189 | n/a | int resource; |
---|
190 | n/a | PyObject *limits; |
---|
191 | n/a | |
---|
192 | n/a | if (!PyArg_ParseTuple(args, "iO:setrlimit", &resource, &limits)) |
---|
193 | n/a | return NULL; |
---|
194 | n/a | |
---|
195 | n/a | if (resource < 0 || resource >= RLIM_NLIMITS) { |
---|
196 | n/a | PyErr_SetString(PyExc_ValueError, |
---|
197 | n/a | "invalid resource specified"); |
---|
198 | n/a | return NULL; |
---|
199 | n/a | } |
---|
200 | n/a | |
---|
201 | n/a | if (py2rlimit(limits, &rl) < 0) { |
---|
202 | n/a | return NULL; |
---|
203 | n/a | } |
---|
204 | n/a | |
---|
205 | n/a | if (setrlimit(resource, &rl) == -1) { |
---|
206 | n/a | if (errno == EINVAL) |
---|
207 | n/a | PyErr_SetString(PyExc_ValueError, |
---|
208 | n/a | "current limit exceeds maximum limit"); |
---|
209 | n/a | else if (errno == EPERM) |
---|
210 | n/a | PyErr_SetString(PyExc_ValueError, |
---|
211 | n/a | "not allowed to raise maximum limit"); |
---|
212 | n/a | else |
---|
213 | n/a | PyErr_SetFromErrno(PyExc_OSError); |
---|
214 | n/a | return NULL; |
---|
215 | n/a | } |
---|
216 | n/a | Py_RETURN_NONE; |
---|
217 | n/a | } |
---|
218 | n/a | |
---|
219 | n/a | #ifdef HAVE_PRLIMIT |
---|
220 | n/a | static PyObject * |
---|
221 | n/a | resource_prlimit(PyObject *self, PyObject *args) |
---|
222 | n/a | { |
---|
223 | n/a | struct rlimit old_limit, new_limit; |
---|
224 | n/a | int resource, retval; |
---|
225 | n/a | pid_t pid; |
---|
226 | n/a | PyObject *limits = NULL; |
---|
227 | n/a | |
---|
228 | n/a | if (!PyArg_ParseTuple(args, _Py_PARSE_PID "i|O:prlimit", |
---|
229 | n/a | &pid, &resource, &limits)) |
---|
230 | n/a | return NULL; |
---|
231 | n/a | |
---|
232 | n/a | if (resource < 0 || resource >= RLIM_NLIMITS) { |
---|
233 | n/a | PyErr_SetString(PyExc_ValueError, |
---|
234 | n/a | "invalid resource specified"); |
---|
235 | n/a | return NULL; |
---|
236 | n/a | } |
---|
237 | n/a | |
---|
238 | n/a | if (limits != NULL) { |
---|
239 | n/a | if (py2rlimit(limits, &new_limit) < 0) { |
---|
240 | n/a | return NULL; |
---|
241 | n/a | } |
---|
242 | n/a | retval = prlimit(pid, resource, &new_limit, &old_limit); |
---|
243 | n/a | } |
---|
244 | n/a | else { |
---|
245 | n/a | retval = prlimit(pid, resource, NULL, &old_limit); |
---|
246 | n/a | } |
---|
247 | n/a | |
---|
248 | n/a | if (retval == -1) { |
---|
249 | n/a | if (errno == EINVAL) { |
---|
250 | n/a | PyErr_SetString(PyExc_ValueError, |
---|
251 | n/a | "current limit exceeds maximum limit"); |
---|
252 | n/a | } else { |
---|
253 | n/a | PyErr_SetFromErrno(PyExc_OSError); |
---|
254 | n/a | } |
---|
255 | n/a | return NULL; |
---|
256 | n/a | } |
---|
257 | n/a | return rlimit2py(old_limit); |
---|
258 | n/a | } |
---|
259 | n/a | #endif /* HAVE_PRLIMIT */ |
---|
260 | n/a | |
---|
261 | n/a | static PyObject * |
---|
262 | n/a | resource_getpagesize(PyObject *self, PyObject *unused) |
---|
263 | n/a | { |
---|
264 | n/a | long pagesize = 0; |
---|
265 | n/a | #if defined(HAVE_GETPAGESIZE) |
---|
266 | n/a | pagesize = getpagesize(); |
---|
267 | n/a | #elif defined(HAVE_SYSCONF) |
---|
268 | n/a | #if defined(_SC_PAGE_SIZE) |
---|
269 | n/a | pagesize = sysconf(_SC_PAGE_SIZE); |
---|
270 | n/a | #else |
---|
271 | n/a | /* Irix 5.3 has _SC_PAGESIZE, but not _SC_PAGE_SIZE */ |
---|
272 | n/a | pagesize = sysconf(_SC_PAGESIZE); |
---|
273 | n/a | #endif |
---|
274 | n/a | #endif |
---|
275 | n/a | return Py_BuildValue("i", pagesize); |
---|
276 | n/a | |
---|
277 | n/a | } |
---|
278 | n/a | |
---|
279 | n/a | /* List of functions */ |
---|
280 | n/a | |
---|
281 | n/a | static struct PyMethodDef |
---|
282 | n/a | resource_methods[] = { |
---|
283 | n/a | {"getrusage", resource_getrusage, METH_VARARGS}, |
---|
284 | n/a | {"getrlimit", resource_getrlimit, METH_VARARGS}, |
---|
285 | n/a | #ifdef HAVE_PRLIMIT |
---|
286 | n/a | {"prlimit", resource_prlimit, METH_VARARGS}, |
---|
287 | n/a | #endif |
---|
288 | n/a | {"setrlimit", resource_setrlimit, METH_VARARGS}, |
---|
289 | n/a | {"getpagesize", resource_getpagesize, METH_NOARGS}, |
---|
290 | n/a | {NULL, NULL} /* sentinel */ |
---|
291 | n/a | }; |
---|
292 | n/a | |
---|
293 | n/a | |
---|
294 | n/a | /* Module initialization */ |
---|
295 | n/a | |
---|
296 | n/a | |
---|
297 | n/a | static struct PyModuleDef resourcemodule = { |
---|
298 | n/a | PyModuleDef_HEAD_INIT, |
---|
299 | n/a | "resource", |
---|
300 | n/a | NULL, |
---|
301 | n/a | -1, |
---|
302 | n/a | resource_methods, |
---|
303 | n/a | NULL, |
---|
304 | n/a | NULL, |
---|
305 | n/a | NULL, |
---|
306 | n/a | NULL |
---|
307 | n/a | }; |
---|
308 | n/a | |
---|
309 | n/a | PyMODINIT_FUNC |
---|
310 | n/a | PyInit_resource(void) |
---|
311 | n/a | { |
---|
312 | n/a | PyObject *m, *v; |
---|
313 | n/a | |
---|
314 | n/a | /* Create the module and add the functions */ |
---|
315 | n/a | m = PyModule_Create(&resourcemodule); |
---|
316 | n/a | if (m == NULL) |
---|
317 | n/a | return NULL; |
---|
318 | n/a | |
---|
319 | n/a | /* Add some symbolic constants to the module */ |
---|
320 | n/a | Py_INCREF(PyExc_OSError); |
---|
321 | n/a | PyModule_AddObject(m, "error", PyExc_OSError); |
---|
322 | n/a | if (!initialized) { |
---|
323 | n/a | if (PyStructSequence_InitType2(&StructRUsageType, |
---|
324 | n/a | &struct_rusage_desc) < 0) |
---|
325 | n/a | return NULL; |
---|
326 | n/a | } |
---|
327 | n/a | |
---|
328 | n/a | Py_INCREF(&StructRUsageType); |
---|
329 | n/a | PyModule_AddObject(m, "struct_rusage", |
---|
330 | n/a | (PyObject*) &StructRUsageType); |
---|
331 | n/a | |
---|
332 | n/a | /* insert constants */ |
---|
333 | n/a | #ifdef RLIMIT_CPU |
---|
334 | n/a | PyModule_AddIntMacro(m, RLIMIT_CPU); |
---|
335 | n/a | #endif |
---|
336 | n/a | |
---|
337 | n/a | #ifdef RLIMIT_FSIZE |
---|
338 | n/a | PyModule_AddIntMacro(m, RLIMIT_FSIZE); |
---|
339 | n/a | #endif |
---|
340 | n/a | |
---|
341 | n/a | #ifdef RLIMIT_DATA |
---|
342 | n/a | PyModule_AddIntMacro(m, RLIMIT_DATA); |
---|
343 | n/a | #endif |
---|
344 | n/a | |
---|
345 | n/a | #ifdef RLIMIT_STACK |
---|
346 | n/a | PyModule_AddIntMacro(m, RLIMIT_STACK); |
---|
347 | n/a | #endif |
---|
348 | n/a | |
---|
349 | n/a | #ifdef RLIMIT_CORE |
---|
350 | n/a | PyModule_AddIntMacro(m, RLIMIT_CORE); |
---|
351 | n/a | #endif |
---|
352 | n/a | |
---|
353 | n/a | #ifdef RLIMIT_NOFILE |
---|
354 | n/a | PyModule_AddIntMacro(m, RLIMIT_NOFILE); |
---|
355 | n/a | #endif |
---|
356 | n/a | |
---|
357 | n/a | #ifdef RLIMIT_OFILE |
---|
358 | n/a | PyModule_AddIntMacro(m, RLIMIT_OFILE); |
---|
359 | n/a | #endif |
---|
360 | n/a | |
---|
361 | n/a | #ifdef RLIMIT_VMEM |
---|
362 | n/a | PyModule_AddIntMacro(m, RLIMIT_VMEM); |
---|
363 | n/a | #endif |
---|
364 | n/a | |
---|
365 | n/a | #ifdef RLIMIT_AS |
---|
366 | n/a | PyModule_AddIntMacro(m, RLIMIT_AS); |
---|
367 | n/a | #endif |
---|
368 | n/a | |
---|
369 | n/a | #ifdef RLIMIT_RSS |
---|
370 | n/a | PyModule_AddIntMacro(m, RLIMIT_RSS); |
---|
371 | n/a | #endif |
---|
372 | n/a | |
---|
373 | n/a | #ifdef RLIMIT_NPROC |
---|
374 | n/a | PyModule_AddIntMacro(m, RLIMIT_NPROC); |
---|
375 | n/a | #endif |
---|
376 | n/a | |
---|
377 | n/a | #ifdef RLIMIT_MEMLOCK |
---|
378 | n/a | PyModule_AddIntMacro(m, RLIMIT_MEMLOCK); |
---|
379 | n/a | #endif |
---|
380 | n/a | |
---|
381 | n/a | #ifdef RLIMIT_SBSIZE |
---|
382 | n/a | PyModule_AddIntMacro(m, RLIMIT_SBSIZE); |
---|
383 | n/a | #endif |
---|
384 | n/a | |
---|
385 | n/a | /* Linux specific */ |
---|
386 | n/a | #ifdef RLIMIT_MSGQUEUE |
---|
387 | n/a | PyModule_AddIntMacro(m, RLIMIT_MSGQUEUE); |
---|
388 | n/a | #endif |
---|
389 | n/a | |
---|
390 | n/a | #ifdef RLIMIT_NICE |
---|
391 | n/a | PyModule_AddIntMacro(m, RLIMIT_NICE); |
---|
392 | n/a | #endif |
---|
393 | n/a | |
---|
394 | n/a | #ifdef RLIMIT_RTPRIO |
---|
395 | n/a | PyModule_AddIntMacro(m, RLIMIT_RTPRIO); |
---|
396 | n/a | #endif |
---|
397 | n/a | |
---|
398 | n/a | #ifdef RLIMIT_RTTIME |
---|
399 | n/a | PyModule_AddIntMacro(m, RLIMIT_RTTIME); |
---|
400 | n/a | #endif |
---|
401 | n/a | |
---|
402 | n/a | #ifdef RLIMIT_SIGPENDING |
---|
403 | n/a | PyModule_AddIntMacro(m, RLIMIT_SIGPENDING); |
---|
404 | n/a | #endif |
---|
405 | n/a | |
---|
406 | n/a | /* target */ |
---|
407 | n/a | #ifdef RUSAGE_SELF |
---|
408 | n/a | PyModule_AddIntMacro(m, RUSAGE_SELF); |
---|
409 | n/a | #endif |
---|
410 | n/a | |
---|
411 | n/a | #ifdef RUSAGE_CHILDREN |
---|
412 | n/a | PyModule_AddIntMacro(m, RUSAGE_CHILDREN); |
---|
413 | n/a | #endif |
---|
414 | n/a | |
---|
415 | n/a | #ifdef RUSAGE_BOTH |
---|
416 | n/a | PyModule_AddIntMacro(m, RUSAGE_BOTH); |
---|
417 | n/a | #endif |
---|
418 | n/a | |
---|
419 | n/a | #ifdef RUSAGE_THREAD |
---|
420 | n/a | PyModule_AddIntMacro(m, RUSAGE_THREAD); |
---|
421 | n/a | #endif |
---|
422 | n/a | |
---|
423 | n/a | /* FreeBSD specific */ |
---|
424 | n/a | |
---|
425 | n/a | #ifdef RLIMIT_SWAP |
---|
426 | n/a | PyModule_AddIntMacro(m, RLIMIT_SWAP); |
---|
427 | n/a | #endif |
---|
428 | n/a | |
---|
429 | n/a | #ifdef RLIMIT_SBSIZE |
---|
430 | n/a | PyModule_AddIntMacro(m, RLIMIT_SBSIZE); |
---|
431 | n/a | #endif |
---|
432 | n/a | |
---|
433 | n/a | #ifdef RLIMIT_NPTS |
---|
434 | n/a | PyModule_AddIntMacro(m, RLIMIT_NPTS); |
---|
435 | n/a | #endif |
---|
436 | n/a | |
---|
437 | n/a | if (sizeof(RLIM_INFINITY) > sizeof(long)) { |
---|
438 | n/a | v = PyLong_FromLongLong((long long) RLIM_INFINITY); |
---|
439 | n/a | } else |
---|
440 | n/a | { |
---|
441 | n/a | v = PyLong_FromLong((long) RLIM_INFINITY); |
---|
442 | n/a | } |
---|
443 | n/a | if (v) { |
---|
444 | n/a | PyModule_AddObject(m, "RLIM_INFINITY", v); |
---|
445 | n/a | } |
---|
446 | n/a | initialized = 1; |
---|
447 | n/a | return m; |
---|
448 | n/a | } |
---|