diff options
author | Lennart Poettering <lennart@poettering.net> | 2019-07-23 10:33:39 +0200 |
---|---|---|
committer | Lennart Poettering <lennart@poettering.net> | 2019-07-23 16:08:07 +0200 |
commit | 11eae36d297a7b8767abd66b53021b47ff18b4ec (patch) | |
tree | 402326eb1ab250b531b169acadf33385960a961f /src | |
parent | 290320effadc0a988524af7e88a70c064e6e602c (diff) | |
download | systemd-11eae36d297a7b8767abd66b53021b47ff18b4ec.tar.gz |
logind: at start-up automatically clean up orphaned inhibitors
Diffstat (limited to 'src')
-rw-r--r-- | src/login/logind-inhibit.c | 19 | ||||
-rw-r--r-- | src/login/logind-inhibit.h | 2 | ||||
-rw-r--r-- | 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); |