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
ddf8a5af4d
commit
62f3d9d529
@ -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);
|
||||
|
Loading…
Reference in New Issue
Block a user