summaryrefslogtreecommitdiff
path: root/trafgen.c
diff options
context:
space:
mode:
authorTobias Klauser <tklauser@distanz.ch>2016-04-26 10:32:34 +0200
committerTobias Klauser <tklauser@distanz.ch>2016-04-26 11:22:11 +0200
commit01a9a2a5a8c56ce8699616a608a28de4e537ff56 (patch)
treeaf75edf3ba777c3bec5603f1234134a5787bc56f /trafgen.c
parentf3057cdf8518d4931a12beb3f4322638500efec8 (diff)
trafgen: Use mkostemp_or_die() to create unique temporary file
Use the mkostemp_or_die() wrapper introduced in commit a87f181bd836 ("ioops: Add mkostemp_or_die") to safely create a unique temporary file instead of using rand() to manually create a (potentially unsafe) temporary filename. Signed-off-by: Tobias Klauser <tklauser@distanz.ch>
Diffstat (limited to 'trafgen.c')
-rw-r--r--trafgen.c10
1 files changed, 2 insertions, 8 deletions
diff --git a/trafgen.c b/trafgen.c
index 949f909..002b01a 100644
--- a/trafgen.c
+++ b/trafgen.c
@@ -417,15 +417,9 @@ static struct cpu_stats *setup_shared_var(unsigned int cpus)
char *zbuff, file[256];
struct cpu_stats *buff;
+ slprintf(file, sizeof(file), ".tmp_mmap.XXXXXX");
+ fd = mkostemp_or_die(file, O_RDWR | O_CREAT | O_TRUNC);
zbuff = xzmalloc(len);
- slprintf(file, sizeof(file), ".tmp_mmap.%u", (unsigned int) rand());
-
- fd = creat(file, S_IRUSR | S_IWUSR);
- bug_on(fd < 0);
- close(fd);
-
- fd = open_or_die_m(file, O_RDWR | O_CREAT | O_TRUNC,
- S_IRUSR | S_IWUSR);
write_or_die(fd, zbuff, len);
xfree(zbuff);