Honour the TMPDIR environment variable instead of always using /tmp

as a place to store temporary files.
This commit is contained in:
apb 2009-04-11 09:41:18 +00:00
parent ef685eeea9
commit af9429a671
4 changed files with 50 additions and 19 deletions

View File

@ -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 @@ static sigset_t caught_signals; /* Set of signals we handle */
#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 @@ JobStart(GNode *gn, int flags)
(!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 @@ JobStart(GNode *gn, int flags)
}
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 @@ JobStart(GNode *gn, int flags)
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 @@ void
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 @@ Job_Init(void)
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,

View File

@ -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
/*

View File

@ -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 @@ Also known as "loud" behavior.
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 @@ uses the following environment variables, if they exist:
.Ev MAKEOBJDIR ,
.Ev MAKEOBJDIRPREFIX ,
.Ev MAKESYSPATH ,
.Ev PWD ,
and
.Ev PWD .
.Ev TMPDIR .
.Pp
.Ev MAKEOBJDIRPREFIX
and

View File

@ -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