chiark / gitweb /
logind: Ensure the user, seat and session files are updated when the session is closing.
[elogind.git] / src / login / logind-session.c
index a43ecad2b1d46750213198e053cc955fc35e48cf..9740e23a1670f2556455ced06148dddc3de5e8fc 100644 (file)
@@ -25,6 +25,8 @@
 #include <sys/epoll.h>
 #include <fcntl.h>
 
+#include "systemd/sd-id128.h"
+#include "systemd/sd-messages.h"
 #include "strv.h"
 #include "util.h"
 #include "mkdir.h"
@@ -374,10 +376,8 @@ 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.");
-                return -ENOMEM;
-        }
+        if (!f)
+                return log_oom();
 
         c = stpcpy(f, "/tmp/.X11-unix/X");
         memcpy(c, s->display+1, k);
@@ -395,9 +395,8 @@ static int session_link_x11_socket(Session *s) {
 
         t = strappend(s->user->runtime_path, "/X11-display");
         if (!t) {
-                log_error("Out of memory.");
                 free(f);
-                return -ENOMEM;
+                return log_oom();
         }
 
         if (link(f, t) < 0) {
@@ -468,10 +467,8 @@ static int session_create_cgroup(Session *s) {
         assert(s->user->cgroup_path);
 
         if (!s->cgroup_path) {
-                if (asprintf(&p, "%s/%s", s->user->cgroup_path, s->id) < 0) {
-                        log_error("Out of memory.");
-                        return -ENOMEM;
-                }
+                if (asprintf(&p, "%s/%s", s->user->cgroup_path, s->id) < 0)
+                        return log_oom();
         } else
                 p = s->cgroup_path;
 
@@ -547,8 +544,13 @@ int session_start(Session *s) {
         if (r < 0)
                 return r;
 
-        log_full(s->type == SESSION_TTY || s->type == SESSION_X11 ? LOG_INFO : LOG_DEBUG,
-                 "New session %s of user %s.", s->id, s->user->name);
+        log_struct(s->type == SESSION_TTY || s->type == SESSION_X11 ? LOG_INFO : LOG_DEBUG,
+                   "MESSAGE_ID=" SD_ID128_FORMAT_STR, SD_ID128_FORMAT_VAL(SD_MESSAGE_SESSION_START),
+                   "SESSION_ID=%s", s->id,
+                   "USER_ID=%s", s->user->name,
+                   "LEADER=%lu", (unsigned long) s->leader,
+                   "MESSAGE=New session %s of user %s.", s->id, s->user->name,
+                   NULL);
 
         /* Create cgroup */
         r = session_create_cgroup(s);
@@ -669,10 +671,8 @@ static int session_unlink_x11_socket(Session *s) {
         s->user->display = NULL;
 
         t = strappend(s->user->runtime_path, "/X11-display");
-        if (!t) {
-                log_error("Out of memory.");
-                return -ENOMEM;
-        }
+        if (!t)
+                return log_oom();
 
         r = unlink(t);
         free(t);
@@ -686,8 +686,13 @@ int session_stop(Session *s) {
         assert(s);
 
         if (s->started)
-                log_full(s->type == SESSION_TTY || s->type == SESSION_X11 ? LOG_INFO : LOG_DEBUG,
-                         "Removed session %s.", s->id);
+                log_struct(s->type == SESSION_TTY || s->type == SESSION_X11 ? LOG_INFO : LOG_DEBUG,
+                           "MESSAGE_ID=" SD_ID128_FORMAT_STR, SD_ID128_FORMAT_VAL(SD_MESSAGE_SESSION_STOP),
+                           "SESSION_ID=%s", s->id,
+                           "USER_ID=%s", s->user->name,
+                           "LEADER=%lu", (unsigned long) s->leader,
+                           "MESSAGE=Removed session %s.", s->id,
+                           NULL);
 
         /* Kill cgroup */
         k = session_terminate_cgroup(s);
@@ -709,9 +714,11 @@ int session_stop(Session *s) {
                         seat_set_active(s->seat, NULL);
 
                 seat_send_changed(s->seat, "Sessions\0");
+                seat_save(s->seat);
         }
 
         user_send_changed(s->user, "Sessions\0");
+        user_save(s->user);
 
         s->started = false;
 
@@ -865,6 +872,9 @@ void session_remove_fifo(Session *s) {
                 assert_se(epoll_ctl(s->manager->epoll_fd, EPOLL_CTL_DEL, s->fifo_fd, NULL) == 0);
                 close_nointr_nofail(s->fifo_fd);
                 s->fifo_fd = -1;
+
+                session_save(s);
+                user_save(s->user);
         }
 
         if (s->fifo_path) {