Skip to content

Commit a571717

Browse files
authored
#2708, macos / cmdline / environ; raise AD instead of OSError(0) (#2709)
The problem originates from sysctl(KERN_PROCARGS2) (macOS bug)
1 parent 8b98c3e commit a571717

5 files changed

Lines changed: 14 additions & 4 deletions

File tree

.dprint.jsonc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@
2424
".github/PULL_REQUEST_TEMPLATE.md",
2525
],
2626
"plugins": [
27-
"https://plugins.dprint.dev/markdown-0.19.0.wasm",
28-
"https://plugins.dprint.dev/json-0.20.0.wasm",
29-
"https://plugins.dprint.dev/g-plane/pretty_yaml-v0.5.1.wasm",
27+
"https://plugins.dprint.dev/markdown-0.20.0.wasm",
28+
"https://plugins.dprint.dev/json-0.21.1.wasm",
29+
"https://plugins.dprint.dev/g-plane/pretty_yaml-v0.6.0.wasm",
3030
],
3131
}

HISTORY.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@
2020
Fedorov)
2121
- 2707_, [macOS]: fix potential memory leaks in error paths of
2222
`Process.memory_full_info()` and `Process.threads()`.
23+
- 2708_, [macOS]: Process.cmdline()`_ and `Process.environ()`_ may fail with
24+
``OSError: [Errno 0] Undefined error`` (from ``sysctl(KERN_PROCARGS2)``).
25+
They now raise `AccessDenied`_ instead.
2326

2427
7.2.1
2528
=====

psutil/_psposix.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,7 @@ def can_use_pidfd():
259259

260260
@memoize
261261
def can_use_kqueue():
262+
# Availability: macOS, BSD
262263
names = (
263264
"kqueue",
264265
"KQ_EV_ADD",

psutil/arch/osx/proc_utils.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,12 @@ psutil_sysctl_procargs(pid_t pid, char *procargs, size_t *argmax) {
9797
psutil_oserror_ad("sysctl(KERN_PROCARGS2) -> EIO");
9898
return -1;
9999
}
100+
if (errno == 0) {
101+
// see: https://github.com/giampaolo/psutil/issues/2708
102+
psutil_debug("sysctl(KERN_PROCARGS2) -> errno 0");
103+
psutil_oserror_ad("sysctl(KERN_PROCARGS2) -> errno 0");
104+
return 0;
105+
}
100106
psutil_oserror_wsyscall("sysctl(KERN_PROCARGS2)");
101107
return -1;
102108
}

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ line-length = 79
44
skip-string-normalization = true
55
# https://black.readthedocs.io/en/stable/the_black_code_style/future_style.html
66
preview = true
7-
enable-unstable-feature = ["hug_parens_with_braces_and_square_brackets", "multiline_string_handling", "string_processing", "wrap_long_dict_values_in_parens"]
7+
enable-unstable-feature = ["hug_parens_with_braces_and_square_brackets", "string_processing", "wrap_long_dict_values_in_parens"]
88

99
[tool.ruff]
1010
# https://beta.ruff.rs/docs/settings/

0 commit comments

Comments
 (0)