svn commit: r333793 - head/usr.sbin/pmcannotate

Andrew Gallatin gallatin at FreeBSD.org
Fri May 18 14:14:05 UTC 2018


Author: gallatin
Date: Fri May 18 14:14:04 2018
New Revision: 333793
URL: https://svnweb.freebsd.org/changeset/base/333793

Log:
  Teach pmcannotate about $TMPDIR and _PATH_TMP
  
  Convert pmcannotate to using $TMPDIR and _PATH_TMP rather than hard
  coding /tmp for temporary files.  Pmcannotate sometimes needs quite a
  lot of space to store the output from objdump, and will fail in odd
  ways if that output is truncated due to lack of space in /tmp.
  
  Reviewed by:	jtl
  Sponsored by:	Netflix

Modified:
  head/usr.sbin/pmcannotate/pmcannotate.c

Modified: head/usr.sbin/pmcannotate/pmcannotate.c
==============================================================================
--- head/usr.sbin/pmcannotate/pmcannotate.c	Fri May 18 13:49:12 2018	(r333792)
+++ head/usr.sbin/pmcannotate/pmcannotate.c	Fri May 18 14:14:04 2018	(r333793)
@@ -37,6 +37,7 @@ __FBSDID("$FreeBSD$");
 #include <sys/queue.h>
 
 #include <ctype.h>
+#include <paths.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
@@ -47,7 +48,7 @@ __FBSDID("$FreeBSD$");
 #define	FNBUFF	512
 #define	LNBUFF	512
 
-#define	TMPPATH	"/tmp/pmcannotate.XXXXXX"
+#define	TMPNAME	"pmcannotate.XXXXXX"
 
 #define	FATAL(ptr, x ...) do {						\
 	fqueue_deleteall();						\
@@ -671,7 +672,8 @@ usage(const char *progname)
 int
 main(int argc, char *argv[])
 {
-	char buffer[LNBUFF], fname[FNBUFF], tbfl[] = TMPPATH, tofl[] = TMPPATH;
+	char buffer[LNBUFF], fname[FNBUFF];
+	char *tbfl, *tofl, *tmpdir;
 	char tmpf[MAXPATHLEN * 2 + 50];
 	float limit;
 	char *bin, *exec, *kfile, *ofile;
@@ -721,6 +723,17 @@ main(int argc, char *argv[])
 		    exec);
 
 	bzero(tmpf, sizeof(tmpf));
+	tmpdir = getenv("TMPDIR");
+	if (tmpdir == NULL) {
+		asprintf(&tbfl, "%s/%s", _PATH_TMP, TMPNAME);
+		asprintf(&tofl, "%s/%s", _PATH_TMP, TMPNAME);
+	} else {
+		asprintf(&tbfl, "%s/%s", tmpdir, TMPNAME);
+		asprintf(&tofl, "%s/%s", tmpdir, TMPNAME);
+	}
+	if (tofl == NULL || tbfl == NULL)
+		FATAL(exec, "%s: Cannot create tempfile templates\n",
+		    exec);
 	if (mkstemp(tofl) == -1)
 		FATAL(exec, "%s: Impossible to create the tmp file\n",
 		    exec);


More information about the svn-src-all mailing list