|
45 | 45 | #include "psi-util.h" |
46 | 46 | #include "selinux-util.h" |
47 | 47 | #include "smack-util.h" |
| 48 | +#include "special.h" |
48 | 49 | #include "stat-util.h" |
49 | 50 | #include "string-table.h" |
50 | 51 | #include "string-util.h" |
@@ -992,14 +993,14 @@ static int condition_test_psi(Condition *c, char **env) { |
992 | 993 | if (r == 1) { |
993 | 994 | pressure_path = path_join("/proc/pressure", pressure_type); |
994 | 995 | if (!pressure_path) |
995 | | - return log_oom(); |
| 996 | + return log_oom_debug(); |
996 | 997 |
|
997 | 998 | value = first; |
998 | 999 | } else { |
999 | 1000 | const char *controller = strjoina(pressure_type, ".pressure"); |
1000 | | - _cleanup_free_ char *slice_path = NULL; |
| 1001 | + _cleanup_free_ char *slice_path = NULL, *root_scope = NULL; |
1001 | 1002 | CGroupMask mask, required_mask; |
1002 | | - char *slice; |
| 1003 | + char *slice, *e; |
1003 | 1004 |
|
1004 | 1005 | required_mask = c->type == CONDITION_MEMORY_PRESSURE ? CGROUP_MASK_MEMORY : |
1005 | 1006 | c->type == CONDITION_CPU_PRESSURE ? CGROUP_MASK_CPU : |
@@ -1030,6 +1031,26 @@ static int condition_test_psi(Condition *c, char **env) { |
1030 | 1031 | if (r < 0) |
1031 | 1032 | return log_debug_errno(r, "Cannot determine slice \"%s\" cgroup path: %m", slice); |
1032 | 1033 |
|
| 1034 | + /* We might be running under the user manager, so get the root path and prefix it accordingly. */ |
| 1035 | + r = cg_pid_get_path(SYSTEMD_CGROUP_CONTROLLER, getpid_cached(), &root_scope); |
| 1036 | + if (r < 0) |
| 1037 | + return log_debug_errno(r, "Failed to get root cgroup path: %m"); |
| 1038 | + |
| 1039 | + /* Drop init.scope, we want the parent. We could get an empty or / path, but that's fine, |
| 1040 | + * just skip it in that case. */ |
| 1041 | + e = endswith(root_scope, "/" SPECIAL_INIT_SCOPE); |
| 1042 | + if (e) |
| 1043 | + *e = 0; |
| 1044 | + if (!empty_or_root(root_scope)) { |
| 1045 | + _cleanup_free_ char *slice_joined = NULL; |
| 1046 | + |
| 1047 | + slice_joined = path_join(root_scope, slice_path); |
| 1048 | + if (!slice_joined) |
| 1049 | + return log_oom_debug(); |
| 1050 | + |
| 1051 | + free_and_replace(slice_path, slice_joined); |
| 1052 | + } |
| 1053 | + |
1033 | 1054 | r = cg_get_path(SYSTEMD_CGROUP_CONTROLLER, slice_path, controller, &pressure_path); |
1034 | 1055 | if (r < 0) |
1035 | 1056 | return log_debug_errno(r, "Error getting cgroup pressure path from %s: %m", slice_path); |
|
0 commit comments