timedatectl.c revision 7f35b7bc4a241e9aa3b1512fd345cbf5b2e5a782
b44cd8821087f2afebf85fec5b588f5720a9415cTom Gundersen/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
b44cd8821087f2afebf85fec5b588f5720a9415cTom Gundersen This file is part of systemd.
b44cd8821087f2afebf85fec5b588f5720a9415cTom Gundersen Copyright 2012 Lennart Poettering
b44cd8821087f2afebf85fec5b588f5720a9415cTom Gundersen Copyright 2013 Kay Sievers
b44cd8821087f2afebf85fec5b588f5720a9415cTom Gundersen systemd is free software; you can redistribute it and/or modify it
b44cd8821087f2afebf85fec5b588f5720a9415cTom Gundersen under the terms of the GNU Lesser General Public License as published by
b44cd8821087f2afebf85fec5b588f5720a9415cTom Gundersen the Free Software Foundation; either version 2.1 of the License, or
b44cd8821087f2afebf85fec5b588f5720a9415cTom Gundersen (at your option) any later version.
b44cd8821087f2afebf85fec5b588f5720a9415cTom Gundersen systemd is distributed in the hope that it will be useful, but
b44cd8821087f2afebf85fec5b588f5720a9415cTom Gundersen WITHOUT ANY WARRANTY; without even the implied warranty of
b44cd8821087f2afebf85fec5b588f5720a9415cTom Gundersen MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
b44cd8821087f2afebf85fec5b588f5720a9415cTom Gundersen Lesser General Public License for more details.
b44cd8821087f2afebf85fec5b588f5720a9415cTom Gundersen You should have received a copy of the GNU Lesser General Public License
b44cd8821087f2afebf85fec5b588f5720a9415cTom Gundersen along with systemd; If not, see <http://www.gnu.org/licenses/>.
ff734080aa02cd70b13bc0fdeec4a5886166163aTom Gundersenstatic bool arg_adjust_system_clock = false;
b44cd8821087f2afebf85fec5b588f5720a9415cTom Gundersenstatic bool arg_no_pager = false;
b44cd8821087f2afebf85fec5b588f5720a9415cTom Gundersenstatic BusTransport arg_transport = BUS_TRANSPORT_LOCAL;
b44cd8821087f2afebf85fec5b588f5720a9415cTom Gundersenstatic bool arg_ask_password = true;
b44cd8821087f2afebf85fec5b588f5720a9415cTom Gundersenstatic void pager_open_if_enabled(void) {
b44cd8821087f2afebf85fec5b588f5720a9415cTom Gundersenstatic void polkit_agent_open_if_enabled(void) {
b44cd8821087f2afebf85fec5b588f5720a9415cTom Gundersen /* Open the polkit agent as a child process if necessary */
b44cd8821087f2afebf85fec5b588f5720a9415cTom Gundersentypedef struct StatusInfo {
b44cd8821087f2afebf85fec5b588f5720a9415cTom Gundersenstatic const char *jump_str(int delta_minutes, char *s, size_t size) {
b44cd8821087f2afebf85fec5b588f5720a9415cTom Gundersen return "one hour forward";
b44cd8821087f2afebf85fec5b588f5720a9415cTom Gundersen return "one hour backwards";
b44cd8821087f2afebf85fec5b588f5720a9415cTom Gundersen snprintf(s, size, "%i minutes backwards", -delta_minutes);
b44cd8821087f2afebf85fec5b588f5720a9415cTom Gundersen snprintf(s, size, "%i minutes forward", delta_minutes);
ff734080aa02cd70b13bc0fdeec4a5886166163aTom Gundersen /* Enforce the values of /etc/localtime */
ff734080aa02cd70b13bc0fdeec4a5886166163aTom Gundersen fprintf(stderr, "Warning: ignoring the TZ variable, reading the system's timezone setting only.\n\n");
ff734080aa02cd70b13bc0fdeec4a5886166163aTom Gundersen assert_se(strftime(a, sizeof(a), "%a %Y-%m-%d %H:%M:%S %Z", localtime_r(&sec, &tm)) > 0);
ff734080aa02cd70b13bc0fdeec4a5886166163aTom Gundersen assert_se(strftime(a, sizeof(a), "%a %Y-%m-%d %H:%M:%S UTC", gmtime_r(&sec, &tm)) > 0);
ff734080aa02cd70b13bc0fdeec4a5886166163aTom Gundersen rtc_sec = (time_t)(i->rtc_time / USEC_PER_SEC);
ff734080aa02cd70b13bc0fdeec4a5886166163aTom Gundersen assert_se(strftime(a, sizeof(a), "%a %Y-%m-%d %H:%M:%S", gmtime_r(&rtc_sec, &tm)) > 0);
ff734080aa02cd70b13bc0fdeec4a5886166163aTom Gundersen assert_se(strftime(a, sizeof(a), "%Z, %z", localtime_r(&sec, &tm)) > 0);
ff734080aa02cd70b13bc0fdeec4a5886166163aTom Gundersen " NTP enabled: %s\n"
ff734080aa02cd70b13bc0fdeec4a5886166163aTom Gundersen "NTP synchronized: %s\n"
ff734080aa02cd70b13bc0fdeec4a5886166163aTom Gundersen " RTC in local TZ: %s\n",
ff734080aa02cd70b13bc0fdeec4a5886166163aTom Gundersen i->ntp_capable ? yes_no(i->ntp_enabled) : "n/a",
ff734080aa02cd70b13bc0fdeec4a5886166163aTom Gundersen assert_se(strftime(a, sizeof(a), "%a %Y-%m-%d %H:%M:%S %Z", localtime_r(&t, &tm)) > 0);
ff734080aa02cd70b13bc0fdeec4a5886166163aTom Gundersen assert_se(strftime(b, sizeof(b), "%a %Y-%m-%d %H:%M:%S %Z", localtime_r(&tc, &tm)) > 0);
ff734080aa02cd70b13bc0fdeec4a5886166163aTom Gundersen assert_se(strftime(a, sizeof(a), "%a %Y-%m-%d %H:%M:%S %Z", localtime_r(&t, &tm)) > 0);
ff734080aa02cd70b13bc0fdeec4a5886166163aTom Gundersen assert_se(strftime(b, sizeof(b), "%a %Y-%m-%d %H:%M:%S %Z", localtime_r(&tn, &tm)) > 0);
ff734080aa02cd70b13bc0fdeec4a5886166163aTom Gundersen printf(" Next DST change: DST %s (the clock jumps %s) at\n"
ff734080aa02cd70b13bc0fdeec4a5886166163aTom Gundersen is_dstn ? "begins" : "ends", jump_str(dn, s, sizeof(s)), a, b);
if (i->rtc_local)
bus,
"org.freedesktop.timedate1",
"/org/freedesktop/timedate1",
"org.freedesktop.timedate1",
name,
&error,
*target = b;
bus,
"org.freedesktop.timedate1",
"/org/freedesktop/timedate1",
"org.freedesktop.timedate1",
name,
&error,
r = sd_bus_get_property(
bus,
"org.freedesktop.timedate1",
"/org/freedesktop/timedate1",
"org.freedesktop.timedate1",
&error,
&reply,
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) {
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;
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;
goto finish;
pager_close();
return ret;