#include "sd-bus.h"
#include "bus-error.h"
-#include "bus-util.h"
+#include "bus-locator.h"
+#include "bus-map-properties.h"
+#include "bus-print-properties.h"
#include "format-table.h"
#include "in-addr-util.h"
#include "main-func.h"
#include "pager.h"
#include "parse-util.h"
#include "pretty-print.h"
-#include "spawn-polkit-agent.h"
#include "sparse-endian.h"
+#include "spawn-polkit-agent.h"
#include "string-table.h"
#include "strv.h"
#include "terminal-util.h"
TABLE_STRING, "Local time:",
TABLE_STRING, have_time && n > 0 ? a : "n/a");
if (r < 0)
- return log_error_errno(r, "Failed to add cell(s): %m");
+ return table_log_add_error(r);
if (have_time)
n = strftime(a, sizeof a, "%a %Y-%m-%d %H:%M:%S UTC", gmtime_r(&sec, &tm));
TABLE_STRING, "Universal time:",
TABLE_STRING, have_time && n > 0 ? a : "n/a");
if (r < 0)
- return log_error_errno(r, "Failed to add cell(s): %m");
+ return table_log_add_error(r);
if (i->rtc_time > 0) {
time_t rtc_sec;
TABLE_STRING, "RTC time:",
TABLE_STRING, i->rtc_time > 0 && n > 0 ? a : "n/a");
if (r < 0)
- return log_error_errno(r, "Failed to add cell(s): %m");
+ return table_log_add_error(r);
if (have_time)
n = strftime(a, sizeof a, "%Z, %z", localtime_r(&sec, &tm));
r = table_add_cell(table, NULL, TABLE_STRING, "Time zone:");
if (r < 0)
- return log_error_errno(r, "Failed to add cell(s): %m");
+ return table_log_add_error(r);
r = table_add_cell_stringf(table, NULL, "%s (%s)", strna(i->timezone), have_time && n > 0 ? a : "n/a");
if (r < 0)
- return log_error_errno(r, "Failed to add cell(s): %m");
+ return table_log_add_error(r);
/* Restore the $TZ */
TABLE_STRING, "RTC in local TZ:",
TABLE_BOOLEAN, i->rtc_local);
if (r < 0)
- return log_error_errno(r, "Failed to add cell(s): %m");
+ return table_log_add_error(r);
r = table_print(table, NULL);
if (r < 0)
- return log_error_errno(r, "Failed to show table: %m");
+ return table_log_print_error(r);
if (i->rtc_local)
printf("\n%s"
if (r < 0)
return log_error_errno(r, "Failed to parse time specification '%s': %m", argv[1]);
- r = sd_bus_call_method(bus,
- "org.freedesktop.timedate1",
- "/org/freedesktop/timedate1",
- "org.freedesktop.timedate1",
- "SetTime",
- &error,
- NULL,
- "xbb", (int64_t) t, relative, interactive);
+ r = bus_call_method(
+ bus,
+ bus_timedate,
+ "SetTime",
+ &error,
+ NULL,
+ "xbb", (int64_t) t, relative, interactive);
if (r < 0)
return log_error_errno(r, "Failed to set time: %s", bus_error_message(&error, r));
polkit_agent_open_if_enabled(arg_transport, arg_ask_password);
- r = sd_bus_call_method(bus,
- "org.freedesktop.timedate1",
- "/org/freedesktop/timedate1",
- "org.freedesktop.timedate1",
- "SetTimezone",
- &error,
- NULL,
- "sb", argv[1], arg_ask_password);
+ r = bus_call_method(bus, bus_timedate, "SetTimezone", &error, NULL, "sb", argv[1], arg_ask_password);
if (r < 0)
return log_error_errno(r, "Failed to set time zone: %s", bus_error_message(&error, r));
if (b < 0)
return log_error_errno(b, "Failed to parse local RTC setting '%s': %m", argv[1]);
- r = sd_bus_call_method(bus,
- "org.freedesktop.timedate1",
- "/org/freedesktop/timedate1",
- "org.freedesktop.timedate1",
- "SetLocalRTC",
- &error,
- NULL,
- "bbb", b, arg_adjust_system_clock, arg_ask_password);
+ r = bus_call_method(
+ bus,
+ bus_timedate,
+ "SetLocalRTC",
+ &error,
+ NULL,
+ "bbb", b, arg_adjust_system_clock, arg_ask_password);
if (r < 0)
return log_error_errno(r, "Failed to set local RTC: %s", bus_error_message(&error, r));
if (b < 0)
return log_error_errno(b, "Failed to parse NTP setting '%s': %m", argv[1]);
- r = sd_bus_call_method(bus,
- "org.freedesktop.timedate1",
- "/org/freedesktop/timedate1",
- "org.freedesktop.timedate1",
- "SetNTP",
- &error,
- NULL,
- "bb", b, arg_ask_password);
+ r = bus_call_method(bus, bus_timedate, "SetNTP", &error, NULL, "bb", b, arg_ask_password);
if (r < 0)
return log_error_errno(r, "Failed to set ntp: %s", bus_error_message(&error, r));
int r;
char** zones;
- r = sd_bus_call_method(bus,
- "org.freedesktop.timedate1",
- "/org/freedesktop/timedate1",
- "org.freedesktop.timedate1",
- "ListTimezones",
- &error,
- &reply,
- NULL);
+ r = bus_call_method(bus, bus_timedate, "ListTimezones", &error, &reply, NULL);
if (r < 0)
return log_error_errno(r, "Failed to request list of time zones: %s",
bus_error_message(&error, r));
[3] = "not synchronized",
};
-#pragma GCC diagnostic push
-#pragma GCC diagnostic ignored "-Wtype-limits"
+DISABLE_WARNING_TYPE_LIMITS;
DEFINE_PRIVATE_STRING_TABLE_LOOKUP_TO_STRING(ntp_leap, uint32_t);
-#pragma GCC diagnostic pop
+REENABLE_WARNING;
static int print_ntp_status_info(NTPStatusInfo *i) {
char ts[FORMAT_TIMESPAN_MAX], jitter[FORMAT_TIMESPAN_MAX],
r = table_add_cell(table, NULL, TABLE_STRING, "Server:");
if (r < 0)
- return log_error_errno(r, "Failed to add cell(s): %m");
+ return table_log_add_error(r);
r = table_add_cell_stringf(table, NULL, "%s (%s)", i->server_address, i->server_name);
if (r < 0)
- return log_error_errno(r, "Failed to add cell(s): %m");
+ return table_log_add_error(r);
r = table_add_cell(table, NULL, TABLE_STRING, "Poll interval:");
if (r < 0)
- return log_error_errno(r, "Failed to add cell(s): %m");
+ return table_log_add_error(r);
r = table_add_cell_stringf(table, NULL, "%s (min: %s; max %s)",
format_timespan(ts, sizeof(ts), i->poll_interval, 0),
format_timespan(tmin, sizeof(tmin), i->poll_min, 0),
format_timespan(tmax, sizeof(tmax), i->poll_max, 0));
if (r < 0)
- return log_error_errno(r, "Failed to add cell(s): %m");
+ return table_log_add_error(r);
if (i->packet_count == 0) {
r = table_add_many(table,
TABLE_STRING, "Packet count:",
TABLE_STRING, "0");
if (r < 0)
- return log_error_errno(r, "Failed to add cell(s): %m");
+ return table_log_add_error(r);
r = table_print(table, NULL);
if (r < 0)
- return log_error_errno(r, "Failed to show table: %m");
+ return table_log_print_error(r);
return 0;
}
log_error("Invalid NTP response");
r = table_print(table, NULL);
if (r < 0)
- return log_error_errno(r, "Failed to show table: %m");
+ return table_log_print_error(r);
return 0;
}
TABLE_UINT32, i->stratum,
TABLE_STRING, "Reference:");
if (r < 0)
- return log_error_errno(r, "Failed to add cell(s): %m");
+ return table_log_add_error(r);
if (i->stratum <= 1)
r = table_add_cell(table, NULL, TABLE_STRING, i->reference.str);
else
r = table_add_cell_stringf(table, NULL, "%" PRIX32, be32toh(i->reference.val));
if (r < 0)
- return log_error_errno(r, "Failed to add cell(s): %m");
+ return table_log_add_error(r);
r = table_add_cell(table, NULL, TABLE_STRING, "Precision:");
if (r < 0)
- return log_error_errno(r, "Failed to add cell(s): %m");
+ return table_log_add_error(r);
r = table_add_cell_stringf(table, NULL, "%s (%" PRIi32 ")",
format_timespan(ts, sizeof(ts), DIV_ROUND_UP((nsec_t) (exp2(i->precision) * NSEC_PER_SEC), NSEC_PER_USEC), 0),
i->precision);
if (r < 0)
- return log_error_errno(r, "Failed to add cell(s): %m");
+ return table_log_add_error(r);
r = table_add_cell(table, NULL, TABLE_STRING, "Root distance:");
if (r < 0)
- return log_error_errno(r, "Failed to add cell(s): %m");
+ return table_log_add_error(r);
r = table_add_cell_stringf(table, NULL, "%s (max: %s)",
format_timespan(ts, sizeof(ts), root_distance, 0),
format_timespan(tmax, sizeof(tmax), i->root_distance_max, 0));
if (r < 0)
- return log_error_errno(r, "Failed to add cell(s): %m");
+ return table_log_add_error(r);
r = table_add_cell(table, NULL, TABLE_STRING, "Offset:");
if (r < 0)
- return log_error_errno(r, "Failed to add cell(s): %m");
+ return table_log_add_error(r);
r = table_add_cell_stringf(table, NULL, "%s%s",
offset_sign ? "+" : "-",
format_timespan(ts, sizeof(ts), offset, 0));
if (r < 0)
- return log_error_errno(r, "Failed to add cell(s): %m");
+ return table_log_add_error(r);
r = table_add_many(table,
TABLE_STRING, "Delay:",
TABLE_STRING, "Packet count:",
TABLE_UINT64, i->packet_count);
if (r < 0)
- return log_error_errno(r, "Failed to add cell(s): %m");
+ return table_log_add_error(r);
if (!i->spike) {
r = table_add_cell(table, NULL, TABLE_STRING, "Frequency:");
if (r < 0)
- return log_error_errno(r, "Failed to add cell(s): %m");
+ return table_log_add_error(r);
r = table_add_cell_stringf(table, NULL, "%+.3fppm", (double) i->freq / 0x10000);
if (r < 0)
- return log_error_errno(r, "Failed to add cell(s): %m");
+ return table_log_add_error(r);
}
r = table_print(table, NULL);
if (r < 0)
- log_error_errno(r, "Failed to show table: %m");
+ return table_log_print_error(r);
return 0;
}
r = sd_bus_message_read(m, "s", &name);
if (r < 0)
- return log_error_errno(r, "Failed to read interface name: %m");
+ return bus_log_parse_error(r);
if (!streq_ptr(name, "org.freedesktop.timesync1.Manager"))
return 0;
return r;
assert(r < 0);
- r = sd_bus_call_method(
- bus,
- "org.freedesktop.network1",
- "/org/freedesktop/network1",
- "org.freedesktop.network1.Manager",
- "GetLinkByName",
- &error,
- &reply,
- "s", str);
+ r = bus_call_method(bus, bus_network_mgr, "GetLinkByName", &error, &reply, "s", str);
if (r < 0)
return log_error_errno(r, "Failed to get ifindex of interfaces %s: %s", str, bus_error_message(&error, r));
polkit_agent_open_if_enabled(arg_transport, arg_ask_password);
- r = sd_bus_message_new_method_call(
- bus,
- &req,
- "org.freedesktop.network1",
- "/org/freedesktop/network1",
- "org.freedesktop.network1.Manager",
- "SetLinkNTP");
+ r = bus_message_new_method_call(bus, &req, bus_network_mgr, "SetLinkNTP");
if (r < 0)
return bus_log_create_error(r);
polkit_agent_open_if_enabled(arg_transport, arg_ask_password);
- r = sd_bus_call_method(
- bus,
- "org.freedesktop.network1",
- "/org/freedesktop/network1",
- "org.freedesktop.network1.Manager",
- "RevertLinkNTP",
- &error,
- NULL,
- "i", ifindex);
+ r = bus_call_method(bus, bus_network_mgr, "RevertLinkNTP", &error, NULL, "i", ifindex);
if (r < 0)
return log_error_errno(r, "Failed to revert interface configuration: %s", bus_error_message(&error, r));
int r;
setlocale(LC_ALL, "");
- log_show_color(true);
- log_parse_environment();
- log_open();
+ log_setup_cli();
r = parse_argv(argc, argv);
if (r <= 0)
r = bus_connect_transport(arg_transport, arg_host, false, &bus);
if (r < 0)
- return log_error_errno(r, "Failed to create bus connection: %m");
+ return bus_log_connect_error(r);
return timedatectl_main(bus, argc, argv);
}