diff --git a/src/home/homed-home.c b/src/home/homed-home.c index 6e9cfd27767..d16509d5743 100644 --- a/src/home/homed-home.c +++ b/src/home/homed-home.c @@ -11,6 +11,7 @@ #include "blockdev-util.h" #include "btrfs-util.h" #include "bus-common-errors.h" +#include "bus-locator.h" #include "data-fd-util.h" #include "env-util.h" #include "errno-list.h" @@ -2117,15 +2118,7 @@ int home_killall(Home *h) { if (asprintf(&unit, "user-" UID_FMT ".slice", h->uid) < 0) return log_oom(); - r = sd_bus_call_method( - h->manager->bus, - "org.freedesktop.systemd1", - "/org/freedesktop/systemd1", - "org.freedesktop.systemd1.Manager", - "KillUnit", - &error, - NULL, - "ssi", unit, "all", SIGKILL); + r = bus_call_method(h->manager->bus, bus_systemd_mgr, "KillUnit", &error, NULL, "ssi", unit, "all", SIGKILL); if (r < 0) log_full_errno(sd_bus_error_has_name(&error, BUS_ERROR_NO_SUCH_UNIT) ? LOG_DEBUG : LOG_WARNING, r, "Failed to kill login processes of user, ignoring: %s", bus_error_message(&error, r)); diff --git a/src/hostname/hostnamectl.c b/src/hostname/hostnamectl.c index a0e949d82c7..8d3cca5c621 100644 --- a/src/hostname/hostnamectl.c +++ b/src/hostname/hostnamectl.c @@ -15,6 +15,7 @@ #include "build.h" #include "bus-common-errors.h" #include "bus-error.h" +#include "bus-locator.h" #include "bus-map-properties.h" #include "format-table.h" #include "hostname-setup.h" @@ -298,13 +299,7 @@ static int get_one_name(sd_bus *bus, const char* attr, char **ret) { /* This obtains one string property, and copy it if 'ret' is set, or print it otherwise. */ - r = sd_bus_get_property( - bus, - "org.freedesktop.hostname1", - "/org/freedesktop/hostname1", - "org.freedesktop.hostname1", - attr, - &error, &reply, "s"); + r = bus_get_property(bus, bus_hostname, attr, &error, &reply, "s"); if (r < 0) return log_error_errno(r, "Could not get property: %s", bus_error_message(&error, r)); @@ -408,15 +403,7 @@ static int show_status(int argc, char **argv, void *userdata) { _cleanup_(json_variant_unrefp) JsonVariant *v = NULL; const char *text = NULL; - r = sd_bus_call_method( - bus, - "org.freedesktop.hostname1", - "/org/freedesktop/hostname1", - "org.freedesktop.hostname1", - "Describe", - &error, - &reply, - NULL); + r = bus_call_method(bus, bus_hostname, "Describe", &error, &reply, NULL); if (r < 0) return log_error_errno(r, "Could not get description: %s", bus_error_message(&error, r)); @@ -448,14 +435,7 @@ static int set_simple_string_internal(sd_bus *bus, sd_bus_error *error, const ch if (!error) error = &e; - r = sd_bus_call_method( - bus, - "org.freedesktop.hostname1", - "/org/freedesktop/hostname1", - "org.freedesktop.hostname1", - method, - error, NULL, - "sb", value, arg_ask_password); + r = bus_call_method(bus, bus_hostname, method, error, NULL, "sb", value, arg_ask_password); if (r < 0) return log_error_errno(r, "Could not set %s: %s", target, bus_error_message(error, r)); diff --git a/src/journal-remote/journal-gatewayd.c b/src/journal-remote/journal-gatewayd.c index b6e8469922f..4b4eec01855 100644 --- a/src/journal-remote/journal-gatewayd.c +++ b/src/journal-remote/journal-gatewayd.c @@ -15,6 +15,7 @@ #include "alloc-util.h" #include "build.h" +#include "bus-locator.h" #include "bus-util.h" #include "errno-util.h" #include "fd-util.h" @@ -704,14 +705,7 @@ static int get_virtualization(char **v) { if (r < 0) return r; - r = sd_bus_get_property_string( - bus, - "org.freedesktop.systemd1", - "/org/freedesktop/systemd1", - "org.freedesktop.systemd1.Manager", - "Virtualization", - NULL, - &b); + r = bus_get_property_string(bus, bus_systemd_mgr, "Virtualization", NULL, &b); if (r < 0) return r; diff --git a/src/journal/journalctl.c b/src/journal/journalctl.c index b0b95311f1c..5f3a121ac9f 100644 --- a/src/journal/journalctl.c +++ b/src/journal/journalctl.c @@ -21,6 +21,7 @@ #include "alloc-util.h" #include "build.h" #include "bus-error.h" +#include "bus-locator.h" #include "bus-util.h" #include "catalog.h" #include "chase.h" @@ -2246,15 +2247,7 @@ static int run(int argc, char *argv[]) { if (r < 0) return log_error_errno(r, "Failed to open system bus: %m"); - r = sd_bus_call_method( - bus, - "org.freedesktop.machine1", - "/org/freedesktop/machine1", - "org.freedesktop.machine1.Manager", - "OpenMachineRootDirectory", - &error, - &reply, - "s", arg_machine); + r = bus_call_method(bus, bus_machine_mgr, "OpenMachineRootDirectory", &error, &reply, "s", arg_machine); if (r < 0) return log_error_errno(r, "Failed to open root directory: %s", bus_error_message(&error, r)); diff --git a/src/login/inhibit.c b/src/login/inhibit.c index 25ba848492d..75dba8c08f5 100644 --- a/src/login/inhibit.c +++ b/src/login/inhibit.c @@ -11,6 +11,7 @@ #include "alloc-util.h" #include "build.h" #include "bus-error.h" +#include "bus-locator.h" #include "bus-util.h" #include "fd-util.h" #include "format-table.h" @@ -41,15 +42,7 @@ static int inhibit(sd_bus *bus, sd_bus_error *error) { int r; int fd; - r = sd_bus_call_method( - bus, - "org.freedesktop.login1", - "/org/freedesktop/login1", - "org.freedesktop.login1.Manager", - "Inhibit", - error, - &reply, - "ssss", arg_what, arg_who, arg_why, arg_mode); + r = bus_call_method(bus, bus_login_mgr, "Inhibit", error, &reply, "ssss", arg_what, arg_who, arg_why, arg_mode); if (r < 0) return r; @@ -68,15 +61,7 @@ static int print_inhibitors(sd_bus *bus) { pager_open(arg_pager_flags); - r = sd_bus_call_method( - bus, - "org.freedesktop.login1", - "/org/freedesktop/login1", - "org.freedesktop.login1.Manager", - "ListInhibitors", - &error, - &reply, - ""); + r = bus_call_method(bus, bus_login_mgr, "ListInhibitors", &error, &reply, NULL); if (r < 0) return log_error_errno(r, "Could not get active inhibitors: %s", bus_error_message(&error, r)); diff --git a/src/login/loginctl.c b/src/login/loginctl.c index dfc738c6d02..29fc14b5718 100644 --- a/src/login/loginctl.c +++ b/src/login/loginctl.c @@ -917,14 +917,7 @@ static int show_user(int argc, char *argv[], void *userdata) { if (r < 0) return log_error_errno(r, "Failed to look up user %s: %m", argv[i]); - r = sd_bus_call_method( - bus, - "org.freedesktop.login1", - "/org/freedesktop/login1", - "org.freedesktop.login1.Manager", - "GetUser", - &error, &reply, - "u", (uint32_t) uid); + r = bus_call_method(bus, bus_login_mgr, "GetUser", &error, &reply, "u", (uint32_t) uid); if (r < 0) return log_error_errno(r, "Failed to get user: %s", bus_error_message(&error, r)); diff --git a/src/login/logind-user.c b/src/login/logind-user.c index 3920467f444..6161af9a745 100644 --- a/src/login/logind-user.c +++ b/src/login/logind-user.c @@ -6,6 +6,7 @@ #include "alloc-util.h" #include "bus-common-errors.h" #include "bus-error.h" +#include "bus-locator.h" #include "bus-util.h" #include "cgroup-util.h" #include "clean-ipc.h" @@ -388,13 +389,7 @@ static int user_update_slice(User *u) { u->user_record->io_weight == UINT64_MAX) return 0; - r = sd_bus_message_new_method_call( - u->manager->bus, - &m, - "org.freedesktop.systemd1", - "/org/freedesktop/systemd1", - "org.freedesktop.systemd1.Manager", - "SetUnitProperties"); + r = bus_message_new_method_call(u->manager->bus, &m, bus_systemd_mgr, "SetUnitProperties"); if (r < 0) return bus_log_create_error(r); diff --git a/src/login/test-inhibit.c b/src/login/test-inhibit.c index aefae277fc0..f59cca8fed7 100644 --- a/src/login/test-inhibit.c +++ b/src/login/test-inhibit.c @@ -5,6 +5,7 @@ #include "sd-bus.h" +#include "bus-locator.h" #include "bus-util.h" #include "fd-util.h" #include "macro.h" @@ -16,14 +17,7 @@ static int inhibit(sd_bus *bus, const char *what) { int fd; int r; - r = sd_bus_call_method(bus, - "org.freedesktop.login1", - "/org/freedesktop/login1", - "org.freedesktop.login1.Manager", - "Inhibit", - &error, - &reply, - "ssss", what, who, reason, mode); + r = bus_call_method(bus, bus_login_mgr, "Inhibit", &error, &reply, "ssss", what, who, reason, mode); assert_se(r >= 0); r = sd_bus_message_read_basic(reply, SD_BUS_TYPE_UNIX_FD, &fd); @@ -41,14 +35,7 @@ static void print_inhibitors(sd_bus *bus) { unsigned n = 0; int r; - r = sd_bus_call_method(bus, - "org.freedesktop.login1", - "/org/freedesktop/login1", - "org.freedesktop.login1.Manager", - "ListInhibitors", - &error, - &reply, - ""); + r = bus_call_method(bus, bus_login_mgr, "ListInhibitors", &error, &reply, NULL); assert_se(r >= 0); r = sd_bus_message_enter_container(reply, SD_BUS_TYPE_ARRAY, "(ssssuu)"); diff --git a/src/login/test-session-properties.c b/src/login/test-session-properties.c index 48aa21abef2..b5b5f60eaaa 100644 --- a/src/login/test-session-properties.c +++ b/src/login/test-session-properties.c @@ -57,7 +57,7 @@ TEST(set_type) { /* Type is reset to the original value when we release control of the session */ assert_se(!streq(type, "tty")); - assert_se(bus_call_method(bus, &session, "ReleaseControl", NULL, NULL, "") >= 0); + assert_se(bus_call_method(bus, &session, "ReleaseControl", NULL, NULL, NULL) >= 0); type = mfree(type); assert_se(bus_get_property_string(bus, &session, "Type", NULL, &type) >= 0); assert_se(streq(type, "tty")); diff --git a/src/login/user-runtime-dir.c b/src/login/user-runtime-dir.c index f96a2d86623..5a16d1684d7 100644 --- a/src/login/user-runtime-dir.c +++ b/src/login/user-runtime-dir.c @@ -6,6 +6,7 @@ #include "sd-bus.h" #include "bus-error.h" +#include "bus-locator.h" #include "dev-setup.h" #include "format-util.h" #include "fs-util.h" @@ -33,13 +34,13 @@ static int acquire_runtime_dir_properties(uint64_t *size, uint64_t *inodes) { if (r < 0) return log_error_errno(r, "Failed to connect to system bus: %m"); - r = sd_bus_get_property_trivial(bus, "org.freedesktop.login1", "/org/freedesktop/login1", "org.freedesktop.login1.Manager", "RuntimeDirectorySize", &error, 't', size); + r = bus_get_property_trivial(bus, bus_login_mgr, "RuntimeDirectorySize", &error, 't', size); if (r < 0) { log_warning_errno(r, "Failed to acquire runtime directory size, ignoring: %s", bus_error_message(&error, r)); *size = physical_memory_scale(10U, 100U); /* 10% */ } - r = sd_bus_get_property_trivial(bus, "org.freedesktop.login1", "/org/freedesktop/login1", "org.freedesktop.login1.Manager", "RuntimeDirectoryInodesMax", &error, 't', inodes); + r = bus_get_property_trivial(bus, bus_login_mgr, "RuntimeDirectoryInodesMax", &error, 't', inodes); if (r < 0) { log_warning_errno(r, "Failed to acquire number of inodes for runtime directory, ignoring: %s", bus_error_message(&error, r)); *inodes = DIV_ROUND_UP(*size, 4096); diff --git a/src/network/networkd-manager.c b/src/network/networkd-manager.c index aae619a0a8b..303b76c0c69 100644 --- a/src/network/networkd-manager.c +++ b/src/network/networkd-manager.c @@ -148,12 +148,10 @@ static int manager_connect_bus(Manager *m) { if (r < 0) return log_error_errno(r, "Failed to request match on Connected signal: %m"); - r = sd_bus_match_signal_async( + r = bus_match_signal_async( m->bus, NULL, - "org.freedesktop.login1", - "/org/freedesktop/login1", - "org.freedesktop.login1.Manager", + bus_login_mgr, "PrepareForSleep", match_prepare_for_sleep, NULL, m); if (r < 0) diff --git a/src/nspawn/nspawn.c b/src/nspawn/nspawn.c index 5d49e05064c..74b15dcb44a 100644 --- a/src/nspawn/nspawn.c +++ b/src/nspawn/nspawn.c @@ -30,6 +30,7 @@ #include "btrfs-util.h" #include "build.h" #include "bus-error.h" +#include "bus-locator.h" #include "bus-util.h" #include "cap-list.h" #include "capability-util.h" @@ -2092,13 +2093,7 @@ static int resolved_listening(void) { if (r == 0) return 0; - r = sd_bus_get_property_string(bus, - "org.freedesktop.resolve1", - "/org/freedesktop/resolve1", - "org.freedesktop.resolve1.Manager", - "DNSStubListener", - &error, - &dns_stub_listener_mode); + r = bus_get_property_string(bus, bus_resolve_mgr, "DNSStubListener", &error, &dns_stub_listener_mode); if (r < 0) return log_debug_errno(r, "Failed to query DNSStubListener property: %s", bus_error_message(&error, r)); diff --git a/src/oom/oomctl.c b/src/oom/oomctl.c index d18f9998410..eb15f508de0 100644 --- a/src/oom/oomctl.c +++ b/src/oom/oomctl.c @@ -5,6 +5,7 @@ #include "build.h" #include "bus-error.h" +#include "bus-locator.h" #include "copy.h" #include "main-func.h" #include "pretty-print.h" @@ -55,15 +56,7 @@ static int dump_state(int argc, char *argv[], void *userdata) { pager_open(arg_pager_flags); - r = sd_bus_call_method( - bus, - "org.freedesktop.oom1", - "/org/freedesktop/oom1", - "org.freedesktop.oom1.Manager", - "DumpByFileDescriptor", - &error, - &reply, - NULL); + r = bus_call_method(bus, bus_oom_mgr, "DumpByFileDescriptor", &error, &reply, NULL); if (r < 0) return log_error_errno(r, "Failed to dump context: %s", bus_error_message(&error, r)); diff --git a/src/portable/portable.c b/src/portable/portable.c index e5f2f38a211..7ab3ac6e975 100644 --- a/src/portable/portable.c +++ b/src/portable/portable.c @@ -4,6 +4,7 @@ #include "bus-common-errors.h" #include "bus-error.h" +#include "bus-locator.h" #include "chase.h" #include "conf-files.h" #include "copy.h" @@ -780,13 +781,7 @@ static int unit_file_is_active( _cleanup_(sd_bus_message_unrefp) sd_bus_message *m = NULL, *reply = NULL; const char *at, *prefix, *joined; - r = sd_bus_message_new_method_call( - bus, - &m, - "org.freedesktop.systemd1", - "/org/freedesktop/systemd1", - "org.freedesktop.systemd1.Manager", - "ListUnitsByPatterns"); + r = bus_message_new_method_call(bus, &m, bus_systemd_mgr, "ListUnitsByPatterns"); if (r < 0) return r; diff --git a/src/portable/portablectl.c b/src/portable/portablectl.c index eec9c63d0b8..39f17a8de7b 100644 --- a/src/portable/portablectl.c +++ b/src/portable/portablectl.c @@ -242,13 +242,7 @@ static int maybe_reload(sd_bus **bus) { if (r < 0) return r; - r = sd_bus_message_new_method_call( - *bus, - &m, - "org.freedesktop.systemd1", - "/org/freedesktop/systemd1", - "org.freedesktop.systemd1.Manager", - "Reload"); + r = bus_message_new_method_call(*bus, &m, bus_systemd_mgr, "Reload"); if (r < 0) return bus_log_create_error(r); @@ -566,12 +560,10 @@ static int maybe_enable_disable(sd_bus *bus, const char *path, bool enable) { if (!names) return log_oom(); - r = sd_bus_message_new_method_call( + r = bus_message_new_method_call( bus, &m, - "org.freedesktop.systemd1", - "/org/freedesktop/systemd1", - "org.freedesktop.systemd1.Manager", + bus_systemd_mgr, enable ? "EnableUnitFilesWithFlags" : "DisableUnitFilesWithFlags"); if (r < 0) return bus_log_create_error(r); diff --git a/src/resolve/resolved-bus.c b/src/resolve/resolved-bus.c index 1c1e5bc3aad..12d0d28babb 100644 --- a/src/resolve/resolved-bus.c +++ b/src/resolve/resolved-bus.c @@ -3,6 +3,7 @@ #include "alloc-util.h" #include "bus-common-errors.h" #include "bus-get-properties.h" +#include "bus-locator.h" #include "bus-log-control-api.h" #include "bus-message-util.h" #include "bus-polkit.h" @@ -2282,12 +2283,10 @@ int manager_connect_bus(Manager *m) { if (r < 0) return log_error_errno(r, "Failed to attach bus to event loop: %m"); - r = sd_bus_match_signal_async( + r = bus_match_signal_async( m->bus, NULL, - "org.freedesktop.login1", - "/org/freedesktop/login1", - "org.freedesktop.login1.Manager", + bus_login_mgr, "PrepareForSleep", match_prepare_for_sleep, NULL, diff --git a/src/resolve/test-dnssec-complex.c b/src/resolve/test-dnssec-complex.c index d8aeb7061f9..976d197bb49 100644 --- a/src/resolve/test-dnssec-complex.c +++ b/src/resolve/test-dnssec-complex.c @@ -7,6 +7,7 @@ #include "af-list.h" #include "alloc-util.h" #include "bus-common-errors.h" +#include "bus-locator.h" #include "dns-type.h" #include "random-util.h" #include "resolved-def.h" @@ -46,13 +47,7 @@ static void test_rr_lookup(sd_bus *bus, const char *name, uint16_t type, const c name = m; } - assert_se(sd_bus_message_new_method_call( - bus, - &req, - "org.freedesktop.resolve1", - "/org/freedesktop/resolve1", - "org.freedesktop.resolve1.Manager", - "ResolveRecord") >= 0); + assert_se(bus_message_new_method_call(bus, &req, bus_resolve_mgr, "ResolveRecord") >= 0); assert_se(sd_bus_message_append(req, "isqqt", 0, name, DNS_CLASS_IN, type, UINT64_C(0)) >= 0); @@ -83,13 +78,7 @@ static void test_hostname_lookup(sd_bus *bus, const char *name, int family, cons name = m; } - assert_se(sd_bus_message_new_method_call( - bus, - &req, - "org.freedesktop.resolve1", - "/org/freedesktop/resolve1", - "org.freedesktop.resolve1.Manager", - "ResolveHostname") >= 0); + assert_se(bus_message_new_method_call(bus, &req, bus_resolve_mgr, "ResolveHostname") >= 0); assert_se(sd_bus_message_append(req, "isit", 0, name, family, UINT64_C(0)) >= 0); diff --git a/src/shared/bus-locator.c b/src/shared/bus-locator.c index 5b9a6dbc438..ff7a872bdb3 100644 --- a/src/shared/bus-locator.c +++ b/src/shared/bus-locator.c @@ -39,6 +39,12 @@ const BusLocator* const bus_network_mgr = &(BusLocator){ .interface = "org.freedesktop.network1.Manager" }; +const BusLocator* const bus_oom_mgr = &(BusLocator){ + .destination = "org.freedesktop.oom1", + .path = "/org/freedesktop/oom1", + .interface = "org.freedesktop.oom1.Manager" +}; + const BusLocator* const bus_portable_mgr = &(BusLocator){ .destination = "org.freedesktop.portable1", .path = "/org/freedesktop/portable1", @@ -63,6 +69,12 @@ const BusLocator* const bus_timedate = &(BusLocator){ .interface = "org.freedesktop.timedate1" }; +const BusLocator* const bus_timesync_mgr = &(BusLocator){ + .destination = "org.freedesktop.timesync1", + .path = "/org/freedesktop/timesync1", + .interface = "org.freedesktop.timesync1.Manager" +}; + const BusLocator* const bus_hostname = &(BusLocator){ .destination = "org.freedesktop.hostname1", .path = "/org/freedesktop/hostname1", diff --git a/src/shared/bus-locator.h b/src/shared/bus-locator.h index 9662c906e18..4f50a9727f5 100644 --- a/src/shared/bus-locator.h +++ b/src/shared/bus-locator.h @@ -10,16 +10,18 @@ typedef struct BusLocator { } BusLocator; extern const BusLocator* const bus_home_mgr; +extern const BusLocator* const bus_hostname; extern const BusLocator* const bus_import_mgr; extern const BusLocator* const bus_locale; extern const BusLocator* const bus_login_mgr; extern const BusLocator* const bus_machine_mgr; extern const BusLocator* const bus_network_mgr; +extern const BusLocator* const bus_oom_mgr; extern const BusLocator* const bus_portable_mgr; extern const BusLocator* const bus_resolve_mgr; extern const BusLocator* const bus_systemd_mgr; extern const BusLocator* const bus_timedate; -extern const BusLocator* const bus_hostname; +extern const BusLocator* const bus_timesync_mgr; /* Shorthand flavors of the sd-bus convenience helpers with destination,path,interface strings encapsulated * within a single struct. */ diff --git a/src/sleep/sleep.c b/src/sleep/sleep.c index a8a451ee1a8..a9445c1a619 100644 --- a/src/sleep/sleep.c +++ b/src/sleep/sleep.c @@ -147,13 +147,7 @@ static int lock_all_homes(void) { if (r < 0) return log_warning_errno(r, "Failed to connect to system bus, ignoring: %m"); - r = sd_bus_message_new_method_call( - bus, - &m, - "org.freedesktop.home1", - "/org/freedesktop/home1", - "org.freedesktop.home1.Manager", - "LockAllHomes"); + r = bus_message_new_method_call(bus, &m, bus_home_mgr, "LockAllHomes"); if (r < 0) return bus_log_create_error(r); diff --git a/src/update-utmp/update-utmp.c b/src/update-utmp/update-utmp.c index 7449a2321c5..4996272eb3a 100644 --- a/src/update-utmp/update-utmp.c +++ b/src/update-utmp/update-utmp.c @@ -13,6 +13,7 @@ #include "alloc-util.h" #include "bus-error.h" +#include "bus-locator.h" #include "bus-util.h" #include "format-util.h" #include "log.h" @@ -50,14 +51,7 @@ static usec_t get_startup_monotonic_time(Context *c) { assert(c); - r = sd_bus_get_property_trivial( - c->bus, - "org.freedesktop.systemd1", - "/org/freedesktop/systemd1", - "org.freedesktop.systemd1.Manager", - "UserspaceTimestampMonotonic", - &error, - 't', &t); + r = bus_get_property_trivial(c->bus, bus_systemd_mgr, "UserspaceTimestampMonotonic", &error, 't', &t); if (r < 0) { log_error_errno(r, "Failed to get timestamp: %s", bus_error_message(&error, r)); return 0;