chiark / gitweb /
login: track login class (i.e. one of "user", "greeter", "lock-screen") for each...
[elogind.git] / src / login / logind-session.c
index 63ee75808b546f9ef668b380ebde57907c89d797..af9c12dcd57d22c35eff72c5c500506115f4ed71 100644 (file)
@@ -145,6 +145,11 @@ int session_save(Session *s) {
                         "TYPE=%s\n",
                         session_type_to_string(s->type));
 
+        if (s->class >= 0)
+                fprintf(f,
+                        "CLASS=%s\n",
+                        session_class_to_string(s->class));
+
         if (s->cgroup_path)
                 fprintf(f,
                         "CGROUP=%s\n",
@@ -185,7 +190,7 @@ int session_save(Session *s) {
                         "SERVICE=%s\n",
                         s->service);
 
-        if (s->seat && seat_is_vtconsole(s->seat))
+        if (s->seat && seat_can_multi_session(s->seat))
                 fprintf(f,
                         "VTNR=%i\n",
                         s->vtnr);
@@ -225,7 +230,8 @@ int session_load(Session *s) {
                 *vtnr = NULL,
                 *leader = NULL,
                 *audit_id = NULL,
-                *type = NULL;
+                *type = NULL,
+                *class = NULL;
 
         int k, r;
 
@@ -245,6 +251,7 @@ int session_load(Session *s) {
                            "VTNR",           &vtnr,
                            "LEADER",         &leader,
                            "TYPE",           &type,
+                           "CLASS",          &class,
                            NULL);
 
         if (r < 0)
@@ -270,7 +277,7 @@ int session_load(Session *s) {
                         seat_attach_session(o, s);
         }
 
-        if (vtnr && s->seat && seat_is_vtconsole(s->seat)) {
+        if (vtnr && s->seat && seat_can_multi_session(s->seat)) {
                 int v;
 
                 k = safe_atoi(vtnr, &v);
@@ -297,6 +304,14 @@ int session_load(Session *s) {
                         s->type = t;
         }
 
+        if (class) {
+                SessionClass c;
+
+                c = session_class_from_string(class);
+                if (c >= 0)
+                        s->class = c;
+        }
+
         if (s->fifo_path) {
                 int fd;
 
@@ -324,7 +339,6 @@ finish:
 
 int session_activate(Session *s) {
         int r;
-        Session *old_active;
 
         assert(s);
 
@@ -343,10 +357,7 @@ int session_activate(Session *s) {
         if (r < 0)
                 return r;
 
-        old_active = s->seat->active;
-        s->seat->active = s;
-
-        return seat_apply_acls(s->seat, old_active);
+        return seat_set_active(s->seat, s);
 }
 
 static int session_link_x11_socket(Session *s) {
@@ -380,15 +391,13 @@ static int session_link_x11_socket(Session *s) {
                 return -ENOENT;
         }
 
-        t = strappend(s->user->runtime_path, "/X11/display");
+        t = strappend(s->user->runtime_path, "/X11-display");
         if (!t) {
                 log_error("Out of memory");
                 free(f);
                 return -ENOMEM;
         }
 
-        mkdir_parents(t, 0755);
-
         if (link(f, t) < 0) {
                 if (errno == EEXIST) {
                         unlink(t);
@@ -440,7 +449,7 @@ static int session_create_one_group(Session *s, const char *controller, const ch
         if (r < 0)
                 return r;
 
-        r = cg_set_task_access(controller, path, 0644, s->user->uid, s->user->gid);
+        r = cg_set_task_access(controller, path, 0644, s->user->uid, s->user->gid, -1);
         if (r >= 0)
                 r = cg_set_group_access(controller, path, 0755, s->user->uid, s->user->gid);
 
@@ -607,6 +616,23 @@ static int session_terminate_cgroup(Session *s) {
                         log_error("Failed to kill session cgroup: %s", strerror(-r));
 
         } else {
+                if (s->leader > 0) {
+                        Session *t;
+
+                        /* We still send a HUP to the leader process,
+                         * even if we are not supposed to kill the
+                         * whole cgroup. But let's first check the
+                         * leader still exists and belongs to our
+                         * session... */
+
+                        r = manager_get_session_by_pid(s->manager, s->leader, &t);
+                        if (r > 0 && t == s) {
+                                kill(s->leader, SIGTERM); /* for normal processes */
+                                kill(s->leader, SIGHUP);  /* for shells */
+                                kill(s->leader, SIGCONT); /* in case they are stopped */
+                        }
+                }
+
                 r = cg_is_empty_recursive(SYSTEMD_CGROUP_CONTROLLER, s->cgroup_path, true);
                 if (r < 0)
                         log_error("Failed to check session cgroup: %s", strerror(-r));
@@ -614,8 +640,7 @@ static int session_terminate_cgroup(Session *s) {
                         r = cg_delete(SYSTEMD_CGROUP_CONTROLLER, s->cgroup_path);
                         if (r < 0)
                                 log_error("Failed to delete session cgroup: %s", strerror(-r));
-                } else
-                        r = -EBUSY;
+                }
         }
 
         STRV_FOREACH(k, s->user->manager->controllers)
@@ -626,7 +651,7 @@ static int session_terminate_cgroup(Session *s) {
         free(s->cgroup_path);
         s->cgroup_path = NULL;
 
-        return r;
+        return 0;
 }
 
 static int session_unlink_x11_socket(Session *s) {
@@ -641,7 +666,7 @@ static int session_unlink_x11_socket(Session *s) {
 
         s->user->display = NULL;
 
-        t = strappend(s->user->runtime_path, "/X11/display");
+        t = strappend(s->user->runtime_path, "/X11-display");
         if (!t) {
                 log_error("Out of memory");
                 return -ENOMEM;
@@ -937,6 +962,14 @@ static const char* const session_type_table[_SESSION_TYPE_MAX] = {
 
 DEFINE_STRING_TABLE_LOOKUP(session_type, SessionType);
 
+static const char* const session_class_table[_SESSION_CLASS_MAX] = {
+        [SESSION_USER] = "user",
+        [SESSION_GREETER] = "greeter",
+        [SESSION_LOCK_SCREEN] = "lock-screen"
+};
+
+DEFINE_STRING_TABLE_LOOKUP(session_class, SessionClass);
+
 static const char* const kill_who_table[_KILL_WHO_MAX] = {
         [KILL_LEADER] = "leader",
         [KILL_ALL] = "all"