summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYu Watanabe <watanabe.yu+github@gmail.com>2022-01-13 00:09:38 +0900
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2022-04-28 18:02:59 +0200
commit9029ab8ae01f315cc9ce795ad52e09013e10d893 (patch)
tree77cfd45ac2d2cb7f6f69a7770fa7cab067a0c1e4
parent0a54e62e46fa256c31e01cd5f191b1035a449f60 (diff)
downloadsystemd-9029ab8ae01f315cc9ce795ad52e09013e10d893.tar.gz
pid1,cgroup-show: ignore -EOPNOTSUPP in cg_read_pid()
The function is called in recursion, and cgroup.procs in some subcgroups may not be read. Fixes #22089. (cherry picked from commit 1fb50408ce23e67e0be94ead69c891d26b4823e2) (cherry picked from commit 1b003bbc806198dbdd57b405d968f30565495e70)
-rw-r--r--src/core/dbus-unit.c8
-rw-r--r--src/shared/cgroup-show.c17
2 files changed, 18 insertions, 7 deletions
diff --git a/src/core/dbus-unit.c b/src/core/dbus-unit.c
index fe320f1b05..0419f6205e 100644
--- a/src/core/dbus-unit.c
+++ b/src/core/dbus-unit.c
@@ -1295,11 +1295,15 @@ static int append_cgroup(sd_bus_message *reply, const char *p, Set *pids) {
for (;;) {
pid_t pid;
+ /* libvirt / qemu uses threaded mode and cgroup.procs cannot be read at the lower levels.
+ * From https://www.kernel.org/doc/html/latest/admin-guide/cgroup-v2.html#threads,
+ * “cgroup.procs” in a threaded domain cgroup contains the PIDs of all processes in
+ * the subtree and is not readable in the subtree proper. */
r = cg_read_pid(f, &pid);
+ if (IN_SET(r, 0, -EOPNOTSUPP))
+ break;
if (r < 0)
return r;
- if (r == 0)
- break;
if (is_kernel_thread(pid) > 0)
continue;
diff --git a/src/shared/cgroup-show.c b/src/shared/cgroup-show.c
index c7e63be508..c324652552 100644
--- a/src/shared/cgroup-show.c
+++ b/src/shared/cgroup-show.c
@@ -86,7 +86,6 @@ static int show_cgroup_one_by_path(
_cleanup_fclose_ FILE *f = NULL;
_cleanup_free_ char *p = NULL;
size_t n = 0;
- pid_t pid;
char *fn;
int r;
@@ -99,7 +98,18 @@ static int show_cgroup_one_by_path(
if (!f)
return -errno;
- while ((r = cg_read_pid(f, &pid)) > 0) {
+ for (;;) {
+ pid_t pid;
+
+ /* libvirt / qemu uses threaded mode and cgroup.procs cannot be read at the lower levels.
+ * From https://www.kernel.org/doc/html/latest/admin-guide/cgroup-v2.html#threads,
+ * “cgroup.procs” in a threaded domain cgroup contains the PIDs of all processes in
+ * the subtree and is not readable in the subtree proper. */
+ r = cg_read_pid(f, &pid);
+ if (IN_SET(r, 0, -EOPNOTSUPP))
+ break;
+ if (r < 0)
+ return r;
if (!(flags & OUTPUT_KERNEL_THREADS) && is_kernel_thread(pid) > 0)
continue;
@@ -110,9 +120,6 @@ static int show_cgroup_one_by_path(
pids[n++] = pid;
}
- if (r < 0)
- return r;
-
show_pid_array(pids, n, prefix, n_columns, false, more, flags);
return 0;