From: Emil Velikov Date: Sat, 24 May 2025 15:10:11 +0000 (+0100) Subject: tools/depmod: use nsec granularity when checking timestamps X-Git-Url: http://git.ipfire.org/gitweb/gitweb.cgi?a=commitdiff_plain;h=249795046644e1be82d36e3e7f46497949b3d650;p=thirdparty%2Fkmod.git tools/depmod: use nsec granularity when checking timestamps 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 Link: https://github.com/kmod-project/kmod/pull/359 Signed-off-by: Lucas De Marchi --- diff --git a/shared/util.c b/shared/util.c index 571f4afa..b09f7662 100644 --- a/shared/util.c +++ b/shared/util.c @@ -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; diff --git a/shared/util.h b/shared/util.h index 1f59ec44..fd03736a 100644 --- a/shared/util.h +++ b/shared/util.h @@ -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); diff --git a/tools/depmod.c b/tools/depmod.c index 3390222a..3f8c9381 100644 --- a/tools/depmod.c +++ b/tools/depmod.c @@ -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; }