Skip to content

Commit

Permalink
#1040 / users() / sunos: fix unicode
Browse files Browse the repository at this point in the history
  • Loading branch information
giampaolo committed May 2, 2017
1 parent 9c6e126 commit d1ddeb5
Showing 1 changed file with 21 additions and 3 deletions.
24 changes: 21 additions & 3 deletions psutil/_psutil_sunos.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
Expand All @@ -477,13 +489,19 @@ 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();

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)
Expand Down

0 comments on commit d1ddeb5

Please sign in to comment.