summaryrefslogtreecommitdiff
path: root/psutil/arch/windows/wmi.c
diff options
context:
space:
mode:
Diffstat (limited to 'psutil/arch/windows/wmi.c')
-rw-r--r--psutil/arch/windows/wmi.c26
1 files changed, 14 insertions, 12 deletions
diff --git a/psutil/arch/windows/wmi.c b/psutil/arch/windows/wmi.c
index f9a847d3..5fad4053 100644
--- a/psutil/arch/windows/wmi.c
+++ b/psutil/arch/windows/wmi.c
@@ -64,22 +64,28 @@ psutil_init_loadavg_counter(PyObject *self, PyObject *args) {
HANDLE event;
HANDLE waitHandle;
- if ((PdhOpenQueryW(NULL, 0, &hQuery)) != ERROR_SUCCESS)
- goto error;
+ if ((PdhOpenQueryW(NULL, 0, &hQuery)) != ERROR_SUCCESS) {
+ PyErr_Format(PyExc_RuntimeError, "PdhOpenQueryW failed");
+ return NULL;
+ }
s = PdhAddEnglishCounterW(hQuery, szCounterPath, 0, &hCounter);
- if (s != ERROR_SUCCESS)
- goto error;
+ if (s != ERROR_SUCCESS) {
+ PyErr_Format(PyExc_RuntimeError, "PdhAddEnglishCounterW failed");
+ return NULL;
+ }
event = CreateEventW(NULL, FALSE, FALSE, L"LoadUpdateEvent");
if (event == NULL) {
- PyErr_SetFromWindowsErr(0);
+ PyErr_SetFromOSErrnoWithSyscall("CreateEventW");
return NULL;
}
s = PdhCollectQueryDataEx(hQuery, SAMPLING_INTERVAL, event);
- if (s != ERROR_SUCCESS)
- goto error;
+ if (s != ERROR_SUCCESS) {
+ PyErr_Format(PyExc_RuntimeError, "PdhCollectQueryDataEx failed");
+ return NULL;
+ }
ret = RegisterWaitForSingleObject(
&waitHandle,
@@ -91,15 +97,11 @@ psutil_init_loadavg_counter(PyObject *self, PyObject *args) {
WT_EXECUTEDEFAULT);
if (ret == 0) {
- PyErr_SetFromWindowsErr(0);
+ PyErr_SetFromOSErrnoWithSyscall("RegisterWaitForSingleObject");
return NULL;
}
Py_RETURN_NONE;
-
-error:
- PyErr_SetFromWindowsErr(0);
- return NULL;
}