[systemd-commits] 3 commits - src/login

David Herrmann dvdhrm at kemper.freedesktop.org
Thu Nov 28 08:42:13 PST 2013


 src/login/loginctl.c       |    2 +-
 src/login/logind-core.c    |   12 ++++++------
 src/login/logind-dbus.c    |    5 ++---
 src/login/logind-seat.c    |   18 +++++++++++-------
 src/login/logind-seat.h    |    2 +-
 src/login/logind-session.c |   29 +++++++++++++----------------
 src/login/logind-session.h |    3 +--
 src/login/logind.h         |    2 +-
 src/login/pam-module.c     |    2 +-
 9 files changed, 37 insertions(+), 38 deletions(-)

New commits:
commit 486cd82c8f7642016895b72bcc09a1bfe885a783
Author: David Herrmann <dh.herrmann at gmail.com>
Date:   Thu Nov 28 17:29:01 2013 +0100

    logind: remove unused session->closing field
    
    This field is always false, drop it. If you want a reliable way to get
    session state, call session_get_state(). Testing for any flags directly
    doesn't work currently so don't pretend it would.

diff --git a/src/login/logind-dbus.c b/src/login/logind-dbus.c
index 9538150..a4bdf5f 100644
--- a/src/login/logind-dbus.c
+++ b/src/login/logind-dbus.c
@@ -1252,7 +1252,6 @@ static int have_multiple_sessions(
          * count, and non-login sessions do not count either. */
         HASHMAP_FOREACH(session, m->sessions, i)
                 if (session->class == SESSION_USER &&
-                    !session->closing &&
                     session->user->uid != uid)
                         return true;
 
diff --git a/src/login/logind-session.c b/src/login/logind-session.c
index a72b13e..beaa601 100644
--- a/src/login/logind-session.c
+++ b/src/login/logind-session.c
@@ -954,9 +954,6 @@ void session_add_to_gc_queue(Session *s) {
 SessionState session_get_state(Session *s) {
         assert(s);
 
-        if (s->closing)
-                return SESSION_CLOSING;
-
         if (s->scope_job)
                 return SESSION_OPENING;
 
diff --git a/src/login/logind-session.h b/src/login/logind-session.h
index 939476a..ee93101 100644
--- a/src/login/logind-session.h
+++ b/src/login/logind-session.h
@@ -107,7 +107,6 @@ struct Session {
 
         bool in_gc_queue:1;
         bool started:1;
-        bool closing:1;
 
         sd_bus_message *create_message;
 

commit c506027af881a9e4210845a7a8a6ec5910aa0f3b
Author: David Herrmann <dh.herrmann at gmail.com>
Date:   Thu Nov 28 17:25:25 2013 +0100

    logind: require VTs on seat0 and forbid elsewhere
    
    Sessions on seat0 must pass us a vtnr, otherwise, you shouldn't try
    attaching it to seat0. For seats without VTs, we do the exact opposite: we
    forbid VTs.
    
    There can be odd situations if the session-files contain invalid
    combinations. However, we try to keep sessions alive and restore state as
    good as possible.

diff --git a/src/login/logind-dbus.c b/src/login/logind-dbus.c
index 4239b37..9538150 100644
--- a/src/login/logind-dbus.c
+++ b/src/login/logind-dbus.c
@@ -514,7 +514,7 @@ static int method_create_session(sd_bus *bus, sd_bus_message *message, void *use
 
         if (seat) {
                 if (seat_has_vts(seat)) {
-                        if (vtnr > 63)
+                        if (!vtnr || vtnr > 63)
                                 return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "VT number out of range");
                 } else {
                         if (vtnr != 0)
diff --git a/src/login/logind-seat.c b/src/login/logind-seat.c
index eac5a5f..b1a5ec3 100644
--- a/src/login/logind-seat.c
+++ b/src/login/logind-seat.c
@@ -408,6 +408,9 @@ int seat_attach_session(Seat *s, Session *session) {
         assert(session);
         assert(!session->seat);
 
+        if (!seat_has_vts(s) != !session->vtnr)
+                return -EINVAL;
+
         session->seat = s;
         LIST_PREPEND(sessions_by_seat, s->sessions, session);
 
diff --git a/src/login/logind-session.c b/src/login/logind-session.c
index cd87088..a72b13e 100644
--- a/src/login/logind-session.c
+++ b/src/login/logind-session.c
@@ -334,21 +334,21 @@ int session_load(Session *s) {
                         s->remote = k;
         }
 
+        if (vtnr)
+                safe_atou(vtnr, &s->vtnr);
+
         if (seat && !s->seat) {
                 Seat *o;
 
                 o = hashmap_get(s->manager->seats, seat);
                 if (o)
-                        seat_attach_session(o, s);
+                        r = seat_attach_session(o, s);
+                if (!o || r < 0)
+                        log_error("Cannot attach session %s to seat %s", s->id, seat);
         }
 
-        if (vtnr && s->seat && seat_has_vts(s->seat)) {
-                unsigned int v;
-
-                k = safe_atou(vtnr, &v);
-                if (k >= 0 && v >= 1)
-                        s->vtnr = v;
-        }
+        if (!s->seat || !seat_has_vts(s->seat))
+                s->vtnr = 0;
 
         if (leader) {
                 k = parse_pid(leader, &s->leader);

commit 92bd5ff3a062c3f9475b9d9d39b9335bfeb7705e
Author: David Herrmann <dh.herrmann at gmail.com>
Date:   Thu Nov 28 17:05:34 2013 +0100

    logind: make VT numbers unsigned
    
    Fix the whole code to use "unsigned int" for vtnr. 0 is an invalid vtnr so
    we don't need negative numbers at all.
    
    Note that most code already assumes it's unsigned so in case there's a
    negative vtnr, our code may, under special circumstances, silently break.
    So this patch makes sure all sources of vtnrs verify the validity. Also
    note that the dbus api already uses unsigned ints.

diff --git a/src/login/loginctl.c b/src/login/loginctl.c
index 2aedbcf..5547cb2 100644
--- a/src/login/loginctl.c
+++ b/src/login/loginctl.c
@@ -251,7 +251,7 @@ typedef struct SessionStatusInfo {
         uid_t uid;
         const char *name;
         usec_t timestamp;
-        int vtnr;
+        unsigned int vtnr;
         const char *seat;
         const char *tty;
         const char *display;
diff --git a/src/login/logind-core.c b/src/login/logind-core.c
index 72ee9fe..3f8e813 100644
--- a/src/login/logind-core.c
+++ b/src/login/logind-core.c
@@ -436,7 +436,7 @@ bool manager_shall_kill(Manager *m, const char *user) {
         return strv_contains(m->kill_only_users, user);
 }
 
-static int vt_is_busy(int vtnr) {
+static int vt_is_busy(unsigned int vtnr) {
         struct vt_stat vt_stat;
         int r = 0, fd;
 
@@ -462,7 +462,7 @@ static int vt_is_busy(int vtnr) {
         return r;
 }
 
-int manager_spawn_autovt(Manager *m, int vtnr) {
+int manager_spawn_autovt(Manager *m, unsigned int vtnr) {
         _cleanup_bus_error_free_ sd_bus_error error = SD_BUS_ERROR_NULL;
         _cleanup_free_ char *name = NULL;
         int r;
@@ -470,11 +470,11 @@ int manager_spawn_autovt(Manager *m, int vtnr) {
         assert(m);
         assert(vtnr >= 1);
 
-        if ((unsigned) vtnr > m->n_autovts &&
-            (unsigned) vtnr != m->reserve_vt)
+        if (vtnr > m->n_autovts &&
+            vtnr != m->reserve_vt)
                 return 0;
 
-        if ((unsigned) vtnr != m->reserve_vt) {
+        if (vtnr != m->reserve_vt) {
                 /* If this is the reserved TTY, we'll start the getty
                  * on it in any case, but otherwise only if it is not
                  * busy. */
@@ -486,7 +486,7 @@ int manager_spawn_autovt(Manager *m, int vtnr) {
                         return -EBUSY;
         }
 
-        if (asprintf(&name, "autovt at tty%i.service", vtnr) < 0)
+        if (asprintf(&name, "autovt at tty%u.service", vtnr) < 0)
                 return log_oom();
 
         r = sd_bus_call_method(
diff --git a/src/login/logind-dbus.c b/src/login/logind-dbus.c
index e0333cd..4239b37 100644
--- a/src/login/logind-dbus.c
+++ b/src/login/logind-dbus.c
@@ -496,7 +496,7 @@ static int method_create_session(sd_bus *bus, sd_bus_message *message, void *use
                 if (v <= 0)
                         return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Cannot determine VT number from virtual console TTY %s", tty);
 
-                if (vtnr <= 0)
+                if (!vtnr)
                         vtnr = (uint32_t) v;
                 else if (vtnr != (uint32_t) v)
                         return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Specified TTY and VT number do not match");
diff --git a/src/login/logind-seat.c b/src/login/logind-seat.c
index ca0e8d7..eac5a5f 100644
--- a/src/login/logind-seat.c
+++ b/src/login/logind-seat.c
@@ -166,13 +166,13 @@ int seat_load(Seat *s) {
         return 0;
 }
 
-static int vt_allocate(int vtnr) {
+static int vt_allocate(unsigned int vtnr) {
         _cleanup_free_ char *p = NULL;
         _cleanup_close_ int fd = -1;
 
         assert(vtnr >= 1);
 
-        if (asprintf(&p, "/dev/tty%i", vtnr) < 0)
+        if (asprintf(&p, "/dev/tty%u", vtnr) < 0)
                 return -ENOMEM;
 
         fd = open_terminal(p, O_RDWR|O_NOCTTY|O_CLOEXEC);
@@ -270,7 +270,7 @@ int seat_set_active(Seat *s, Session *session) {
         return 0;
 }
 
-int seat_active_vt_changed(Seat *s, int vtnr) {
+int seat_active_vt_changed(Seat *s, unsigned int vtnr) {
         Session *i, *new_active = NULL;
         int r;
 
@@ -280,7 +280,7 @@ int seat_active_vt_changed(Seat *s, int vtnr) {
         if (!seat_has_vts(s))
                 return -EINVAL;
 
-        log_debug("VT changed to %i", vtnr);
+        log_debug("VT changed to %u", vtnr);
 
         LIST_FOREACH(sessions_by_seat, i, s->sessions)
                 if (i->vtnr == vtnr) {
@@ -297,7 +297,8 @@ int seat_active_vt_changed(Seat *s, int vtnr) {
 int seat_read_active_vt(Seat *s) {
         char t[64];
         ssize_t k;
-        int r, vtnr;
+        unsigned int vtnr;
+        int r;
 
         assert(s);
 
@@ -320,13 +321,13 @@ int seat_read_active_vt(Seat *s) {
                 return -EIO;
         }
 
-        r = safe_atoi(t+3, &vtnr);
+        r = safe_atou(t+3, &vtnr);
         if (r < 0) {
                 log_error("Failed to parse VT number %s", t+3);
                 return r;
         }
 
-        if (vtnr <= 0) {
+        if (!vtnr) {
                 log_error("VT number invalid: %s", t+3);
                 return -EIO;
         }
diff --git a/src/login/logind-seat.h b/src/login/logind-seat.h
index 80c6b8b..1254268 100644
--- a/src/login/logind-seat.h
+++ b/src/login/logind-seat.h
@@ -55,7 +55,7 @@ int seat_load(Seat *s);
 
 int seat_apply_acls(Seat *s, Session *old_active);
 int seat_set_active(Seat *s, Session *session);
-int seat_active_vt_changed(Seat *s, int vtnr);
+int seat_active_vt_changed(Seat *s, unsigned int vtnr);
 int seat_read_active_vt(Seat *s);
 int seat_preallocate_vts(Seat *s);
 
diff --git a/src/login/logind-session.c b/src/login/logind-session.c
index c12683c..cd87088 100644
--- a/src/login/logind-session.c
+++ b/src/login/logind-session.c
@@ -229,7 +229,7 @@ int session_save(Session *s) {
                 fprintf(f, "SERVICE=%s\n", s->service);
 
         if (s->seat && seat_has_vts(s->seat))
-                fprintf(f, "VTNR=%i\n", s->vtnr);
+                fprintf(f, "VTNR=%u\n", s->vtnr);
 
         if (s->leader > 0)
                 fprintf(f, "LEADER=%lu\n", (unsigned long) s->leader);
@@ -343,9 +343,9 @@ int session_load(Session *s) {
         }
 
         if (vtnr && s->seat && seat_has_vts(s->seat)) {
-                int v;
+                unsigned int v;
 
-                k = safe_atoi(vtnr, &v);
+                k = safe_atou(vtnr, &v);
                 if (k >= 0 && v >= 1)
                         s->vtnr = v;
         }
@@ -421,7 +421,7 @@ int session_activate(Session *s) {
 
         /* on seats with VTs, we let VTs manage session-switching */
         if (seat_has_vts(s->seat)) {
-                if (s->vtnr <= 0)
+                if (!s->vtnr)
                         return -ENOTSUP;
 
                 return chvt(s->vtnr);
@@ -981,13 +981,13 @@ int session_kill(Session *s, KillWho who, int signo) {
 static int session_open_vt(Session *s) {
         char path[128];
 
-        if (s->vtnr <= 0)
+        if (!s->vtnr)
                 return -1;
 
         if (s->vtfd >= 0)
                 return s->vtfd;
 
-        sprintf(path, "/dev/tty%d", s->vtnr);
+        sprintf(path, "/dev/tty%u", s->vtnr);
         s->vtfd = open(path, O_RDWR | O_CLOEXEC | O_NONBLOCK | O_NOCTTY);
         if (s->vtfd < 0) {
                 log_error("cannot open VT %s of session %s: %m", path, s->id);
@@ -1044,7 +1044,7 @@ void session_mute_vt(Session *s) {
         return;
 
 error:
-        log_error("cannot mute VT %d for session %s (%d/%d)", s->vtnr, s->id, r, errno);
+        log_error("cannot mute VT %u for session %s (%d/%d)", s->vtnr, s->id, r, errno);
         session_restore_vt(s);
 }
 
diff --git a/src/login/logind-session.h b/src/login/logind-session.h
index aab39b7..939476a 100644
--- a/src/login/logind-session.h
+++ b/src/login/logind-session.h
@@ -90,7 +90,7 @@ struct Session {
         char *scope_job;
 
         Seat *seat;
-        int vtnr;
+        unsigned int vtnr;
         int vtfd;
         sd_event_source *vt_source;
 
diff --git a/src/login/logind.h b/src/login/logind.h
index 814964f..b84137c 100644
--- a/src/login/logind.h
+++ b/src/login/logind.h
@@ -137,7 +137,7 @@ int manager_process_button_device(Manager *m, struct udev_device *d);
 
 int manager_startup(Manager *m);
 int manager_run(Manager *m);
-int manager_spawn_autovt(Manager *m, int vtnr);
+int manager_spawn_autovt(Manager *m, unsigned int vtnr);
 
 void manager_gc(Manager *m, bool drop_not_started);
 
diff --git a/src/login/pam-module.c b/src/login/pam-module.c
index be5901f..45428a0 100644
--- a/src/login/pam-module.c
+++ b/src/login/pam-module.c
@@ -284,7 +284,7 @@ _public_ PAM_EXTERN int pam_sm_open_session(
         if (!isempty(cvtnr))
                 safe_atou32(cvtnr, &vtnr);
 
-        if (!isempty(display) && vtnr <= 0) {
+        if (!isempty(display) && !vtnr) {
                 if (isempty(seat))
                         get_seat_from_display(display, &seat, &vtnr);
                 else if (streq(seat, "seat0"))



More information about the systemd-commits mailing list