summaryrefslogtreecommitdiff
path: root/psutil/_psutil_sunos.c
diff options
context:
space:
mode:
authorGiampaolo Rodola <g.rodola@gmail.com>2017-05-02 05:38:03 +0200
committerGiampaolo Rodola <g.rodola@gmail.com>2017-05-02 05:38:03 +0200
commitd1ddeb5b4ec34afa86f168243e25699234ac22b4 (patch)
tree6c7e67683679cb38ecafbf01ebd7803a53c5c49d /psutil/_psutil_sunos.c
parent9c6e126e57ae87eddc43cfcb96e655e0b88f5308 (diff)
downloadpsutil-d1ddeb5b4ec34afa86f168243e25699234ac22b4.tar.gz
#1040 / users() / sunos: fix unicode
Diffstat (limited to 'psutil/_psutil_sunos.c')
-rw-r--r--psutil/_psutil_sunos.c24
1 files changed, 21 insertions, 3 deletions
diff --git a/psutil/_psutil_sunos.c b/psutil/_psutil_sunos.c
index 6a0471d8..ceb32cf5 100644
--- a/psutil/_psutil_sunos.c
+++ b/psutil/_psutil_sunos.c
@@ -454,6 +454,9 @@ psutil_users(PyObject *self, PyObject *args) {
struct utmpx *ut;
PyObject *py_retlist = PyList_New(0);
PyObject *py_tuple = NULL;
+ PyObject *py_username = NULL;
+ PyObject *py_tty = NULL;
+ PyObject *py_hostname = NULL;
PyObject *py_user_proc = NULL;
if (py_retlist == NULL)
@@ -464,11 +467,20 @@ psutil_users(PyObject *self, PyObject *args) {
py_user_proc = Py_True;
else
py_user_proc = Py_False;
+ py_username = PyUnicode_DecodeFSDefault(ut->ut_user);
+ if (! py_username)
+ goto error;
+ py_tty = PyUnicode_DecodeFSDefault(ut->ut_line);
+ if (! py_tty)
+ goto error;
+ py_hostname = PyUnicode_DecodeFSDefault(ut->ut_host);
+ if (! py_hostname)
+ goto error;
py_tuple = Py_BuildValue(
"(sssfOi)",
- ut->ut_user, // username
- ut->ut_line, // tty
- ut->ut_host, // hostname
+ py_username, // username
+ py_tty, // tty
+ py_hostname, // hostname
(float)ut->ut_tv.tv_sec, // tstamp
py_user_proc, // (bool) user process
ut->ut_pid // process id
@@ -477,6 +489,9 @@ psutil_users(PyObject *self, PyObject *args) {
goto error;
if (PyList_Append(py_retlist, py_tuple))
goto error;
+ Py_DECREF(py_username);
+ Py_DECREF(py_tty);
+ Py_DECREF(py_hostname);
Py_DECREF(py_tuple);
}
endutent();
@@ -484,6 +499,9 @@ psutil_users(PyObject *self, PyObject *args) {
return py_retlist;
error:
+ Py_XDECREF(py_username);
+ Py_XDECREF(py_tty);
+ Py_XDECREF(py_hostname);
Py_XDECREF(py_tuple);
Py_DECREF(py_retlist);
if (ut != NULL)