Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/usr.bin/make cached_stats: do not conflate stat and lstat



details:   https://anonhg.NetBSD.org/src/rev/1d0685977d26
branches:  trunk
changeset: 934057:1d0685977d26
user:      sjg <sjg%NetBSD.org@localhost>
date:      Fri Jun 05 18:03:59 2020 +0000

description:
cached_stats: do not conflate stat and lstat

While make uses lstat quite rarely, it does so for reason.
Avoid confusing the results.

Reviewed by: christos

diffstat:

 usr.bin/make/dir.c |  31 ++++++++++++++++++++-----------
 1 files changed, 20 insertions(+), 11 deletions(-)

diffs (76 lines):

diff -r d509af82756e -r 1d0685977d26 usr.bin/make/dir.c
--- a/usr.bin/make/dir.c        Fri Jun 05 17:20:56 2020 +0000
+++ b/usr.bin/make/dir.c        Fri Jun 05 18:03:59 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: dir.c,v 1.73 2018/07/12 18:03:31 christos Exp $        */
+/*     $NetBSD: dir.c,v 1.74 2020/06/05 18:03:59 sjg Exp $     */
 
 /*
  * Copyright (c) 1988, 1989, 1990 The Regents of the University of California.
@@ -70,14 +70,14 @@
  */
 
 #ifndef MAKE_NATIVE
-static char rcsid[] = "$NetBSD: dir.c,v 1.73 2018/07/12 18:03:31 christos Exp $";
+static char rcsid[] = "$NetBSD: dir.c,v 1.74 2020/06/05 18:03:59 sjg Exp $";
 #else
 #include <sys/cdefs.h>
 #ifndef lint
 #if 0
 static char sccsid[] = "@(#)dir.c      8.2 (Berkeley) 1/2/94";
 #else
-__RCSID("$NetBSD: dir.c,v 1.73 2018/07/12 18:03:31 christos Exp $");
+__RCSID("$NetBSD: dir.c,v 1.74 2020/06/05 18:03:59 sjg Exp $");
 #endif
 #endif /* not lint */
 #endif
@@ -263,7 +263,8 @@
  * mtime and mode are all we care about.
  */
 struct cache_st {
-    time_t mtime;
+    time_t lmtime;                     /* lstat */
+    time_t mtime;                      /* stat */
     mode_t  mode;
 };
 
@@ -287,13 +288,15 @@
        cst = entry->clientPtr;
 
        memset(st, 0, sizeof(*st));
-       st->st_mtime = cst->mtime;
        st->st_mode = cst->mode;
-        if (DEBUG(DIR)) {
-            fprintf(debug_file, "Using cached time %s for %s\n",
-               Targ_FmtTime(st->st_mtime), pathname);
+       st->st_mtime = (flags & CST_LSTAT) ? cst->lmtime : cst->mtime;
+       if (st->st_mtime) {
+           if (DEBUG(DIR)) {
+               fprintf(debug_file, "Using cached time %s for %s\n",
+                       Targ_FmtTime(st->st_mtime), pathname);
+           }
+           return 0;
        }
-       return 0;
     }
 
     rc = (flags & CST_LSTAT) ? lstat(pathname, st) : stat(pathname, st);
@@ -305,10 +308,16 @@
 
     if (!entry)
        entry = Hash_CreateEntry(htp, pathname, NULL);
-    if (!entry->clientPtr)
+    if (!entry->clientPtr) {
        entry->clientPtr = bmake_malloc(sizeof(*cst));
+       memset(entry->clientPtr, 0, sizeof(*cst));
+    }
     cst = entry->clientPtr;
-    cst->mtime = st->st_mtime;
+    if ((flags & CST_LSTAT)) {
+       cst->lmtime = st->st_mtime;
+    } else {
+       cst->mtime = st->st_mtime;
+    }
     cst->mode = st->st_mode;
     if (DEBUG(DIR)) {
        fprintf(debug_file, "   Caching %s for %s\n",



Home | Main Index | Thread Index | Old Index