X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=blobdiff_plain;f=src%2Flogin%2Flogind-session.c;h=e438c66332c7443d1250fdf7b5cc5bb213955b81;hb=461b1822321d6be0d7fd8be29bf3b4993ebd1b85;hp=5c8d549316045eb15d5d8a92a299bf20f326ca51;hpb=d2e54fae5ca7a0f71b5ac8b356a589ff0a09ea0a;p=elogind.git diff --git a/src/login/logind-session.c b/src/login/logind-session.c index 5c8d54931..e438c6633 100644 --- a/src/login/logind-session.c +++ b/src/login/logind-session.c @@ -88,7 +88,7 @@ void session_free(Session *s) { } if (s->cgroup_path) - hashmap_remove(s->manager->cgroups, s->cgroup_path); + hashmap_remove(s->manager->session_cgroups, s->cgroup_path); free(s->cgroup_path); strv_free(s->controllers); @@ -133,11 +133,13 @@ int session_save(Session *s) { "UID=%lu\n" "USER=%s\n" "ACTIVE=%i\n" + "STATE=%s\n" "REMOTE=%i\n" "KILL_PROCESSES=%i\n", (unsigned long) s->user->uid, s->user->name, session_is_active(s), + session_state_to_string(session_get_state(s)), s->remote, s->kill_processes); @@ -527,7 +529,7 @@ static int session_create_cgroup(Session *s) { } } - hashmap_put(s->manager->cgroups, s->cgroup_path, s); + hashmap_put(s->manager->session_cgroups, s->cgroup_path, s); return 0; } @@ -646,7 +648,7 @@ static int session_terminate_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); + hashmap_remove(s->manager->session_cgroups, s->cgroup_path); free(s->cgroup_path); s->cgroup_path = NULL; @@ -913,6 +915,18 @@ void session_add_to_gc_queue(Session *s) { s->in_gc_queue = true; } +SessionState session_get_state(Session *s) { + assert(s); + + if (s->fifo_fd < 0) + return SESSION_CLOSING; + + if (session_is_active(s)) + return SESSION_ACTIVE; + + return SESSION_ONLINE; +} + int session_kill(Session *s, KillWho who, int signo) { int r = 0; Set *pid_set = NULL; @@ -954,6 +968,14 @@ int session_kill(Session *s, KillWho who, int signo) { return r; } +static const char* const session_state_table[_SESSION_TYPE_MAX] = { + [SESSION_ONLINE] = "online", + [SESSION_ACTIVE] = "active", + [SESSION_CLOSING] = "closing" +}; + +DEFINE_STRING_TABLE_LOOKUP(session_state, SessionState); + static const char* const session_type_table[_SESSION_TYPE_MAX] = { [SESSION_TTY] = "tty", [SESSION_X11] = "x11",