chiark / gitweb /
Prep v220: Update src/login/org.freedesktop.login1.conf to the most recent version.
[elogind.git] / src / login / logind-seat.c
index 72bcfc4a52b89ac0c4a7ac4fad7a216d62b2968c..495ec50be06d21e1da86505f5c394b01c78b53af 100644 (file)
@@ -178,6 +178,34 @@ static int vt_allocate(unsigned int vtnr) {
         return 0;
 }
 
+int seat_preallocate_vts(Seat *s) {
+        int r = 0;
+        unsigned i;
+
+        assert(s);
+        assert(s->manager);
+
+        log_debug("Preallocating VTs...");
+
+        if (s->manager->n_autovts <= 0)
+                return 0;
+
+        if (!seat_has_vts(s))
+                return 0;
+
+        for (i = 1; i <= s->manager->n_autovts; i++) {
+                int q;
+
+                q = vt_allocate(i);
+                if (q < 0) {
+                        log_error_errno(q, "Failed to preallocate VT %u: %m", i);
+                        r = q;
+                }
+        }
+
+        return r;
+}
+
 int seat_apply_acls(Seat *s, Session *old_active) {
         int r;
 
@@ -328,6 +356,7 @@ int seat_active_vt_changed(Seat *s, unsigned int vtnr) {
         }
 
         r = seat_set_active(s, new_active);
+        manager_spawn_autovt(s->manager, vtnr);
 
         return r;
 }
@@ -385,6 +414,9 @@ int seat_start(Seat *s) {
                    LOG_MESSAGE("New seat %s.", s->id),
                    NULL);
 
+        /* Initialize VT magic stuff */
+        seat_preallocate_vts(s);
+
         /* Read current VT */
         seat_read_active_vt(s);
 
@@ -454,7 +486,7 @@ void seat_evict_position(Seat *s, Session *session) {
                  * position (eg., during gdm->session transition), so let's look
                  * for it and set it on the free slot. */
                 LIST_FOREACH(sessions_by_seat, iter, s->sessions) {
-                        if (iter->position == pos) {
+                        if (iter->position == pos && session_get_state(iter) != SESSION_CLOSING) {
                                 s->positions[pos] = iter;
                                 break;
                         }
@@ -473,7 +505,7 @@ void seat_claim_position(Seat *s, Session *session, unsigned int pos) {
         seat_evict_position(s, session);
 
         session->position = pos;
-        if (pos > 0 && !s->positions[pos])
+        if (pos > 0)
                 s->positions[pos] = session;
 }