From: Zbigniew Jędrzejewski-Szmek Date: Wed, 5 Jun 2024 10:21:34 +0000 (+0200) Subject: timesync: make public defines for clock epoch files X-Git-Tag: v257-rc1~1133^2~8 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=455a2eb953435941ca558e309eacd1070fdcd012;p=thirdparty%2Fsystemd.git timesync: make public defines for clock epoch files No functional change yet, just moving stuff around and message format adjustments. EPOCH_CLOCK_FILE is also made public for consistency, even though I don't plan to use it outside of the one location. --- diff --git a/src/shared/clock-util.c b/src/shared/clock-util.c index 37d02325b74..57041d0e767 100644 --- a/src/shared/clock-util.c +++ b/src/shared/clock-util.c @@ -132,8 +132,6 @@ int clock_reset_timewarp(void) { return RET_NERRNO(settimeofday(NULL, &tz)); } -#define EPOCH_FILE "/usr/lib/clock-epoch" - int clock_apply_epoch(ClockChangeDirection *ret_attempted_change) { usec_t epoch_usec, now_usec; struct stat st; @@ -143,9 +141,9 @@ int clock_apply_epoch(ClockChangeDirection *ret_attempted_change) { assert(ret_attempted_change); - if (stat(EPOCH_FILE, &st) < 0) { + if (stat(EPOCH_CLOCK_FILE, &st) < 0) { if (errno != ENOENT) - log_warning_errno(errno, "Cannot stat " EPOCH_FILE ": %m"); + log_warning_errno(errno, "Cannot stat " EPOCH_CLOCK_FILE ": %m"); epoch_usec = (usec_t) TIME_EPOCH * USEC_PER_SEC; } else diff --git a/src/shared/clock-util.h b/src/shared/clock-util.h index c8f6d1b1f1e..730d1cebe8a 100644 --- a/src/shared/clock-util.h +++ b/src/shared/clock-util.h @@ -18,3 +18,7 @@ int clock_reset_timewarp(void); int clock_get_hwclock(struct tm *tm); int clock_set_hwclock(const struct tm *tm); int clock_apply_epoch(ClockChangeDirection *ret_attempted_change); + +#define EPOCH_CLOCK_FILE "/usr/lib/clock-epoch" +#define TIMESYNCD_CLOCK_FILE_DIR "/var/lib/systemd/timesync/" +#define TIMESYNCD_CLOCK_FILE TIMESYNCD_CLOCK_FILE_DIR "clock" diff --git a/src/timesync/timesyncd-manager.c b/src/timesync/timesyncd-manager.c index 8e0eda07973..faf894fb47f 100644 --- a/src/timesync/timesyncd-manager.c +++ b/src/timesync/timesyncd-manager.c @@ -15,6 +15,7 @@ #include "alloc-util.h" #include "bus-polkit.h" +#include "clock-util.h" #include "common-signal.h" #include "dns-domain.h" #include "event-util.h" @@ -1199,9 +1200,9 @@ static int manager_save_time_and_rearm(Manager *m, usec_t t) { * clock, but otherwise uses the specified timestamp. Note that whenever we acquire an NTP sync the * specified timestamp value might be more accurate than the system clock, since the latter is * subject to slow adjustments. */ - r = touch_file(CLOCK_FILE, false, t, UID_INVALID, GID_INVALID, MODE_INVALID); + r = touch_file(TIMESYNCD_CLOCK_FILE, false, t, UID_INVALID, GID_INVALID, MODE_INVALID); if (r < 0) - log_debug_errno(r, "Failed to update " CLOCK_FILE ", ignoring: %m"); + log_debug_errno(r, "Failed to update "TIMESYNCD_CLOCK_FILE", ignoring: %m"); m->save_on_exit = true; diff --git a/src/timesync/timesyncd-manager.h b/src/timesync/timesyncd-manager.h index 027ec52dac7..4313d72ce45 100644 --- a/src/timesync/timesyncd-manager.h +++ b/src/timesync/timesyncd-manager.h @@ -32,9 +32,6 @@ typedef struct Manager Manager; #define DEFAULT_SAVE_TIME_INTERVAL_USEC (60 * USEC_PER_SEC) -#define STATE_DIR "/var/lib/systemd/timesync" -#define CLOCK_FILE STATE_DIR "/clock" - struct Manager { sd_bus *bus; sd_event *event; diff --git a/src/timesync/timesyncd.c b/src/timesync/timesyncd.c index 5c308a04bcf..9d36974c710 100644 --- a/src/timesync/timesyncd.c +++ b/src/timesync/timesyncd.c @@ -81,27 +81,27 @@ static int load_clock_timestamp(uid_t uid, gid_t gid) { * is particularly helpful on systems lacking a battery backed RTC. We also will adjust the time to * at least the build time of systemd. */ - fd = open(CLOCK_FILE, O_RDWR|O_CLOEXEC, 0644); + fd = open(TIMESYNCD_CLOCK_FILE, O_RDWR|O_CLOEXEC, 0644); if (fd < 0) { if (errno != ENOENT) - log_debug_errno(errno, "Unable to open timestamp file '" CLOCK_FILE "', ignoring: %m"); + log_debug_errno(errno, "Unable to open timestamp file "TIMESYNCD_CLOCK_FILE", ignoring: %m"); - r = mkdir_safe_label(STATE_DIR, 0755, uid, gid, + r = mkdir_safe_label(TIMESYNCD_CLOCK_FILE_DIR, 0755, uid, gid, MKDIR_FOLLOW_SYMLINK | MKDIR_WARN_MODE); if (r < 0) - log_debug_errno(r, "Failed to create state directory, ignoring: %m"); + log_debug_errno(r, "Failed to create "TIMESYNCD_CLOCK_FILE_DIR", ignoring: %m"); /* create stamp file with the compiled-in date */ - r = touch_file(CLOCK_FILE, /* parents= */ false, min, uid, gid, 0644); + r = touch_file(TIMESYNCD_CLOCK_FILE, /* parents= */ false, min, uid, gid, 0644); if (r < 0) - log_debug_errno(r, "Failed to create %s, ignoring: %m", CLOCK_FILE); + log_debug_errno(r, "Failed to create %s, ignoring: %m", TIMESYNCD_CLOCK_FILE); } else { struct stat st; usec_t stamp; /* check if the recorded time is later than the compiled-in one */ if (fstat(fd, &st) < 0) - return log_error_errno(errno, "Unable to stat timestamp file '" CLOCK_FILE "': %m"); + return log_error_errno(errno, "Unable to stat timestamp file "TIMESYNCD_CLOCK_FILE": %m"); stamp = timespec_load(&st.st_mtim); if (stamp > min) @@ -112,7 +112,7 @@ static int load_clock_timestamp(uid_t uid, gid_t gid) { r = fchmod_and_chown(fd, 0644, uid, gid); if (r < 0) log_full_errno(ERRNO_IS_PRIVILEGE(r) ? LOG_DEBUG : LOG_WARNING, r, - "Failed to chmod or chown %s, ignoring: %m", CLOCK_FILE); + "Failed to chmod or chown %s, ignoring: %m", TIMESYNCD_CLOCK_FILE); (void) advance_tstamp(fd, &st); } @@ -220,9 +220,9 @@ static int run(int argc, char *argv[]) { /* if we got an authoritative time, store it in the file system */ if (m->save_on_exit) { - r = touch(CLOCK_FILE); + r = touch(TIMESYNCD_CLOCK_FILE); if (r < 0) - log_debug_errno(r, "Failed to touch " CLOCK_FILE ", ignoring: %m"); + log_debug_errno(r, "Failed to touch "TIMESYNCD_CLOCK_FILE", ignoring: %m"); } return 0;