diff options
author | Giampaolo Rodola <g.rodola@gmail.com> | 2016-04-11 14:23:18 +0200 |
---|---|---|
committer | Giampaolo Rodola <g.rodola@gmail.com> | 2016-04-11 14:23:18 +0200 |
commit | c05812d9fa4e71aeec08de66b726027d2dcf4e9e (patch) | |
tree | d8f9d0537023dcb3f2ce1388f921db2a0a3af122 | |
parent | 2db4494e7795e2149209da3dbdbccb45672906b4 (diff) | |
download | psutil-c05812d9fa4e71aeec08de66b726027d2dcf4e9e.tar.gz |
service descr: handle unicode errors
-rw-r--r-- | psutil/_pswindows.py | 6 | ||||
-rw-r--r-- | psutil/arch/windows/services.c | 5 |
2 files changed, 8 insertions, 3 deletions
diff --git a/psutil/_pswindows.py b/psutil/_pswindows.py index a7ca5be1..3567e72d 100644 --- a/psutil/_pswindows.py +++ b/psutil/_pswindows.py @@ -348,13 +348,15 @@ class WindowsService(object): try: yield except WindowsError as err: + NO_SUCH_SERVICE_SET = (cext.ERROR_INVALID_NAME, + cext.ERROR_SERVICE_DOES_NOT_EXIST) if err.errno in ACCESS_DENIED_SET: raise AccessDenied( pid=None, name=self._name, msg="service %r is not querable (not enough privileges)" % self._name) - elif err.winerror in (cext.ERROR_INVALID_NAME, - cext.ERROR_SERVICE_DOES_NOT_EXIST): + elif err.winerror in NO_SUCH_SERVICE_SET or \ + err.errno in NO_SUCH_SERVICE_SET: raise NoSuchProcess( pid=None, name=self._name, msg="service %r does not exist)" % self._name) diff --git a/psutil/arch/windows/services.c b/psutil/arch/windows/services.c index 6162fd28..ddfe30ee 100644 --- a/psutil/arch/windows/services.c +++ b/psutil/arch/windows/services.c @@ -342,7 +342,10 @@ psutil_winservice_query_descr(PyObject *self, PyObject *args) { py_retstr = Py_BuildValue("s", ""); } else { - py_retstr = Py_BuildValue("s", scd->lpDescription); + // py_retstr = Py_BuildValue("s", scd->lpDescription); + py_retstr = PyUnicode_Decode( + scd->lpDescription, _tcslen(scd->lpDescription), + Py_FileSystemDefaultEncoding, "replace"); } if (!py_retstr) goto error; |