- assert(s->user->cgroup_path);
-
- if (!s->cgroup_path) {
- if (asprintf(&p, "%s/%s", s->user->cgroup_path, s->id) < 0) {
- log_error("Out of memory");
- return -ENOMEM;
- }
- } else
- p = s->cgroup_path;
-
- r = session_create_one_group(s, SYSTEMD_CGROUP_CONTROLLER, p);
- if (r < 0) {
- log_error("Failed to create "SYSTEMD_CGROUP_CONTROLLER":%s: %s", p, strerror(-r));
- free(p);
- s->cgroup_path = NULL;
- return r;
- }
-
- s->cgroup_path = p;
-
- STRV_FOREACH(k, s->controllers) {
-
- if (strv_contains(s->reset_controllers, *k))
- continue;
-
- r = session_create_one_group(s, *k, p);
- if (r < 0)
- log_warning("Failed to create %s:%s: %s", *k, p, strerror(-r));
- }
-
- STRV_FOREACH(k, s->manager->controllers) {
-
- if (strv_contains(s->reset_controllers, *k) ||
- strv_contains(s->manager->reset_controllers, *k) ||
- strv_contains(s->controllers, *k))
- continue;
-
- r = session_create_one_group(s, *k, p);
- if (r < 0)
- log_warning("Failed to create %s:%s: %s", *k, p, strerror(-r));
- }
-
- if (s->leader > 0) {
-
- STRV_FOREACH(k, s->reset_controllers) {
- r = cg_attach(*k, "/", s->leader);
- if (r < 0)
- log_warning("Failed to reset controller %s: %s", *k, strerror(-r));
-
- }
-
- STRV_FOREACH(k, s->manager->reset_controllers) {
-
- if (strv_contains(s->reset_controllers, *k) ||
- strv_contains(s->controllers, *k))
- continue;
-
- r = cg_attach(*k, "/", s->leader);
- if (r < 0)
- log_warning("Failed to reset controller %s: %s", *k, strerror(-r));
+ assert(s->user->slice);
+
+ if (!s->scope) {
+ _cleanup_bus_error_free_ sd_bus_error error = SD_BUS_ERROR_NULL;
+ _cleanup_free_ char *description = NULL;
+ char *scope, *job = NULL;
+
+ description = strjoin("Session ", s->id, " of user ", s->user->name, NULL);
+ if (!description)
+ return log_oom();
+
+ scope = strjoin("session-", s->id, ".scope", NULL);
+ if (!scope)
+ return log_oom();
+
+ r = manager_start_scope(s->manager, scope, s->leader, s->user->slice, description, "systemd-logind.service", "systemd-user-session.service", &error, &job);
+ if (r < 0) {
+ log_error("Failed to start session scope %s: %s %s",
+ scope, bus_error_message(&error, r), error.name);
+ free(scope);
+ return r;
+ } else {
+ s->scope = scope;