extra_compile_args=["-Wall", "-Wextra"],
)
+procname_ext = Extension(
+ "tests.procname._ext",
+ sources=["tests/procname/ext.c"],
+ define_macros=[("_GNU_SOURCE", "1")],
+ extra_compile_args=["-Wall", "-Wextra"],
+)
+
extensions = [gpiod_ext]
if "GPIOD_WITH_TESTS" in environ and environ["GPIOD_WITH_TESTS"] == "1":
extensions.append(gpiosim_ext)
+ extensions.append(procname_ext)
with open("gpiod/version.py", "r") as fd:
exec(fd.read())
# SPDX-License-Identifier: LGPL-2.1-or-later
# SPDX-FileCopyrightText: 2022 Bartosz Golaszewski <brgl@bgdev.pl>
-SUBDIRS = gpiosim
+SUBDIRS = gpiosim procname
EXTRA_DIST = \
helpers.py \
from .tests_module import *
from .tests_line_request import *
+from . import procname
+
+procname.set_process_name("python-gpiod")
+
unittest.main()
--- /dev/null
+# SPDX-License-Identifier: LGPL-2.1-or-later
+# SPDX-FileCopyrightText: 2022 Bartosz Golaszewski <brgl@bgdev.pl>
+
+EXTRA_DIST = \
+ ext.c \
+ __init__.py
--- /dev/null
+# SPDX-License-Identifier: GPL-2.0-or-later
+# SPDX-FileCopyrightText: 2022 Bartosz Golaszewski <brgl@bgdev.pl>
+
+from ._ext import set_process_name
--- /dev/null
+// 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);
+}
bindings/python/examples/Makefile
bindings/python/tests/Makefile
bindings/python/tests/gpiosim/Makefile
+ bindings/python/tests/procname/Makefile
bindings/rust/libgpiod-sys/src/Makefile
bindings/rust/libgpiod-sys/Makefile
bindings/rust/libgpiod/src/Makefile