]> git.ipfire.org Git - thirdparty/kmod.git/commitdiff
Check if struct stat has mtim member
authorLucas De Marchi <lucas.demarchi@profusion.mobi>
Tue, 17 Jan 2012 14:10:42 +0000 (12:10 -0200)
committerLucas De Marchi <lucas.demarchi@profusion.mobi>
Tue, 17 Jan 2012 14:22:55 +0000 (12:22 -0200)
Not all libc's have a mtim member in struct stat (dietlibc doesn't).
Change ts_usec() to receive a struct stat as parameter and implement it
accordingly for both cases.

configure.ac
libkmod/libkmod-config.c
libkmod/libkmod-index.c
libkmod/libkmod-util.c
libkmod/libkmod-util.h
libkmod/libkmod.c

index 66c2d51a54ee4ddb829c5164bf7fb623de6e5172..19f78d520a5bb14435b3260ae72210414d602e74 100644 (file)
@@ -79,6 +79,9 @@ AS_IF([test "x$enable_debug" = "xyes"], [
        AC_DEFINE(ENABLE_DEBUG, [1], [Debug messages.])
 ])
 
+# dietlibc doesn't have st.st_mtim struct member
+AC_CHECK_MEMBERS([struct stat.st_mtim], [], [], [#include <sys/stat.h>])
+
 CC_CHECK_CFLAGS_APPEND([ \
                        -pipe \
                        -DANOTHER_BRICK_IN_THE \
@@ -125,7 +128,6 @@ CC_CHECK_CFLAGS_APPEND([ \
                        -Wl,--as-needed \
                        -Wl,--gc-sections])
 
-
 AC_CONFIG_HEADERS(config.h)
 AC_CONFIG_FILES([
        Makefile
index c1da16fc6a70c43c4a41b1613ed3fa662f5b43a7..f970f9e167e7eeea1485af67a8016a5ce33ea967 100644 (file)
@@ -795,7 +795,7 @@ static int conf_files_list(struct kmod_ctx *ctx, struct kmod_list **list,
                return err;
        }
 
-       *path_stamp = ts_usec(&st.st_mtim);
+       *path_stamp = stat_mstamp(&st);
 
        if (S_ISREG(st.st_mode)) {
                conf_files_insert_sorted(ctx, list, path, NULL);
index 9d3b9395db0ce99b34d478dddc6a88f34e9f570c..c1c3c9942e93f0050936093a6edba4a7df2aa334 100644 (file)
@@ -830,7 +830,7 @@ struct index_mm *index_mm_open(struct kmod_ctx *ctx, const char *filename,
        idx->ctx = ctx;
        close(fd);
 
-       *stamp = ts_usec(&st.st_mtim);
+       *stamp = stat_mstamp(&st);
 
        return idx;
 
index 7c2611b38e7acd37a5d25ea40f43cd85b77a5d79..9a662b6e251dce9d53da482476b18af35963b6c8 100644 (file)
@@ -341,8 +341,12 @@ char *path_make_absolute_cwd(const char *p)
 
 #define USEC_PER_SEC  1000000ULL
 #define NSEC_PER_USEC 1000ULL
-unsigned long long ts_usec(const struct timespec *ts)
+unsigned long long stat_mstamp(const struct stat *st)
 {
-       return (unsigned long long) ts->tv_sec * USEC_PER_SEC +
-              (unsigned long long) ts->tv_nsec / NSEC_PER_USEC;
+#ifdef HAVE_STRUCT_STAT_ST_MTIM
+       return (unsigned long long) st->st_mtim.tv_sec * USEC_PER_SEC +
+              (unsigned long long) st->st_mtim.tv_nsec / NSEC_PER_USEC;
+#else
+       return (unsigned long long) st->st_mtime;
+#endif
 }
index c9a1a218b58bfc35163e89dad29f640e815fef58..317b2f717d8992051609c2f22178744d2dadaa80 100644 (file)
@@ -24,6 +24,6 @@ char *path_make_absolute_cwd(const char *p) __must_check __attribute__((nonnull(
 int alias_normalize(const char *alias, char buf[PATH_MAX], size_t *len) __must_check __attribute__((nonnull(1,2)));
 char *modname_normalize(const char *modname, char buf[PATH_MAX], size_t *len) __attribute__((nonnull(1, 2)));
 char *path_to_modname(const char *path, char buf[PATH_MAX], size_t *len) __attribute__((nonnull(2)));
-unsigned long long ts_usec(const struct timespec *ts);
+unsigned long long stat_mstamp(const struct stat *st);
 
 #endif
index 91fdf7b6714a2883c879a0fc7f964c49f06ec638..5edd594e33e3956e4a969d4e1b0345610ae6dd05 100644 (file)
@@ -620,7 +620,7 @@ static bool is_cache_invalid(const char *path, unsigned long long stamp)
        if (stat(path, &st) < 0)
                return true;
 
-       if (stamp != ts_usec(&st.st_mtim))
+       if (stamp != stat_mstamp(&st))
                return true;
 
        return false;