X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=blobdiff_plain;f=src%2Flogin%2Flogind-session.c;h=10ea5265174dec96976d37a010c7dcea353fd0d7;hb=9e5548644f76e893c246d54ae613856b67b8dc1d;hp=c12683c60c1cd77e04413645f93234308c9ef3c0;hpb=90a18413f8be577a649900eca977e060273f2b5b;p=elogind.git diff --git a/src/login/logind-session.c b/src/login/logind-session.c index c12683c60..10ea52651 100644 --- a/src/login/logind-session.c +++ b/src/login/logind-session.c @@ -79,7 +79,7 @@ Session* session_new(Manager *m, const char *id) { return NULL; } - s->id = path_get_file_name(s->state_file); + s->id = basename(s->state_file); if (hashmap_put(m->sessions, s->id, s) < 0) { hashmap_free(s->devices); @@ -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); @@ -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)) { - int v; - - k = safe_atoi(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); @@ -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); @@ -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; @@ -981,13 +978,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 +1041,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); }