From: Luca Boccassi Date: Sun, 4 Aug 2024 22:47:29 +0000 (+0100) Subject: logind: add PreparingForShutdownWithMetadata property X-Git-Tag: v257-rc1~732 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=1e0ef014393122f14e02a8b4b20820cb739890e4;p=thirdparty%2Fsystemd.git logind: add PreparingForShutdownWithMetadata property The PrepareForShutdownWithMetadata signal was added via e4aab5cf1a00bbb73f325f4f785dd4171ccdae77 but a corresponding property was not. A property has to be a single type, so the bool needs to be one of the key/value pairs as 'ba{sv}' is not a valid property. --- diff --git a/man/org.freedesktop.login1.xml b/man/org.freedesktop.login1.xml index bf00800cefc..1008c59a32b 100644 --- a/man/org.freedesktop.login1.xml +++ b/man/org.freedesktop.login1.xml @@ -256,6 +256,8 @@ node /org/freedesktop/login1 { @org.freedesktop.DBus.Property.EmitsChangedSignal("false") readonly b PreparingForShutdown = ...; @org.freedesktop.DBus.Property.EmitsChangedSignal("false") + readonly a{sv} PreparingForShutdownWithMetadata = [...]; + @org.freedesktop.DBus.Property.EmitsChangedSignal("false") readonly b PreparingForSleep = ...; readonly (st) ScheduledShutdown = ...; @org.freedesktop.DBus.Property.EmitsChangedSignal("false") @@ -526,6 +528,8 @@ node /org/freedesktop/login1 { + + @@ -815,8 +819,14 @@ node /org/freedesktop/login1 { The PreparingForShutdown and PreparingForSleep boolean properties are true during the interval between the two PrepareForShutdown() and - PrepareForSleep() signals respectively. Note that these properties do not - send out PropertyChanged signals. + PrepareForSleep() signals respectively. The + PreparingForShutdownWithMetadata property provides a list of key/value pair + metadata fields. Currently it lists a preparing boolean that corresponds to the + PreparingForShutdown property, and, if a shutdown is being prepared, it will also + contain a type string which defines the type of shutdown. The type can be one of + power-off, reboot, halt, + kexec or soft-reboot. Note that these properties do not send out + PropertyChanged signals. The RebootParameter property shows the value set with the SetRebootParameter() method described above. @@ -1609,7 +1619,8 @@ node /org/freedesktop/login1/session/1 { SleepOperation, DesignatedMaintenanceTime, and ListSessionsEx() were added in version 256. - HandleSecureAttentionKey, and + HandleSecureAttentionKey, + PreparingForShutdownWithMetadata, and SecureAttentionKey() were added in version 257. diff --git a/src/login/logind-dbus.c b/src/login/logind-dbus.c index 98f14bd0b19..2f60f15131c 100644 --- a/src/login/logind-dbus.c +++ b/src/login/logind-dbus.c @@ -341,6 +341,35 @@ static int property_get_preparing( return sd_bus_message_append(reply, "b", b); } +static int property_get_preparing_shutdown_with_metadata( + sd_bus *bus, + const char *path, + const char *interface, + const char *property, + sd_bus_message *reply, + void *userdata, + sd_bus_error *error) { + + Manager *m = ASSERT_PTR(userdata); + + assert(bus); + assert(reply); + + if (!m->delayed_action || !(m->delayed_action->inhibit_what & INHIBIT_SHUTDOWN)) + return sd_bus_message_append(reply, "a{sv}", 1, "preparing", "b", false); + + return sd_bus_message_append( + reply, + "a{sv}", + 2, + "preparing", + "b", + true, + "type", + "s", + handle_action_to_string(m->delayed_action->handle)); +} + static int property_get_sleep_operations( sd_bus *bus, const char *path, @@ -3718,6 +3747,7 @@ static const sd_bus_vtable manager_vtable[] = { SD_BUS_PROPERTY("IdleAction", "s", property_get_handle_action, offsetof(Manager, idle_action), SD_BUS_VTABLE_PROPERTY_CONST), SD_BUS_PROPERTY("IdleActionUSec", "t", NULL, offsetof(Manager, idle_action_usec), SD_BUS_VTABLE_PROPERTY_CONST), SD_BUS_PROPERTY("PreparingForShutdown", "b", property_get_preparing, 0, 0), + SD_BUS_PROPERTY("PreparingForShutdownWithMetadata", "a{sv}", property_get_preparing_shutdown_with_metadata, 0, 0), SD_BUS_PROPERTY("PreparingForSleep", "b", property_get_preparing, 0, 0), SD_BUS_PROPERTY("ScheduledShutdown", "(st)", property_get_scheduled_shutdown, 0, SD_BUS_VTABLE_PROPERTY_EMITS_CHANGE), SD_BUS_PROPERTY("DesignatedMaintenanceTime", "s", property_get_maintenance_time, 0, 0), diff --git a/test/units/TEST-82-SOFTREBOOT.sh b/test/units/TEST-82-SOFTREBOOT.sh index 9f3d4066c3a..eb6fb375615 100755 --- a/test/units/TEST-82-SOFTREBOOT.sh +++ b/test/units/TEST-82-SOFTREBOOT.sh @@ -273,6 +273,10 @@ EOF touch /run/TEST-82-SOFTREBOOT.touch systemctl --no-block --check-inhibitors=yes soft-reboot + # Ensure the property works too + type="$(busctl --json=short get-property org.freedesktop.login1 /org/freedesktop/login1 org.freedesktop.login1.Manager PreparingForShutdownWithMetadata | jq -r '.data.type.data')" + test "$type" = "soft-reboot" + # Now block until the soft-boot killing spree kills us exec sleep infinity fi