bin/115447: [patch] teach make(1) to respect TMPDIR environment
variable
Eugene Grosbein
eugen at grosbein.pp.ru
Sun Aug 12 08:30:02 PDT 2007
>Number: 115447
>Category: bin
>Synopsis: [patch] teach make(1) to respect TMPDIR environment variable
>Confidential: no
>Severity: non-critical
>Priority: low
>Responsible: freebsd-bugs
>State: open
>Quarter:
>Keywords:
>Date-Required:
>Class: change-request
>Submitter-Id: current-users
>Arrival-Date: Sun Aug 12 15:30:01 GMT 2007
>Closed-Date:
>Last-Modified:
>Originator: Eugene Grosbein
>Release: FreeBSD 6.2-STABLE i386
>Organization:
Svyaz-Service JSC
>Environment:
System: FreeBSD grosbein.pp.ru 6.2-STABLE FreeBSD 6.2-STABLE #0: Sat Aug 11 18:41:38 KRAST 2007 eu at grosbein.pp.ru:/home/obj/usr/local/src/sys/DADV i386
>Description:
System make(1) uses hardcoded /tmp path for its temporary files.
Let's teach it to use TMPDIR environment variable if it's set.
Very often /tmp is located on root filesystem and often
this filesystem has not softupdates flag set. Taking make's
temporary directory out for such filesystem to memory disk
descreases "make -j3 buildworld" real time to more than 3 minutes
for my system (2xPentium-D 2.8Ghz, UDMA100 IDE HDD).
>How-To-Repeat:
Watch load of drive containing /tmp with "systat -vm 3"
while "make buildworld" runs when /usr/src and /usr/obj are located
on another device. make(1) makes high load on /tmp.
>Fix:
--- usr.bin/make/job.c.orig 2007-08-11 09:38:05.000000000 +0800
+++ usr.bin/make/job.c 2007-08-11 09:52:43.000000000 +0800
@@ -118,6 +118,7 @@
#include <errno.h>
#include <fcntl.h>
#include <inttypes.h>
+#include <limits.h>
#include <string.h>
#include <signal.h>
#include <stdlib.h>
@@ -141,7 +142,7 @@
#include "util.h"
#include "var.h"
-#define TMPPAT "/tmp/makeXXXXXXXXXX"
+#define TMPPAT "makeXXXXXXXXXX"
#ifndef USE_KQUEUE
/*
@@ -240,7 +241,7 @@
*/
struct {
/* Name of file to which shell output was rerouted */
- char of_outFile[sizeof(TMPPAT)];
+ char of_outFile[PATH_MAX];
/*
* Stream open to the output file. Used to funnel all
@@ -1576,7 +1577,8 @@
Boolean noExec; /* Set true if we decide not to run the job */
int tfd; /* File descriptor for temp file */
LstNode *ln;
- char tfile[sizeof(TMPPAT)];
+ char tfile[PATH_MAX];
+ char *tdir;
if (interrupted) {
JobPassSig(interrupted);
@@ -1617,6 +1619,9 @@
cmdsOK = TRUE;
}
+ if ( (tdir = getenv("TMPDIR")) == NULL )
+ tdir = "/tmp";
+
/*
* If the -n flag wasn't given, we open up OUR (not the child's)
* temporary file to stuff commands in it. The thing is rd/wr so we
@@ -1632,7 +1637,7 @@
DieHorribly();
}
- strcpy(tfile, TMPPAT);
+ snprintf(tfile, sizeof(tfile), "%s/%s", tdir, TMPPAT);
if ((tfd = mkstemp(tfile)) == -1)
Punt("Cannot create temp file: %s", strerror(errno));
job->cmdFILE = fdopen(tfd, "w+");
@@ -1811,7 +1816,7 @@
} else {
fprintf(stdout, "Remaking `%s'\n", gn->name);
fflush(stdout);
- strcpy(job->outFile, TMPPAT);
+ snprintf(job->outFile, sizeof(job->outFile), "%s/%s", tdir, TMPPAT);
if ((job->outFd = mkstemp(job->outFile)) == -1)
Punt("cannot create temp file: %s",
strerror(errno));
Eugene Grosbein
>Release-Note:
>Audit-Trail:
>Unformatted:
More information about the freebsd-bugs
mailing list