X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=blobdiff_plain;f=src%2Ftimedate%2Ftimedatectl.c;h=469a65e6359958cac7ee6612ea88d73ba87579de;hb=857a493d55f94731394e4d9f61ffce661858e9a0;hp=8c6e7c9212100e2651ec28e49336e5537b733129;hpb=6d0274f11547a0f11200bb82bf598a5a253e12cf;p=elogind.git diff --git a/src/timedate/timedatectl.c b/src/timedate/timedatectl.c index 8c6e7c921..469a65e63 100644 --- a/src/timedate/timedatectl.c +++ b/src/timedate/timedatectl.c @@ -34,7 +34,7 @@ #include "strv.h" #include "pager.h" -static bool arg_fix_system = false; +static bool arg_adjust_system_clock = false; static bool arg_no_pager = false; static enum transport { TRANSPORT_NORMAL, @@ -69,11 +69,9 @@ typedef struct StatusInfo { } StatusInfo; static bool ntp_synced(void) { - struct timex txc; zero(txc); - if (adjtimex(&txc) < 0) return false; @@ -90,6 +88,8 @@ static void print_status_info(StatusInfo *i) { time_t sec; int r; + assert(i); + n = now(CLOCK_REALTIME); sec = (time_t) (n / USEC_PER_SEC); @@ -191,6 +191,7 @@ static int show_status(DBusConnection *bus, char **args, unsigned n) { return -EIO; } + zero(info); dbus_message_iter_recurse(&iter, &sub); while (dbus_message_iter_get_arg_type(&sub) != DBUS_TYPE_INVALID) { @@ -301,7 +302,7 @@ static int set_local_rtc(DBusConnection *bus, char **args, unsigned n) { } b = r; - q = arg_fix_system; + q = arg_adjust_system_clock; return bus_method_call_with_reply( bus, @@ -348,16 +349,10 @@ static int set_ntp(DBusConnection *bus, char **args, unsigned n) { DBUS_TYPE_INVALID); } -static int zone_compare(const void *_a, const void *_b) { - const char **a = (const char**) _a, **b = (const char**) _b; - - return strcmp(*a, *b); -} - static int list_timezones(DBusConnection *bus, char **args, unsigned n) { _cleanup_fclose_ FILE *f = NULL; _cleanup_strv_free_ char **zones = NULL; - size_t n_zones; + size_t n_zones = 0; char **i; assert(args); @@ -415,12 +410,11 @@ static int list_timezones(DBusConnection *bus, char **args, unsigned n) { } if (zones) - zones[n_zones] = 0; - - qsort(zones, n_zones, sizeof(char*), zone_compare); + zones[n_zones] = NULL; pager_open_if_enabled(); + strv_sort(zones); STRV_FOREACH(i, zones) puts(*i); @@ -429,21 +423,22 @@ static int list_timezones(DBusConnection *bus, char **args, unsigned n) { static int help(void) { - printf("%s [OPTIONS...] {COMMAND} ...\n\n" - "Query or control system time and date settings.\n\n" + printf("%s [OPTIONS...] COMMAND ...\n\n" + "Query or change system time and date settings.\n\n" " -h --help Show this help\n" " --version Show package version\n" - " --fix-system Adjust system clock when changing local RTC mode\n" + " --adjust-system-clock\n" + " Adjust system clock when changing local RTC mode\n" " --no-pager Do not pipe output into a pager\n" " --no-ask-password Do not prompt for password\n" " -H --host=[USER@]HOST Operate on remote host\n\n" "Commands:\n" - " status Show current time settings\n" - " set-time [TIME] Set system time\n" - " set-timezone [ZONE] Set system timezone\n" - " list-timezones Show known timezones\n" - " set-local-rtc [BOOL] Control whether RTC is in local time\n" - " set-ntp [BOOL] Control whether NTP is enabled\n", + " status Show current time settings\n" + " set-time TIME Set system time\n" + " set-timezone ZONE Set system timezone\n" + " list-timezones Show known timezones\n" + " set-local-rtc BOOL Control whether RTC is in local time\n" + " set-ntp BOOL Control whether NTP is enabled\n", program_invocation_short_name); return 0; @@ -454,19 +449,19 @@ static int parse_argv(int argc, char *argv[]) { enum { ARG_VERSION = 0x100, ARG_NO_PAGER, - ARG_FIX_SYSTEM, + ARG_ADJUST_SYSTEM_CLOCK, ARG_NO_ASK_PASSWORD }; static const struct option options[] = { - { "help", no_argument, NULL, 'h' }, - { "version", no_argument, NULL, ARG_VERSION }, - { "no-pager", no_argument, NULL, ARG_NO_PAGER }, - { "host", required_argument, NULL, 'H' }, - { "privileged", no_argument, NULL, 'P' }, - { "no-ask-password", no_argument, NULL, ARG_NO_ASK_PASSWORD }, - { "fix-system", no_argument, NULL, ARG_FIX_SYSTEM }, - { NULL, 0, NULL, 0 } + { "help", no_argument, NULL, 'h' }, + { "version", no_argument, NULL, ARG_VERSION }, + { "no-pager", no_argument, NULL, ARG_NO_PAGER }, + { "host", required_argument, NULL, 'H' }, + { "privileged", no_argument, NULL, 'P' }, + { "no-ask-password", no_argument, NULL, ARG_NO_ASK_PASSWORD }, + { "adjust-system-clock", no_argument, NULL, ARG_ADJUST_SYSTEM_CLOCK }, + { NULL, 0, NULL, 0 } }; int c; @@ -474,7 +469,7 @@ static int parse_argv(int argc, char *argv[]) { assert(argc >= 0); assert(argv); - while ((c = getopt_long(argc, argv, "+hp:as:H:P", options, NULL)) >= 0) { + while ((c = getopt_long(argc, argv, "+hH:P", options, NULL)) >= 0) { switch (c) { @@ -497,8 +492,8 @@ static int parse_argv(int argc, char *argv[]) { arg_host = optarg; break; - case ARG_FIX_SYSTEM: - arg_fix_system = true; + case ARG_ADJUST_SYSTEM_CLOCK: + arg_adjust_system_clock = true; break; case ARG_NO_PAGER: