From eugen@grosbein.pp.ru  Sun Aug 12 15:25:07 2007
Return-Path: <eugen@grosbein.pp.ru>
Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34])
	by hub.freebsd.org (Postfix) with ESMTP id A9D4B16A418
	for <FreeBSD-gnats-submit@freebsd.org>; Sun, 12 Aug 2007 15:25:07 +0000 (UTC)
	(envelope-from eugen@grosbein.pp.ru)
Received: from grosbein.pp.ru (grgw.svzserv.kemerovo.su [213.184.64.166])
	by mx1.freebsd.org (Postfix) with ESMTP id E211B13C458
	for <FreeBSD-gnats-submit@freebsd.org>; Sun, 12 Aug 2007 15:25:05 +0000 (UTC)
	(envelope-from eugen@grosbein.pp.ru)
Received: from grosbein.pp.ru (localhost [127.0.0.1])
	by grosbein.pp.ru (8.14.1/8.14.1) with ESMTP id l7CFP0ST001929
	for <FreeBSD-gnats-submit@freebsd.org>; Sun, 12 Aug 2007 23:25:01 +0800 (KRAST)
	(envelope-from eugen@grosbein.pp.ru)
Received: (from eugen@localhost)
	by grosbein.pp.ru (8.14.1/8.14.1/Submit) id l7CFP0Ll001925;
	Sun, 12 Aug 2007 23:25:00 +0800 (KRAST)
	(envelope-from eugen)
Message-Id: <200708121525.l7CFP0Ll001925@grosbein.pp.ru>
Date: Sun, 12 Aug 2007 23:25:00 +0800 (KRAST)
From: Eugene Grosbein <eugen@grosbein.pp.ru>
Reply-To: Eugene Grosbein <eugen@grosbein.pp.ru>
To: FreeBSD-gnats-submit@freebsd.org
Cc:
Subject: [patch] teach make(1) to respect TMPDIR environment variable
X-Send-Pr-Version: 3.113
X-GNATS-Notify:

>Number:         115447
>Category:       bin
>Synopsis:       [patch] [request] teach make(1) to respect TMPDIR environment variable
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    harti
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          change-request
>Submitter-Id:   current-users
>Arrival-Date:   Sun Aug 12 15:30:01 GMT 2007
>Closed-Date:    Fri Mar 15 23:41:55 UTC 2013
>Last-Modified:  Fri Mar 15 23:41:55 UTC 2013
>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@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:
State-Changed-From-To: open->feedback 
State-Changed-By: remko 
State-Changed-When: Tue Aug 14 15:00:20 UTC 2007 
State-Changed-Why:  
So, you are still refusing my emails. I had a little question [perhaps a 
dumb one] but lets first try to get us talking. No reply in 24 hours 
from my mailserver, if this also happens with this ticket, I will close 
this ticket. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=115447 
State-Changed-From-To: feedback->open 
State-Changed-By: remko 
State-Changed-When: Wed Aug 15 05:36:15 UTC 2007 
State-Changed-Why:  
My question was answered [which I could not check normally 
on the net], Thanks Eugene for the answer, returning the 
PR ticket to the state of ''open''. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=115447 
Responsible-Changed-From-To: freebsd-bugs->harti 
Responsible-Changed-By: harti 
Responsible-Changed-When: Thu Jan 22 11:39:18 UTC 2009 
Responsible-Changed-Why:  
I look into this. Seems like a good idea. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=115447 

