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.
This commit is contained in:
Zbigniew Jędrzejewski-Szmek 2024-06-05 12:21:34 +02:00
parent f11aaf7dfb
commit 455a2eb953
5 changed files with 19 additions and 19 deletions

View file

@ -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

View file

@ -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"

View file

@ -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;

View file

@ -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;

View file

@ -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;