]> git.armaanb.net Git - opendoas.git/blobdiff - persist_timestamp.c
persist_timestamp: make tmpfs requirement optional and only available on linux
[opendoas.git] / persist_timestamp.c
index c608dca7f357f83452ed5485e9600cca43f02c3c..3f2ee18fc0f0c06389581fb2df57ea17493cf407 100644 (file)
 #include "includes.h"
 
 #ifndef TIMESTAMP_DIR
-# define TIMESTAMP_DIR "/tmp/doas"
+#      define TIMESTAMP_DIR "/tmp/doas"
 #endif
-#ifndef TMPFS_MAGIC
-# define TMPFS_MAGIC 0x01021994
+
+#if defined(TIMESTAMP_TMPFS) && defined(__linux__)
+#      ifndef TMPFS_MAGIC
+#              define TMPFS_MAGIC 0x01021994
+#      endif
 #endif
 
 #define        timespecisset(tsp)              ((tsp)->tv_sec || (tsp)->tv_nsec)
@@ -153,8 +156,11 @@ check:
                errx(1, "timestamp directory is not owned by root");
        if (statfs(dir, &sf) == -1)
                err(1, "statfs");
+
+#if defined(TIMESTAMP_TMPFS) && defined(__linux__)
        if (sf.f_type != TMPFS_MAGIC)
                errx(1, "timestamp directory not on tmpfs");
+#endif
 
        free(buf);
        return 0;
@@ -171,7 +177,7 @@ persist_check(int fd, int secs)
        if (!timespecisset(&ts_mono) || !timespecisset(&ts_real))
                errx(1, "timespecisset");
 
-       if (clock_gettime(CLOCK_MONOTONIC, &mono) == -1 ||
+       if (clock_gettime(CLOCK_MONOTONIC_RAW, &mono) == -1 ||
            clock_gettime(CLOCK_REALTIME, &real) == -1)
                err(1, "clock_gettime");
 
@@ -196,7 +202,7 @@ persist_set(int fd, int secs)
 {
        struct timespec mono, real, ts_mono, ts_real, timeout;
 
-       if (clock_gettime(CLOCK_MONOTONIC, &mono) == -1 ||
+       if (clock_gettime(CLOCK_MONOTONIC_RAW, &mono) == -1 ||
            clock_gettime(CLOCK_REALTIME, &real) == -1)
                err(1, "clock_gettime");