timesyncd.c revision b26fa1a2fbcfee7d03b0c8fd15ec3aa64ae70b9f
/***
This file is part of systemd.
Copyright 2014 Kay Sievers, Lennart Poettering
under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation; either version 2.1 of the License, or
(at your option) any later version.
systemd is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with systemd; If not, see <http://www.gnu.org/licenses/>.
***/
#include "sd-daemon.h"
#include "sd-event.h"
#include "capability-util.h"
#include "clock-util.h"
#include "fd-util.h"
#include "fs-util.h"
#include "network-util.h"
#include "signal-util.h"
#include "timesyncd-conf.h"
#include "timesyncd-manager.h"
#include "user-util.h"
int r;
/* Let's try to make sure that the clock is always
* monotonically increasing, by saving the clock whenever we
* have a new NTP time, or when we shut down, and restoring it
* when we start again. This is particularly helpful on
* systems lacking a battery backed RTC. We also will adjust
* the time to at least the build time of systemd. */
if (fd >= 0) {
/* check if the recorded time is later than the compiled-in one */
if (r >= 0) {
}
/* Try to fix the access mode, so that we can still
touch the file after dropping priviliges */
} else
/* create stamp file with the compiled-in date */
char date[FORMAT_TIMESTAMP_MAX];
log_info("System clock time unset or jumped backwards, restoring from recorded timestamp: %s",
}
return 0;
}
const char *user = "systemd-timesync";
int r;
log_open();
umask(0022);
if (argc != 1) {
log_error("This program does not take arguments.");
r = -EINVAL;
goto finish;
}
if (r < 0) {
goto finish;
}
if (r < 0)
goto finish;
if (r < 0)
goto finish;
r = manager_new(&m);
if (r < 0) {
log_error_errno(r, "Failed to allocate manager: %m");
goto finish;
}
if (clock_is_localtime() > 0) {
log_info("The system is configured to read the RTC time in the local time zone. "
"This mode can not be fully supported. All system time to RTC updates are disabled.");
m->rtc_local_time = true;
}
r = manager_parse_config_file(m);
if (r < 0)
log_warning_errno(r, "Failed to parse configuration file: %m");
sd_notify(false,
"READY=1\n"
"STATUS=Daemon is running");
if (network_is_online()) {
r = manager_connect(m);
if (r < 0)
goto finish;
}
r = sd_event_loop(m->event);
if (r < 0) {
log_error_errno(r, "Failed to run event loop: %m");
goto finish;
}
/* if we got an authoritative time, store it in the file system */
if (m->sync)
sd_event_get_exit_code(m->event, &r);
sd_notify(false,
"STOPPING=1\n"
"STATUS=Shutting down...");
return r < 0 ? EXIT_FAILURE : EXIT_SUCCESS;
}