summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGiampaolo Rodola <g.rodola@gmail.com>2020-01-24 19:43:25 +0000
committerGiampaolo Rodola <g.rodola@gmail.com>2020-01-24 19:43:25 +0000
commitf4f236a6f4bab5a55144c17ad727648ed5756f9c (patch)
tree41150f2dd055e343d79aa6d651ab06f622bc200c
parentf5f4dd4f5ea6c885b9592760c3141c8d5252ab2c (diff)
downloadpsutil-f4f236a6f4bab5a55144c17ad727648ed5756f9c.tar.gz
use PyLong_FromPid
-rw-r--r--psutil/_psutil_bsd.c19
1 files changed, 13 insertions, 6 deletions
diff --git a/psutil/_psutil_bsd.c b/psutil/_psutil_bsd.c
index b117fd50..183f4f43 100644
--- a/psutil/_psutil_bsd.c
+++ b/psutil/_psutil_bsd.c
@@ -794,6 +794,7 @@ psutil_users(PyObject *self, PyObject *args) {
PyObject *py_tty = NULL;
PyObject *py_hostname = NULL;
PyObject *py_tuple = NULL;
+ PyObject *py_pid = NULL;
if (py_retlist == NULL)
return NULL;
@@ -864,17 +865,21 @@ psutil_users(PyObject *self, PyObject *args) {
py_hostname = PyUnicode_DecodeFSDefault(utx->ut_host);
if (! py_hostname)
goto error;
+#ifdef PSUTIL_OPENBSD
+ py_pid = Py_BuildValue("i", -1); // set to None later
+#else
+ py_pid = PyLong_FromPid(utx->ut_pid);
+#endif
+ if (! py_pid)
+ goto error;
+
py_tuple = Py_BuildValue(
- "(OOOfi)",
+ "(OOOfO)",
py_username, // username
py_tty, // tty
py_hostname, // hostname
(float)utx->ut_tv.tv_sec, // start time
-#ifdef PSUTIL_OPENBSD
- -1 // process id (set to None later)
-#else
- utx->ut_pid // process id
-#endif
+ py_pid // process id
);
if (!py_tuple) {
@@ -889,6 +894,7 @@ psutil_users(PyObject *self, PyObject *args) {
Py_CLEAR(py_tty);
Py_CLEAR(py_hostname);
Py_CLEAR(py_tuple);
+ Py_CLEAR(py_pid);
}
endutxent();
@@ -900,6 +906,7 @@ error:
Py_XDECREF(py_tty);
Py_XDECREF(py_hostname);
Py_XDECREF(py_tuple);
+ Py_XDECREF(py_pid);
Py_DECREF(py_retlist);
return NULL;
}