Fix major bug in make(1) ... due to shadowing of the dotLast path used for

the .DOTLAST primitive by a boolean variable with the same name, this whole
mechanism was broken ... it doesn't save much stat calls but it was wrong.

Thanks to Jason Thorpe for the other shadow-variable fixing patches he
made.
This commit is contained in:
reinoud 2002-01-27 01:50:54 +00:00
parent 2bc20613fa
commit a233fbd53e
11 changed files with 66 additions and 71 deletions

View File

@ -1,4 +1,4 @@
# $NetBSD: Makefile,v 1.25 2001/10/31 03:59:42 tv Exp $
# $NetBSD: Makefile,v 1.26 2002/01/27 01:50:54 reinoud Exp $
# @(#)Makefile 5.2 (Berkeley) 12/28/90
CPPFLAGS+= -I${.CURDIR}
@ -11,6 +11,7 @@ SRCS+= lstAppend.c lstAtEnd.c lstAtFront.c lstClose.c lstConcat.c \
lstInit.c lstInsert.c lstIsAtEnd.c lstIsEmpty.c lstLast.c \
lstMember.c lstNext.c lstOpen.c lstRemove.c lstReplace.c lstSucc.c
.PATH: ${.CURDIR}/lst.lib
WARNS=2
WFORMAT= 1
.if make(install)
SUBDIR= PSD.doc

View File

