timedatectl.c revision eb9da376d76b48585b3b63b4f91903b54f7abd36
4e731273edfe852a3eee2949cd20f49fd5b4f6d7Lennart Poettering/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
4e731273edfe852a3eee2949cd20f49fd5b4f6d7Lennart Poettering This file is part of systemd.
4e731273edfe852a3eee2949cd20f49fd5b4f6d7Lennart Poettering Copyright 2012 Lennart Poettering
4e731273edfe852a3eee2949cd20f49fd5b4f6d7Lennart Poettering Copyright 2013 Kay Sievers
4e731273edfe852a3eee2949cd20f49fd5b4f6d7Lennart Poettering systemd is free software; you can redistribute it and/or modify it
4e731273edfe852a3eee2949cd20f49fd5b4f6d7Lennart Poettering under the terms of the GNU Lesser General Public License as published by
4e731273edfe852a3eee2949cd20f49fd5b4f6d7Lennart Poettering the Free Software Foundation; either version 2.1 of the License, or
4e731273edfe852a3eee2949cd20f49fd5b4f6d7Lennart Poettering (at your option) any later version.
4e731273edfe852a3eee2949cd20f49fd5b4f6d7Lennart Poettering systemd is distributed in the hope that it will be useful, but
4e731273edfe852a3eee2949cd20f49fd5b4f6d7Lennart Poettering WITHOUT ANY WARRANTY; without even the implied warranty of
4e731273edfe852a3eee2949cd20f49fd5b4f6d7Lennart Poettering MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
4e731273edfe852a3eee2949cd20f49fd5b4f6d7Lennart Poettering Lesser General Public License for more details.
4e731273edfe852a3eee2949cd20f49fd5b4f6d7Lennart Poettering You should have received a copy of the GNU Lesser General Public License
4e731273edfe852a3eee2949cd20f49fd5b4f6d7Lennart Poettering along with systemd; If not, see <http://www.gnu.org/licenses/>.
4e731273edfe852a3eee2949cd20f49fd5b4f6d7Lennart Poetteringstatic bool arg_no_pager = false;
4e731273edfe852a3eee2949cd20f49fd5b4f6d7Lennart Poetteringstatic bool arg_ask_password = true;
4e731273edfe852a3eee2949cd20f49fd5b4f6d7Lennart Poetteringstatic BusTransport arg_transport = BUS_TRANSPORT_LOCAL;
4e731273edfe852a3eee2949cd20f49fd5b4f6d7Lennart Poetteringstatic bool arg_adjust_system_clock = false;
4e731273edfe852a3eee2949cd20f49fd5b4f6d7Lennart Poetteringstatic void pager_open_if_enabled(void) {
4e731273edfe852a3eee2949cd20f49fd5b4f6d7Lennart Poetteringstatic void polkit_agent_open_if_enabled(void) {
4e731273edfe852a3eee2949cd20f49fd5b4f6d7Lennart Poettering /* Open the polkit agent as a child process if necessary */
4e731273edfe852a3eee2949cd20f49fd5b4f6d7Lennart Poetteringtypedef struct StatusInfo {
4e731273edfe852a3eee2949cd20f49fd5b4f6d7Lennart Poetteringstatic const char *jump_str(int delta_minutes, char *s, size_t size) {
4e731273edfe852a3eee2949cd20f49fd5b4f6d7Lennart Poettering return "one hour forward";
4e731273edfe852a3eee2949cd20f49fd5b4f6d7Lennart Poettering return "one hour backwards";
4e731273edfe852a3eee2949cd20f49fd5b4f6d7Lennart Poettering snprintf(s, size, "%i minutes backwards", -delta_minutes);
4e731273edfe852a3eee2949cd20f49fd5b4f6d7Lennart Poettering snprintf(s, size, "%i minutes forward", delta_minutes);
4e731273edfe852a3eee2949cd20f49fd5b4f6d7Lennart Poetteringstatic void print_status_info(const StatusInfo *i) {
4e731273edfe852a3eee2949cd20f49fd5b4f6d7Lennart Poettering /* Enforce the values of /etc/localtime */
4e731273edfe852a3eee2949cd20f49fd5b4f6d7Lennart Poettering fprintf(stderr, "Warning: ignoring the TZ variable, reading the system's timezone setting only.\n\n");
4e731273edfe852a3eee2949cd20f49fd5b4f6d7Lennart Poettering assert_se(strftime(a, sizeof(a), "%a %Y-%m-%d %H:%M:%S %Z", localtime_r(&sec, &tm)) > 0);
4e731273edfe852a3eee2949cd20f49fd5b4f6d7Lennart Poettering assert_se(strftime(a, sizeof(a), "%a %Y-%m-%d %H:%M:%S UTC", gmtime_r(&sec, &tm)) > 0);
4e731273edfe852a3eee2949cd20f49fd5b4f6d7Lennart Poettering rtc_sec = (time_t)(i->rtc_time / USEC_PER_SEC);
4e731273edfe852a3eee2949cd20f49fd5b4f6d7Lennart Poettering assert_se(strftime(a, sizeof(a), "%a %Y-%m-%d %H:%M:%S", gmtime_r(&rtc_sec, &tm)) > 0);
4e731273edfe852a3eee2949cd20f49fd5b4f6d7Lennart Poettering assert_se(strftime(a, sizeof(a), "%Z, %z", localtime_r(&sec, &tm)) > 0);
4e731273edfe852a3eee2949cd20f49fd5b4f6d7Lennart Poettering " NTP enabled: %s\n"
4e731273edfe852a3eee2949cd20f49fd5b4f6d7Lennart Poettering "NTP synchronized: %s\n"
4e731273edfe852a3eee2949cd20f49fd5b4f6d7Lennart Poettering " RTC in local TZ: %s\n",
4e731273edfe852a3eee2949cd20f49fd5b4f6d7Lennart Poettering i->ntp_capable ? yes_no(i->ntp_enabled) : "n/a",
c573dcfeb1abd390cd4c4288056df97752ef18f0Evgeny Vereshchagin printf(" DST active: %s\n", yes_no(is_dstc));
c573dcfeb1abd390cd4c4288056df97752ef18f0Evgeny Vereshchagin assert_se(strftime(a, sizeof(a), "%a %Y-%m-%d %H:%M:%S %Z", localtime_r(&t, &tm)) > 0);
c573dcfeb1abd390cd4c4288056df97752ef18f0Evgeny Vereshchagin assert_se(strftime(b, sizeof(b), "%a %Y-%m-%d %H:%M:%S %Z", localtime_r(&tc, &tm)) > 0);
c573dcfeb1abd390cd4c4288056df97752ef18f0Evgeny Vereshchagin assert_se(strftime(a, sizeof(a), "%a %Y-%m-%d %H:%M:%S %Z", localtime_r(&t, &tm)) > 0);
c573dcfeb1abd390cd4c4288056df97752ef18f0Evgeny Vereshchagin assert_se(strftime(b, sizeof(b), "%a %Y-%m-%d %H:%M:%S %Z", localtime_r(&tn, &tm)) > 0);
c573dcfeb1abd390cd4c4288056df97752ef18f0Evgeny Vereshchagin printf(" Next DST change: DST %s (the clock jumps %s) at\n"
if (i->rtc_local)
"org.freedesktop.timedate1",
"/org/freedesktop/timedate1",
map,
&info);
goto fail;
fail:
usec_t t;
"org.freedesktop.timedate1",
"/org/freedesktop/timedate1",
"org.freedesktop.timedate1",
&error,
NULL,
"org.freedesktop.timedate1",
"/org/freedesktop/timedate1",
"org.freedesktop.timedate1",
&error,
NULL,
"org.freedesktop.timedate1",
"/org/freedesktop/timedate1",
"org.freedesktop.timedate1",
&error,
NULL,
"org.freedesktop.timedate1",
"/org/freedesktop/timedate1",
"org.freedesktop.timedate1",
&error,
NULL,
return -errno;
char l[LINE_MAX], *p, **z, *w;
size_t k;
if (!fgets(l, sizeof(l), f)) {
if (feof(f))
return -errno;
p = strstrip(l);
w = strndup(p, k);
return log_oom();
free(w);
return log_oom();
zones = z;
if (zones)
static int help(void) {
return help();
case ARG_VERSION:
case ARG_NO_ASK_PASSWORD:
arg_ask_password = false;
case ARG_ADJUST_SYSTEM_CLOCK:
arg_adjust_system_clock = true;
case ARG_NO_PAGER:
arg_no_pager = true;
return -EINVAL;
const char* verb;
MORE,
LESS,
} argc_cmp;
const int argc;
} verbs[] = {
int left;
if (left <= 0)
help();
return -EINVAL;
case EQUAL:
return -EINVAL;
case MORE:
return -EINVAL;
case LESS:
return -EINVAL;
log_open();
goto finish;
goto finish;
pager_close();