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
This commit is contained in:
parent
f097a19eab
commit
b4cc08389a
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=333793
@ -37,6 +37,7 @@ __FBSDID("$FreeBSD$");
|
|||||||
#include <sys/queue.h>
|
#include <sys/queue.h>
|
||||||
|
|
||||||
#include <ctype.h>
|
#include <ctype.h>
|
||||||
|
#include <paths.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
@ -47,7 +48,7 @@ __FBSDID("$FreeBSD$");
|
|||||||
#define FNBUFF 512
|
#define FNBUFF 512
|
||||||
#define LNBUFF 512
|
#define LNBUFF 512
|
||||||
|
|
||||||
#define TMPPATH "/tmp/pmcannotate.XXXXXX"
|
#define TMPNAME "pmcannotate.XXXXXX"
|
||||||
|
|
||||||
#define FATAL(ptr, x ...) do { \
|
#define FATAL(ptr, x ...) do { \
|
||||||
fqueue_deleteall(); \
|
fqueue_deleteall(); \
|
||||||
@ -671,7 +672,8 @@ usage(const char *progname)
|
|||||||
int
|
int
|
||||||
main(int argc, char *argv[])
|
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];
|
char tmpf[MAXPATHLEN * 2 + 50];
|
||||||
float limit;
|
float limit;
|
||||||
char *bin, *exec, *kfile, *ofile;
|
char *bin, *exec, *kfile, *ofile;
|
||||||
@ -721,6 +723,17 @@ main(int argc, char *argv[])
|
|||||||
exec);
|
exec);
|
||||||
|
|
||||||
bzero(tmpf, sizeof(tmpf));
|
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)
|
if (mkstemp(tofl) == -1)
|
||||||
FATAL(exec, "%s: Impossible to create the tmp file\n",
|
FATAL(exec, "%s: Impossible to create the tmp file\n",
|
||||||
exec);
|
exec);
|
||||||
|
Loading…
Reference in New Issue
Block a user