@ -1,4 +1,4 @@
/* $NetBSD: compat.c,v 1.36 2001/10/16 18:50:12 sjg Exp $ */
/* $NetBSD: compat.c,v 1.37 2002/01/27 01:50:54 reinoud Exp $ */
/*
* Copyright (c) 1988, 1989, 1990 The Regents of the University of California.
@ -39,14 +39,14 @@
*/
#ifdef MAKE_BOOTSTRAP
static char rcsid[] = "$NetBSD: compat.c,v 1.36 2001/10/16 18:50:12 sjg Exp $";
static char rcsid[] = "$NetBSD: compat.c,v 1.37 2002/01/27 01:50:54 reinoud Exp $";
#else
#include <sys/cdefs.h>
#ifndef lint
#if 0
static char sccsid[] = "@(#)compat.c 8.2 (Berkeley) 3/19/94";
#else
__RCSID("$NetBSD: compat.c,v 1.36 2001/10/16 18:50:12 sjg Exp $");
__RCSID("$NetBSD: compat.c,v 1.37 2002/01/27 01:50:54 reinoud Exp $");
#endif
#endif /* not lint */
#endif
@ -162,7 +162,7 @@ CompatRunCommand (cmdp, gnp)
int reason; /* Reason for child's death */
int status; /* Description of child's death */
int cpid; /* Child actually found */
ReturnStatus stat; /* Status of fork */
ReturnStatus retstat; /* Status of fork */
LstNode cmdNode; /* Node where current command is located */
char **av; /* Argument vector for thing to exec */
int argc; /* Number of arguments in av or 0 if not
@ -304,13 +304,13 @@ CompatRunCommand (cmdp, gnp)
*/
while (1) {
while ((stat = wait(&reason)) != cpid) {
if (stat == -1 && errno != EINTR) {
while ((retstat = wait(&reason)) != cpid) {
if (retstat == -1 && errno != EINTR) {
break;
}
}
if (stat > -1) {
if (retstat > -1) {
if (WIFSTOPPED(reason)) {
status = WSTOPSIG(reason); /* stopped */
} else if (WIFEXITED(reason)) {
@ -345,7 +345,7 @@ CompatRunCommand (cmdp, gnp)
}
break;
} else {
Fatal ("error in wait: %d: %s", stat, strerror(errno));
Fatal ("error in wait: %d: %s", retstat, strerror(errno));
/*NOTREACHED*/
}
}

View File

@ -1,4 +1,4 @@
/* $NetBSD: dir.c,v 1.30 2002/01/26 22:36:41 christos Exp $ */
/* $NetBSD: dir.c,v 1.31 2002/01/27 01:50:54 reinoud Exp $ */
/*
* Copyright (c) 1988, 1989, 1990 The Regents of the University of California.
@ -39,14 +39,14 @@
*/
#ifdef MAKE_BOOTSTRAP
static char rcsid[] = "$NetBSD: dir.c,v 1.30 2002/01/26 22:36:41 christos Exp $";
static char rcsid[] = "$NetBSD: dir.c,v 1.31 2002/01/27 01:50:54 reinoud 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.30 2002/01/26 22:36:41 christos Exp $");
__RCSID("$NetBSD: dir.c,v 1.31 2002/01/27 01:50:54 reinoud Exp $");
#endif
#endif /* not lint */
#endif
@ -940,7 +940,7 @@ Dir_FindFile (name, path)
register char *file; /* the current filename to check */
register Path *p; /* current path member */
register char *cp; /* index of first slash, if any */
Boolean lastDot = FALSE; /* true we should search dot last */
Boolean hasLastDot = FALSE; /* true we should search dot last */
Boolean hasSlash; /* true if 'name' contains a / */
struct stat stb; /* Buffer for stat, if necessary */
Hash_Entry *entry; /* Entry for mtimes table */
@ -972,10 +972,9 @@ Dir_FindFile (name, path)
if ((ln = Lst_First (path)) != NILLNODE) {
p = (Path *) Lst_Datum (ln);
if (p == dotLast)
lastDot = TRUE;
if (DEBUG(DIR)) {
printf("[dot last]...");
if (p == dotLast) {
hasLastDot = TRUE;
if (DEBUG(DIR)) printf("[dot last]...");
}
}
@ -986,7 +985,7 @@ Dir_FindFile (name, path)
* (fish.c) and what pmake finds (./fish.c).
* Unless we found the magic DOTLAST path...
*/
if (!lastDot && name[0] != '/')
if (!hasLastDot && name[0] != '/')
if ((file = DirFindDot(hasSlash, name, cp)) != NULL)
return file;
@ -1012,7 +1011,7 @@ Dir_FindFile (name, path)
}
Lst_Close (path);
if (lastDot && name[0] != '/')
if (hasLastDot && name[0] != '/')
if ((file = DirFindDot(hasSlash, name, cp)) != NULL)
return file;
@ -1043,7 +1042,7 @@ Dir_FindFile (name, path)
printf("failed. Trying subdirectories...");
}
if (!lastDot && cur && (file = DirLookupSubdir(cur, name)) != NULL)
if (!hasLastDot && cur && (file = DirLookupSubdir(cur, name)) != NULL)
return file;
(void) Lst_Open (path);
@ -1060,7 +1059,7 @@ Dir_FindFile (name, path)
}
Lst_Close (path);
if (lastDot && cur && (file = DirLookupSubdir(cur, name)) != NULL)
if (hasLastDot && cur && (file = DirLookupSubdir(cur, name)) != NULL)
return file;
if (DEBUG(DIR)) {

View File

@ -1,4 +1,4 @@
/* $NetBSD: main.c,v 1.81 2001/12/11 20:50:58 tv Exp $ */
/* $NetBSD: main.c,v 1.82 2002/01/27 01:50:54 reinoud Exp $ */
/*
* Copyright (c) 1988, 1989, 1990, 1993
@ -39,7 +39,7 @@
*/
#ifdef MAKE_BOOTSTRAP
static char rcsid[] = "$NetBSD: main.c,v 1.81 2001/12/11 20:50:58 tv Exp $";
static char rcsid[] = "$NetBSD: main.c,v 1.82 2002/01/27 01:50:54 reinoud Exp $";
#else
#include <sys/cdefs.h>
#ifndef lint
@ -51,7 +51,7 @@ __COPYRIGHT("@(#) Copyright (c) 1988, 1989, 1990, 1993\n\
#if 0
static char sccsid[] = "@(#)main.c 8.3 (Berkeley) 3/19/94";
#else
__RCSID("$NetBSD: main.c,v 1.81 2001/12/11 20:50:58 tv Exp $");
__RCSID("$NetBSD: main.c,v 1.82 2002/01/27 01:50:54 reinoud Exp $");
#endif
#endif /* not lint */
#endif
@ -835,7 +835,7 @@ main(argc, argv)
* <directory>:<directory>:<directory>...
*/
if (Var_Exists("VPATH", VAR_CMD)) {
char *vpath, *path, *cp, savec;
char *vpath, savec;
/*
* GCC stores string constants in read-only memory, but
* Var_Subst will want to write this thing, so store it
@ -1046,7 +1046,7 @@ Check_Cwd_av(ac, av, copy)
int copy;
{
static char *make[4];
static char *curdir = NULL;
static char *cur_dir = NULL;
char *cp, **mp;
int is_cmd, next_cmd;
int i;
@ -1068,7 +1068,7 @@ Check_Cwd_av(ac, av, copy)
} else
++make[0];
make[2] = NULL;
curdir = Var_Value(".CURDIR", VAR_GLOBAL, &cp);
cur_dir = Var_Value(".CURDIR", VAR_GLOBAL, &cp);
}
if (ac == 0 || av == NULL)
return NULL; /* initialization only */
@ -1135,9 +1135,9 @@ Check_Cwd_av(ac, av, copy)
if (strcmp(cp, *mp) == 0) {
#ifdef check_cwd_debug
fprintf(stderr, " %s == '%s', chdir(%s)\n",
cp, *mp, curdir);
cp, *mp, cur_dir);
#endif
return curdir;
return cur_dir;
}
}
}

