summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2017-11-24 22:02:22 +0100
committerSven Eden <yamakuzure@gmx.net>2017-11-24 22:02:22 +0100
commita2b4834ce9095833079fcf9575a25bdb98d4e0be (patch)
tree60d668f204dfc3c7f3946bc5074e90acca8980d8 /src
parent3323d919b6e2f09e33f63fd44ead2c370be285c8 (diff)
core: warn about left-over processes in cgroup on unit start
Now that we don't kill control processes anymore, let's at least warn about any processes left-over in the unit cgroup at the moment of starting the unit.
Diffstat (limited to 'src')
-rw-r--r--src/core/cgroup.c42
-rw-r--r--src/core/cgroup.h1
2 files changed, 30 insertions, 13 deletions
diff --git a/src/core/cgroup.c b/src/core/cgroup.c
index a0371512d..dd63fda23 100644
--- a/src/core/cgroup.c
+++ b/src/core/cgroup.c
@@ -1395,6 +1395,31 @@ int unit_watch_cgroup(Unit *u) {
return 0;
}
+int unit_pick_cgroup_path(Unit *u) {
+ _cleanup_free_ char *path = NULL;
+ int r;
+
+ assert(u);
+
+ if (u->cgroup_path)
+ return 0;
+
+ if (!UNIT_HAS_CGROUP_CONTEXT(u))
+ return -EINVAL;
+
+ path = unit_default_cgroup_path(u);
+ if (!path)
+ return log_oom();
+
+ r = unit_set_cgroup_path(u, path);
+ if (r == -EEXIST)
+ return log_unit_error_errno(u, r, "Control group %s exists already.", path);
+ if (r < 0)
+ return log_unit_error_errno(u, r, "Failed to set unit's control group path to %s: %m", path);
+
+ return 0;
+}
+
static int unit_create_cgroup(
Unit *u,
CGroupMask target_mask,
@@ -1410,19 +1435,10 @@ static int unit_create_cgroup(
if (!c)
return 0;
- if (!u->cgroup_path) {
- _cleanup_free_ char *path = NULL;
-
- path = unit_default_cgroup_path(u);
- if (!path)
- return log_oom();
-
- r = unit_set_cgroup_path(u, path);
- if (r == -EEXIST)
- return log_unit_error_errno(u, r, "Control group %s exists already.", path);
- if (r < 0)
- return log_unit_error_errno(u, r, "Failed to set unit's control group path to %s: %m", path);
- }
+ /* Figure out our cgroup path */
+ r = unit_pick_cgroup_path(u);
+ if (r < 0)
+ return r;
/* First, create our own group */
r = cg_create_everywhere(u->manager->cgroup_supported, target_mask, u->cgroup_path);
diff --git a/src/core/cgroup.h b/src/core/cgroup.h
index 1f0fefe9d..ab32a4919 100644
--- a/src/core/cgroup.h
+++ b/src/core/cgroup.h
@@ -169,6 +169,7 @@ void unit_update_cgroup_members_masks(Unit *u);
char *unit_default_cgroup_path(Unit *u);
int unit_set_cgroup_path(Unit *u, const char *path);
+int unit_pick_cgroup_path(Unit *u);
int unit_realize_cgroup(Unit *u);
void unit_release_cgroup(Unit *u);