X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=blobdiff_plain;f=src%2Ftimedate%2Ftimedatectl.c;h=80afc57131b68c0b295dffcd2767306654bb8df5;hb=0fb0c56f5283a8a94560f595768a801c8240a9bd;hp=d379bccd7f4707194a161ae8ede9eff585b3e09b;hpb=bd5ce8e9fc10a593822344c098ccbe8c47fe34e9;p=elogind.git diff --git a/src/timedate/timedatectl.c b/src/timedate/timedatectl.c index d379bccd7..80afc5713 100644 --- a/src/timedate/timedatectl.c +++ b/src/timedate/timedatectl.c @@ -44,14 +44,15 @@ static enum transport { TRANSPORT_POLKIT } arg_transport = TRANSPORT_NORMAL; static bool arg_ask_password = true; -static const char *arg_host = NULL; +static char *arg_host = NULL; +static char *arg_user = NULL; static void pager_open_if_enabled(void) { if (arg_no_pager) return; - pager_open(); + pager_open(false); } static void polkit_agent_open_if_enabled(void) { @@ -68,21 +69,9 @@ typedef struct StatusInfo { const char *timezone; bool local_rtc; bool ntp; + bool can_ntp; } StatusInfo; -static bool ntp_synced(void) { - struct timex txc; - - zero(txc); - if (adjtimex(&txc) < 0) - return false; - - if (txc.status & STA_UNSYNC) - return false; - - return true; -} - static const char *jump_str(int delta_minutes, char *s, size_t size) { if (delta_minutes == 60) return "one hour forward"; @@ -153,7 +142,7 @@ static void print_status_info(StatusInfo *i) { " RTC in local TZ: %s\n", strna(i->timezone), a, - yes_no(i->ntp), + i->can_ntp ? yes_no(i->ntp) : "n/a", yes_no(ntp_synced()), yes_no(i->local_rtc)); @@ -173,10 +162,10 @@ static void print_status_info(StatusInfo *i) { zero(tm); assert_se(strftime(b, sizeof(b), "%a %Y-%m-%d %H:%M:%S %Z", localtime_r(&tc, &tm)) > 0); char_array_0(b); - printf(" Last DST change: DST became %s\n" + printf(" Last DST change: DST %s at\n" " %s\n" " %s\n", - is_dstc ? "active" : "inactive", a, b); + is_dstc ? "began" : "ended", a, b); t = tn - 1; zero(tm); @@ -186,10 +175,10 @@ static void print_status_info(StatusInfo *i) { zero(tm); assert_se(strftime(b, sizeof(b), "%a %Y-%m-%d %H:%M:%S %Z", localtime_r(&tn, &tm)) > 0); char_array_0(b); - printf(" Next DST change: DST will become %s, the clock will jump %s\n" + printf(" Next DST change: DST %s (the clock jumps %s) at\n" " %s\n" " %s\n", - is_dstn ? "active" : "inactive", jump_str(dn, s, sizeof(s)), a, b); + is_dstn ? "begins" : "ends", jump_str(dn, s, sizeof(s)), a, b); free(zc); free(zn); @@ -197,7 +186,7 @@ static void print_status_info(StatusInfo *i) { if (i->local_rtc) fputs("\n" ANSI_HIGHLIGHT_ON - "Warning: The RTC is configured to maintain time in the local time zone. This\n" + "Warning: The RTC is configured to maintain time in the local timezone. This\n" " mode is not fully supported and will create various problems with time\n" " zone changes and daylight saving adjustments. If at all possible use\n" " RTC in UTC, by calling 'timedatectl set-local-rtc 0'" ANSI_HIGHLIGHT_OFF ".\n", stdout); @@ -228,6 +217,8 @@ static int status_property(const char *name, DBusMessageIter *iter, StatusInfo * i->local_rtc = b; else if (streq(name, "NTP")) i->ntp = b; + else if (streq(name, "CanNTP")) + i->can_ntp = b; } } @@ -239,7 +230,7 @@ static int show_status(DBusConnection *bus, char **args, unsigned n) { const char *interface = ""; int r; DBusMessageIter iter, sub, sub2, sub3; - StatusInfo info; + StatusInfo info = {}; assert(args); @@ -263,7 +254,6 @@ 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) { @@ -303,7 +293,7 @@ static int show_status(DBusConnection *bus, char **args, unsigned n) { static int set_time(DBusConnection *bus, char **args, unsigned n) { _cleanup_dbus_message_unref_ DBusMessage *reply = NULL; - dbus_bool_t relative = false, interactive = true; + dbus_bool_t relative = false, interactive = arg_ask_password; usec_t t; dbus_int64_t u; int r; @@ -337,7 +327,7 @@ static int set_time(DBusConnection *bus, char **args, unsigned n) { static int set_timezone(DBusConnection *bus, char **args, unsigned n) { _cleanup_dbus_message_unref_ DBusMessage *reply = NULL; - dbus_bool_t interactive = true; + dbus_bool_t interactive = arg_ask_password; assert(args); assert(n == 2); @@ -359,7 +349,7 @@ static int set_timezone(DBusConnection *bus, char **args, unsigned n) { static int set_local_rtc(DBusConnection *bus, char **args, unsigned n) { _cleanup_dbus_message_unref_ DBusMessage *reply = NULL; - dbus_bool_t interactive = true, b, q; + dbus_bool_t interactive = arg_ask_password, b, q; int r; assert(args); @@ -392,7 +382,7 @@ static int set_local_rtc(DBusConnection *bus, char **args, unsigned n) { static int set_ntp(DBusConnection *bus, char **args, unsigned n) { _cleanup_dbus_message_unref_ DBusMessage *reply = NULL; - dbus_bool_t interactive = true, b; + dbus_bool_t interactive = arg_ask_password, b; int r; assert(args); @@ -425,7 +415,6 @@ 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 = 0; - char **i; assert(args); assert(n == 1); @@ -487,8 +476,7 @@ static int list_timezones(DBusConnection *bus, char **args, unsigned n) { pager_open_if_enabled(); strv_sort(zones); - STRV_FOREACH(i, zones) - puts(*i); + strv_print(zones); return 0; } @@ -502,6 +490,7 @@ static int help(void) { " --adjust-system-clock\n" " Adjust system clock when changing local RTC mode\n" " --no-pager Do not pipe output into a pager\n" + " -P --privileged Acquire privileges before execution\n" " --no-ask-password Do not prompt for password\n" " -H --host=[USER@]HOST Operate on remote host\n\n" "Commands:\n" @@ -541,7 +530,7 @@ static int parse_argv(int argc, char *argv[]) { assert(argc >= 0); assert(argv); - while ((c = getopt_long(argc, argv, "+hH:P", options, NULL)) >= 0) { + while ((c = getopt_long(argc, argv, "hH:P", options, NULL)) >= 0) { switch (c) { @@ -551,7 +540,6 @@ static int parse_argv(int argc, char *argv[]) { case ARG_VERSION: puts(PACKAGE_STRING); - puts(DISTRIBUTION); puts(SYSTEMD_FEATURES); return 0; @@ -561,7 +549,11 @@ static int parse_argv(int argc, char *argv[]) { case 'H': arg_transport = TRANSPORT_SSH; - arg_host = optarg; + parse_user_at_host(optarg, &arg_user, &arg_host); + break; + + case ARG_NO_ASK_PASSWORD: + arg_ask_password = false; break; case ARG_ADJUST_SYSTEM_CLOCK: