diff options
author | Giampaolo Rodola <g.rodola@gmail.com> | 2017-05-03 00:52:48 +0200 |
---|---|---|
committer | Giampaolo Rodola <g.rodola@gmail.com> | 2017-05-03 00:52:48 +0200 |
commit | 4c07213c20840325eec14c24182d64b5abaae2d0 (patch) | |
tree | b1aa3e019d0bbb0b2f9792683c3289a1fb6b57cf | |
parent | 721dfe2598c8c4d0f2c5bbfdbe5d88d68d6fd0ec (diff) | |
download | psutil-4c07213c20840325eec14c24182d64b5abaae2d0.tar.gz |
#fix 1046: reset user SetErrorMode instead of resetting it to sysstem default
-rw-r--r-- | HISTORY.rst | 1 | ||||
-rw-r--r-- | psutil/_psutil_windows.c | 7 |
2 files changed, 5 insertions, 3 deletions
diff --git a/HISTORY.rst b/HISTORY.rst index 85092fa6..94126cd3 100644 --- a/HISTORY.rst +++ b/HISTORY.rst @@ -35,6 +35,7 @@ None - OpenBSD: connections('unix'): laddr and raddr are now set to "" instead of None +- 1046_: [Windows] disk_partitions() on Windows overrides user's SetErrorMode. *2017-04-10* diff --git a/psutil/_psutil_windows.c b/psutil/_psutil_windows.c index b1a62977..1c742afb 100644 --- a/psutil/_psutil_windows.c +++ b/psutil/_psutil_windows.c @@ -2447,6 +2447,7 @@ psutil_disk_partitions(PyObject *self, PyObject *args) { int all; int type; int ret; + unsigned int old_mode = 0; char opts[20]; LPTSTR fs_type[MAX_PATH + 1] = { 0 }; DWORD pflags = 0; @@ -2460,7 +2461,7 @@ psutil_disk_partitions(PyObject *self, PyObject *args) { // avoid to visualize a message box in case something goes wrong // see https://github.com/giampaolo/psutil/issues/264 - SetErrorMode(SEM_FAILCRITICALERRORS); + old_mode = SetErrorMode(SEM_FAILCRITICALERRORS); if (! PyArg_ParseTuple(args, "O", &py_all)) goto error; @@ -2541,11 +2542,11 @@ next: drive_letter = strchr(drive_letter, 0) + 1; } - SetErrorMode(0); + SetErrorMode(old_mode); return py_retlist; error: - SetErrorMode(0); + SetErrorMode(old_mode); Py_XDECREF(py_tuple); Py_DECREF(py_retlist); return NULL; |