summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGiampaolo Rodola <g.rodola@gmail.com>2017-11-12 02:51:03 +0100
committerGiampaolo Rodola <g.rodola@gmail.com>2017-11-12 02:51:03 +0100
commit128f38dc84bc0fc2f2f50c255e8a431edf3930cc (patch)
treed36bf3f3a0d7a246bd64fedaaba2cb489065d822
parentca73eebc911ebfb3db0f1bcc9305d3270524519d (diff)
downloadpsutil-128f38dc84bc0fc2f2f50c255e8a431edf3930cc.tar.gz
define a setup() function which is called on import by all C modules
-rw-r--r--psutil/_psutil_aix.c2
-rw-r--r--psutil/_psutil_bsd.c2
-rw-r--r--psutil/_psutil_common.c18
-rw-r--r--psutil/_psutil_common.h11
-rw-r--r--psutil/_psutil_linux.c2
-rw-r--r--psutil/_psutil_osx.c2
-rw-r--r--psutil/_psutil_sunos.c2
-rw-r--r--psutil/_psutil_windows.c1
8 files changed, 29 insertions, 11 deletions
diff --git a/psutil/_psutil_aix.c b/psutil/_psutil_aix.c
index a4ea584e..4d522ba2 100644
--- a/psutil/_psutil_aix.c
+++ b/psutil/_psutil_aix.c
@@ -978,6 +978,8 @@ void init_psutil_aix(void)
PyModule_AddIntConstant(module, "TCPS_TIME_WAIT", TCPS_TIME_WAIT);
PyModule_AddIntConstant(module, "PSUTIL_CONN_NONE", PSUTIL_CONN_NONE);
+ psutil_setup();
+
if (module == NULL)
INITERROR;
#if PY_MAJOR_VERSION >= 3
diff --git a/psutil/_psutil_bsd.c b/psutil/_psutil_bsd.c
index edb790a9..f1adb1d3 100644
--- a/psutil/_psutil_bsd.c
+++ b/psutil/_psutil_bsd.c
@@ -1088,6 +1088,8 @@ void init_psutil_bsd(void)
// PSUTIL_CONN_NONE
PyModule_AddIntConstant(module, "PSUTIL_CONN_NONE", 128);
+ psutil_setup();
+
if (module == NULL)
INITERROR;
#if PY_MAJOR_VERSION >= 3
diff --git a/psutil/_psutil_common.c b/psutil/_psutil_common.c
index 7a2665d7..97b1494e 100644
--- a/psutil/_psutil_common.c
+++ b/psutil/_psutil_common.c
@@ -58,7 +58,7 @@ AccessDenied(void) {
}
-static int _psutil_testing = -1;
+static int _psutil_testing = 0;
/*
@@ -67,12 +67,6 @@ static int _psutil_testing = -1;
*/
int
psutil_is_testing(void) {
- if (_psutil_testing == -1) {
- if (getenv("PSUTIL_TESTING") != NULL)
- _psutil_testing = 1;
- else
- _psutil_testing = 0;
- }
return _psutil_testing;
}
@@ -88,3 +82,13 @@ psutil_set_testing(PyObject *self, PyObject *args) {
Py_INCREF(Py_None);
return Py_None;
}
+
+
+/*
+ * Called on module import on all platforms.
+ */
+void
+psutil_setup(void) {
+ if (getenv("PSUTIL_TESTING") != NULL)
+ _psutil_testing = 1;
+}
diff --git a/psutil/_psutil_common.h b/psutil/_psutil_common.h
index c76b1ecd..2b71caa4 100644
--- a/psutil/_psutil_common.h
+++ b/psutil/_psutil_common.h
@@ -9,11 +9,14 @@
// a signaler for connections without an actual status
static const int PSUTIL_CONN_NONE = 128;
-PyObject* AccessDenied(void);
-PyObject* NoSuchProcess(void);
-int psutil_is_testing(void);
-PyObject* psutil_set_testing(PyObject *self, PyObject *args);
#if PY_MAJOR_VERSION < 3
PyObject* PyUnicode_DecodeFSDefault(char *s);
PyObject* PyUnicode_DecodeFSDefaultAndSize(char *s, Py_ssize_t size);
#endif
+
+PyObject* AccessDenied(void);
+PyObject* NoSuchProcess(void);
+
+int psutil_is_testing(void);
+PyObject* psutil_set_testing(PyObject *self, PyObject *args);
+void psutil_setup(void);
diff --git a/psutil/_psutil_linux.c b/psutil/_psutil_linux.c
index 254208b4..d1f0d145 100644
--- a/psutil/_psutil_linux.c
+++ b/psutil/_psutil_linux.c
@@ -713,6 +713,8 @@ void init_psutil_linux(void)
PyModule_AddIntConstant(module, "DUPLEX_FULL", DUPLEX_FULL);
PyModule_AddIntConstant(module, "DUPLEX_UNKNOWN", DUPLEX_UNKNOWN);
+ psutil_setup();
+
if (module == NULL)
INITERROR;
#if PY_MAJOR_VERSION >= 3
diff --git a/psutil/_psutil_osx.c b/psutil/_psutil_osx.c
index 93ebd849..4ff301d4 100644
--- a/psutil/_psutil_osx.c
+++ b/psutil/_psutil_osx.c
@@ -1927,6 +1927,8 @@ init_psutil_osx(void)
PyModule_AddIntConstant(module, "TCPS_TIME_WAIT", TCPS_TIME_WAIT);
PyModule_AddIntConstant(module, "PSUTIL_CONN_NONE", PSUTIL_CONN_NONE);
+ psutil_setup();
+
if (module == NULL)
INITERROR;
#if PY_MAJOR_VERSION >= 3
diff --git a/psutil/_psutil_sunos.c b/psutil/_psutil_sunos.c
index 7b47ef1b..15508461 100644
--- a/psutil/_psutil_sunos.c
+++ b/psutil/_psutil_sunos.c
@@ -1679,6 +1679,8 @@ void init_psutil_sunos(void)
PyModule_AddIntConstant(module, "TCPS_BOUND", TCPS_BOUND);
PyModule_AddIntConstant(module, "PSUTIL_CONN_NONE", PSUTIL_CONN_NONE);
+ psutil_setup();
+
if (module == NULL)
INITERROR;
#if PY_MAJOR_VERSION >= 3
diff --git a/psutil/_psutil_windows.c b/psutil/_psutil_windows.c
index 1e7b3ad4..574885b6 100644
--- a/psutil/_psutil_windows.c
+++ b/psutil/_psutil_windows.c
@@ -3805,6 +3805,7 @@ void init_psutil_windows(void)
// set SeDebug for the current process
psutil_set_se_debug();
+ psutil_setup();
#if PY_MAJOR_VERSION >= 3
return module;