summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndreas Schneider <asn@samba.org>2023-01-24 21:44:34 +0100
committerJule Anger <janger@samba.org>2023-02-10 10:52:15 +0000
commitf6bbd277dcb05b1d4a92aa7ee2dd5b2a0ed2ecc8 (patch)
treec1c756713d12baae79d409aef5fa3f84ad0e1399
parent0853cda5d927fd44edf12e8db3ccb97a17648fa8 (diff)
downloadsamba-f6bbd277dcb05b1d4a92aa7ee2dd5b2a0ed2ecc8.tar.gz
param: Use a higher time resolution for lp_file_list_changed()
It is possible that in our test environment one of the config 'include' files change more than once per second. To avoid missing a file update we use a higher time resolution than seconds. BUG: https://bugzilla.samba.org/show_bug.cgi?id=15301 Signed-off-by: Andreas Schneider <asn@samba.org> Reviewed-by: Ralph Boehme <slow@samba.org> (cherry picked from commit ac0e844ea87be7974ba6ff81745b3b0cfeecaa57)
-rw-r--r--lib/param/loadparm.c16
-rw-r--r--lib/param/loadparm.h2
-rw-r--r--source3/param/loadparm.c34
3 files changed, 37 insertions, 15 deletions
diff --git a/lib/param/loadparm.c b/lib/param/loadparm.c
index 7d7b314a407..c1d1f5393d1 100644
--- a/lib/param/loadparm.c
+++ b/lib/param/loadparm.c
@@ -1009,6 +1009,8 @@ void add_to_file_list(TALLOC_CTX *mem_ctx, struct file_lists **list,
const char *fname, const char *subfname)
{
struct file_lists *f = *list;
+ struct stat sb = {0};
+ int rc;
while (f) {
if (f->name && !strcmp(f->name, fname))
@@ -1017,7 +1019,7 @@ void add_to_file_list(TALLOC_CTX *mem_ctx, struct file_lists **list,
}
if (!f) {
- f = talloc(mem_ctx, struct file_lists);
+ f = talloc_zero(mem_ctx, struct file_lists);
if (!f)
goto fail;
f->next = *list;
@@ -1032,12 +1034,14 @@ void add_to_file_list(TALLOC_CTX *mem_ctx, struct file_lists **list,
goto fail;
}
*list = f;
- f->modtime = file_modtime(subfname);
- } else {
- time_t t = file_modtime(subfname);
- if (t)
- f->modtime = t;
}
+
+ rc = stat(subfname, &sb);
+ if (rc != 0) {
+ return;
+ }
+ f->modtime = get_mtimespec(&sb);
+
return;
fail:
diff --git a/lib/param/loadparm.h b/lib/param/loadparm.h
index 98263f0e62b..af6b530366a 100644
--- a/lib/param/loadparm.h
+++ b/lib/param/loadparm.h
@@ -102,7 +102,7 @@ struct file_lists {
struct file_lists *next;
char *name;
char *subfname;
- time_t modtime;
+ struct timespec modtime;
};
#define DEFAULT_NAME_RESOLVE_ORDER "lmhosts wins host bcast"
diff --git a/source3/param/loadparm.c b/source3/param/loadparm.c
index 56a8bc2d28b..0eb63fe3f36 100644
--- a/source3/param/loadparm.c
+++ b/source3/param/loadparm.c
@@ -79,6 +79,7 @@
#include "auth/credentials/credentials.h"
#include "source3/lib/substitute.h"
#include "source3/librpc/gen_ndr/ads.h"
+#include "lib/util/time_basic.h"
#ifdef HAVE_SYS_SYSCTL_H
#include <sys/sysctl.h>
@@ -2408,8 +2409,15 @@ bool lp_file_list_changed(void)
return true;
}
} else {
- time_t mod_time;
+ struct timespec mod_time = {
+ .tv_sec = 0,
+ };
+ struct timeval_buf tbuf = {
+ .buf = {0},
+ };
char *n2 = NULL;
+ struct stat sb = {0};
+ int rc;
n2 = talloc_sub_basic(talloc_tos(),
get_current_username(),
@@ -2419,19 +2427,29 @@ bool lp_file_list_changed(void)
return false;
}
DEBUGADD(6, ("file %s -> %s last mod_time: %s\n",
- f->name, n2, ctime(&f->modtime)));
-
- mod_time = file_modtime(n2);
+ f->name, n2,
+ timespec_string_buf(&f->modtime,
+ true,
+ &tbuf)));
+
+ rc = stat(n2, &sb);
+ if (rc == 0) {
+ mod_time = get_mtimespec(&sb);
+ }
- if (mod_time &&
- ((f->modtime != mod_time) ||
+ if (mod_time.tv_sec > 0 &&
+ ((timespec_compare(&mod_time, &f->modtime) != 0) ||
(f->subfname == NULL) ||
(strcmp(n2, f->subfname) != 0)))
{
+ f->modtime = mod_time;
+
DEBUGADD(6,
("file %s modified: %s\n", n2,
- ctime(&mod_time)));
- f->modtime = mod_time;
+ timespec_string_buf(&f->modtime,
+ true,
+ &tbuf)));
+
TALLOC_FREE(f->subfname);
f->subfname = talloc_strdup(f, n2);
if (f->subfname == NULL) {