Module Name:    src
Committed By:   apb
Date:           Sat Apr 11 09:41:18 UTC 2009

Modified Files:
        src/usr.bin/make: job.c job.h make.1 pathnames.h

Log Message:
Honour the TMPDIR environment variable instead of always using /tmp
as a place to store temporary files.


To generate a diff of this commit:
cvs rdiff -u -r1.144 -r1.145 src/usr.bin/make/job.c
cvs rdiff -u -r1.38 -r1.39 src/usr.bin/make/job.h
cvs rdiff -u -r1.153 -r1.154 src/usr.bin/make/make.1
cvs rdiff -u -r1.16 -r1.17 src/usr.bin/make/pathnames.h

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/usr.bin/make/job.c
diff -u src/usr.bin/make/job.c:1.144 src/usr.bin/make/job.c:1.145
--- src/usr.bin/make/job.c:1.144	Fri Jan 23 21:26:30 2009
+++ src/usr.bin/make/job.c	Sat Apr 11 09:41:18 2009
@@ -1,4 +1,4 @@
-/*	$NetBSD: job.c,v 1.144 2009/01/23 21:26:30 dsl Exp $	*/
+/*	$NetBSD: job.c,v 1.145 2009/04/11 09:41:18 apb Exp $	*/
 
 /*
  * Copyright (c) 1988, 1989, 1990 The Regents of the University of California.
@@ -70,14 +70,14 @@
  */
 
 #ifndef MAKE_NATIVE
-static char rcsid[] = "$NetBSD: job.c,v 1.144 2009/01/23 21:26:30 dsl Exp $";
+static char rcsid[] = "$NetBSD: job.c,v 1.145 2009/04/11 09:41:18 apb Exp $";
 #else
 #include <sys/cdefs.h>
 #ifndef lint
 #if 0
 static char sccsid[] = "@(#)job.c	8.2 (Berkeley) 3/19/94";
 #else
-__RCSID("$NetBSD: job.c,v 1.144 2009/01/23 21:26:30 dsl Exp $");
+__RCSID("$NetBSD: job.c,v 1.145 2009/04/11 09:41:18 apb Exp $");
 #endif
 #endif /* not lint */
 #endif
@@ -342,6 +342,8 @@
 #define KILLPG(pid, sig)	killpg((pid), (sig))
 #endif
 
+static char *tmpdir;		/* directory name, always ending with "/" */
+
 static void JobChildSig(int);
 static void JobContinueSig(int);
 static Job *JobFindPid(int, int);