From: dfilter@FreeBSD.ORG (dfilter service)
To: bug-followup@FreeBSD.org
Cc:  
Subject: Re: bin/115447: commit references a PR
Date: Sun, 10 Jan 2010 20:26:12 +0000 (UTC)

 Author: harti
 Date: Sun Jan 10 20:26:03 2010
 New Revision: 202045
 URL: http://svn.freebsd.org/changeset/base/202045
 
 Log:
   Make make respect the TMPDIR environment variable.
   
   PR:		bin/115447
   Submitted by:	Eugene Grosbein
 
 Modified:
   head/usr.bin/make/job.c
 
 Modified: head/usr.bin/make/job.c
 ==============================================================================
 --- head/usr.bin/make/job.c	Sun Jan 10 20:22:05 2010	(r202044)
 +++ head/usr.bin/make/job.c	Sun Jan 10 20:26:03 2010	(r202045)
 @@ -114,6 +114,7 @@ __FBSDID("$FreeBSD$");
  #include <errno.h>
  #include <fcntl.h>
  #include <inttypes.h>
 +#include <limits.h>
  #include <string.h>
  #include <signal.h>
  #include <stdlib.h>
 @@ -137,7 +138,8 @@ __FBSDID("$FreeBSD$");
  #include "util.h"
  #include "var.h"
  
 -#define	TMPPAT	"/tmp/makeXXXXXXXXXX"
 +#define	TMPPAT	"makeXXXXXXXXXX"
 +#define	TMPDIR	"/tmp"
  
  #ifndef USE_KQUEUE
  /*
 @@ -236,7 +238,7 @@ typedef struct Job {
  		 */
  		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
 @@ -1566,7 +1568,8 @@ JobStart(GNode *gn, int flags, Job *prev
  	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];
 +	const char *tdir;
  
  	if (interrupted) {
  		JobPassSig(interrupted);
 @@ -1607,6 +1610,9 @@ JobStart(GNode *gn, int flags, Job *prev
  		cmdsOK = TRUE;
  	}
  
 +	if ((tdir = getenv("TMPDIR")) == NULL)
 +		tdir = TMPDIR;
 +
  	/*
  	 * 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
 @@ -1622,7 +1628,7 @@ JobStart(GNode *gn, int flags, Job *prev
  			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+");
 @@ -1801,7 +1807,10 @@ JobStart(GNode *gn, int flags, Job *prev
  		} else {
  			fprintf(stdout, "Remaking `%s'\n", gn->name);
  			fflush(stdout);
 -			strcpy(job->outFile, TMPPAT);
 +			if ((tdir = getenv("TMPDIR")) == NULL)
 +				tdir = TMPDIR;
 +			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));
 _______________________________________________
 svn-src-all@freebsd.org mailing list
 http://lists.freebsd.org/mailman/listinfo/svn-src-all
 To unsubscribe, send any mail to "svn-src-all-unsubscribe@freebsd.org"
 

From: Eugene Grosbein <eugen@eg.sd.rdtc.ru>
To: bug-followup@freebsd.org
Cc: harti@freebsd.org
Subject: Re: bin/115447: [patch] [request] teach make(1) to respect TMPDIR environment variable
Date: Tue, 23 Nov 2010 01:21:07 +0600

 Hi!
 
 Thank you for commintting this. Please perform MFC to RELENG_8
 for upcoming 8.2-RELEASE.
 
 Eugene Grosbein
State-Changed-From-To: open->patched 
State-Changed-By: eadler 
State-Changed-When: Tue Mar 1 10:14:40 EST 2011 
State-Changed-Why:  
committed into head 

http://www.freebsd.org/cgi/query-pr.cgi?pr=115447 

From: Eugene Grosbein <egrosbein@rdtc.ru>
To: bug-followup@FreeBSD.ORG
Cc: Harti Brandt <harti@FreeBSD.ORG>
Subject: bin/115447: [patch] [request] teach make(1) to respect TMPDIR environment
 variable
Date: Mon, 01 Aug 2011 00:32:44 +0700

 Hi!
 
 Please perform MFC for fix you've made for
 http://www.freebsd.org/cgi/query-pr.cgi?pr=bin/115447
 
 Thanks.
 
 Eugene Grosbein
State-Changed-From-To: patched->closed 
State-Changed-By: eadler 
State-Changed-When: Fri Mar 15 23:41:53 UTC 2013 
State-Changed-Why:  
MFCed/fixed by now or it will never be MFCed 

http://www.freebsd.org/cgi/query-pr.cgi?pr=115447 
>Unformatted:
