From: Yu Watanabe Date: Wed, 12 Jan 2022 15:09:38 +0000 (+0900) Subject: pid1,cgroup-show: ignore -EOPNOTSUPP in cg_read_pid() X-Git-Tag: v251-rc1~511 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=1fb50408ce23e67e0be94ead69c891d26b4823e2;p=thirdparty%2Fsystemd.git 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. --- diff --git a/src/core/dbus-unit.c b/src/core/dbus-unit.c index eef491740cf..1128c42ad94 100644 --- a/src/core/dbus-unit.c +++ b/src/core/dbus-unit.c @@ -1314,11 +1314,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 40bc2bff051..48dd4d80013 100644 --- a/src/shared/cgroup-show.c +++ b/src/shared/cgroup-show.c @@ -89,7 +89,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; @@ -102,7 +101,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; @@ -113,9 +123,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;