if (kill(pid, sig) < 0) {
if (ret >= 0 && errno != ESRCH)
ret = -errno;
- } else if (ret == 0) {
-
+ } else {
if (sigcont)
kill(pid, SIGCONT);
- ret = 1;
+ if (ret == 0)
+ ret = 1;
}
done = false;
} else
controller = SYSTEMD_CGROUP_CONTROLLER;
- if (pid == 0)
- fs = "/proc/self/cgroup";
- else
- fs = procfs_file_alloca(pid, "cgroup");
+ fs = procfs_file_alloca(pid, "cgroup");
f = fopen(fs, "re");
if (!f)
}
int cg_path_get_machine_name(const char *path, char **machine) {
- const char *e, *n, *x;
- char *s, *r;
- size_t l;
-
- assert(path);
- assert(machine);
-
- /* Skip slices, if there are any */
- e = skip_slices(path);
-
- n = strchrnul(e, '/');
- if (e == n)
- return -ENOENT;
-
- s = strndupa(e, n - e);
- s = cg_unescape(s);
-
- x = startswith(s, "machine-");
- if (!x)
- return -ENOENT;
- if (!endswith(x, ".scope"))
- return -ENOENT;
+ _cleanup_free_ char *u = NULL, *sl = NULL;
+ int r;
- l = strlen(x);
- if (l <= 6)
- return -ENOENT;
+ r = cg_path_get_unit(path, &u);
+ if (r < 0)
+ return r;
- r = strndup(x, l - 6);
- if (!r)
+ sl = strjoin("/run/systemd/machines/unit:", u, NULL);
+ if (!sl)
return -ENOMEM;
- *machine = r;
- return 0;
+ return readlink_malloc(sl, machine);
}
int cg_pid_get_machine_name(pid_t pid, char **machine) {
int cg_path_get_session(const char *path, char **session) {
const char *e, *n, *x;
- char *s, *r;
+ char *s;
size_t l;
assert(path);
- assert(session);
/* Skip slices, if there are any */
e = skip_slices(path);
if (l <= 6)
return -ENOENT;
- r = strndup(x, l - 6);
- if (!r)
- return -ENOMEM;
+ if (session) {
+ char *r;
+
+ r = strndup(x, l - 6);
+ if (!r)
+ return -ENOMEM;
+
+ *session = r;
+ }
- *session = r;
return 0;
}
_cleanup_free_ char *cgroup = NULL;
int r;
- assert(session);
-
r = cg_pid_get_path_shifted(pid, NULL, &cgroup);
if (r < 0)
return r;