summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGiampaolo Rodola <g.rodola@gmail.com>2020-12-14 14:40:33 +0100
committerGiampaolo Rodola <g.rodola@gmail.com>2020-12-14 14:40:33 +0100
commit88469734c1c5fa5a38a00ebc91367ac36bed40ed (patch)
tree5f48eae4f6c2cb51ef9fd806ffab4a9300334820
parent995ed7263a5a47f7e5a06fab137db91a8a388c88 (diff)
downloadpsutil-88469734c1c5fa5a38a00ebc91367ac36bed40ed.tar.gz
adjust exception msg and debug msg
Signed-off-by: Giampaolo Rodola <g.rodola@gmail.com>
-rw-r--r--psutil/_psutil_bsd.c6
-rw-r--r--psutil/_psutil_common.c6
-rw-r--r--psutil/_psutil_osx.c5
-rw-r--r--psutil/_psutil_windows.c22
-rw-r--r--psutil/arch/freebsd/specific.c2
-rw-r--r--psutil/arch/netbsd/specific.c6
-rw-r--r--psutil/arch/osx/process_info.c4
-rw-r--r--psutil/arch/windows/process_info.c8
8 files changed, 27 insertions, 32 deletions
diff --git a/psutil/_psutil_bsd.c b/psutil/_psutil_bsd.c
index c1b811c6..1956ff27 100644
--- a/psutil/_psutil_bsd.c
+++ b/psutil/_psutil_bsd.c
@@ -477,10 +477,10 @@ psutil_proc_environ(PyObject *self, PyObject *args) {
kvm_close(kd);
return py_retdict;
case EPERM:
- AccessDenied("kvm_getenvv");
+ AccessDenied("kvm_getenvv -> EPERM");
break;
case ESRCH:
- NoSuchProcess("kvm_getenvv");
+ NoSuchProcess("kvm_getenvv -> ESRCH");
break;
#if defined(PSUTIL_FREEBSD)
case ENOMEM:
@@ -489,7 +489,7 @@ psutil_proc_environ(PyObject *self, PyObject *args) {
// "sudo procstat -e <pid of your XOrg server>".)
// Map the error condition to 'AccessDenied'.
sprintf(errbuf,
- "kvm_getenvv(pid=%ld, ki_uid=%d): errno=ENOMEM",
+ "kvm_getenvv(pid=%ld, ki_uid=%d) -> ENOMEM",
pid, p->ki_uid);
AccessDenied(errbuf);
break;
diff --git a/psutil/_psutil_common.c b/psutil/_psutil_common.c
index e72904de..2bf4ad79 100644
--- a/psutil/_psutil_common.c
+++ b/psutil/_psutil_common.c
@@ -105,7 +105,8 @@ NoSuchProcess(const char *syscall) {
PyObject *exc;
char msg[1024];
- sprintf(msg, "No such process (originated from %s)", syscall);
+ sprintf(msg, "assume no such process (originated from %s)", syscall);
+ psutil_debug(msg);
exc = PyObject_CallFunction(PyExc_OSError, "(is)", ESRCH, msg);
PyErr_SetObject(PyExc_OSError, exc);
Py_XDECREF(exc);
@@ -122,7 +123,8 @@ AccessDenied(const char *syscall) {
PyObject *exc;
char msg[1024];
- sprintf(msg, "Access denied (originated from %s)", syscall);
+ sprintf(msg, "assume access denied (originated from %s)", syscall);
+ psutil_debug(msg);
exc = PyObject_CallFunction(PyExc_OSError, "(is)", EACCES, msg);
PyErr_SetObject(PyExc_OSError, exc);
Py_XDECREF(exc);
diff --git a/psutil/_psutil_osx.c b/psutil/_psutil_osx.c
index ee8d1c83..8df186cb 100644
--- a/psutil/_psutil_osx.c
+++ b/psutil/_psutil_osx.c
@@ -97,9 +97,10 @@ psutil_task_for_pid(pid_t pid, mach_port_t *task)
err = task_for_pid(mach_task_self(), pid, task);
if (err != KERN_SUCCESS) {
if (psutil_pid_exists(pid) == 0)
- NoSuchProcess("task_for_pid");
+ NoSuchProcess("task_for_pid -> psutil_pid_exists -> 0");
else if (psutil_is_zombie(pid) == 1)
- PyErr_SetString(ZombieProcessError, "task_for_pid() failed");
+ PyErr_SetString(ZombieProcessError,
+ "task_for_pid -> psutil_is_zombie -> 1");
else {
psutil_debug(
"task_for_pid() failed (pid=%ld, err=%i, errno=%i, msg='%s'); "
diff --git a/psutil/_psutil_windows.c b/psutil/_psutil_windows.c
index b836d708..66177985 100644
--- a/psutil/_psutil_windows.c
+++ b/psutil/_psutil_windows.c
@@ -162,9 +162,7 @@ psutil_proc_kill(PyObject *self, PyObject *args) {
if (hProcess == NULL) {
if (GetLastError() == ERROR_INVALID_PARAMETER) {
// see https://github.com/giampaolo/psutil/issues/24
- psutil_debug("OpenProcess -> ERROR_INVALID_PARAMETER turned "
- "into NoSuchProcess");
- NoSuchProcess("OpenProcess");
+ NoSuchProcess("OpenProcess -> ERROR_INVALID_PARAMETER");
}
else {
PyErr_SetFromWindowsErr(0);
@@ -280,7 +278,7 @@ psutil_proc_times(PyObject *self, PyObject *args) {
if (GetLastError() == ERROR_ACCESS_DENIED) {
// usually means the process has died so we throw a NoSuchProcess
// here
- NoSuchProcess("GetProcessTimes");
+ NoSuchProcess("GetProcessTimes -> ERROR_ACCESS_DENIED");
}
else {
PyErr_SetFromWindowsErr(0);
@@ -332,7 +330,7 @@ psutil_proc_cmdline(PyObject *self, PyObject *args, PyObject *kwdict) {
pid_return = psutil_pid_is_running(pid);
if (pid_return == 0)
- return NoSuchProcess("psutil_pid_is_running");
+ return NoSuchProcess("psutil_pid_is_running -> 0");
if (pid_return == -1)
return NULL;
@@ -356,7 +354,7 @@ psutil_proc_environ(PyObject *self, PyObject *args) {
pid_return = psutil_pid_is_running(pid);
if (pid_return == 0)
- return NoSuchProcess("psutil_pid_is_running");
+ return NoSuchProcess("psutil_pid_is_running -> 0");
if (pid_return == -1)
return NULL;
@@ -383,7 +381,7 @@ psutil_proc_exe(PyObject *self, PyObject *args) {
return NULL;
if (pid == 0)
- return AccessDenied("forced for PID 0");
+ return AccessDenied("automatically set for PID 0");
buffer = MALLOC_ZERO(bufferSize);
if (! buffer)
@@ -417,7 +415,7 @@ psutil_proc_exe(PyObject *self, PyObject *args) {
if (! NT_SUCCESS(status)) {
FREE(buffer);
if (psutil_pid_is_running(pid) == 0)
- NoSuchProcess("NtQuerySystemInformation");
+ NoSuchProcess("psutil_pid_is_running -> 0");
else
psutil_SetFromNTStatusErr(status, "NtQuerySystemInformation");
return NULL;
@@ -536,10 +534,10 @@ psutil_GetProcWsetInformation(
if (!NT_SUCCESS(status)) {
if (status == STATUS_ACCESS_DENIED) {
- AccessDenied("NtQueryVirtualMemory");
+ AccessDenied("NtQueryVirtualMemory -> STATUS_ACCESS_DENIED");
}
else if (psutil_pid_is_running(pid) == 0) {
- NoSuchProcess("psutil_pid_is_running");
+ NoSuchProcess("psutil_pid_is_running -> 0");
}
else {
PyErr_Clear();
@@ -644,7 +642,7 @@ psutil_proc_cwd(PyObject *self, PyObject *args) {
pid_return = psutil_pid_is_running(pid);
if (pid_return == 0)
- return NoSuchProcess("psutil_pid_is_running");
+ return NoSuchProcess("psutil_pid_is_running -> 0");
if (pid_return == -1)
return NULL;
@@ -709,7 +707,7 @@ psutil_proc_threads(PyObject *self, PyObject *args) {
pid_return = psutil_pid_is_running(pid);
if (pid_return == 0) {
- NoSuchProcess("psutil_pid_is_running");
+ NoSuchProcess("psutil_pid_is_running -> 0");
goto error;
}
if (pid_return == -1)
diff --git a/psutil/arch/freebsd/specific.c b/psutil/arch/freebsd/specific.c
index e7517a40..e498a7b3 100644
--- a/psutil/arch/freebsd/specific.c
+++ b/psutil/arch/freebsd/specific.c
@@ -262,7 +262,7 @@ psutil_proc_exe(PyObject *self, PyObject *args) {
if (ret == -1)
return NULL;
else if (ret == 0)
- return NoSuchProcess("psutil_pid_exists");
+ return NoSuchProcess("psutil_pid_exists -> 0");
else
strcpy(pathname, "");
}
diff --git a/psutil/arch/netbsd/specific.c b/psutil/arch/netbsd/specific.c
index 9dab3618..2fbc2418 100644
--- a/psutil/arch/netbsd/specific.c
+++ b/psutil/arch/netbsd/specific.c
@@ -126,7 +126,7 @@ psutil_proc_cwd(PyObject *self, PyObject *args) {
int name[] = { CTL_KERN, KERN_PROC_ARGS, pid, KERN_PROC_CWD};
if (sysctl(name, 4, path, &pathlen, NULL, 0) != 0) {
if (errno == ENOENT)
- NoSuchProcess("");
+ NoSuchProcess("sysctl -> ENOENT");
else
PyErr_SetFromErrno(PyExc_OSError);
return NULL;
@@ -142,7 +142,7 @@ psutil_proc_cwd(PyObject *self, PyObject *args) {
free(buf);
if (len == -1) {
if (errno == ENOENT)
- NoSuchProcess("readlink (ENOENT)");
+ NoSuchProcess("readlink -> ENOENT");
else
PyErr_SetFromErrno(PyExc_OSError);
return NULL;
@@ -198,7 +198,7 @@ psutil_proc_exe(PyObject *self, PyObject *args) {
if (ret == -1)
return NULL;
else if (ret == 0)
- return NoSuchProcess("psutil_pid_exists");
+ return NoSuchProcess("psutil_pid_exists -> 0");
else
strcpy(pathname, "");
}
diff --git a/psutil/arch/osx/process_info.c b/psutil/arch/osx/process_info.c
index 3732f91d..eda60c38 100644
--- a/psutil/arch/osx/process_info.c
+++ b/psutil/arch/osx/process_info.c
@@ -125,19 +125,17 @@ psutil_sysctl_procargs(pid_t pid, char *procargs, size_t argmax) {
if (sysctl(mib, 3, procargs, &argmax, NULL, 0) < 0) {
if (psutil_pid_exists(pid) == 0) {
- NoSuchProcess("");
+ NoSuchProcess("psutil_pid_exists -> 0");
return 1;
}
// In case of zombie process we'll get EINVAL. We translate it
// to NSP and _psosx.py will translate it to ZP.
if (errno == EINVAL) {
- psutil_debug("sysctl(KERN_PROCARGS2) -> EINVAL translated to NSP");
NoSuchProcess("sysctl(KERN_PROCARGS2) -> EINVAL");
return 1;
}
// There's nothing we can do other than raising AD.
if (errno == EIO) {
- psutil_debug("sysctl(KERN_PROCARGS2) -> EIO translated to AD");
AccessDenied("sysctl(KERN_PROCARGS2) -> EIO");
return 1;
}
diff --git a/psutil/arch/windows/process_info.c b/psutil/arch/windows/process_info.c
index 36283add..80b38d6d 100644
--- a/psutil/arch/windows/process_info.c
+++ b/psutil/arch/windows/process_info.c
@@ -55,11 +55,7 @@ psutil_convert_winerr(ULONG err, char* syscall) {
char fullmsg[8192];
if (err == ERROR_NOACCESS) {
- sprintf(
- fullmsg,
- "(originated from %s -> ERROR_NOACCESS; converted to AccessDenied)",
- syscall);
- psutil_debug(fullmsg);
+ sprintf(fullmsg, "%s -> ERROR_NOACCESS", syscall);
AccessDenied(fullmsg);
}
else {
@@ -434,7 +430,7 @@ psutil_cmdline_query_proc(DWORD pid, WCHAR **pdata, SIZE_T *psize) {
// https://github.com/giampaolo/psutil/issues/1501
if (status == STATUS_NOT_FOUND) {
AccessDenied("NtQueryInformationProcess(ProcessBasicInformation) -> "
- "STATUS_NOT_FOUND translated into PermissionError");
+ "STATUS_NOT_FOUND");
goto error;
}