diff options
Diffstat (limited to 'src/timesync')
-rw-r--r-- | src/timesync/timesyncd-conf.c | 26 | ||||
-rw-r--r-- | src/timesync/timesyncd-manager.c | 33 | ||||
-rw-r--r-- | src/timesync/timesyncd-server.c | 1 | ||||
-rw-r--r-- | src/timesync/timesyncd.c | 19 |
4 files changed, 46 insertions, 33 deletions
diff --git a/src/timesync/timesyncd-conf.c b/src/timesync/timesyncd-conf.c index df4d89a620..001a0f4d41 100644 --- a/src/timesync/timesyncd-conf.c +++ b/src/timesync/timesyncd-conf.c @@ -19,14 +19,15 @@ along with systemd; If not, see <http://www.gnu.org/licenses/>. ***/ - +#include "alloc-util.h" +#include "def.h" +#include "extract-word.h" +#include "string-util.h" +#include "timesyncd-conf.h" #include "timesyncd-manager.h" #include "timesyncd-server.h" -#include "timesyncd-conf.h" int manager_parse_server_string(Manager *m, ServerType type, const char *string) { - const char *word, *state; - size_t length; ServerName *first; int r; @@ -35,17 +36,20 @@ int manager_parse_server_string(Manager *m, ServerType type, const char *string) first = type == SERVER_FALLBACK ? m->fallback_servers : m->system_servers; - FOREACH_WORD_QUOTED(word, length, string, state) { - char buffer[length+1]; + for (;;) { + _cleanup_free_ char *word = NULL; bool found = false; ServerName *n; - memcpy(buffer, word, length); - buffer[length] = 0; + r = extract_first_word(&string, &word, NULL, 0); + if (r < 0) + return log_error_errno(r, "Failed to parse timesyncd server syntax \"%s\": %m", string); + if (r == 0) + break; /* Filter out duplicates */ LIST_FOREACH(names, n, first) - if (streq_ptr(n->string, buffer)) { + if (streq_ptr(n->string, word)) { found = true; break; } @@ -53,7 +57,7 @@ int manager_parse_server_string(Manager *m, ServerType type, const char *string) if (found) continue; - r = server_name_new(m, NULL, type, buffer); + r = server_name_new(m, NULL, type, word); if (r < 0) return r; } @@ -85,7 +89,7 @@ int config_parse_servers( else { r = manager_parse_server_string(m, ltype, rvalue); if (r < 0) { - log_syntax(unit, LOG_ERR, filename, line, -r, "Failed to parse NTP server string '%s'. Ignoring.", rvalue); + log_syntax(unit, LOG_ERR, filename, line, r, "Failed to parse NTP server string '%s'. Ignoring.", rvalue); return 0; } } diff --git a/src/timesync/timesyncd-manager.c b/src/timesync/timesyncd-manager.c index 40e0fd31fe..8dca538b3b 100644 --- a/src/timesync/timesyncd-manager.c +++ b/src/timesync/timesyncd-manager.c @@ -19,31 +19,36 @@ along with systemd; If not, see <http://www.gnu.org/licenses/>. ***/ -#include <stdlib.h> #include <errno.h> -#include <time.h> #include <math.h> #include <netinet/in.h> #include <netinet/ip.h> +#include <resolv.h> +#include <stdlib.h> +#include <sys/socket.h> #include <sys/timerfd.h> #include <sys/timex.h> -#include <sys/socket.h> -#include <resolv.h> #include <sys/types.h> +#include <time.h> -#include "missing.h" -#include "util.h" -#include "sparse-endian.h" -#include "log.h" -#include "socket-util.h" +#include "sd-daemon.h" + +#include "alloc-util.h" +#include "fd-util.h" +#include "fs-util.h" #include "list.h" +#include "log.h" +#include "missing.h" +#include "network-util.h" #include "ratelimit.h" +#include "socket-util.h" +#include "sparse-endian.h" +#include "string-util.h" #include "strv.h" -#include "sd-daemon.h" -#include "network-util.h" +#include "time-util.h" #include "timesyncd-conf.h" #include "timesyncd-manager.h" -#include "time-util.h" +#include "util.h" #ifndef ADJ_SETOFFSET #define ADJ_SETOFFSET 0x0100 /* add 'time' to current time */ @@ -365,7 +370,7 @@ static int manager_adjust_clock(Manager *m, double offset, int leap_sec) { r = clock_adjtime(CLOCK_REALTIME, &tmx); if (r < 0) - return r; + return -errno; touch("/var/lib/systemd/clock"); @@ -662,7 +667,7 @@ static int manager_receive_response(sd_event_source *source, int fd, uint32_t re m->sync = true; r = manager_adjust_clock(m, offset, leap_sec); if (r < 0) - log_error_errno(errno, "Failed to call clock_adjtime(): %m"); + log_error_errno(r, "Failed to call clock_adjtime(): %m"); } log_debug("interval/delta/delay/jitter/drift " USEC_FMT "s/%+.3fs/%.3fs/%.3fs/%+ippm%s", diff --git a/src/timesync/timesyncd-server.c b/src/timesync/timesyncd-server.c index ec3fe1fc4e..f98e6b4cf0 100644 --- a/src/timesync/timesyncd-server.c +++ b/src/timesync/timesyncd-server.c @@ -19,6 +19,7 @@ along with systemd; If not, see <http://www.gnu.org/licenses/>. ***/ +#include "alloc-util.h" #include "timesyncd-server.h" int server_address_new( diff --git a/src/timesync/timesyncd.c b/src/timesync/timesyncd.c index 3cb7d435cd..7f70eaaea0 100644 --- a/src/timesync/timesyncd.c +++ b/src/timesync/timesyncd.c @@ -19,15 +19,18 @@ along with systemd; If not, see <http://www.gnu.org/licenses/>. ***/ -#include "sd-event.h" #include "sd-daemon.h" -#include "capability.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-manager.h" #include "timesyncd-conf.h" +#include "timesyncd-manager.h" +#include "user-util.h" static int load_clock_timestamp(uid_t uid, gid_t gid) { _cleanup_close_ int fd = -1; @@ -57,12 +60,12 @@ static int load_clock_timestamp(uid_t uid, gid_t gid) { /* Try to fix the access mode, so that we can still touch the file after dropping priviliges */ - fchmod(fd, 0644); - fchown(fd, uid, gid); + (void) fchmod(fd, 0644); + (void) fchown(fd, uid, gid); } else /* create stamp file with the compiled-in date */ - touch_file("/var/lib/systemd/clock", true, min, uid, gid, 0644); + (void) touch_file("/var/lib/systemd/clock", true, min, uid, gid, 0644); ct = now(CLOCK_REALTIME); if (ct < min) { @@ -150,7 +153,7 @@ int main(int argc, char *argv[]) { /* if we got an authoritative time, store it in the file system */ if (m->sync) - touch("/var/lib/systemd/clock"); + (void) touch("/var/lib/systemd/clock"); sd_event_get_exit_code(m->event, &r); |