timedate: switch to BusLocator-oriented helpers

Mechanical substitution reducing some verbosity
This commit is contained in:
Vito Caputo 2020-05-03 00:03:16 -07:00
parent 8010c205dd
commit 43fe4f7613
2 changed files with 29 additions and 90 deletions

View file

@ -239,14 +239,13 @@ static int set_time(int argc, char **argv, void *userdata) {
if (r < 0) if (r < 0)
return log_error_errno(r, "Failed to parse time specification '%s': %m", argv[1]); return log_error_errno(r, "Failed to parse time specification '%s': %m", argv[1]);
r = sd_bus_call_method(bus, r = bus_call_method(
"org.freedesktop.timedate1", bus,
"/org/freedesktop/timedate1", bus_timedate,
"org.freedesktop.timedate1", "SetTime",
"SetTime", &error,
&error, NULL,
NULL, "xbb", (int64_t) t, relative, interactive);
"xbb", (int64_t) t, relative, interactive);
if (r < 0) if (r < 0)
return log_error_errno(r, "Failed to set time: %s", bus_error_message(&error, r)); return log_error_errno(r, "Failed to set time: %s", bus_error_message(&error, r));
@ -260,14 +259,7 @@ static int set_timezone(int argc, char **argv, void *userdata) {
polkit_agent_open_if_enabled(arg_transport, arg_ask_password); polkit_agent_open_if_enabled(arg_transport, arg_ask_password);
r = sd_bus_call_method(bus, r = bus_call_method(bus, bus_timedate, "SetTimezone", &error, NULL, "sb", argv[1], arg_ask_password);
"org.freedesktop.timedate1",
"/org/freedesktop/timedate1",
"org.freedesktop.timedate1",
"SetTimezone",
&error,
NULL,
"sb", argv[1], arg_ask_password);
if (r < 0) if (r < 0)
return log_error_errno(r, "Failed to set time zone: %s", bus_error_message(&error, r)); return log_error_errno(r, "Failed to set time zone: %s", bus_error_message(&error, r));
@ -285,14 +277,13 @@ static int set_local_rtc(int argc, char **argv, void *userdata) {
if (b < 0) if (b < 0)
return log_error_errno(b, "Failed to parse local RTC setting '%s': %m", argv[1]); return log_error_errno(b, "Failed to parse local RTC setting '%s': %m", argv[1]);
r = sd_bus_call_method(bus, r = bus_call_method(
"org.freedesktop.timedate1", bus,
"/org/freedesktop/timedate1", bus_timedate,
"org.freedesktop.timedate1", "SetLocalRTC",
"SetLocalRTC", &error,
&error, NULL,
NULL, "bbb", b, arg_adjust_system_clock, arg_ask_password);
"bbb", b, arg_adjust_system_clock, arg_ask_password);
if (r < 0) if (r < 0)
return log_error_errno(r, "Failed to set local RTC: %s", bus_error_message(&error, r)); return log_error_errno(r, "Failed to set local RTC: %s", bus_error_message(&error, r));
@ -310,14 +301,7 @@ static int set_ntp(int argc, char **argv, void *userdata) {
if (b < 0) if (b < 0)
return log_error_errno(b, "Failed to parse NTP setting '%s': %m", argv[1]); return log_error_errno(b, "Failed to parse NTP setting '%s': %m", argv[1]);
r = sd_bus_call_method(bus, r = bus_call_method(bus, bus_timedate, "SetNTP", &error, NULL, "bb", b, arg_ask_password);
"org.freedesktop.timedate1",
"/org/freedesktop/timedate1",
"org.freedesktop.timedate1",
"SetNTP",
&error,
NULL,
"bb", b, arg_ask_password);
if (r < 0) if (r < 0)
return log_error_errno(r, "Failed to set ntp: %s", bus_error_message(&error, r)); return log_error_errno(r, "Failed to set ntp: %s", bus_error_message(&error, r));
@ -331,14 +315,7 @@ static int list_timezones(int argc, char **argv, void *userdata) {
int r; int r;
char** zones; char** zones;
r = sd_bus_call_method(bus, r = bus_call_method(bus, bus_timedate, "ListTimezones", &error, &reply, NULL);
"org.freedesktop.timedate1",
"/org/freedesktop/timedate1",
"org.freedesktop.timedate1",
"ListTimezones",
&error,
&reply,
NULL);
if (r < 0) if (r < 0)
return log_error_errno(r, "Failed to request list of time zones: %s", return log_error_errno(r, "Failed to request list of time zones: %s",
bus_error_message(&error, r)); bus_error_message(&error, r));
@ -843,15 +820,7 @@ static int parse_ifindex_bus(sd_bus *bus, const char *str) {
return r; return r;
assert(r < 0); assert(r < 0);
r = sd_bus_call_method( r = bus_call_method(bus, bus_network_mgr, "GetLinkByName", &error, &reply, "s", str);
bus,
"org.freedesktop.network1",
"/org/freedesktop/network1",
"org.freedesktop.network1.Manager",
"GetLinkByName",
&error,
&reply,
"s", str);
if (r < 0) if (r < 0)
return log_error_errno(r, "Failed to get ifindex of interfaces %s: %s", str, bus_error_message(&error, r)); return log_error_errno(r, "Failed to get ifindex of interfaces %s: %s", str, bus_error_message(&error, r));
@ -876,13 +845,7 @@ static int verb_ntp_servers(int argc, char **argv, void *userdata) {
polkit_agent_open_if_enabled(arg_transport, arg_ask_password); polkit_agent_open_if_enabled(arg_transport, arg_ask_password);
r = sd_bus_message_new_method_call( r = bus_message_new_method_call(bus, &req, bus_network_mgr, "SetLinkNTP");
bus,
&req,
"org.freedesktop.network1",
"/org/freedesktop/network1",
"org.freedesktop.network1.Manager",
"SetLinkNTP");
if (r < 0) if (r < 0)
return bus_log_create_error(r); return bus_log_create_error(r);
@ -914,15 +877,7 @@ static int verb_revert(int argc, char **argv, void *userdata) {
polkit_agent_open_if_enabled(arg_transport, arg_ask_password); polkit_agent_open_if_enabled(arg_transport, arg_ask_password);
r = sd_bus_call_method( r = bus_call_method(bus, bus_network_mgr, "RevertLinkNTP", &error, NULL, "i", ifindex);
bus,
"org.freedesktop.network1",
"/org/freedesktop/network1",
"org.freedesktop.network1.Manager",
"RevertLinkNTP",
&error,
NULL,
"i", ifindex);
if (r < 0) if (r < 0)
return log_error_errno(r, "Failed to revert interface configuration: %s", bus_error_message(&error, r)); return log_error_errno(r, "Failed to revert interface configuration: %s", bus_error_message(&error, r));

View file

@ -471,11 +471,9 @@ static int unit_start_or_stop(UnitStatusInfo *u, sd_bus *bus, sd_bus_error *erro
assert(bus); assert(bus);
assert(error); assert(error);
r = sd_bus_call_method( r = bus_call_method(
bus, bus,
"org.freedesktop.systemd1", bus_systemd_mgr,
"/org/freedesktop/systemd1",
"org.freedesktop.systemd1.Manager",
start ? "StartUnit" : "StopUnit", start ? "StartUnit" : "StopUnit",
error, error,
&reply, &reply,
@ -515,11 +513,9 @@ static int unit_enable_or_disable(UnitStatusInfo *u, sd_bus *bus, sd_bus_error *
log_unit_info(u, "%s unit.", enable ? "Enabling" : "Disabling"); log_unit_info(u, "%s unit.", enable ? "Enabling" : "Disabling");
if (enable) if (enable)
r = sd_bus_call_method( r = bus_call_method(
bus, bus,
"org.freedesktop.systemd1", bus_systemd_mgr,
"/org/freedesktop/systemd1",
"org.freedesktop.systemd1.Manager",
"EnableUnitFiles", "EnableUnitFiles",
error, error,
NULL, NULL,
@ -527,11 +523,9 @@ static int unit_enable_or_disable(UnitStatusInfo *u, sd_bus *bus, sd_bus_error *
u->name, u->name,
false, true); false, true);
else else
r = sd_bus_call_method( r = bus_call_method(
bus, bus,
"org.freedesktop.systemd1", bus_systemd_mgr,
"/org/freedesktop/systemd1",
"org.freedesktop.systemd1.Manager",
"DisableUnitFiles", "DisableUnitFiles",
error, error,
NULL, NULL,
@ -541,15 +535,7 @@ static int unit_enable_or_disable(UnitStatusInfo *u, sd_bus *bus, sd_bus_error *
if (r < 0) if (r < 0)
return r; return r;
r = sd_bus_call_method( r = bus_call_method(bus, bus_systemd_mgr, "Reload", error, NULL, NULL);
bus,
"org.freedesktop.systemd1",
"/org/freedesktop/systemd1",
"org.freedesktop.systemd1.Manager",
"Reload",
error,
NULL,
NULL);
if (r < 0) if (r < 0)
return r; return r;
@ -952,12 +938,10 @@ static int method_set_ntp(sd_bus_message *m, void *userdata, sd_bus_error *error
u->path = mfree(u->path); u->path = mfree(u->path);
if (!c->slot_job_removed) { if (!c->slot_job_removed) {
r = sd_bus_match_signal_async( r = bus_match_signal_async(
bus, bus,
&slot, &slot,
"org.freedesktop.systemd1", bus_systemd_mgr,
"/org/freedesktop/systemd1",
"org.freedesktop.systemd1.Manager",
"JobRemoved", "JobRemoved",
match_job_removed, NULL, c); match_job_removed, NULL, c);
if (r < 0) if (r < 0)