2017-03-12 08:08:30 -03:00
|
|
|
/*[clinic input]
|
|
|
|
preserve
|
|
|
|
[clinic start generated code]*/
|
|
|
|
|
2022-02-05 15:52:01 -04:00
|
|
|
#if defined(HAVE_GETRUSAGE)
|
|
|
|
|
2017-03-12 08:08:30 -03:00
|
|
|
PyDoc_STRVAR(resource_getrusage__doc__,
|
|
|
|
"getrusage($module, who, /)\n"
|
|
|
|
"--\n"
|
|
|
|
"\n");
|
|
|
|
|
|
|
|
#define RESOURCE_GETRUSAGE_METHODDEF \
|
|
|
|
{"getrusage", (PyCFunction)resource_getrusage, METH_O, resource_getrusage__doc__},
|
|
|
|
|
|
|
|
static PyObject *
|
|
|
|
resource_getrusage_impl(PyObject *module, int who);
|
|
|
|
|
|
|
|
static PyObject *
|
|
|
|
resource_getrusage(PyObject *module, PyObject *arg)
|
|
|
|
{
|
|
|
|
PyObject *return_value = NULL;
|
|
|
|
int who;
|
|
|
|
|
2023-08-24 19:51:22 -03:00
|
|
|
who = PyLong_AsInt(arg);
|
2018-12-25 07:23:47 -04:00
|
|
|
if (who == -1 && PyErr_Occurred()) {
|
2017-03-12 08:08:30 -03:00
|
|
|
goto exit;
|
|
|
|
}
|
|
|
|
return_value = resource_getrusage_impl(module, who);
|
|
|
|
|
|
|
|
exit:
|
|
|
|
return return_value;
|
|
|
|
}
|
|
|
|
|
2022-02-05 15:52:01 -04:00
|
|
|
#endif /* defined(HAVE_GETRUSAGE) */
|
|
|
|
|
2017-03-12 08:08:30 -03:00
|
|
|
PyDoc_STRVAR(resource_getrlimit__doc__,
|
|
|
|
"getrlimit($module, resource, /)\n"
|
|
|
|
"--\n"
|
|
|
|
"\n");
|
|
|
|
|
|
|
|
#define RESOURCE_GETRLIMIT_METHODDEF \
|
|
|
|
{"getrlimit", (PyCFunction)resource_getrlimit, METH_O, resource_getrlimit__doc__},
|
|
|
|
|
|
|
|
static PyObject *
|
|
|
|
resource_getrlimit_impl(PyObject *module, int resource);
|
|
|
|
|
|
|
|
static PyObject *
|
|
|
|
resource_getrlimit(PyObject *module, PyObject *arg)
|
|
|
|
{
|
|
|
|
PyObject *return_value = NULL;
|
|
|
|
int resource;
|
|
|
|
|
2023-08-24 19:51:22 -03:00
|
|
|
resource = PyLong_AsInt(arg);
|
2018-12-25 07:23:47 -04:00
|
|
|
if (resource == -1 && PyErr_Occurred()) {
|
2017-03-12 08:08:30 -03:00
|
|
|
goto exit;
|
|
|
|
}
|
|
|
|
return_value = resource_getrlimit_impl(module, resource);
|
|
|
|
|
|
|
|
exit:
|
|
|
|
return return_value;
|
|
|
|
}
|
|
|
|
|
|
|
|
PyDoc_STRVAR(resource_setrlimit__doc__,
|
|
|
|
"setrlimit($module, resource, limits, /)\n"
|
|
|
|
"--\n"
|
|
|
|
"\n");
|
|
|
|
|
|
|
|
#define RESOURCE_SETRLIMIT_METHODDEF \
|
2023-10-17 18:52:58 -03:00
|
|
|
{"setrlimit", (PyCFunction)(void(*)(void))resource_setrlimit, METH_FASTCALL, resource_setrlimit__doc__},
|
2017-03-12 08:08:30 -03:00
|
|
|
|
|
|
|
static PyObject *
|
|
|
|
resource_setrlimit_impl(PyObject *module, int resource, PyObject *limits);
|
|
|
|
|
|
|
|
static PyObject *
|
2017-12-15 07:11:11 -04:00
|
|
|
resource_setrlimit(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
|
2017-03-12 08:08:30 -03:00
|
|
|
{
|
|
|
|
PyObject *return_value = NULL;
|
|
|
|
int resource;
|
|
|
|
PyObject *limits;
|
|
|
|
|
2023-10-17 18:52:58 -03:00
|
|
|
if (nargs != 2) {
|
|
|
|
PyErr_Format(PyExc_TypeError, "setrlimit expected 2 arguments, got %zd", nargs);
|
2017-03-12 08:08:30 -03:00
|
|
|
goto exit;
|
|
|
|
}
|
2023-08-24 19:51:22 -03:00
|
|
|
resource = PyLong_AsInt(args[0]);
|
2019-01-11 10:01:14 -04:00
|
|
|
if (resource == -1 && PyErr_Occurred()) {
|
|
|
|
goto exit;
|
|
|
|
}
|
|
|
|
limits = args[1];
|
2017-03-12 08:08:30 -03:00
|
|
|
return_value = resource_setrlimit_impl(module, resource, limits);
|
|
|
|
|
|
|
|
exit:
|
|
|
|
return return_value;
|
|
|
|
}
|
|
|
|
|
|
|
|
#if defined(HAVE_PRLIMIT)
|
|
|
|
|
|
|
|
PyDoc_STRVAR(resource_prlimit__doc__,
|
2022-07-29 08:48:11 -03:00
|
|
|
"prlimit($module, pid, resource, limits=None, /)\n"
|
|
|
|
"--\n"
|
|
|
|
"\n");
|
2017-03-12 08:08:30 -03:00
|
|
|
|
|
|
|
#define RESOURCE_PRLIMIT_METHODDEF \
|
2023-10-17 18:52:58 -03:00
|
|
|
{"prlimit", (PyCFunction)(void(*)(void))resource_prlimit, METH_FASTCALL, resource_prlimit__doc__},
|
2017-03-12 08:08:30 -03:00
|
|
|
|
|
|
|
static PyObject *
|
|
|
|
resource_prlimit_impl(PyObject *module, pid_t pid, int resource,
|
2022-07-29 08:48:11 -03:00
|
|
|
PyObject *limits);
|
2017-03-12 08:08:30 -03:00
|
|
|
|
|
|
|
static PyObject *
|
2022-07-29 08:48:11 -03:00
|
|
|
resource_prlimit(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
|
2017-03-12 08:08:30 -03:00
|
|
|
{
|
|
|
|
PyObject *return_value = NULL;
|
|
|
|
pid_t pid;
|
|
|
|
int resource;
|
2022-07-29 08:48:11 -03:00
|
|
|
PyObject *limits = Py_None;
|
|
|
|
|
2023-10-17 18:52:58 -03:00
|
|
|
if (nargs < 2) {
|
|
|
|
PyErr_Format(PyExc_TypeError, "prlimit expected at least 2 arguments, got %zd", nargs);
|
|
|
|
goto exit;
|
|
|
|
}
|
|
|
|
if (nargs > 3) {
|
|
|
|
PyErr_Format(PyExc_TypeError, "prlimit expected at most 3 arguments, got %zd", nargs);
|
2022-07-29 08:48:11 -03:00
|
|
|
goto exit;
|
|
|
|
}
|
|
|
|
pid = PyLong_AsPid(args[0]);
|
|
|
|
if (pid == -1 && PyErr_Occurred()) {
|
|
|
|
goto exit;
|
|
|
|
}
|
2023-08-24 19:51:22 -03:00
|
|
|
resource = PyLong_AsInt(args[1]);
|
2022-07-29 08:48:11 -03:00
|
|
|
if (resource == -1 && PyErr_Occurred()) {
|
|
|
|
goto exit;
|
|
|
|
}
|
|
|
|
if (nargs < 3) {
|
|
|
|
goto skip_optional;
|
2017-03-12 08:08:30 -03:00
|
|
|
}
|
2022-07-29 08:48:11 -03:00
|
|
|
limits = args[2];
|
|
|
|
skip_optional:
|
|
|
|
return_value = resource_prlimit_impl(module, pid, resource, limits);
|
2017-03-12 08:08:30 -03:00
|
|
|
|
|
|
|
exit:
|
|
|
|
return return_value;
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif /* defined(HAVE_PRLIMIT) */
|
|
|
|
|
|
|
|
PyDoc_STRVAR(resource_getpagesize__doc__,
|
|
|
|
"getpagesize($module, /)\n"
|
|
|
|
"--\n"
|
|
|
|
"\n");
|
|
|
|
|
|
|
|
#define RESOURCE_GETPAGESIZE_METHODDEF \
|
|
|
|
{"getpagesize", (PyCFunction)resource_getpagesize, METH_NOARGS, resource_getpagesize__doc__},
|
|
|
|
|
|
|
|
static int
|
|
|
|
resource_getpagesize_impl(PyObject *module);
|
|
|
|
|
|
|
|
static PyObject *
|
|
|
|
resource_getpagesize(PyObject *module, PyObject *Py_UNUSED(ignored))
|
|
|
|
{
|
|
|
|
PyObject *return_value = NULL;
|
|
|
|
int _return_value;
|
|
|
|
|
|
|
|
_return_value = resource_getpagesize_impl(module);
|
|
|
|
if ((_return_value == -1) && PyErr_Occurred()) {
|
|
|
|
goto exit;
|
|
|
|
}
|
|
|
|
return_value = PyLong_FromLong((long)_return_value);
|
|
|
|
|
|
|
|
exit:
|
|
|
|
return return_value;
|
|
|
|
}
|
|
|
|
|
2022-02-05 15:52:01 -04:00
|
|
|
#ifndef RESOURCE_GETRUSAGE_METHODDEF
|
|
|
|
#define RESOURCE_GETRUSAGE_METHODDEF
|
|
|
|
#endif /* !defined(RESOURCE_GETRUSAGE_METHODDEF) */
|
|
|
|
|
2017-03-12 08:08:30 -03:00
|
|
|
#ifndef RESOURCE_PRLIMIT_METHODDEF
|
|
|
|
#define RESOURCE_PRLIMIT_METHODDEF
|
|
|
|
#endif /* !defined(RESOURCE_PRLIMIT_METHODDEF) */
|
2023-10-17 18:52:58 -03:00
|
|
|
/*[clinic end generated code: output=e45883ace510414a input=a9049054013a1b77]*/
|