param: Use a higher time resolution for lp_file_list_changed()
authorAndreas Schneider <asn@samba.org>
Tue, 24 Jan 2023 20:44:34 +0000 (21:44 +0100)
committerAndreas Schneider <asn@cryptomilk.org>
Thu, 26 Jan 2023 12:15:33 +0000 (12:15 +0000)
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.

Signed-off-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Ralph Boehme <slow@samba.org>
lib/param/loadparm.c
lib/param/loadparm.h
source3/param/loadparm.c

index 7d7b314a407991fe018db70f1497b3e023dcc398..c1d1f5393d1811fe48a6d9fbc1068b3e02c3b11f 100644 (file)
@@ -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:
index 98263f0e62b28047a8f09d70dd4a65e7566649a9..af6b530366a2680ff986ea03935fe246755e50db 100644 (file)
@@ -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"
index 56a8bc2d28b5806357bcea4008a865ecb1546674..0eb63fe3f368d21524e6c6eda294001e50df2832 100644 (file)
@@ -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) {