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 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82
|
/*
* Copyright (c) 2009, Giampaolo Rodola'. All rights reserved.
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*
* Linux-specific functions.
*/
#ifndef _GNU_SOURCE
#define _GNU_SOURCE 1
#endif
#include <Python.h>
#include <linux/ethtool.h> // DUPLEX_*
#include "arch/all/init.h"
// May happen on old RedHat versions, see:
// https://github.com/giampaolo/psutil/issues/607
#ifndef DUPLEX_UNKNOWN
#define DUPLEX_UNKNOWN 0xff
#endif
static PyMethodDef mod_methods[] = {
// --- per-process functions
#ifdef PSUTIL_HAS_IOPRIO
{"proc_ioprio_get", psutil_proc_ioprio_get, METH_VARARGS},
{"proc_ioprio_set", psutil_proc_ioprio_set, METH_VARARGS},
#endif
#ifdef PSUTIL_HAS_CPU_AFFINITY
{"proc_cpu_affinity_get", psutil_proc_cpu_affinity_get, METH_VARARGS},
{"proc_cpu_affinity_set", psutil_proc_cpu_affinity_set, METH_VARARGS},
#endif
// --- system related functions
{"disk_partitions", psutil_disk_partitions, METH_VARARGS},
{"net_if_duplex_speed", psutil_net_if_duplex_speed, METH_VARARGS},
// --- linux specific
{"linux_sysinfo", psutil_linux_sysinfo, METH_VARARGS},
// --- others
{"check_pid_range", psutil_check_pid_range, METH_VARARGS},
{"set_debug", psutil_set_debug, METH_VARARGS},
{NULL, NULL, 0, NULL}
};
static struct PyModuleDef moduledef = {
PyModuleDef_HEAD_INIT,
"_psutil_linux",
NULL,
-1,
mod_methods,
NULL,
NULL,
NULL,
NULL
};
PyObject *
PyInit__psutil_linux(void) {
PyObject *mod = PyModule_Create(&moduledef);
if (mod == NULL)
return NULL;
#ifdef Py_GIL_DISABLED
if (PyUnstable_Module_SetGIL(mod, Py_MOD_GIL_NOT_USED))
return NULL;
#endif
if (psutil_setup() != 0)
return NULL;
if (PyModule_AddIntConstant(mod, "version", PSUTIL_VERSION))
return NULL;
if (PyModule_AddIntConstant(mod, "DUPLEX_HALF", DUPLEX_HALF))
return NULL;
if (PyModule_AddIntConstant(mod, "DUPLEX_FULL", DUPLEX_FULL))
return NULL;
if (PyModule_AddIntConstant(mod, "DUPLEX_UNKNOWN", DUPLEX_UNKNOWN))
return NULL;
return mod;
}
|