From: Luca Boccassi Date: Wed, 30 Oct 2024 13:44:00 +0000 (+0000) Subject: logind: add BlockWeakInhibited property X-Git-Tag: v257-rc1~97 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=14b0fcdf6d285794f36ba55ec04e868c0c73b3b5;p=thirdparty%2Fsystemd.git logind: add BlockWeakInhibited property Fixes https://github.com/systemd/systemd/issues/34091 Follow-up for 804874d26ac73e0af07c4c5d7165c95372f03f6d --- diff --git a/man/org.freedesktop.login1.xml b/man/org.freedesktop.login1.xml index 91e7364b40e..00ca82487a8 100644 --- a/man/org.freedesktop.login1.xml +++ b/man/org.freedesktop.login1.xml @@ -216,6 +216,7 @@ node /org/freedesktop/login1 { readonly t IdleSinceHint = ...; readonly t IdleSinceHintMonotonic = ...; readonly s BlockInhibited = '...'; + readonly s BlockWeakInhibited = '...'; readonly s DelayInhibited = '...'; @org.freedesktop.DBus.Property.EmitsChangedSignal("const") readonly t InhibitDelayMaxUSec = ...; @@ -488,6 +489,8 @@ node /org/freedesktop/login1 { + + @@ -805,9 +808,10 @@ node /org/freedesktop/login1 { timestamps of the last change of the idle hint boolean, in CLOCK_REALTIME and CLOCK_MONOTONIC timestamps, respectively, in microseconds since the epoch. - The BlockInhibited and DelayInhibited properties encode - the currently active locks of the respective modes. They are colon separated lists of - shutdown, sleep, and idle (see above). + The BlockInhibited, BlockWeakInhibited, and + DelayInhibited properties encode the currently active locks of the respective + modes. They are colon separated lists of shutdown, sleep, and + idle (see above). NCurrentSessions and NCurrentInhibitors contain the number of currently registered sessions and inhibitors. @@ -1634,7 +1638,8 @@ node /org/freedesktop/login1/session/1 { ListSessionsEx() were added in version 256. HandleSecureAttentionKey, SecureAttentionKey(), PreparingForShutdownWithMetadata, DesignatedMaintenanceTime, - CanIdle, and CanLock were added in version 257. + CanIdle, CanLock, + and BlockWeakInhibited were added in version 257. Session Objects diff --git a/src/login/logind-dbus.c b/src/login/logind-dbus.c index 3cec6109d8c..094f9a64bd4 100644 --- a/src/login/logind-dbus.c +++ b/src/login/logind-dbus.c @@ -310,7 +310,14 @@ static int property_get_inhibited( assert(bus); assert(reply); - w = manager_inhibit_what(m, /* block= */ streq(property, "BlockInhibited")); + if (streq(property, "BlockInhibited")) + w = manager_inhibit_what(m, INHIBIT_BLOCK); + else if (streq(property, "BlockWeakInhibited")) + w = manager_inhibit_what(m, INHIBIT_BLOCK_WEAK); + else if (streq(property, "DelayInhibited")) + w = manager_inhibit_what(m, INHIBIT_DELAY); + else + assert_not_reached(); return sd_bus_message_append(reply, "s", inhibit_what_to_string(w)); } @@ -3745,6 +3752,7 @@ static const sd_bus_vtable manager_vtable[] = { SD_BUS_PROPERTY("IdleSinceHint", "t", property_get_idle_since_hint, 0, SD_BUS_VTABLE_PROPERTY_EMITS_CHANGE), SD_BUS_PROPERTY("IdleSinceHintMonotonic", "t", property_get_idle_since_hint, 0, SD_BUS_VTABLE_PROPERTY_EMITS_CHANGE), SD_BUS_PROPERTY("BlockInhibited", "s", property_get_inhibited, 0, SD_BUS_VTABLE_PROPERTY_EMITS_CHANGE), + SD_BUS_PROPERTY("BlockWeakInhibited", "s", property_get_inhibited, 0, SD_BUS_VTABLE_PROPERTY_EMITS_CHANGE), SD_BUS_PROPERTY("DelayInhibited", "s", property_get_inhibited, 0, SD_BUS_VTABLE_PROPERTY_EMITS_CHANGE), SD_BUS_PROPERTY("InhibitDelayMaxUSec", "t", NULL, offsetof(Manager, inhibit_delay_max), SD_BUS_VTABLE_PROPERTY_CONST), SD_BUS_PROPERTY("UserStopDelayUSec", "t", NULL, offsetof(Manager, user_stop_delay), SD_BUS_VTABLE_PROPERTY_CONST), diff --git a/src/login/logind-inhibit.c b/src/login/logind-inhibit.c index 70905c92b39..27ad8f16526 100644 --- a/src/login/logind-inhibit.c +++ b/src/login/logind-inhibit.c @@ -363,16 +363,14 @@ bool inhibitor_is_orphan(Inhibitor *i) { return false; } -InhibitWhat manager_inhibit_what(Manager *m, bool block) { +InhibitWhat manager_inhibit_what(Manager *m, InhibitMode mode) { Inhibitor *i; InhibitWhat what = 0; assert(m); HASHMAP_FOREACH(i, m->inhibitors) - if (i->started && - ((!block && i->mode == INHIBIT_DELAY) || - (block && IN_SET(i->mode, INHIBIT_BLOCK, INHIBIT_BLOCK_WEAK)))) + if (i->started && i->mode == mode) what |= i->what; return what; diff --git a/src/login/logind-inhibit.h b/src/login/logind-inhibit.h index 8712fb1900c..16abd6958cc 100644 --- a/src/login/logind-inhibit.h +++ b/src/login/logind-inhibit.h @@ -66,7 +66,7 @@ int inhibitor_create_fifo(Inhibitor *i); bool inhibitor_is_orphan(Inhibitor *i); -InhibitWhat manager_inhibit_what(Manager *m, bool block); +InhibitWhat manager_inhibit_what(Manager *m, InhibitMode mode); bool manager_is_inhibited(Manager *m, InhibitWhat w, bool block, dual_timestamp *since, bool ignore_inactive, bool ignore_uid, uid_t uid, Inhibitor **offending); static inline bool inhibit_what_is_valid(InhibitWhat w) {