X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=blobdiff_plain;f=src%2Flogin%2Flogind-seat.c;h=8d13a63688180d7b029cab930e272259a4e9e64d;hb=1b99ea27bc3ffa1fc6f7cfe89563d891a9aed4c5;hp=126c5b84cc5b4f4ade8dddfb53174c635ddb6754;hpb=be94d95499bf9c63fe9331e9b9ecc64f32fe9d79;p=elogind.git diff --git a/src/login/logind-seat.c b/src/login/logind-seat.c index 126c5b84c..8d13a6368 100644 --- a/src/login/logind-seat.c +++ b/src/login/logind-seat.c @@ -19,21 +19,18 @@ along with systemd; If not, see . ***/ -#include #include #include #include -#include -#include #include -#include "sd-id128.h" #include "sd-messages.h" #include "logind-seat.h" #include "logind-acl.h" #include "util.h" #include "mkdir.h" -#include "path-util.h" +#include "formats-util.h" +#include "terminal-util.h" Seat *seat_new(Manager *m, const char *id) { Seat *s; @@ -96,11 +93,11 @@ int seat_save(Seat *s) { r = mkdir_safe_label("/run/systemd/seats", 0755, 0, 0); if (r < 0) - goto finish; + goto fail; r = fopen_temporary(s->state_file, &f, &temp_path); if (r < 0) - goto finish; + goto fail; fchmod(fileno(f), 0644); @@ -144,19 +141,24 @@ int seat_save(Seat *s) { i->sessions_by_seat_next ? ' ' : '\n'); } - fflush(f); + r = fflush_and_check(f); + if (r < 0) + goto fail; - if (ferror(f) || rename(temp_path, s->state_file) < 0) { + if (rename(temp_path, s->state_file) < 0) { r = -errno; - unlink(s->state_file); - unlink(temp_path); + goto fail; } -finish: - if (r < 0) - log_error_errno(r, "Failed to save seat data %s: %m", s->state_file); + return 0; - return r; +fail: + (void) unlink(s->state_file); + + if (temp_path) + (void) unlink(temp_path); + + return log_error_errno(r, "Failed to save seat data %s: %m", s->state_file); } int seat_load(Seat *s) { @@ -272,7 +274,7 @@ int seat_set_active(Seat *s, Session *session) { int seat_switch_to(Seat *s, unsigned int num) { /* Public session positions skip 0 (there is only F1-F12). Maybe it * will get reassigned in the future, so return error for now. */ - if (!num) + if (num == 0) return -EINVAL; if (num >= s->position_count || !s->positions[num]) { @@ -289,12 +291,12 @@ int seat_switch_to(Seat *s, unsigned int num) { int seat_switch_to_next(Seat *s) { unsigned int start, i; - if (!s->position_count) + if (s->position_count == 0) return -EINVAL; start = 1; - if (s->active && s->active->pos > 0) - start = s->active->pos; + if (s->active && s->active->position > 0) + start = s->active->position; for (i = start + 1; i < s->position_count; ++i) if (s->positions[i]) @@ -310,12 +312,12 @@ int seat_switch_to_next(Seat *s) { int seat_switch_to_previous(Seat *s) { unsigned int start, i; - if (!s->position_count) + if (s->position_count == 0) return -EINVAL; start = 1; - if (s->active && s->active->pos > 0) - start = s->active->pos; + if (s->active && s->active->position > 0) + start = s->active->position; for (i = start - 1; i > 0; --i) if (s->positions[i]) @@ -475,21 +477,21 @@ int seat_stop_sessions(Seat *s, bool force) { void seat_evict_position(Seat *s, Session *session) { Session *iter; - unsigned int pos = session->pos; + unsigned int pos = session->position; - session->pos = 0; + session->position = 0; - if (!pos) + if (pos == 0) return; if (pos < s->position_count && s->positions[pos] == session) { s->positions[pos] = NULL; /* There might be another session claiming the same - * position (eg., during gdm->session transition), so lets look + * 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->pos == pos) { + if (iter->position == pos && session_get_state(iter) != SESSION_CLOSING) { s->positions[pos] = iter; break; } @@ -507,15 +509,15 @@ void seat_claim_position(Seat *s, Session *session, unsigned int pos) { seat_evict_position(s, session); - session->pos = pos; - if (pos > 0 && !s->positions[pos]) + session->position = pos; + if (pos > 0) s->positions[pos] = session; } static void seat_assign_position(Seat *s, Session *session) { unsigned int pos; - if (session->pos > 0) + if (session->position > 0) return; for (pos = 1; pos < s->position_count; ++pos) @@ -602,7 +604,7 @@ bool seat_can_graphical(Seat *s) { int seat_get_idle_hint(Seat *s, dual_timestamp *t) { Session *session; bool idle_hint = true; - dual_timestamp ts = { 0, 0 }; + dual_timestamp ts = DUAL_TIMESTAMP_NULL; assert(s);