View File

@ -1,4 +1,4 @@
/* $NetBSD: make.c,v 1.39 2001/07/03 18:08:51 christos Exp $ */
/* $NetBSD: make.c,v 1.40 2002/01/27 01:50:55 reinoud Exp $ */
/*
* Copyright (c) 1988, 1989, 1990, 1993
@ -39,14 +39,14 @@
*/
#ifdef MAKE_BOOTSTRAP
static char rcsid[] = "$NetBSD: make.c,v 1.39 2001/07/03 18:08:51 christos Exp $";
static char rcsid[] = "$NetBSD: make.c,v 1.40 2002/01/27 01:50:55 reinoud Exp $";
#else
#include <sys/cdefs.h>
#ifndef lint
#if 0
static char sccsid[] = "@(#)make.c 8.1 (Berkeley) 6/6/93";
#else
__RCSID("$NetBSD: make.c,v 1.39 2001/07/03 18:08:51 christos Exp $");
__RCSID("$NetBSD: make.c,v 1.40 2002/01/27 01:50:55 reinoud Exp $");
#endif
#endif /* not lint */
#endif
@ -650,7 +650,6 @@ Make_Update (cgn)
* of this node.
*/
if (Lst_Open (cgn->iParents) == SUCCESS) {
char *p1;
char *cpref = Var_Value(PREFIX, cgn, &p1);
while ((ln = Lst_Next (cgn->iParents)) != NILLNODE) {

View File

@ -1,4 +1,4 @@
/* $NetBSD: parse.c,v 1.77 2002/01/26 20:42:14 christos Exp $ */
/* $NetBSD: parse.c,v 1.78 2002/01/27 01:50:55 reinoud Exp $ */
/*
* Copyright (c) 1988, 1989, 1990, 1993
@ -39,14 +39,14 @@
*/
#ifdef MAKE_BOOTSTRAP
static char rcsid[] = "$NetBSD: parse.c,v 1.77 2002/01/26 20:42:14 christos Exp $";
static char rcsid[] = "$NetBSD: parse.c,v 1.78 2002/01/27 01:50:55 reinoud Exp $";
#else
#include <sys/cdefs.h>
#ifndef lint
#if 0
static char sccsid[] = "@(#)parse.c 8.3 (Berkeley) 3/19/94";
#else
__RCSID("$NetBSD: parse.c,v 1.77 2002/01/26 20:42:14 christos Exp $");
__RCSID("$NetBSD: parse.c,v 1.78 2002/01/27 01:50:55 reinoud Exp $");
#endif
#endif /* not lint */
#endif
@ -1255,7 +1255,6 @@ ParseDoDependency (line)
* If it was .OBJDIR, the source is a new definition for .OBJDIR,
* and will cause make to do a new chdir to that path.
*/
char savec;
while (*cp && !isspace ((unsigned char)*cp)) {
cp++;
}
@ -1317,8 +1316,6 @@ ParseDoDependency (line)
}
if (*cp == LPAREN) {
GNode *gn;
sources = Lst_Init (FALSE);
if (Arch_ParseArchive (&line, sources, VAR_CMD) != SUCCESS) {
Parse_Error (PARSE_FATAL,
@ -1926,18 +1923,18 @@ ParseDoInclude (line)
*---------------------------------------------------------------------
*/
static void
ParseSetParseFile(fname)
char *fname;
ParseSetParseFile(filename)
char *filename;
{
char *slash;
slash = strrchr(fname, '/');
slash = strrchr(filename, '/');
if (slash == 0) {
Var_Set(".PARSEDIR", ".", VAR_GLOBAL, 0);
Var_Set(".PARSEFILE", fname, VAR_GLOBAL, 0);
Var_Set(".PARSEFILE", filename, VAR_GLOBAL, 0);
} else {
*slash = '\0';
Var_Set(".PARSEDIR", fname, VAR_GLOBAL, 0);
Var_Set(".PARSEDIR", filename, VAR_GLOBAL, 0);
Var_Set(".PARSEFILE", slash+1, VAR_GLOBAL, 0);
*slash = '/';
}

View File

@ -1,4 +1,4 @@
/* $NetBSD: suff.c,v 1.35 2001/11/14 19:27:40 tv Exp $ */
/* $NetBSD: suff.c,v 1.36 2002/01/27 01:50:55 reinoud Exp $ */
/*
* Copyright (c) 1988, 1989, 1990, 1993
@ -39,14 +39,14 @@
*/
#ifdef MAKE_BOOTSTRAP
static char rcsid[] = "$NetBSD: suff.c,v 1.35 2001/11/14 19:27:40 tv Exp $";
static char rcsid[] = "$NetBSD: suff.c,v 1.36 2002/01/27 01:50:55 reinoud Exp $";
#else
#include <sys/cdefs.h>
#ifndef lint
#if 0
static char sccsid[] = "@(#)suff.c 8.4 (Berkeley) 3/21/94";
#else
__RCSID("$NetBSD: suff.c,v 1.35 2001/11/14 19:27:40 tv Exp $");
__RCSID("$NetBSD: suff.c,v 1.36 2002/01/27 01:50:55 reinoud Exp $");
#endif
#endif /* not lint */
#endif
@ -1958,7 +1958,6 @@ SuffFindNormalDeps(gn, slst)
if (ln != NILLNODE) {
int prefLen; /* Length of the prefix */
Src *targ;
/*
* Allocate a Src structure to which things can be transformed

View File

@ -1,4 +1,4 @@
/* $NetBSD: targ.c,v 1.24 2001/11/12 01:33:49 tv Exp $ */
/* $NetBSD: targ.c,v 1.25 2002/01/27 01:50:55 reinoud Exp $ */
/*
* Copyright (c) 1988, 1989, 1990, 1993
@ -39,14 +39,14 @@
*/
#ifdef MAKE_BOOTSTRAP
static char rcsid[] = "$NetBSD: targ.c,v 1.24 2001/11/12 01:33:49 tv Exp $";
static char rcsid[] = "$NetBSD: targ.c,v 1.25 2002/01/27 01:50:55 reinoud Exp $";
#else
#include <sys/cdefs.h>
#ifndef lint
#if 0
static char sccsid[] = "@(#)targ.c 8.2 (Berkeley) 3/19/94";
#else
__RCSID("$NetBSD: targ.c,v 1.24 2001/11/12 01:33:49 tv Exp $");
__RCSID("$NetBSD: targ.c,v 1.25 2002/01/27 01:50:55 reinoud Exp $");
#endif
#endif /* not lint */
#endif
@ -503,13 +503,13 @@ Targ_PrintCmd (cmd, dummy)
*-----------------------------------------------------------------------
*/
char *
Targ_FmtTime (time)
time_t time;
Targ_FmtTime (tm)
time_t tm;
{
struct tm *parts;
static char buf[128];
parts = localtime(&time);
parts = localtime(&tm);
(void)strftime(buf, sizeof buf, "%k:%M:%S %b %d, %Y", parts);
return(buf);
}

View File

@ -1,4 +1,4 @@
/* $NetBSD: trace.c,v 1.3 2001/01/23 02:48:05 cgd Exp $ */
/* $NetBSD: trace.c,v 1.4 2002/01/27 01:50:55 reinoud Exp $ */
/*-
* Copyright (c) 2000 The NetBSD Foundation, Inc.
@ -38,11 +38,11 @@
#ifdef MAKE_BOOTSTRAP
static char rcsid[] = "$NetBSD: trace.c,v 1.3 2001/01/23 02:48:05 cgd Exp $";
static char rcsid[] = "$NetBSD: trace.c,v 1.4 2002/01/27 01:50:55 reinoud Exp $";
#else
#include <sys/cdefs.h>
#ifndef lint
__RCSID("$NetBSD: trace.c,v 1.3 2001/01/23 02:48:05 cgd Exp $");
__RCSID("$NetBSD: trace.c,v 1.4 2002/01/27 01:50:55 reinoud Exp $");
#endif /* not lint */
#endif
@ -98,15 +98,15 @@ Trace_Log(event, job)
TrEvent event;
Job *job;
{
struct timeval now;
struct timeval rightnow;
if (trfile == NULL)
return;
gettimeofday(&now, NULL);
gettimeofday(&rightnow, NULL);
fprintf(trfile, "%ld.%06d %d %d %s %d %s",
now.tv_sec, (int)now.tv_usec,
rightnow.tv_sec, (int)rightnow.tv_usec,
jobTokensRunning, jobTokensFree,
evname[event], trpid, trwd);
if (job != NULL) {

View File

@ -1,15 +1,15 @@
/* $NetBSD: util.c,v 1.28 2002/01/25 17:51:32 tv Exp $ */
/* $NetBSD: util.c,v 1.29 2002/01/27 01:50:55 reinoud Exp $ */
/*
* Missing stuff from OS's
*/
#ifdef MAKE_BOOTSTRAP
static char rcsid[] = "$NetBSD: util.c,v 1.28 2002/01/25 17:51:32 tv Exp $";
static char rcsid[] = "$NetBSD: util.c,v 1.29 2002/01/27 01:50:55 reinoud Exp $";
#else
#include <sys/cdefs.h>
#ifndef lint
__RCSID("$NetBSD: util.c,v 1.28 2002/01/25 17:51:32 tv Exp $");
__RCSID("$NetBSD: util.c,v 1.29 2002/01/27 01:50:55 reinoud Exp $");
#endif
#endif
@ -425,7 +425,7 @@ snprintf(va_alist)
}
#if defined(MAKE_BOOTSTRAP) && !defined(HAVE_STRFTIME)
int
size_t
strftime(buf, len, fmt, tm)
char *buf;
size_t len;

View File

@ -1,4 +1,4 @@
/* $NetBSD: var.c,v 1.66 2001/12/25 14:50:36 lukem Exp $ */
/* $NetBSD: var.c,v 1.67 2002/01/27 01:50:55 reinoud Exp $ */
/*
* Copyright (c) 1988, 1989, 1990, 1993
@ -39,14 +39,14 @@
*/
#ifdef MAKE_BOOTSTRAP
static char rcsid[] = "$NetBSD: var.c,v 1.66 2001/12/25 14:50:36 lukem Exp $";
static char rcsid[] = "$NetBSD: var.c,v 1.67 2002/01/27 01:50:55 reinoud Exp $";
#else
#include <sys/cdefs.h>
#ifndef lint
#if 0
static char sccsid[] = "@(#)var.c 8.3 (Berkeley) 3/19/94";
#else
__RCSID("$NetBSD: var.c,v 1.66 2001/12/25 14:50:36 lukem Exp $");
__RCSID("$NetBSD: var.c,v 1.67 2002/01/27 01:50:55 reinoud Exp $");
#endif
#endif /* not lint */
#endif
@ -2474,10 +2474,10 @@ Var_Parse (str, ctxt, err, lengthPtr, freePtr)
#ifdef SUNSHCMD
case 's':
if (tstr[1] == 'h' && (tstr[2] == endc || tstr[2] == ':')) {
char *err;
newStr = Cmd_Exec (str, &err);
if (err)
Error (err, str);
char *errstr;
newStr = Cmd_Exec (str, &errstr);
if (errstr)
Error (errstr, str);
cp = tstr + 2;
termc = *cp;
break;