diff options
author | Mark Hindley <mark@hindley.org.uk> | 2018-11-12 09:10:28 +0000 |
---|---|---|
committer | Mark Hindley <mark@hindley.org.uk> | 2018-11-12 09:21:21 +0000 |
commit | 2cc17d30309a1db16cccbf376a59ae40e47b6959 (patch) | |
tree | cd51ee95799631af348ebae8630a69219bee99cd /src/login/logind-seat.c | |
parent | ae65e91a5439f395e0da0cd8ffda95d6289849e1 (diff) | |
parent | d4a3f291e3955648ea1d29e674b0f8f9b1556257 (diff) |
Merge remote-tracking branch 'upstream/v239-stable' into merge_upstream.
Diffstat (limited to 'src/login/logind-seat.c')
-rw-r--r-- | src/login/logind-seat.c | 58 |
1 files changed, 33 insertions, 25 deletions
diff --git a/src/login/logind-seat.c b/src/login/logind-seat.c index 0ee5f70f5..c8fc4bb8e 100644 --- a/src/login/logind-seat.c +++ b/src/login/logind-seat.c @@ -21,33 +21,42 @@ #include "terminal-util.h" #include "util.h" -Seat *seat_new(Manager *m, const char *id) { - Seat *s; +int seat_new(Seat** ret, Manager *m, const char *id) { + _cleanup_(seat_freep) Seat *s = NULL; + int r; + assert(ret); assert(m); assert(id); - s = new0(Seat, 1); + if (!seat_name_is_valid(id)) + return -EINVAL; + + s = new(Seat, 1); if (!s) - return NULL; + return -ENOMEM; + + *s = (Seat) { + .manager = m, + }; s->state_file = strappend("/run/systemd/seats/", id); if (!s->state_file) - return mfree(s); + return -ENOMEM; s->id = basename(s->state_file); - s->manager = m; - if (hashmap_put(m->seats, s->id, s) < 0) { - free(s->state_file); - return mfree(s); - } + r = hashmap_put(m->seats, s->id, s); + if (r < 0) + return r; - return s; + *ret = TAKE_PTR(s); + return 0; } -void seat_free(Seat *s) { - assert(s); +Seat* seat_free(Seat *s) { + if (!s) + return NULL; if (s->in_gc_queue) LIST_REMOVE(gc_queue, s->manager->seat_gc_queue, s); @@ -64,7 +73,8 @@ void seat_free(Seat *s) { free(s->positions); free(s->state_file); - free(s); + + return mfree(s); } int seat_save(Seat *s) { @@ -166,7 +176,7 @@ static int vt_allocate(unsigned int vtnr) { xsprintf(p, "/dev/tty%u", vtnr); fd = open_terminal(p, O_RDWR|O_NOCTTY|O_CLOEXEC); if (fd < 0) - return -errno; + return fd; return 0; } @@ -190,10 +200,8 @@ int seat_preallocate_vts(Seat *s) { int q; q = vt_allocate(i); - if (q < 0) { - log_error_errno(q, "Failed to preallocate VT %u: %m", i); - r = q; - } + if (q < 0) + r = log_error_errno(q, "Failed to preallocate VT %u: %m", i); } return r; @@ -212,9 +220,9 @@ int seat_apply_acls(Seat *s, Session *old_active) { !!s->active, s->active ? s->active->user->uid : 0); if (r < 0) - log_error_errno(r, "Failed to apply ACLs: %m"); + return log_error_errno(r, "Failed to apply ACLs: %m"); - return r; + return 0; } int seat_set_active(Seat *s, Session *session) { @@ -234,7 +242,7 @@ int seat_set_active(Seat *s, Session *session) { session_send_changed(old_active, "Active", NULL); } - seat_apply_acls(s, old_active); + (void) seat_apply_acls(s, old_active); if (session && session->started) { session_send_changed(session, "Active", NULL); @@ -427,7 +435,7 @@ int seat_start(Seat *s) { } int seat_stop(Seat *s, bool force) { - int r = 0; + int r; assert(s); @@ -437,9 +445,9 @@ int seat_stop(Seat *s, bool force) { "SEAT_ID=%s", s->id, LOG_MESSAGE("Removed seat %s.", s->id)); - seat_stop_sessions(s, force); + r = seat_stop_sessions(s, force); - unlink(s->state_file); + (void) unlink(s->state_file); seat_add_to_gc_queue(s); if (s->started) |