summaryrefslogtreecommitdiffstats
path: root/usr.bin/make/compat.c
diff options
context:
space:
mode:
authorjkh <jkh@FreeBSD.org>1995-01-23 21:03:17 +0000
committerjkh <jkh@FreeBSD.org>1995-01-23 21:03:17 +0000
commit2dab142d474fb234edc194c7335fd5a627df77a6 (patch)
tree4fe60a8bd60f90f8461d826b8a6c0cd471c798d3 /usr.bin/make/compat.c
parenta8745a0ec131df320b6a7be781964c129c33644f (diff)
downloadFreeBSD-src-2dab142d474fb234edc194c7335fd5a627df77a6.zip
FreeBSD-src-2dab142d474fb234edc194c7335fd5a627df77a6.tar.gz
Bring in a number of changes from NetBSD's make, fixing quite a few
problems in the process: 1. Quoting should work properly now. In particular, Chet's reported bash make problem has gone away. 2. A lot of memory that just wasn't being free'd after use is now freed. This should cause make to take up a LOT less memory when dealing with archive targets. 3. Give proper credit to Adam de Boor in a number of files. Obtained from: NetBSD (and Adam de Boor)
Diffstat (limited to 'usr.bin/make/compat.c')
-rw-r--r--usr.bin/make/compat.c77
1 files changed, 43 insertions, 34 deletions
diff --git a/usr.bin/make/compat.c b/usr.bin/make/compat.c
index a14e296..2ec3c7c 100644
--- a/usr.bin/make/compat.c
+++ b/usr.bin/make/compat.c
@@ -1,6 +1,6 @@
/*
- * Copyright (c) 1988, 1989, 1990, 1993
- * The Regents of the University of California. All rights reserved.
+ * Copyright (c) 1988, 1989, 1990 The Regents of the University of California.
+ * Copyright (c) 1988, 1989 by Adam de Boor
* Copyright (c) 1989 by Berkeley Softworks
* All rights reserved.
*
@@ -53,15 +53,13 @@ static char sccsid[] = "@(#)compat.c 8.2 (Berkeley) 3/19/94";
* thems as need creatin'
*/
+#include <stdio.h>
#include <sys/types.h>
-#include <sys/stat.h>
+#include <sys/signal.h>
#include <sys/wait.h>
-
+#include <sys/errno.h>
+#include <sys/stat.h>
#include <ctype.h>
-#include <errno.h>
-#include <signal.h>
-#include <stdio.h>
-
#include "make.h"
#include "hash.h"
#include "dir.h"
@@ -80,8 +78,8 @@ static char meta[256];
static GNode *curTarg = NILGNODE;
static GNode *ENDNode;
static void CompatInterrupt __P((int));
-static int CompatRunCommand __P((char *, GNode *));
-static int CompatMake __P((GNode *, GNode *));
+static int CompatRunCommand __P((ClientData, ClientData));
+static int CompatMake __P((ClientData, ClientData));
/*-
*-----------------------------------------------------------------------
@@ -102,16 +100,19 @@ static void
CompatInterrupt (signo)
int signo;
{
- struct stat sb;
GNode *gn;
if ((curTarg != NILGNODE) && !Targ_Precious (curTarg)) {
- char *file = Var_Value (TARGET, curTarg);
+ char *p1;
+ char *file = Var_Value (TARGET, curTarg, &p1);
+ struct stat st;
- if (!stat(file, &sb) && S_ISREG(sb.st_mode) &&
- unlink (file) == SUCCESS) {
+ if (!noExecute && lstat(file, &st) != -1 && !S_ISDIR(st.st_mode) &&
+ unlink(file) != -1) {
printf ("*** %s removed\n", file);
}
+ if (p1)
+ free(p1);
/*
* Run .INTERRUPT only if hit with interrupt signal
@@ -122,8 +123,9 @@ CompatInterrupt (signo)
Lst_ForEach(gn->commands, CompatRunCommand, (ClientData)gn);
}
}
+
}
- exit (0);
+ exit (signo);
}
/*-
@@ -141,9 +143,9 @@ CompatInterrupt (signo)
*-----------------------------------------------------------------------
*/
static int
-CompatRunCommand (cmd, gn)
- char *cmd; /* Command to execute */
- GNode *gn; /* Node from which the command came */
+CompatRunCommand (cmdp, gnp)
+ ClientData cmdp; /* Command to execute */
+ ClientData gnp; /* Node from which the command came */
{
char *cmdStart; /* Start of expanded command */
register char *cp;
@@ -159,16 +161,17 @@ CompatRunCommand (cmd, gn)
* dynamically allocated */
Boolean local; /* TRUE if command should be executed
* locally */
+ char *cmd = (char *) cmdp;
+ GNode *gn = (GNode *) gnp;
- /*
+ /*
* Avoid clobbered variable warnings by forcing the compiler
* to ``unregister'' variables
- */
+ */
#if __GNUC__
- (void) &av;
+ (void) &av;
(void) &errCheck;
-#endif
-
+#endif
silent = gn->type & OP_SILENT;
errCheck = !(gn->type & OP_IGNORE);
@@ -183,6 +186,7 @@ CompatRunCommand (cmd, gn)
*/
if (*cmdStart == '\0') {
+ free(cmdStart);
Error("%s expands to empty string", cmd);
return(0);
} else {
@@ -257,7 +261,7 @@ CompatRunCommand (cmd, gn)
* brk_string sticks our name in av[0], so we have to
* skip over it...
*/
- av = brk_string(cmd, &argc);
+ av = brk_string(cmd, &argc, TRUE);
av += 1;
}
@@ -280,16 +284,13 @@ CompatRunCommand (cmd, gn)
}
exit(1);
}
+ free(cmdStart);
+ Lst_Replace (cmdNode, (ClientData) NULL);
/*
* The child is off and running. Now all we can do is wait...
*/
while (1) {
- int id;
-
- if (!local) {
- id = 0;
- }
while ((stat = wait((int *)&reason)) != cpid) {
if (stat == -1 && errno != EINTR) {
@@ -354,10 +355,12 @@ CompatRunCommand (cmd, gn)
*-----------------------------------------------------------------------
*/
static int
-CompatMake (gn, pgn)
- GNode *gn; /* The node to make */
- GNode *pgn; /* Parent to abort if necessary */
+CompatMake (gnp, pgnp)
+ ClientData gnp; /* The node to make */
+ ClientData pgnp; /* Parent to abort if necessary */
{
+ GNode *gn = (GNode *) gnp;
+ GNode *pgn = (GNode *) pgnp;
if (gn->type & OP_USE) {
Make_HandleUse(gn, pgn);
} else if (gn->made == UNMADE) {
@@ -380,7 +383,10 @@ CompatMake (gn, pgn)
}
if (Lst_Member (gn->iParents, pgn) != NILLNODE) {
- Var_Set (IMPSRC, Var_Value(TARGET, gn), pgn);
+ char *p1;
+ Var_Set (IMPSRC, Var_Value(TARGET, gn, &p1), pgn);
+ if (p1)
+ free(p1);
}
/*
@@ -528,7 +534,10 @@ CompatMake (gn, pgn)
pgn->make = FALSE;
} else {
if (Lst_Member (gn->iParents, pgn) != NILLNODE) {
- Var_Set (IMPSRC, Var_Value(TARGET, gn), pgn);
+ char *p1;
+ Var_Set (IMPSRC, Var_Value(TARGET, gn, &p1), pgn);
+ if (p1)
+ free(p1);
}
switch(gn->made) {
case BEINGMADE:
OpenPOWER on IntegriCloud