]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
timesync: make public defines for clock epoch files
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Wed, 5 Jun 2024 10:21:34 +0000 (12:21 +0200)
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Wed, 5 Jun 2024 12:35:56 +0000 (14:35 +0200)
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.

src/shared/clock-util.c
src/shared/clock-util.h
src/timesync/timesyncd-manager.c
src/timesync/timesyncd-manager.h
src/timesync/timesyncd.c

index 37d02325b749ea61bc03473e59190abda8fb86ed..57041d0e7677349175e7204c08f6e31845df04e1 100644 (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
index c8f6d1b1f1e6089fb076dde37fa102a6dce30b50..730d1cebe8a0afc40feab8666e2724a01b338e14 100644 (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"
index 8e0eda07973af40d506107b1bdc590e21ccb2431..faf894fb47fc5750e5c6856fa1b6565f191f0471 100644 (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;
 
index 027ec52dac7025fae61f1e27a88760ea8fb84d80..4313d72ce4568d81d470bf3530cdf9a3c2954619 100644 (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;
index 5c308a04bcfd2f75ae437a1e53ba304149e65384..9d36974c71076e5c146c8e0c7b07470edce2d447 100644 (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;