From 9fd58f30bfad2b5f996210d887885489bba85a83 Mon Sep 17 00:00:00 2001 From: Lucas De Marchi Date: Sat, 31 Dec 2011 18:53:24 -0200 Subject: [PATCH] index: save timestamp of each loaded index --- libkmod/libkmod-index.c | 4 +++- libkmod/libkmod-index.h | 2 +- libkmod/libkmod.c | 7 +++++-- 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/libkmod/libkmod-index.c b/libkmod/libkmod-index.c index 580b059..db1ae4d 100644 --- a/libkmod/libkmod-index.c +++ b/libkmod/libkmod-index.c @@ -716,7 +716,7 @@ static void index_mm_free_node(struct index_mm_node *node) } struct index_mm *index_mm_open(struct kmod_ctx *ctx, const char *filename, - bool populate) + bool populate, unsigned long long *stamp) { int fd; int flags; @@ -775,6 +775,8 @@ struct index_mm *index_mm_open(struct kmod_ctx *ctx, const char *filename, idx->ctx = ctx; close(fd); + *stamp = ts_usec(&st.st_mtim); + return idx; fail: diff --git a/libkmod/libkmod-index.h b/libkmod/libkmod-index.h index c5ae89d..3081dbe 100644 --- a/libkmod/libkmod-index.h +++ b/libkmod/libkmod-index.h @@ -121,7 +121,7 @@ void index_values_free(struct index_value *values); /* Implementation using mmap */ struct index_mm; struct index_mm *index_mm_open(struct kmod_ctx *ctx, const char *filename, - bool populate); + bool populate, unsigned long long *stamp); void index_mm_close(struct index_mm *index); char *index_mm_search(struct index_mm *idx, const char *key); struct index_value *index_mm_searchwild(struct index_mm *idx, const char *key); diff --git a/libkmod/libkmod.c b/libkmod/libkmod.c index b4db9a5..794cc54 100644 --- a/libkmod/libkmod.c +++ b/libkmod/libkmod.c @@ -82,6 +82,7 @@ struct kmod_ctx { struct kmod_config *config; struct hash *modules_by_name; struct index_mm *indexes[_KMOD_INDEX_LAST]; + unsigned long long indexes_stamp[_KMOD_INDEX_LAST]; }; void kmod_log(const struct kmod_ctx *ctx, @@ -383,7 +384,7 @@ static int kmod_lookup_alias_from_alias_bin(struct kmod_ctx *ctx, index_files[index_number], name); realnames = index_mm_searchwild(ctx->indexes[index_number], name); - } else{ + } else { char fn[PATH_MAX]; snprintf(fn, sizeof(fn), "%s/%s.bin", ctx->dirname, @@ -642,7 +643,8 @@ KMOD_EXPORT int kmod_load_resources(struct kmod_ctx *ctx) snprintf(path, sizeof(path), "%s/%s.bin", ctx->dirname, index_files[i]); - ctx->indexes[i] = index_mm_open(ctx, path, true); + ctx->indexes[i] = index_mm_open(ctx, path, true, + &ctx->indexes_stamp[i]); if (ctx->indexes[i] == NULL) goto fail; } @@ -680,6 +682,7 @@ KMOD_EXPORT void kmod_unload_resources(struct kmod_ctx *ctx) if (ctx->indexes[i] != NULL) { index_mm_close(ctx->indexes[i]); ctx->indexes[i] = NULL; + ctx->indexes_stamp[i] = 0; } } } -- 2.7.4