summaryrefslogtreecommitdiff
path: root/src/internal/tpax_tmpfile_impl.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/internal/tpax_tmpfile_impl.c')
-rw-r--r--src/internal/tpax_tmpfile_impl.c32
1 files changed, 22 insertions, 10 deletions
diff --git a/src/internal/tpax_tmpfile_impl.c b/src/internal/tpax_tmpfile_impl.c
index a8e0c10..9dd9d40 100644
--- a/src/internal/tpax_tmpfile_impl.c
+++ b/src/internal/tpax_tmpfile_impl.c
@@ -1,16 +1,20 @@
-/******************************************************/
-/* tpax: a topological pax implementation */
-/* Copyright (C) 2020 Z. Gilboa */
-/* Released under GPLv2 and GPLv3; see COPYING.TPAX. */
-/******************************************************/
+/**************************************************************/
+/* tpax: a topological pax implementation */
+/* Copyright (C) 2020--2021 SysDeer Technologies, LLC */
+/* Released under GPLv2 and GPLv3; see COPYING.TPAX. */
+/**************************************************************/
#define _GNU_SOURCE
+#include <time.h>
#include <fcntl.h>
#include <limits.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <stdio.h>
+#include <inttypes.h>
+
+#define PPRIX64 "%"PRIx64
/* mkostemp might be guarded by non-standard macros */
/* unless HAVE_NO_MKOSTEMP, assume it is available */
@@ -54,8 +58,8 @@ static int tpax_mkostemp(char * tmplate)
int tpax_tmpfile(void)
{
int fd;
- unsigned seed;
- char tmplate[64];
+ void * addr;
+ char tmplate[128];
/* try with __fs_tmpfile() */
if ((fd = tpax_tmpfile_by_framework()) >= 0)
@@ -66,10 +70,18 @@ int tpax_tmpfile(void)
return fd;
/* fallback to mk{o}stemp */
- seed = getpid();
+ addr = tmplate;
memset(tmplate,0,sizeof(tmplate));
- snprintf(tmplate,sizeof(tmplate),"/tmp/tpax_%d_%d_%d_XXXXXXXXXXXX",
- getppid(),getpid(),rand_r(&seed));
+ snprintf(tmplate,sizeof(tmplate),
+ "/tmp/"
+ ".tpax.tmpfile"
+ ".time."PPRIX64
+ ".salt.%p"
+ ".pid.%d"
+ ".XXXXXXXXXXXX",
+ time(0),
+ addr,
+ getpid());
return tpax_mkostemp(tmplate);
}