@@ -1538,11 +1540,10 @@
 	    (!noExecute && !touchFlag)) {
 	/*
 	 * tfile is the name of a file into which all shell commands are
-	 * put. It is used over by removing it before the child shell is
-	 * executed. The XXXXXX in the string are replaced by the pid of
-	 * the make process in a 6-character field with leading zeroes.
+	 * put. It is removed before the child shell is executed, unless
+	 * DEBUG(SCRIPT) is set.
 	 */
-	char     tfile[sizeof(TMPPAT)];
+	char *tfile;
 	sigset_t mask;
 	/*
 	 * We're serious here, but if the commands were bogus, we're
@@ -1553,7 +1554,9 @@
 	}
 
 	JobSigLock(&mask);
-	(void)strcpy(tfile, TMPPAT);
+	tfile = bmake_malloc(strlen(tmpdir) + sizeof(TMPPAT));
+	strcpy(tfile, tmpdir);
+	strcat(tfile, TMPPAT);
 	if ((tfd = mkstemp(tfile)) == -1)
 	    Punt("Could not create temporary file %s", strerror(errno));
 	if (!DEBUG(SCRIPT))
@@ -1584,6 +1587,8 @@
 	if (numCommands == 0) {
 	    noExec = TRUE;
 	}
+
+	free(tfile);
     } else if (NoExecute(gn)) {
 	/*
 	 * Not executing anything -- just print all the commands to stdout
@@ -2116,6 +2121,8 @@
 Job_Init(void)
 {
     GNode         *begin;     /* node for commands to do at the very start */
+    const char    *p;
+    size_t        len;
 
     /* Allocate space for all the job info */
     job_table = bmake_malloc(maxJobs * sizeof *job_table);
@@ -2128,6 +2135,18 @@
 
     lastNode =	  NULL;
 
+    /* set tmpdir, and ensure that it ends with "/" */
+    p = getenv("TMPDIR");
+    if (p == NULL || *p == '\0') {
+	p = _PATH_TMP;
+    }
+    len = strlen(p);
+    tmpdir = bmake_malloc(len + 2);
+    strcpy(tmpdir, p);
+    if (tmpdir[len - 1] != '/') {
+	strcat(tmpdir, "/");
+    }
+
     if (maxJobs == 1) {
 	/*
 	 * If only one job can run at a time, there's no need for a banner,

Index: src/usr.bin/make/job.h
diff -u src/usr.bin/make/job.h:1.38 src/usr.bin/make/job.h:1.39
--- src/usr.bin/make/job.h:1.38	Sat Dec 13 15:19:29 2008
+++ src/usr.bin/make/job.h	Sat Apr 11 09:41:18 2009
@@ -1,4 +1,4 @@
-/*	$NetBSD: job.h,v 1.38 2008/12/13 15:19:29 dsl Exp $	*/
+/*	$NetBSD: job.h,v 1.39 2009/04/11 09:41:18 apb Exp $	*/
 
 /*
  * Copyright (c) 1988, 1989, 1990 The Regents of the University of California.
@@ -80,7 +80,7 @@
 #ifndef _JOB_H_
 #define _JOB_H_
 
-#define TMPPAT	"/tmp/makeXXXXXX"
+#define TMPPAT	"makeXXXXXX"		/* relative to tmpdir */
 
 #ifdef USE_SELECT
 /*

Index: src/usr.bin/make/make.1
diff -u src/usr.bin/make/make.1:1.153 src/usr.bin/make/make.1:1.154
--- src/usr.bin/make/make.1:1.153	Sat Jan 24 13:02:33 2009
+++ src/usr.bin/make/make.1	Sat Apr 11 09:41:18 2009
@@ -1,4 +1,4 @@
-.\"	$NetBSD: make.1,v 1.153 2009/01/24 13:02:33 wiz Exp $
+.\"	$NetBSD: make.1,v 1.154 2009/04/11 09:41:18 apb Exp $
 .\"
 .\" Copyright (c) 1990, 1993
 .\"	The Regents of the University of California.  All rights reserved.
@@ -185,16 +185,24 @@
 Print debugging information about making targets, including modification
 dates.
 .It Ar n
-Don't delete the temporary command scripts created in
+Don't delete the temporary command scripts created when running commands.
+These temporary scripts are created in the directory
+referred to by the
+.Ev TMPDIR
+environment variable, or in
 .Pa /tmp
-when running commands.
-These are created via
-.Xr mkstemp 3
+if
+.Ev TMPDIR
+is unset or set to the empty string.
+The temporary scripts are created by
+.Xr mkstemp 3 ,
 and have names of the form
-.Pa /tmp/makeXXXXX .
+.Pa makeXXXXXX .
 .Em NOTE :
 This can create many file in
-.Pa /tmp
+.Ev TMPDIR
+or
+.Pa /tmp ,
 so use with care.
 .It Ar p
 Print debugging information about makefile parsing.
@@ -1769,8 +1777,9 @@
 .Ev MAKEOBJDIR ,
 .Ev MAKEOBJDIRPREFIX ,
 .Ev MAKESYSPATH ,
+.Ev PWD ,
 and
-.Ev PWD .
+.Ev TMPDIR .
 .Pp
 .Ev MAKEOBJDIRPREFIX
 and

Index: src/usr.bin/make/pathnames.h
diff -u src/usr.bin/make/pathnames.h:1.16 src/usr.bin/make/pathnames.h:1.17
--- src/usr.bin/make/pathnames.h:1.16	Fri Jun 24 04:33:25 2005
+++ src/usr.bin/make/pathnames.h	Sat Apr 11 09:41:18 2009
@@ -1,4 +1,4 @@
-/*	$NetBSD: pathnames.h,v 1.16 2005/06/24 04:33:25 lukem Exp $	*/
+/*	$NetBSD: pathnames.h,v 1.17 2009/04/11 09:41:18 apb Exp $	*/
 
 /*
  * Copyright (c) 1990, 1993
@@ -48,3 +48,6 @@
 #ifndef _PATH_DEFSYSPATH
 #define	_PATH_DEFSYSPATH	"/usr/share/mk"
 #endif
+#ifndef _PATH_TMP
+#define	_PATH_TMP		"/tmp/"		/* with trailing slash */
+#endif

Reply via email to