From 81bb3ca13cd3b2e3dbc0a72821e0ae595a1e086f Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Wed, 16 Feb 2022 22:56:47 +0100 Subject: [PATCH 1/2] logind: fix internal types used for EnableWallMessages The value is used as a boolean, but stored in an unsigned. It's exposed with sd-bus default boolean handling which however expects a (signed) int. Let's clear this up, and use "bool" for this everywhere in non-local scope, and make sure that when we pass it to sd-bus we properly pass an "int". --- src/login/logind-dbus.c | 8 ++++---- src/login/logind.h | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/login/logind-dbus.c b/src/login/logind-dbus.c index 5ba0b1748e..30bddb5402 100644 --- a/src/login/logind-dbus.c +++ b/src/login/logind-dbus.c @@ -2058,10 +2058,10 @@ static int update_schedule_file(Manager *m) { fprintf(f, "USEC="USEC_FMT"\n" - "WARN_WALL=%i\n" + "WARN_WALL=%s\n" "MODE=%s\n", m->scheduled_shutdown_timeout, - m->enable_wall_messages, + one_zero(m->enable_wall_messages), handle_action_to_string(m->scheduled_shutdown_type->handle)); if (!isempty(m->wall_message)) { @@ -3116,7 +3116,7 @@ static int method_set_wall_message( int r; Manager *m = userdata; char *wall_message; - unsigned enable_wall_messages; + int enable_wall_messages; assert(message); assert(m); @@ -3277,7 +3277,7 @@ static int method_inhibit(sd_bus_message *message, void *userdata, sd_bus_error static const sd_bus_vtable manager_vtable[] = { SD_BUS_VTABLE_START(0), - SD_BUS_WRITABLE_PROPERTY("EnableWallMessages", "b", NULL, NULL, offsetof(Manager, enable_wall_messages), 0), + SD_BUS_WRITABLE_PROPERTY("EnableWallMessages", "b", bus_property_get_bool, bus_property_set_bool, offsetof(Manager, enable_wall_messages), 0), SD_BUS_WRITABLE_PROPERTY("WallMessage", "s", NULL, NULL, offsetof(Manager, wall_message), 0), SD_BUS_PROPERTY("NAutoVTs", "u", NULL, offsetof(Manager, n_autovts), SD_BUS_VTABLE_PROPERTY_CONST), diff --git a/src/login/logind.h b/src/login/logind.h index 5647e5069c..af9af9e457 100644 --- a/src/login/logind.h +++ b/src/login/logind.h @@ -87,7 +87,7 @@ struct Manager { bool unlink_nologin; char *wall_message; - unsigned enable_wall_messages; + bool enable_wall_messages; sd_event_source *wall_message_timeout_source; bool shutdown_dry_run; From 0db7e17cba1da277a2074098cfffcc75062b9b2f Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Wed, 16 Feb 2022 22:58:19 +0100 Subject: [PATCH 2/2] logind: fix bool/int confusion for KillUserProcesses bus property sd-bus for compat with old C expects "int" for booleans. Internally we prefer to use C99 "bool" however. When pointing a pointer to it, we need to handle the fact that they are typically differently sized, hence use te right accessors for it. --- src/login/logind-dbus.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/login/logind-dbus.c b/src/login/logind-dbus.c index 30bddb5402..cd0dcea0e5 100644 --- a/src/login/logind-dbus.c +++ b/src/login/logind-dbus.c @@ -3283,7 +3283,7 @@ static const sd_bus_vtable manager_vtable[] = { SD_BUS_PROPERTY("NAutoVTs", "u", NULL, offsetof(Manager, n_autovts), SD_BUS_VTABLE_PROPERTY_CONST), SD_BUS_PROPERTY("KillOnlyUsers", "as", NULL, offsetof(Manager, kill_only_users), SD_BUS_VTABLE_PROPERTY_CONST), SD_BUS_PROPERTY("KillExcludeUsers", "as", NULL, offsetof(Manager, kill_exclude_users), SD_BUS_VTABLE_PROPERTY_CONST), - SD_BUS_PROPERTY("KillUserProcesses", "b", NULL, offsetof(Manager, kill_user_processes), SD_BUS_VTABLE_PROPERTY_CONST), + SD_BUS_PROPERTY("KillUserProcesses", "b", bus_property_get_bool, offsetof(Manager, kill_user_processes), SD_BUS_VTABLE_PROPERTY_CONST), SD_BUS_PROPERTY("RebootParameter", "s", property_get_reboot_parameter, 0, 0), SD_BUS_PROPERTY("RebootToFirmwareSetup", "b", property_get_reboot_to_firmware_setup, 0, 0), SD_BUS_PROPERTY("RebootToBootLoaderMenu", "t", property_get_reboot_to_boot_loader_menu, 0, 0),