X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=blobdiff_plain;f=src%2Flogin%2Flogind-session.c;h=8e6f95e6cd5f38f2469b8c0a3f7cab8eedb71b6c;hb=897e184c7d54156357fd204beafe06ab9bd0341a;hp=dc1d81c4be94271bc1451815709634fd87cb3628;hpb=39883f622f392d8579f4428fc5a789a102efbb10;p=elogind.git diff --git a/src/login/logind-session.c b/src/login/logind-session.c index dc1d81c4b..8e6f95e6c 100644 --- a/src/login/logind-session.c +++ b/src/login/logind-session.c @@ -407,8 +407,7 @@ int session_load(Session *s) { trigger the EOF. */ fd = session_create_fifo(s); - if (fd >= 0) - close_nointr_nofail(fd); + safe_close(fd); } if (realtime) { @@ -490,7 +489,7 @@ static int session_start_scope(Session *s) { if (!scope) return log_oom(); - r = manager_start_scope(s->manager, scope, s->leader, s->user->slice, description, "systemd-logind.service", "systemd-user-session.service", &error, &job); + r = manager_start_scope(s->manager, scope, s->leader, s->user->slice, description, "systemd-logind.service", "systemd-user-sessions.service", &error, &job); if (r < 0) { log_error("Failed to start session scope %s: %s %s", scope, bus_error_message(&error, r), error.name); @@ -683,7 +682,11 @@ void session_release(Session *s) { return; if (!s->timer_event_source) - sd_event_add_monotonic(s->manager->event, now(CLOCK_MONOTONIC) + RELEASE_USEC, 0, release_timeout_callback, s, &s->timer_event_source); + sd_event_add_time(s->manager->event, + &s->timer_event_source, + CLOCK_MONOTONIC, + now(CLOCK_MONOTONIC) + RELEASE_USEC, 0, + release_timeout_callback, s); } bool session_is_active(Session *s) { @@ -844,7 +847,7 @@ int session_create_fifo(Session *s) { } if (!s->fifo_event_source) { - r = sd_event_add_io(s->manager->event, s->fifo_fd, 0, session_dispatch_fifo, s, &s->fifo_event_source); + r = sd_event_add_io(s->manager->event, &s->fifo_event_source, s->fifo_fd, 0, session_dispatch_fifo, s); if (r < 0) return r; @@ -864,13 +867,8 @@ int session_create_fifo(Session *s) { static void session_remove_fifo(Session *s) { assert(s); - if (s->fifo_event_source) - s->fifo_event_source = sd_event_source_unref(s->fifo_event_source); - - if (s->fifo_fd >= 0) { - close_nointr_nofail(s->fifo_fd); - s->fifo_fd = -1; - } + s->fifo_event_source = sd_event_source_unref(s->fifo_event_source); + s->fifo_fd = safe_close(s->fifo_fd); if (s->fifo_path) { unlink(s->fifo_path); @@ -950,7 +948,7 @@ static int session_open_vt(Session *s) { 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); - return -1; + return -errno; } return s->vtfd; @@ -965,7 +963,7 @@ static int session_vt_fn(sd_event_source *source, const struct signalfd_siginfo return 0; } -void session_mute_vt(Session *s) { +void session_prepare_vt(Session *s) { int vt, r; struct vt_mode mode = { 0 }; sigset_t mask; @@ -974,6 +972,10 @@ void session_mute_vt(Session *s) { if (vt < 0) return; + r = fchown(vt, s->user->uid, -1); + if (r < 0) + goto error; + r = ioctl(vt, KDSKBMODE, K_OFF); if (r < 0) goto error; @@ -986,7 +988,7 @@ void session_mute_vt(Session *s) { sigaddset(&mask, SIGUSR1); sigprocmask(SIG_BLOCK, &mask, NULL); - r = sd_event_add_signal(s->manager->event, SIGUSR1, session_vt_fn, s, &s->vt_source); + r = sd_event_add_signal(s->manager->event, &s->vt_source, SIGUSR1, session_vt_fn, s); if (r < 0) goto error; @@ -1008,7 +1010,7 @@ error: } void session_restore_vt(Session *s) { - _cleanup_free_ char *utf8; + _cleanup_free_ char *utf8 = NULL; int vt, kb = K_XLATE; struct vt_mode mode = { 0 }; @@ -1022,13 +1024,15 @@ void session_restore_vt(Session *s) { if (read_one_line_file("/sys/module/vt/parameters/default_utf8", &utf8) >= 0 && *utf8 == '1') kb = K_UNICODE; + ioctl(vt, KDSKBMODE, kb); mode.mode = VT_AUTO; ioctl(vt, VT_SETMODE, &mode); - close_nointr_nofail(vt); - s->vtfd = -1; + fchown(vt, 0, -1); + + s->vtfd = safe_close(s->vtfd); } bool session_is_controller(Session *s, const char *sender) { @@ -1091,7 +1095,7 @@ int session_set_controller(Session *s, const char *sender, bool force) { * exits. * If logind crashes/restarts, we restore the controller during restart * or reset the VT in case it crashed/exited, too. */ - session_mute_vt(s); + session_prepare_vt(s); return 0; } @@ -1115,10 +1119,11 @@ static const char* const session_state_table[_SESSION_STATE_MAX] = { DEFINE_STRING_TABLE_LOOKUP(session_state, SessionState); static const char* const session_type_table[_SESSION_TYPE_MAX] = { + [SESSION_UNSPECIFIED] = "unspecified", [SESSION_TTY] = "tty", [SESSION_X11] = "x11", [SESSION_WAYLAND] = "wayland", - [SESSION_UNSPECIFIED] = "unspecified", + [SESSION_MIR] = "mir", }; DEFINE_STRING_TABLE_LOOKUP(session_type, SessionType);