From a93993584df69c84bd92c6a13453cab861061a51 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Wed, 5 Jul 2023 17:54:01 +0200 Subject: bus-unit-util: add common code for reloading PID 1 We have this very similar code in various places, and it#s not entirely obvious (since we want a prolonged timeout for the reload), hence unify this at one place. --- src/shared/bus-unit-util.c | 20 ++++++++++++++++++++ src/shared/bus-unit-util.h | 2 ++ 2 files changed, 22 insertions(+) (limited to 'src/shared') diff --git a/src/shared/bus-unit-util.c b/src/shared/bus-unit-util.c index 494484f0bf..e7b44cc39b 100644 --- a/src/shared/bus-unit-util.c +++ b/src/shared/bus-unit-util.c @@ -3,6 +3,7 @@ #include "af-list.h" #include "alloc-util.h" #include "bus-error.h" +#include "bus-locator.h" #include "bus-unit-util.h" #include "bus-util.h" #include "cap-list.h" @@ -2811,3 +2812,22 @@ int unit_info_compare(const UnitInfo *a, const UnitInfo *b) { /* Third, order by name */ return strcasecmp(a->id, b->id); } + +int bus_service_manager_reload(sd_bus *bus) { + _cleanup_(sd_bus_error_free) sd_bus_error error = SD_BUS_ERROR_NULL; + _cleanup_(sd_bus_message_unrefp) sd_bus_message *m = NULL; + int r; + + assert(bus); + + r = bus_message_new_method_call(bus, &m, bus_systemd_mgr, "Reload"); + if (r < 0) + return bus_log_create_error(r); + + /* Reloading the daemon may take long, hence set a longer timeout here */ + r = sd_bus_call(bus, m, DAEMON_RELOAD_TIMEOUT_SEC, &error, NULL); + if (r < 0) + return log_error_errno(r, "Failed to reload service manager: %s", bus_error_message(&error, r)); + + return 0; +} diff --git a/src/shared/bus-unit-util.h b/src/shared/bus-unit-util.h index 97d84708b4..267d516cbf 100644 --- a/src/shared/bus-unit-util.h +++ b/src/shared/bus-unit-util.h @@ -30,3 +30,5 @@ int bus_deserialize_and_dump_unit_file_changes(sd_bus_message *m, bool quiet); int unit_load_state(sd_bus *bus, const char *name, char **load_state); int unit_info_compare(const UnitInfo *a, const UnitInfo *b); + +int bus_service_manager_reload(sd_bus *bus); -- cgit v1.2.3