commit f2b48c669ee5b69e3b46f64979739d15f41338c2 Quentin Rameau <quinq@fifth.space> 2020-02-19 21:36:37 +0100 Use a random temporary directory instead of a fixed one Thanks to the persons who asked for this.
config.def.h | 4 ++-- sacc.c | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-)
diff --git a/config.def.h b/config.def.h index 651cdbf..7861e53 100644 --- a/config.def.h +++ b/config.def.h @@ -23,5 +23,5 @@ /* default plumber */ static char *plumber = "xdg-open"; -/* temporary directory */ -static char *tmpdir = "/tmp/sacc"; +/* temporary directory template (must end with six 'X' characters) */ +static char tmpdir[] = "/tmp/sacc-XXXXXX"; diff --git a/sacc.c b/sacc.c index 0cf890b..d86dce7 100644 --- a/sacc.c +++ b/sacc.c @@ -976,7 +976,7 @@ setup(void) sigaction(SIGHUP, &sa, NULL); sigaction(SIGTERM, &sa, NULL); - if (mkdir(tmpdir, S_IRWXU) < 0 && errno != EEXIST) + if (!mkdtemp(tmpdir)) die("mkdir: %s: %s", tmpdir, strerror(errno)); if(interactive = isatty(1)) { uisetup();