diff --git a/src/firstboot/firstboot.c b/src/firstboot/firstboot.c index b993739083..1956ab3b13 100644 --- a/src/firstboot/firstboot.c +++ b/src/firstboot/firstboot.c @@ -12,6 +12,7 @@ #include "build.h" #include "bus-error.h" #include "bus-locator.h" +#include "bus-unit-util.h" #include "bus-util.h" #include "bus-wait-for-jobs.h" #include "chase.h" @@ -1574,7 +1575,6 @@ static int parse_argv(int argc, char *argv[]) { } static int reload_system_manager(sd_bus **bus) { - _cleanup_(sd_bus_error_free) sd_bus_error error = SD_BUS_ERROR_NULL; int r; assert(bus); @@ -1585,9 +1585,10 @@ static int reload_system_manager(sd_bus **bus) { return bus_log_connect_error(r, BUS_TRANSPORT_LOCAL); } - r = bus_call_method(*bus, bus_systemd_mgr, "Reload", &error, NULL, NULL); + r = bus_service_manager_reload(*bus); if (r < 0) - return log_error_errno(r, "Failed to issue method call: %s", bus_error_message(&error, r)); + return r; + log_info("Requested manager reload to apply locale configuration."); return 0; } diff --git a/src/fstab-generator/fstab-generator.c b/src/fstab-generator/fstab-generator.c index b39d93195a..660a98ab92 100644 --- a/src/fstab-generator/fstab-generator.c +++ b/src/fstab-generator/fstab-generator.c @@ -7,6 +7,7 @@ #include "alloc-util.h" #include "bus-error.h" #include "bus-locator.h" +#include "bus-unit-util.h" #include "chase.h" #include "creds-util.h" #include "efi-loader.h" @@ -712,7 +713,6 @@ static int add_mount( static int do_daemon_reload(void) { _cleanup_(sd_bus_flush_close_unrefp) sd_bus *bus = NULL; - _cleanup_(sd_bus_message_unrefp) sd_bus_message *m = NULL; _cleanup_(sd_bus_error_free) sd_bus_error error = SD_BUS_ERROR_NULL; int r, k; @@ -722,13 +722,9 @@ static int do_daemon_reload(void) { if (r < 0) return log_error_errno(r, "Failed to get D-Bus connection: %m"); - r = bus_message_new_method_call(bus, &m, bus_systemd_mgr, "Reload"); + r = bus_service_manager_reload(bus); if (r < 0) - return bus_log_create_error(r); - - r = sd_bus_call(bus, m, DAEMON_RELOAD_TIMEOUT_SEC, &error, NULL); - if (r < 0) - return log_error_errno(r, "Failed to reload daemon: %s", bus_error_message(&error, r)); + return r; /* We need to requeue the two targets so that any new units which previously were not part of the * targets, and which we now added, will be started. */ diff --git a/src/locale/localed.c b/src/locale/localed.c index 9e5b7b03c0..f544a73580 100644 --- a/src/locale/localed.c +++ b/src/locale/localed.c @@ -13,6 +13,7 @@ #include "bus-log-control-api.h" #include "bus-message.h" #include "bus-polkit.h" +#include "bus-unit-util.h" #include "constants.h" #include "kbd-util.h" #include "localed-util.h" @@ -27,18 +28,6 @@ #include "strv.h" #include "user-util.h" -static int reload_system_manager(sd_bus *bus) { - _cleanup_(sd_bus_error_free) sd_bus_error error = SD_BUS_ERROR_NULL; - int r; - - assert(bus); - - r = bus_call_method(bus, bus_systemd_mgr, "Reload", &error, NULL, NULL); - if (r < 0) - return log_error_errno(r, "Failed to reload system manager: %s", bus_error_message(&error, r)); - return 0; -} - static int vconsole_reload(sd_bus *bus) { _cleanup_(sd_bus_error_free) sd_bus_error error = SD_BUS_ERROR_NULL; int r; @@ -326,7 +315,7 @@ static int method_set_locale(sd_bus_message *m, void *userdata, sd_bus_error *er * update its default locale settings. It's important to not use UnsetAndSetEnvironment or a similar * method because in this case unsetting variables means restoring them to PID1 default values, which * may be outdated, since locale.conf has just changed and PID1 hasn't read it */ - (void) reload_system_manager(sd_bus_message_get_bus(m)); + (void) bus_service_manager_reload(sd_bus_message_get_bus(m)); if (!strv_isempty(l_set)) { _cleanup_free_ char *line = NULL; diff --git a/src/machine/machinectl.c b/src/machine/machinectl.c index 83ecfa7aba..7746ecba1a 100644 --- a/src/machine/machinectl.c +++ b/src/machine/machinectl.c @@ -1822,9 +1822,9 @@ static int enable_machine(int argc, char *argv[], void *userdata) { if (r < 0) return r; - r = bus_call_method(bus, bus_systemd_mgr, "Reload", &error, NULL, NULL); + r = bus_service_manager_reload(bus); if (r < 0) - return log_error_errno(r, "Failed to reload daemon: %s", bus_error_message(&error, r)); + return r; if (arg_now) { _cleanup_strv_free_ char **new_args = NULL; diff --git a/src/portable/portablectl.c b/src/portable/portablectl.c index 8744ba75fe..e77ee50dab 100644 --- a/src/portable/portablectl.c +++ b/src/portable/portablectl.c @@ -231,8 +231,6 @@ static int acquire_bus(sd_bus **bus) { } static int maybe_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; if (!arg_reload) @@ -242,16 +240,7 @@ static int maybe_reload(sd_bus **bus) { if (r < 0) return r; - 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 daemon: %s", bus_error_message(&error, r)); - - return 0; + return bus_service_manager_reload(*bus); } static int get_image_metadata(sd_bus *bus, const char *image, char **matches, sd_bus_message **reply) { 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); diff --git a/src/sulogin-shell/sulogin-shell.c b/src/sulogin-shell/sulogin-shell.c index e81bb527ff..7ffafcda55 100644 --- a/src/sulogin-shell/sulogin-shell.c +++ b/src/sulogin-shell/sulogin-shell.c @@ -8,43 +8,21 @@ #include "sd-bus.h" -#include "bus-locator.h" -#include "bus-util.h" #include "bus-error.h" +#include "bus-locator.h" +#include "bus-unit-util.h" +#include "bus-util.h" #include "constants.h" #include "env-util.h" #include "initrd-util.h" #include "log.h" #include "main-func.h" -#include "process-util.h" #include "proc-cmdline.h" +#include "process-util.h" #include "signal-util.h" #include "special.h" #include "unit-def.h" -static int reload_manager(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; - - log_info("Reloading system manager configuration"); - - 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 daemon: %s", bus_error_message(&error, r)); - - return 0; -} - static int target_is_inactive(sd_bus *bus, const char *target) { _cleanup_(sd_bus_error_free) sd_bus_error error = SD_BUS_ERROR_NULL; _cleanup_free_ char *path = NULL, *state = NULL; @@ -151,7 +129,9 @@ static int run(int argc, char *argv[]) { goto fallback; } - if (reload_manager(bus) < 0) + log_info("Reloading system manager configuration."); + r = bus_service_manager_reload(bus); + if (r < 0) goto fallback; const char *target = in_initrd() ? SPECIAL_INITRD_TARGET : SPECIAL_DEFAULT_TARGET; @@ -160,7 +140,7 @@ static int run(int argc, char *argv[]) { if (r < 0) goto fallback; if (!r) { - log_warning("%s is not inactive. Please review the %s setting.\n", target, target); + log_warning("%s is not inactive. Please review the %s setting.", target, target); goto fallback; } @@ -168,7 +148,7 @@ static int run(int argc, char *argv[]) { break; fallback: - log_warning("Fallback to the single-user shell.\n"); + log_warning("Fallback to the single-user shell."); } return 0; diff --git a/src/test/test-cgroup-mask.c b/src/test/test-cgroup-mask.c index b26a834530..c0bf585963 100644 --- a/src/test/test-cgroup-mask.c +++ b/src/test/test-cgroup-mask.c @@ -21,9 +21,9 @@ static void log_cgroup_mask(CGroupMask got, CGroupMask expected) { _cleanup_free_ char *e_store = NULL, *g_store = NULL; assert_se(cg_mask_to_string(expected, &e_store) >= 0); - log_info("Expected mask: %s\n", e_store); + log_info("Expected mask: %s", e_store); assert_se(cg_mask_to_string(got, &g_store) >= 0); - log_info("Got mask: %s\n", g_store); + log_info("Got mask: %s", g_store); } TEST_RET(cgroup_mask, .sd_booted = true) { diff --git a/src/test/test-daemon.c b/src/test/test-daemon.c index faf6476778..e5bc6c457b 100644 --- a/src/test/test-daemon.c +++ b/src/test/test-daemon.c @@ -27,7 +27,7 @@ int main(int argc, char *argv[]) { } for (i = 0; i < n; i++) - log_info("fd=%i name=%s\n", SD_LISTEN_FDS_START + i, l[i]); + log_info("fd=%i name=%s", SD_LISTEN_FDS_START + i, l[i]); sd_notify(0, "STATUS=Starting up"); diff --git a/src/test/test-id128.c b/src/test/test-id128.c index 4a39d06ef8..58dc88110e 100644 --- a/src/test/test-id128.c +++ b/src/test/test-id128.c @@ -214,7 +214,7 @@ TEST(benchmark_sd_id128_get_machine_app_specific) { q = now(CLOCK_MONOTONIC) - t; - log_info("%lf μs each\n", (double) q / iterations); + log_info("%lf μs each", (double) q / iterations); } TEST(id128_at) { diff --git a/src/test/test-json.c b/src/test/test-json.c index 6a544c3fb7..3657075a54 100644 --- a/src/test/test-json.c +++ b/src/test/test-json.c @@ -95,7 +95,7 @@ static void test_variant_one(const char *data, Test test) { assert_se(s); assert_se((size_t) r == strlen(s)); - log_info("formatted normally: %s\n", s); + log_info("formatted normally: %s", s); r = json_parse(data, JSON_PARSE_SENSITIVE, &w, NULL, NULL); assert_se(r == 0); @@ -305,7 +305,7 @@ TEST(build) { JSON_BUILD_STRV((char**) arr_1234))) >= 0); assert_se(json_variant_format(a, 0, &s) >= 0); - log_info("GOT: %s\n", s); + log_info("GOT: %s", s); assert_se(json_parse(s, 0, &b, NULL, NULL) >= 0); assert_se(json_variant_equal(a, b)); @@ -316,10 +316,10 @@ TEST(build) { s = mfree(s); assert_se(json_variant_format(a, 0, &s) >= 0); - log_info("GOT: %s\n", s); + log_info("GOT: %s", s); assert_se(json_parse(s, 0, &b, NULL, NULL) >= 0); assert_se(json_variant_format(b, 0, &t) >= 0); - log_info("GOT: %s\n", t); + log_info("GOT: %s", t); assert_se(streq(s, t)); diff --git a/src/test/test-load-fragment.c b/src/test/test-load-fragment.c index e4ee9f697d..ac0ad80132 100644 --- a/src/test/test-load-fragment.c +++ b/src/test/test-load-fragment.c @@ -923,7 +923,7 @@ TEST(config_parse_memory_limit) { r = config_parse_memory_limit(NULL, "fake", 1, "section", 1, limit_tests[i].limit, 1, limit_tests[i].value, &c, NULL); - log_info("%s=%s\t%"PRIu64"==%"PRIu64"\n", + log_info("%s=%s\t%"PRIu64"==%"PRIu64, limit_tests[i].limit, limit_tests[i].value, *limit_tests[i].result, limit_tests[i].expected); assert_se(r >= 0); diff --git a/src/test/test-process-util.c b/src/test/test-process-util.c index 80ee095786..1aba4d7ae3 100644 --- a/src/test/test-process-util.c +++ b/src/test/test-process-util.c @@ -614,7 +614,7 @@ TEST(getpid_measure) { (void) getpid(); q = now(CLOCK_MONOTONIC) - t; - log_info(" glibc getpid(): %lf μs each\n", (double) q / iterations); + log_info(" glibc getpid(): %lf μs each", (double) q / iterations); iterations *= 50; /* _cached() is about 50 times faster, so we need more iterations */ @@ -623,7 +623,7 @@ TEST(getpid_measure) { (void) getpid_cached(); q = now(CLOCK_MONOTONIC) - t; - log_info("getpid_cached(): %lf μs each\n", (double) q / iterations); + log_info("getpid_cached(): %lf μs each", (double) q / iterations); } TEST(safe_fork) {