chiark / gitweb /
logind: If all user sessions are in closing state, set the overall status to closing.
[elogind.git] / src / login / logind-user.c
index 0a3f22ce9965d60fdb048683bcc11ce84fe28015..a33978c188cc33d3bfe4019fcb1542041355240f 100644 (file)
@@ -259,10 +259,8 @@ static int user_mkdir_runtime_path(User *u) {
         }
 
         if (!u->runtime_path) {
-                if (asprintf(&p, "/run/user/%lu", (unsigned long) u->uid) < 0) {
-                        log_error("Out of memory");
-                        return -ENOMEM;
-                }
+                if (asprintf(&p, "/run/user/%lu", (unsigned long) u->uid) < 0)
+                        return log_oom();
         } else
                 p = u->runtime_path;
 
@@ -286,10 +284,8 @@ static int user_create_cgroup(User *u) {
         assert(u);
 
         if (!u->cgroup_path) {
-                if (asprintf(&p, "%s/%s", u->manager->cgroup_path, u->name) < 0) {
-                        log_error("Out of memory");
-                        return -ENOMEM;
-                }
+                if (asprintf(&p, "%s/%s", u->manager->cgroup_path, u->name) < 0)
+                        return log_oom();
         } else
                 p = u->cgroup_path;
 
@@ -572,15 +568,20 @@ void user_add_to_gc_queue(User *u) {
 
 UserState user_get_state(User *u) {
         Session *i;
+        bool all_closing = true;
 
         assert(u);
 
-        LIST_FOREACH(sessions_by_user, i, u->sessions)
+
+        LIST_FOREACH(sessions_by_user, i, u->sessions) {
                 if (session_is_active(i))
                         return USER_ACTIVE;
+                if (session_get_state(i) != SESSION_CLOSING)
+                        all_closing = false;
+        }
 
         if (u->sessions)
-                return USER_ONLINE;
+                return all_closing ? USER_CLOSING : USER_ONLINE;
 
         if (user_check_linger_file(u) > 0)
                 return USER_LINGERING;