mirror of
https://github.com/systemd/systemd.git
synced 2024-10-30 06:25:37 +03:00
Merge pull request #22498 from yuwata/cgroup-threaded-mode
cgroup: ignore error in attaching process when threaded mode is used
This commit is contained in:
commit
5d11af60ac
@ -1688,6 +1688,30 @@ int cg_slice_to_path(const char *unit, char **ret) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
int cg_is_threaded(const char *controller, const char *path) {
|
||||
_cleanup_free_ char *fs = NULL, *contents = NULL;
|
||||
_cleanup_strv_free_ char **v = NULL;
|
||||
int r;
|
||||
|
||||
r = cg_get_path(controller, path, "cgroup.type", &fs);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
r = read_full_virtual_file(fs, &contents, NULL);
|
||||
if (r == -ENOENT)
|
||||
return false; /* Assume no. */
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
v = strv_split(contents, NULL);
|
||||
if (!v)
|
||||
return -ENOMEM;
|
||||
|
||||
/* If the cgroup is in the threaded mode, it contains "threaded".
|
||||
* If one of the parents or siblings is in the threaded mode, it may contain "invalid". */
|
||||
return strv_contains(v, "threaded") || strv_contains(v, "invalid");
|
||||
}
|
||||
|
||||
int cg_set_attribute(const char *controller, const char *path, const char *attribute, const char *value) {
|
||||
_cleanup_free_ char *p = NULL;
|
||||
int r;
|
||||
|
@ -205,6 +205,8 @@ int cg_pid_get_path(const char *controller, pid_t pid, char **path);
|
||||
|
||||
int cg_rmdir(const char *controller, const char *path);
|
||||
|
||||
int cg_is_threaded(const char *controller, const char *path);
|
||||
|
||||
typedef enum {
|
||||
CG_KEY_MODE_GRACEFUL = 1 << 0,
|
||||
} CGroupKeyMode;
|
||||
|
@ -4250,6 +4250,12 @@ static int exec_child(
|
||||
}
|
||||
|
||||
r = cg_attach_everywhere(params->cgroup_supported, p, 0, NULL, NULL);
|
||||
if (r == -EUCLEAN) {
|
||||
*exit_status = EXIT_CGROUP;
|
||||
return log_unit_error_errno(unit, r, "Failed to attach process to cgroup %s "
|
||||
"because the cgroup or one of its parents or "
|
||||
"siblings is in the threaded mode: %m", p);
|
||||
}
|
||||
if (r < 0) {
|
||||
*exit_status = EXIT_CGROUP;
|
||||
return log_unit_error_errno(unit, r, "Failed to attach to cgroup %s: %m", p);
|
||||
|
@ -346,6 +346,9 @@ int cg_attach(const char *controller, const char *path, pid_t pid) {
|
||||
xsprintf(c, PID_FMT "\n", pid);
|
||||
|
||||
r = write_string_file(fs, c, WRITE_STRING_FILE_DISABLE_BUFFER);
|
||||
if (r == -EOPNOTSUPP && cg_is_threaded(controller, path) > 0)
|
||||
/* When the threaded mode is used, we cannot read/write the file. Let's return recognizable error. */
|
||||
return -EUCLEAN;
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user