]> git.ipfire.org Git - thirdparty/kmod.git/commitdiff
tools/depmod: use nsec granularity when checking timestamps
authorEmil Velikov <emil.l.velikov@gmail.com>
Sat, 24 May 2025 15:10:11 +0000 (16:10 +0100)
committerLucas De Marchi <lucas.de.marchi@gmail.com>
Fri, 30 May 2025 14:04:02 +0000 (09:04 -0500)
Current code uses the POSIX.1-2001 stat::st_mtime which has one second
granularity. Considering the depmod execution time may be smaller, we
should be using the POSIX.1-2008 stat::st_mtim which has nano-second
granularity instead.

Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
Link: https://github.com/kmod-project/kmod/pull/359
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
shared/util.c
shared/util.h
tools/depmod.c

index 571f4afa5f1041b1bbf06315b70022e285c489fd..b09f7662734833b594057c01b190d9f3564bd62a 100644 (file)
@@ -497,7 +497,7 @@ int fd_lookup_path(int fd, char *path, size_t pathlen)
        return len;
 }
 
-static unsigned long long ts_usec(const struct timespec *ts)
+unsigned long long ts_usec(const struct timespec *ts)
 {
        return (unsigned long long)ts->tv_sec * USEC_PER_SEC +
               (unsigned long long)ts->tv_nsec / NSEC_PER_USEC;
index 1f59ec44a7f2e47d700a8d9b5cd00db46edcb2cb..fd03736a39a223fc241df10ab689e59e6ff1fed4 100644 (file)
@@ -63,6 +63,7 @@ _nonnull_all_ int fd_lookup_path(int fd, char *path, size_t pathlen);
 #define MSEC_PER_SEC 1000ULL
 #define NSEC_PER_MSEC 1000000ULL
 
+unsigned long long ts_usec(const struct timespec *ts);
 unsigned long long now_usec(void);
 unsigned long long now_msec(void);
 int sleep_until_msec(unsigned long long msec);
index 3390222adaa54c35f68fad9d8402e894034164ce..3f8c938114c3776c4e79cb585ca8ef8c779da6ab 100644 (file)
@@ -2768,7 +2768,8 @@ invalid_syntax:
        return 0;
 }
 
-static int depfile_up_to_date_dir(DIR *d, time_t mtime, size_t baselen, char *path)
+static int depfile_up_to_date_dir(DIR *d, const struct timespec *ts, size_t baselen,
+                                 char *path)
 {
        struct dirent *de;
        int err = 1, dfd = dirfd(d);
@@ -2816,7 +2817,7 @@ static int depfile_up_to_date_dir(DIR *d, time_t mtime, size_t baselen, char *pa
                        }
                        path[baselen + namelen] = '/';
                        path[baselen + namelen + 1] = '\0';
-                       err = depfile_up_to_date_dir(subdir, mtime, baselen + namelen + 1,
+                       err = depfile_up_to_date_dir(subdir, ts, baselen + namelen + 1,
                                                     path);
                        closedir(subdir);
                } else if (S_ISREG(st.st_mode)) {
@@ -2824,10 +2825,11 @@ static int depfile_up_to_date_dir(DIR *d, time_t mtime, size_t baselen, char *pa
                                continue;
 
                        memcpy(path + baselen, name, namelen + 1);
-                       err = st.st_mtime <= mtime;
+                       err = ts_usec(&st.st_mtim) <= ts_usec(ts);
                        if (err == 0) {
                                DBG("%s %" PRIu64 " is newer than %" PRIu64 "\n", path,
-                                   (uint64_t)st.st_mtime, (uint64_t)mtime);
+                                   (uint64_t)ts_usec(&st.st_mtim),
+                                   (uint64_t)ts_usec(ts));
                        }
                } else {
                        ERR("unsupported file type %s: %o\n", path, st.st_mode & S_IFMT);
@@ -2873,7 +2875,7 @@ static int depfile_up_to_date(const char *dirname)
        baselen++;
        path[baselen] = '\0';
 
-       err = depfile_up_to_date_dir(d, st.st_mtime, baselen, path);
+       err = depfile_up_to_date_dir(d, &st.st_mtim, baselen, path);
        closedir(d);
        return err;
 }