From c506027af881a9e4210845a7a8a6ec5910aa0f3b Mon Sep 17 00:00:00 2001 From: David Herrmann Date: Thu, 28 Nov 2013 17:25:25 +0100 Subject: [PATCH] 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. --- src/login/logind-dbus.c | 2 +- src/login/logind-seat.c | 3 +++ src/login/logind-session.c | 16 ++++++++-------- 3 files changed, 12 insertions(+), 9 deletions(-) diff --git a/src/login/logind-dbus.c b/src/login/logind-dbus.c index 4239b3788..9538150e2 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 eac5a5f26..b1a5ec30e 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 cd8708845..a72b13ee0 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); -- 2.30.2