File: ext.c

package info (click to toggle)
libgpiod 2.2.1-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 6,108 kB
  • sloc: ansic: 26,612; sh: 7,554; cpp: 4,944; python: 2,426; makefile: 811; xml: 49
file content (42 lines) | stat: -rw-r--r-- 817 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
// 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);
}