- if ((r = cg_set_task_access("name=systemd", group, 0755, pw->pw_uid, pw->pw_gid)) < 0 ||
- (r = cg_set_group_access("name=systemd", group, 0755, pw->pw_uid, pw->pw_gid)) < 0) {
+ if (r > 0 && remember) {
+ /* Remember that it was us who created this group, and
+ * that hence we need to remove it too. This is a
+ * protection against removing the cgroup when run
+ * recursively. */
+ if ((r = pam_set_data(handle, "systemd.created", INT_TO_PTR(1), NULL)) != PAM_SUCCESS) {
+ pam_syslog(handle, LOG_ERR, "Failed to install created variable.");
+ return r;
+ }
+ }
+
+ if ((r = cg_set_task_access(SYSTEMD_CGROUP_CONTROLLER, group, 0755, pw->pw_uid, pw->pw_gid)) < 0 ||
+ (r = cg_set_group_access(SYSTEMD_CGROUP_CONTROLLER, group, 0755, pw->pw_uid, pw->pw_gid)) < 0) {