X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=blobdiff_plain;f=src%2Flogin%2Flogind-session.c;h=a43ecad2b1d46750213198e053cc955fc35e48cf;hb=a7b9ecf9b20866a5dc09359b3c65a6e6f00490cf;hp=e297d3feeba689880c2b01e51ffd8c0e31df79b2;hpb=b80efeb9ae23b493d03501caa7e6334d1db65dd9;p=elogind.git diff --git a/src/login/logind-session.c b/src/login/logind-session.c index e297d3fee..a43ecad2b 100644 --- a/src/login/logind-session.c +++ b/src/login/logind-session.c @@ -28,6 +28,7 @@ #include "strv.h" #include "util.h" #include "mkdir.h" +#include "path-util.h" #include "cgroup-util.h" #include "logind-session.h" @@ -49,7 +50,7 @@ Session* session_new(Manager *m, User *u, const char *id) { return NULL; } - s->id = file_name_from_path(s->state_file); + s->id = path_get_file_name(s->state_file); if (hashmap_put(m->sessions, s->id, s) < 0) { free(s->state_file); @@ -87,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); @@ -115,7 +116,7 @@ int session_save(Session *s) { if (!s->started) return 0; - r = safe_mkdir("/run/systemd/sessions", 0755, 0, 0); + r = mkdir_safe_label("/run/systemd/sessions", 0755, 0, 0); if (r < 0) goto finish; @@ -132,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); @@ -372,7 +375,7 @@ static int session_link_x11_socket(Session *s) { k = strspn(s->display+1, "0123456789"); f = new(char, sizeof("/tmp/.X11-unix/X") + k); if (!f) { - log_error("Out of memory"); + log_error("Out of memory."); return -ENOMEM; } @@ -381,7 +384,7 @@ static int session_link_x11_socket(Session *s) { c[k] = 0; if (access(f, F_OK) < 0) { - log_warning("Session %s has display %s with nonexisting socket %s.", s->id, s->display, f); + log_warning("Session %s has display %s with non-existing socket %s.", s->id, s->display, f); free(f); return -ENOENT; } @@ -392,7 +395,7 @@ static int session_link_x11_socket(Session *s) { t = strappend(s->user->runtime_path, "/X11-display"); if (!t) { - log_error("Out of memory"); + log_error("Out of memory."); free(f); return -ENOMEM; } @@ -466,7 +469,7 @@ static int session_create_cgroup(Session *s) { if (!s->cgroup_path) { if (asprintf(&p, "%s/%s", s->user->cgroup_path, s->id) < 0) { - log_error("Out of memory"); + log_error("Out of memory."); return -ENOMEM; } } else @@ -526,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; } @@ -645,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; @@ -667,7 +670,7 @@ static int session_unlink_x11_socket(Session *s) { t = strappend(s->user->runtime_path, "/X11-display"); if (!t) { - log_error("Out of memory"); + log_error("Out of memory."); return -ENOMEM; } @@ -766,7 +769,7 @@ int session_get_idle_hint(Session *s, dual_timestamp *t) { b = u + IDLE_THRESHOLD_USEC < n; if (t) - dual_timestamp_from_realtime(t, u + b ? IDLE_THRESHOLD_USEC : 0); + dual_timestamp_from_realtime(t, u + b*IDLE_THRESHOLD_USEC); return b; @@ -815,7 +818,7 @@ int session_create_fifo(Session *s) { /* Create FIFO */ if (!s->fifo_path) { - r = safe_mkdir("/run/systemd/sessions", 0755, 0, 0); + r = mkdir_safe_label("/run/systemd/sessions", 0755, 0, 0); if (r < 0) return r; @@ -840,7 +843,7 @@ int session_create_fifo(Session *s) { zero(ev); ev.events = 0; - ev.data.u32 = FD_FIFO_BASE + s->fifo_fd; + ev.data.u32 = FD_OTHER_BASE + s->fifo_fd; if (epoll_ctl(s->manager->epoll_fd, EPOLL_CTL_ADD, s->fifo_fd, &ev) < 0) return -errno; @@ -912,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; @@ -953,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",