Use mkstemp instead of tmpnam
tmpname is unsafe and triggers compiler warnings.
Change-Id: Ifd494fd22a28655f66765b1d02f6030e69fd1433
diff --git a/src/unix/proc.c b/src/unix/proc.c
index 1516147..4c11d0f 100644
--- a/src/unix/proc.c
+++ b/src/unix/proc.c
@@ -150,11 +150,21 @@
#endif
snprintf(fifo, strlen(out) + 6, "%s.fifo", out);
+ unlink(fifo); // Clean up legacy fifo from previous runs.
mkfiforet = mkfifo(fifo, 0666);
// If the $out.fifo is not accessible (e.g. /dev/null.fifo), attempt to
// place fifo in temp dir instead.
if (-1 == mkfiforet && errno == EACCES) {
- tmpnam(fifo);
+ // Re-populate `fifo` so it gets cleaned up properly below.
+ snprintf(fifo, 26, "/tmp/fsatrace_fifo.XXXXXX");
+ // NOTE: mkstep here is not strictly safe, it's possible for
+ // other processes to open the same path. Fuchsia uses this tool
+ // in a controlled environment, and this is an unused code path
+ // in production, so we don't consider this as a thread.
+ mkstemp(fifo);
+ // Remove the temp file immediately because we only want a
+ // unique name for fifo.
+ unlink(fifo);
mkfiforet = mkfifo(fifo, 0666);
}
if (-1 == mkfiforet) {