1
0
mirror of https://git.kernel.org/pub/scm/libs/libgpiod/libgpiod.git synced 2026-10-25 12:39:18 +03:00
Files
libgpiod/bindings/python/tests/procname/ext.c
Bartosz Golaszewski 72bce4cd96 bindings: python: tests: set the process name
When we run the test suite by calling the __main__ function of the module,
the name of the process as visible in the system becomes "python". Let's
set it to "python-gpiod" before running the tests. This way gpiosim will
name its configfs attributes appropriately.

Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
2022-12-09 10:06:53 +01:00

43 lines
817 B
C

// SPDX-License-Identifier: LGPL-2.1-or-later
// SPDX-FileCopyrightText: 2022 Bartosz Golaszewski <brgl@bgdev.pl>
#include <Python.h>
#include <sys/prctl.h>
static PyObject *
module_set_process_name(PyObject *Py_UNUSED(self), PyObject *args)
{
const char *name;
int ret;
ret = PyArg_ParseTuple(args, "s", &name);
if (!ret)
return NULL;
ret = prctl(PR_SET_NAME, name);
if (ret)
return PyErr_SetFromErrno(PyExc_OSError);
Py_RETURN_NONE;
}
static PyMethodDef module_methods[] = {
{
.ml_name = "set_process_name",
.ml_meth = (PyCFunction)module_set_process_name,
.ml_flags = METH_VARARGS,
},
{ }
};
static PyModuleDef module_def = {
PyModuleDef_HEAD_INIT,
.m_name = "procname._ext",
.m_methods = module_methods,
};
PyMODINIT_FUNC PyInit__ext(void)
{
return PyModule_Create(&module_def);
}