chiark / gitweb /
logind: properly handle if two session with identical loginuids are attempted to...
[elogind.git] / src / logind-session.c
index 42d28016da6e0207bf790dd7ed4647d4ad9fc06a..9278f30754be4f0fcfbf6e06d5128a28c948fcd4 100644 (file)
@@ -83,6 +83,9 @@ void session_free(Session *s) {
                 LIST_REMOVE(Session, sessions_by_seat, s->seat->sessions, s);
         }
 
+        if (s->cgroup_path)
+                hashmap_remove(s->manager->cgroups, s->cgroup_path);
+
         free(s->cgroup_path);
         strv_free(s->controllers);
 
@@ -468,6 +471,8 @@ static int session_create_cgroup(Session *s) {
                 }
         }
 
+        hashmap_put(s->manager->cgroups, s->cgroup_path, s);
+
         return 0;
 }
 
@@ -480,6 +485,10 @@ int session_start(Session *s) {
         if (s->started)
                 return 0;
 
+        r = user_start(s->user);
+        if (r < 0)
+                return r;
+
         log_info("New session %s of user %s.", s->id, s->user->name);
 
         /* Create cgroup */
@@ -514,7 +523,16 @@ int session_start(Session *s) {
 static bool session_shall_kill(Session *s) {
         assert(s);
 
-        return s->kill_processes;
+        if (!s->kill_processes)
+                return false;
+
+        if (strv_contains(s->manager->kill_exclude_users, s->user->name))
+                return false;
+
+        if (strv_isempty(s->manager->kill_only_users))
+                return true;
+
+        return strv_contains(s->manager->kill_only_users, s->user->name);
 }
 
 static int session_kill_cgroup(Session *s) {
@@ -549,6 +567,8 @@ static int session_kill_cgroup(Session *s) {
         STRV_FOREACH(k, s->user->manager->controllers)
                 cg_trim(*k, s->cgroup_path, true);
 
+        hashmap_remove(s->manager->cgroups, s->cgroup_path);
+
         free(s->cgroup_path);
         s->cgroup_path = NULL;
 
@@ -584,10 +604,8 @@ int session_stop(Session *s) {
 
         assert(s);
 
-        if (!s->started)
-                return 0;
-
-        log_info("Removed session %s.", s->id);
+        if (s->started)
+                log_info("Removed session %s.", s->id);
 
         /* Kill cgroup */
         k = session_kill_cgroup(s);
@@ -599,8 +617,10 @@ int session_stop(Session *s) {
 
         unlink(s->state_file);
         session_add_to_gc_queue(s);
+        user_add_to_gc_queue(s->user);
 
-        session_send_signal(s, false);
+        if (s->started)
+                session_send_signal(s, false);
 
         if (s->seat) {
                 if (s->seat->active == s)