From 1b5e34fe96975d3b9a7811e986dfdbef50232217 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Tue, 23 Jul 2019 10:12:25 +0200 Subject: [PATCH 01/15] logind: add missing OOM check in client tool --- src/login/inhibit.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/login/inhibit.c b/src/login/inhibit.c index d96c8195a2..25ff4d0be6 100644 --- a/src/login/inhibit.c +++ b/src/login/inhibit.c @@ -284,7 +284,6 @@ static int run(int argc, char *argv[]) { if (arg_action == ACTION_LIST) return print_inhibitors(bus); - else { _cleanup_(sd_bus_error_free) sd_bus_error error = SD_BUS_ERROR_NULL; _cleanup_strv_free_ char **arguments = NULL; @@ -295,8 +294,13 @@ static int run(int argc, char *argv[]) { /* Ignore SIGINT and allow the forked process to receive it */ (void) ignore_signals(SIGINT, -1); - if (!arg_who) - arg_who = w = strv_join(argv + optind, " "); + if (!arg_who) { + w = strv_join(argv + optind, " "); + if (!w) + return log_oom(); + + arg_who = w; + } if (!arg_mode) arg_mode = "block"; From 2b695039bd1f52951ea28d444bba9fa1879c2795 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Tue, 23 Jul 2019 10:12:43 +0200 Subject: [PATCH 02/15] logind: check return value of inhibitor_start() --- src/login/logind-dbus.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/login/logind-dbus.c b/src/login/logind-dbus.c index b7c6e00e95..b36616e55a 100644 --- a/src/login/logind-dbus.c +++ b/src/login/logind-dbus.c @@ -3288,7 +3288,9 @@ static int method_inhibit(sd_bus_message *message, void *userdata, sd_bus_error goto fail; } - inhibitor_start(i); + r = inhibitor_start(i); + if (r < 0) + goto fail; return sd_bus_reply_method_return(message, "h", fifo_fd); From 9fb2c8b8c1d1b77718090d5cc908adab53ea734d Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Tue, 23 Jul 2019 10:13:28 +0200 Subject: [PATCH 03/15] logind: use gcc empty structure initialization --- src/login/logind-session.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/login/logind-session.c b/src/login/logind-session.c index f78453736d..5658ba7c68 100644 --- a/src/login/logind-session.c +++ b/src/login/logind-session.c @@ -1181,7 +1181,7 @@ static int session_open_vt(Session *s) { int session_prepare_vt(Session *s) { int vt, r; - struct vt_mode mode = { 0 }; + struct vt_mode mode = {}; if (s->vtnr < 1) return 0; From 61c6e8e49c0995d92e3ded73d01e725fd1b27501 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Tue, 23 Jul 2019 10:13:45 +0200 Subject: [PATCH 04/15] logind: don't claim we'd preallocate VTs when we shortcut it --- src/login/logind-seat.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/login/logind-seat.c b/src/login/logind-seat.c index 9577ff86f4..094fcd668d 100644 --- a/src/login/logind-seat.c +++ b/src/login/logind-seat.c @@ -191,14 +191,14 @@ int seat_preallocate_vts(Seat *s) { assert(s); assert(s->manager); - log_debug("Preallocating VTs..."); - if (s->manager->n_autovts <= 0) return 0; if (!seat_has_vts(s)) return 0; + log_debug("Preallocating VTs..."); + for (i = 1; i <= s->manager->n_autovts; i++) { int q; From 20fff3de756e176c54a310a24061b87b73115d8e Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Tue, 23 Jul 2019 10:17:46 +0200 Subject: [PATCH 05/15] logind: use log_warning_errno() return value where we can Also, change a couple of log error levels to LOG_WARNING, where we encounter an error but then end up ignoring it. --- src/login/logind.c | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) diff --git a/src/login/logind.c b/src/login/logind.c index f4bc1d2eb7..ebdc0965c1 100644 --- a/src/login/logind.c +++ b/src/login/logind.c @@ -295,10 +295,8 @@ static int manager_enumerate_linger_users(Manager *m) { continue; k = manager_add_user_by_name(m, de->d_name, NULL); - if (k < 0) { - log_notice_errno(k, "Couldn't add lingering user %s: %m", de->d_name); - r = k; - } + if (k < 0) + r = log_warning_errno(k, "Couldn't add lingering user %s, ignoring: %m", de->d_name); } return r; @@ -331,9 +329,7 @@ static int manager_enumerate_users(Manager *m) { k = manager_add_user_by_name(m, de->d_name, &u); if (k < 0) { - log_error_errno(k, "Failed to add user by file name %s: %m", de->d_name); - - r = k; + r = log_warning_errno(k, "Failed to add user by file name %s, ignoring: %m", de->d_name); continue; } @@ -486,8 +482,7 @@ static int manager_enumerate_sessions(Manager *m) { k = manager_add_session(m, de->d_name, &s); if (k < 0) { - log_error_errno(k, "Failed to add session by file name %s: %m", de->d_name); - r = k; + r = log_warning_errno(k, "Failed to add session by file name %s, ignoring: %m", de->d_name); continue; } @@ -529,8 +524,7 @@ static int manager_enumerate_inhibitors(Manager *m) { k = manager_add_inhibitor(m, de->d_name, &i); if (k < 0) { - log_notice_errno(k, "Couldn't add inhibitor %s: %m", de->d_name); - r = k; + r = log_warning_errno(k, "Couldn't add inhibitor %s, ignoring: %m", de->d_name); continue; } From b71282efea506950fb14b5a19b04de2fa21a13fd Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Tue, 23 Jul 2019 10:18:40 +0200 Subject: [PATCH 06/15] logind: drop redundant session_id_valid() check session_new() checks that as first step anyway, no need to do this beforehand. --- src/login/logind.c | 6 ------ 1 file changed, 6 deletions(-) diff --git a/src/login/logind.c b/src/login/logind.c index ebdc0965c1..175db697e5 100644 --- a/src/login/logind.c +++ b/src/login/logind.c @@ -474,12 +474,6 @@ static int manager_enumerate_sessions(Manager *m) { if (!dirent_is_file(de)) continue; - if (!session_id_valid(de->d_name)) { - log_warning("Invalid session file name '%s', ignoring.", de->d_name); - r = -EINVAL; - continue; - } - k = manager_add_session(m, de->d_name, &s); if (k < 0) { r = log_warning_errno(k, "Failed to add session by file name %s, ignoring: %m", de->d_name); From 07530d706561cb5fe7b04f5dd642cfb2eb26cb2e Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Tue, 23 Jul 2019 10:19:58 +0200 Subject: [PATCH 07/15] logind: cast to (void) when we ignore a syscall return value that is potentially dangerous --- src/login/logind-inhibit.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/login/logind-inhibit.c b/src/login/logind-inhibit.c index d32e299101..3bb04a5d31 100644 --- a/src/login/logind-inhibit.c +++ b/src/login/logind-inhibit.c @@ -83,7 +83,7 @@ int inhibitor_save(Inhibitor *i) { if (r < 0) goto fail; - fchmod(fileno(f), 0644); + (void) fchmod(fileno(f), 0644); fprintf(f, "# This is private data. Do not parse.\n" From fa39c2de5b5552ffe804d1a5ae9b64dae8c72152 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Tue, 23 Jul 2019 10:22:24 +0200 Subject: [PATCH 08/15] logind: unify inhibitor signal generation in a single function --- src/login/logind-inhibit.c | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/src/login/logind-inhibit.c b/src/login/logind-inhibit.c index 3bb04a5d31..773a7ee008 100644 --- a/src/login/logind-inhibit.c +++ b/src/login/logind-inhibit.c @@ -143,6 +143,16 @@ fail: return log_error_errno(r, "Failed to save inhibit data %s: %m", i->state_file); } +static int bus_manager_send_inhibited_change(Inhibitor *i) { + const char *property; + + assert(i); + + property = i->mode == INHIBIT_BLOCK ? "BlockInhibited" : "DelayInhibited"; + + return manager_send_changed(i->manager, property, NULL); +} + int inhibitor_start(Inhibitor *i) { assert(i); @@ -156,11 +166,11 @@ int inhibitor_start(Inhibitor *i) { i->pid, i->uid, inhibit_mode_to_string(i->mode)); - inhibitor_save(i); - i->started = true; - manager_send_changed(i->manager, i->mode == INHIBIT_BLOCK ? "BlockInhibited" : "DelayInhibited", NULL); + inhibitor_save(i); + + bus_manager_send_inhibited_change(i); return 0; } @@ -179,7 +189,7 @@ int inhibitor_stop(Inhibitor *i) { i->started = false; - manager_send_changed(i->manager, i->mode == INHIBIT_BLOCK ? "BlockInhibited" : "DelayInhibited", NULL); + bus_manager_send_inhibited_change(i); return 0; } From 11b0dd0e307d20fa3da65084bf57618133ee9bb7 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Tue, 23 Jul 2019 10:23:15 +0200 Subject: [PATCH 09/15] logind: add logging to inhibitor_load() Also make some parsing errors, fatals and others (that just care fore 'decoration') non-fatal. The single caller of inhibitor_load() didn't log about any errors, hence let's do this in our function, similar to how this is done in session_load() already. --- src/login/logind-inhibit.c | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/src/login/logind-inhibit.c b/src/login/logind-inhibit.c index 773a7ee008..cca3ce023f 100644 --- a/src/login/logind-inhibit.c +++ b/src/login/logind-inhibit.c @@ -218,7 +218,7 @@ int inhibitor_load(Inhibitor *i) { "MODE", &mode, "FIFO", &i->fifo_path); if (r < 0) - return r; + return log_error_errno(r, "Failed to read %s: %m", i->state_file); w = what ? inhibit_what_from_string(what) : 0; if (w >= 0) @@ -231,19 +231,19 @@ int inhibitor_load(Inhibitor *i) { if (uid) { r = parse_uid(uid, &i->uid); if (r < 0) - return r; + log_debug_errno(r, "Failed to parse UID of inhibitor: %s", uid); } if (pid) { r = parse_pid(pid, &i->pid); if (r < 0) - return r; + log_debug_errno(r, "Failed to parse PID of inhibitor: %s", pid); } if (who) { r = cunescape(who, 0, &cc); if (r < 0) - return r; + return log_oom(); free(i->who); i->who = cc; @@ -252,17 +252,19 @@ int inhibitor_load(Inhibitor *i) { if (why) { r = cunescape(why, 0, &cc); if (r < 0) - return r; + return log_oom(); free(i->why); i->why = cc; } if (i->fifo_path) { - int fd; + _cleanup_close_ int fd = -1; + /* Let's re-open the FIFO on both sides, and close the writing side right away */ fd = inhibitor_create_fifo(i); - safe_close(fd); + if (fd < 0) + return log_error_errno(fd, "Failed to reopen FIFO: %m"); } return 0; From 09f300c4d0dbeb0aae98d30eb2214d4f425527e9 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Tue, 23 Jul 2019 10:25:03 +0200 Subject: [PATCH 10/15] logind: use free_and_replace() where that makes sense --- src/login/logind-inhibit.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/login/logind-inhibit.c b/src/login/logind-inhibit.c index cca3ce023f..8716a9f091 100644 --- a/src/login/logind-inhibit.c +++ b/src/login/logind-inhibit.c @@ -245,8 +245,7 @@ int inhibitor_load(Inhibitor *i) { if (r < 0) return log_oom(); - free(i->who); - i->who = cc; + free_and_replace(i->who, cc); } if (why) { @@ -254,8 +253,7 @@ int inhibitor_load(Inhibitor *i) { if (r < 0) return log_oom(); - free(i->why); - i->why = cc; + free_and_replace(i->why, cc); } if (i->fifo_path) { From 81280b2a6fbad079b5d72f48160bf1d492cc8e57 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Tue, 23 Jul 2019 10:27:19 +0200 Subject: [PATCH 11/15] logind: rework allocation/freeing of inhibitors Let's follow our modern style (i.e. return proper errors, use structure initialization and _cleanup_). Most importantly: remove state file and FIFO removal from inhibitor_free() and let's move it to inhibitor_stop(). This makes sure that state files/FIFOs are not removed when the we terminate logind, i.e. that they can survive logind restarts. Fixes: #11825 --- src/login/logind-core.c | 20 ++++++------- src/login/logind-inhibit.c | 59 +++++++++++++++++++++++--------------- src/login/logind-inhibit.h | 6 ++-- 3 files changed, 48 insertions(+), 37 deletions(-) diff --git a/src/login/logind-core.c b/src/login/logind-core.c index f631ba7219..1d21e90a2e 100644 --- a/src/login/logind-core.c +++ b/src/login/logind-core.c @@ -197,26 +197,22 @@ int manager_add_user_by_uid(Manager *m, uid_t uid, User **_user) { return manager_add_user(m, uid, p->pw_gid, p->pw_name, p->pw_dir, _user); } -int manager_add_inhibitor(Manager *m, const char* id, Inhibitor **_inhibitor) { +int manager_add_inhibitor(Manager *m, const char* id, Inhibitor **ret) { Inhibitor *i; + int r; assert(m); assert(id); i = hashmap_get(m->inhibitors, id); - if (i) { - if (_inhibitor) - *_inhibitor = i; - - return 0; + if (!i) { + r = inhibitor_new(&i, m, id); + if (r < 0) + return r; } - i = inhibitor_new(m, id); - if (!i) - return -ENOMEM; - - if (_inhibitor) - *_inhibitor = i; + if (ret) + *ret = i; return 0; } diff --git a/src/login/logind-inhibit.c b/src/login/logind-inhibit.c index 8716a9f091..11cbb4534c 100644 --- a/src/login/logind-inhibit.c +++ b/src/login/logind-inhibit.c @@ -24,48 +24,59 @@ #include "user-util.h" #include "util.h" -Inhibitor* inhibitor_new(Manager *m, const char* id) { - Inhibitor *i; +int inhibitor_new(Inhibitor **ret, Manager *m, const char* id) { + _cleanup_(inhibitor_freep) Inhibitor *i = NULL; + int r; + assert(ret); assert(m); + assert(id); - i = new0(Inhibitor, 1); + i = new(Inhibitor, 1); if (!i) - return NULL; + return -ENOMEM; + + *i = (Inhibitor) { + .manager = m, + .what = _INHIBIT_WHAT_INVALID, + .mode = _INHIBIT_MODE_INVALID, + .uid = UID_INVALID, + .fifo_fd = -1, + }; i->state_file = path_join("/run/systemd/inhibit", id); if (!i->state_file) - return mfree(i); + return -ENOMEM; i->id = basename(i->state_file); - if (hashmap_put(m->inhibitors, i->id, i) < 0) { - free(i->state_file); - return mfree(i); - } + r = hashmap_put(m->inhibitors, i->id, i); + if (r < 0) + return r; - i->manager = m; - i->fifo_fd = -1; - - return i; + *ret = TAKE_PTR(i); + return 0; } -void inhibitor_free(Inhibitor *i) { - assert(i); +Inhibitor* inhibitor_free(Inhibitor *i) { - hashmap_remove(i->manager->inhibitors, i->id); - - inhibitor_remove_fifo(i); + if (!i) + return NULL; free(i->who); free(i->why); - if (i->state_file) { - (void) unlink(i->state_file); - free(i->state_file); - } + sd_event_source_unref(i->event_source); + safe_close(i->fifo_fd); - free(i); + /* Note that we don't remove neither the state file nor the fifo path here, since we want both to + * survive daemon restarts */ + free(i->state_file); + free(i->fifo_path); + + hashmap_remove(i->manager->inhibitors, i->id); + + return mfree(i); } int inhibitor_save(Inhibitor *i) { @@ -184,6 +195,8 @@ int inhibitor_stop(Inhibitor *i) { i->pid, i->uid, inhibit_mode_to_string(i->mode)); + inhibitor_remove_fifo(i); + if (i->state_file) (void) unlink(i->state_file); diff --git a/src/login/logind-inhibit.h b/src/login/logind-inhibit.h index 650587106d..a5cec63ecd 100644 --- a/src/login/logind-inhibit.h +++ b/src/login/logind-inhibit.h @@ -48,8 +48,10 @@ struct Inhibitor { int fifo_fd; }; -Inhibitor* inhibitor_new(Manager *m, const char *id); -void inhibitor_free(Inhibitor *i); +int inhibitor_new(Inhibitor **ret, Manager *m, const char* id); +Inhibitor* inhibitor_free(Inhibitor *i); + +DEFINE_TRIVIAL_CLEANUP_FUNC(Inhibitor*, inhibitor_free); int inhibitor_save(Inhibitor *i); int inhibitor_load(Inhibitor *i); From 290320effadc0a988524af7e88a70c064e6e602c Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Tue, 23 Jul 2019 10:32:41 +0200 Subject: [PATCH 12/15] logind: un-export and voidify a few functions Let's minimize scope of functions and make sure that functions that semantically should never fail can't return errors. --- src/login/logind-inhibit.c | 10 +++++----- src/login/logind-inhibit.h | 4 +--- 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/src/login/logind-inhibit.c b/src/login/logind-inhibit.c index 11cbb4534c..ca2088150e 100644 --- a/src/login/logind-inhibit.c +++ b/src/login/logind-inhibit.c @@ -24,6 +24,8 @@ #include "user-util.h" #include "util.h" +static void inhibitor_remove_fifo(Inhibitor *i); + int inhibitor_new(Inhibitor **ret, Manager *m, const char* id) { _cleanup_(inhibitor_freep) Inhibitor *i = NULL; int r; @@ -79,7 +81,7 @@ Inhibitor* inhibitor_free(Inhibitor *i) { return mfree(i); } -int inhibitor_save(Inhibitor *i) { +static int inhibitor_save(Inhibitor *i) { _cleanup_free_ char *temp_path = NULL; _cleanup_fclose_ FILE *f = NULL; int r; @@ -186,7 +188,7 @@ int inhibitor_start(Inhibitor *i) { return 0; } -int inhibitor_stop(Inhibitor *i) { +void inhibitor_stop(Inhibitor *i) { assert(i); if (i->started) @@ -203,8 +205,6 @@ int inhibitor_stop(Inhibitor *i) { i->started = false; bus_manager_send_inhibited_change(i); - - return 0; } int inhibitor_load(Inhibitor *i) { @@ -338,7 +338,7 @@ int inhibitor_create_fifo(Inhibitor *i) { return r; } -void inhibitor_remove_fifo(Inhibitor *i) { +static void inhibitor_remove_fifo(Inhibitor *i) { assert(i); i->event_source = sd_event_source_unref(i->event_source); diff --git a/src/login/logind-inhibit.h b/src/login/logind-inhibit.h index a5cec63ecd..e04bc81a86 100644 --- a/src/login/logind-inhibit.h +++ b/src/login/logind-inhibit.h @@ -53,14 +53,12 @@ Inhibitor* inhibitor_free(Inhibitor *i); DEFINE_TRIVIAL_CLEANUP_FUNC(Inhibitor*, inhibitor_free); -int inhibitor_save(Inhibitor *i); int inhibitor_load(Inhibitor *i); int inhibitor_start(Inhibitor *i); -int inhibitor_stop(Inhibitor *i); +void inhibitor_stop(Inhibitor *i); int inhibitor_create_fifo(Inhibitor *i); -void inhibitor_remove_fifo(Inhibitor *i); InhibitWhat manager_inhibit_what(Manager *m, InhibitMode mm); bool manager_is_inhibited(Manager *m, InhibitWhat w, InhibitMode mm, dual_timestamp *since, bool ignore_inactive, bool ignore_uid, uid_t uid, Inhibitor **offending); From 11eae36d297a7b8767abd66b53021b47ff18b4ec Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Tue, 23 Jul 2019 10:33:39 +0200 Subject: [PATCH 13/15] logind: at start-up automatically clean up orphaned inhibitors --- src/login/logind-inhibit.c | 19 +++++++++++++++++++ src/login/logind-inhibit.h | 2 ++ src/login/logind.c | 11 +++++++++-- 3 files changed, 30 insertions(+), 2 deletions(-) diff --git a/src/login/logind-inhibit.c b/src/login/logind-inhibit.c index ca2088150e..8a36155115 100644 --- a/src/login/logind-inhibit.c +++ b/src/login/logind-inhibit.c @@ -13,6 +13,7 @@ #include "fd-util.h" #include "fileio.h" #include "format-util.h" +#include "io-util.h" #include "logind-dbus.h" #include "logind-inhibit.h" #include "mkdir.h" @@ -350,6 +351,24 @@ static void inhibitor_remove_fifo(Inhibitor *i) { } } +bool inhibitor_is_orphan(Inhibitor *i) { + assert(i); + + if (!i->started) + return true; + + if (!i->fifo_path) + return true; + + if (i->fifo_fd < 0) + return true; + + if (pipe_eof(i->fifo_fd) != 0) + return true; + + return false; +} + InhibitWhat manager_inhibit_what(Manager *m, InhibitMode mm) { Inhibitor *i; Iterator j; diff --git a/src/login/logind-inhibit.h b/src/login/logind-inhibit.h index e04bc81a86..c00578a86e 100644 --- a/src/login/logind-inhibit.h +++ b/src/login/logind-inhibit.h @@ -60,6 +60,8 @@ void inhibitor_stop(Inhibitor *i); int inhibitor_create_fifo(Inhibitor *i); +bool inhibitor_is_orphan(Inhibitor *i); + InhibitWhat manager_inhibit_what(Manager *m, InhibitMode mm); bool manager_is_inhibited(Manager *m, InhibitWhat w, InhibitMode mm, dual_timestamp *since, bool ignore_inactive, bool ignore_uid, uid_t uid, Inhibitor **offending); diff --git a/src/login/logind.c b/src/login/logind.c index 175db697e5..3a16e6c871 100644 --- a/src/login/logind.c +++ b/src/login/logind.c @@ -1145,8 +1145,15 @@ static int manager_startup(Manager *m) { HASHMAP_FOREACH(session, m->sessions, i) (void) session_start(session, NULL, NULL); - HASHMAP_FOREACH(inhibitor, m->inhibitors, i) - inhibitor_start(inhibitor); + HASHMAP_FOREACH(inhibitor, m->inhibitors, i) { + (void) inhibitor_start(inhibitor); + + /* Let's see if the inhibitor is dead now, then remove it */ + if (inhibitor_is_orphan(inhibitor)) { + inhibitor_stop(inhibitor); + inhibitor_free(inhibitor); + } + } HASHMAP_FOREACH(button, m->buttons, i) button_check_switches(button); From 9f18eda8ffa5d60176f0cb9251dc85e708bedd0d Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Tue, 23 Jul 2019 12:40:52 +0200 Subject: [PATCH 14/15] logind: make id const, since it points into another buffer --- src/login/logind-inhibit.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/login/logind-inhibit.h b/src/login/logind-inhibit.h index c00578a86e..cea67a08c5 100644 --- a/src/login/logind-inhibit.h +++ b/src/login/logind-inhibit.h @@ -29,7 +29,7 @@ struct Inhibitor { sd_event_source *event_source; - char *id; + const char *id; char *state_file; bool started; From c20b8dad71bf4716471237776291534c593904cd Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Tue, 23 Jul 2019 12:41:05 +0200 Subject: [PATCH 15/15] logind: don't unlink session fifo when exiting logind Let's only close our fds, but not unlink it. That's done when the session is stopped. This should make sure the fd will survive daemon restarts. --- src/login/logind-session.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/login/logind-session.c b/src/login/logind-session.c index 5658ba7c68..7e8025a0ea 100644 --- a/src/login/logind-session.c +++ b/src/login/logind-session.c @@ -96,8 +96,6 @@ Session* session_free(Session *s) { s->timer_event_source = sd_event_source_unref(s->timer_event_source); - session_remove_fifo(s); - session_drop_controller(s); while ((sd = hashmap_first(s->devices))) @@ -145,7 +143,13 @@ Session* session_free(Session *s) { hashmap_remove(s->manager->sessions, s->id); + sd_event_source_unref(s->fifo_event_source); + safe_close(s->fifo_fd); + + /* Note that we remove neither the state file nor the fifo path here, since we want both to survive + * daemon restarts */ free(s->state_file); + free(s->fifo_path); return mfree(s); }