Skip to content

Commit

Permalink
give PROCESS_QUERY_LIMITED_INFO access for GetExitCodeProcess
Browse files Browse the repository at this point in the history
  • Loading branch information
giampaolo committed Oct 1, 2023
1 parent a6c6d5a commit e5d400f
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 21 deletions.
11 changes: 6 additions & 5 deletions psutil/arch/windows/proc.c
Original file line number Diff line number Diff line change
Expand Up @@ -99,14 +99,14 @@ PyObject *
psutil_proc_kill(PyObject *self, PyObject *args) {
HANDLE hProcess;
DWORD pid;
DWORD access = PROCESS_TERMINATE | PROCESS_QUERY_LIMITED_INFORMATION;

if (! PyArg_ParseTuple(args, _Py_PARSE_PID, &pid))
return NULL;
if (pid == 0)
return AccessDenied("automatically set for PID 0");

hProcess = OpenProcess(PROCESS_TERMINATE, FALSE, pid);
hProcess = psutil_check_phandle(hProcess, pid, 0);
hProcess = psutil_handle_from_pid(pid, access);
if (hProcess == NULL) {
return NULL;
}
Expand Down Expand Up @@ -540,12 +540,13 @@ psutil_proc_suspend_or_resume(PyObject *self, PyObject *args) {
DWORD pid;
NTSTATUS status;
HANDLE hProcess;
DWORD access = PROCESS_SUSPEND_RESUME | PROCESS_QUERY_LIMITED_INFORMATION;
PyObject* suspend;

if (! PyArg_ParseTuple(args, _Py_PARSE_PID "O", &pid, &suspend))
return NULL;
if (! PyArg_ParseTuple(args, _Py_PARSE_PID "O", &pid, &suspend))
return NULL;

hProcess = psutil_handle_from_pid(pid, PROCESS_SUSPEND_RESUME);
hProcess = psutil_handle_from_pid(pid, access);
if (hProcess == NULL)
return NULL;

Expand Down
30 changes: 14 additions & 16 deletions psutil/tests/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -971,22 +971,20 @@ def assertPidGone(self, pid):
self.assertNotIn(pid, [x.pid for x in psutil.process_iter()])

def assertProcessGone(self, proc):
with self.assertRaises(psutil.NoSuchProcess):
proc.kill()
# self.assertPidGone(proc.pid)
# ns = process_namespace(proc)
# for fun, name in ns.iter(ns.all, clear_cache=True):
# with self.subTest(proc=proc, name=name):
# try:
# ret = fun()
# except psutil.ZombieProcess:
# raise
# except psutil.NoSuchProcess as exc:
# self._check_proc_exc(proc, exc)
# else:
# msg = "Process.%s() didn't raise NSP and returned %r" % (
# name, ret)
# raise AssertionError(msg)
self.assertPidGone(proc.pid)
ns = process_namespace(proc)
for fun, name in ns.iter(ns.all, clear_cache=True):
with self.subTest(proc=proc, name=name):
try:
ret = fun()
except psutil.ZombieProcess:
raise
except psutil.NoSuchProcess as exc:
self._check_proc_exc(proc, exc)
else:
msg = "Process.%s() didn't raise NSP and returned %r" % (
name, ret)
raise AssertionError(msg)
proc.wait(timeout=0) # assert not raise TimeoutExpired

def assertProcessZombie(self, proc):
Expand Down

0 comments on commit e5d400f

Please sign in to comment.