From 3d4f3e0627887db1d2b6d86da1be2b9c8a8ed3a1 Mon Sep 17 00:00:00 2001 From: Paul Smith Date: Sun, 24 Mar 2024 16:23:28 -0400 Subject: [PATCH] * doc/make.texi: Document temporary file name prefix * src/posixos.c (jobserver_setup): Set prefix for FIFO temp file. Ensure it can't conflict with a "normal" temp file. * src/w32/w32os.c (os_anontmp): Set prefix for anon temp files. --- doc/make.texi | 3 ++- src/posixos.c | 7 ++++--- src/w32/w32os.c | 2 +- 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/doc/make.texi b/doc/make.texi index 5efae41c..874152f3 100644 --- a/doc/make.texi +++ b/doc/make.texi @@ -9462,7 +9462,8 @@ regardless of any @code{.WARNINGS} assignments. In some situations, @code{make} will need to create its own temporary files. These files must not be disturbed while @code{make} is running, including all -recursively-invoked instances of @code{make}. +recursively-invoked instances of @code{make}. All temporary filenames created +by GNU Make will start with the letters @samp{Gm}. @cindex @code{MAKE_TMPDIR} If the environment variable @code{MAKE_TMPDIR} is set then all temporary files diff --git a/src/posixos.c b/src/posixos.c index 7a723591..6b0b716e 100644 --- a/src/posixos.c +++ b/src/posixos.c @@ -152,13 +152,14 @@ jobserver_setup (int slots, const char *style) { /* Unfortunately glibc warns about uses of mktemp even though we aren't using it in dangerous way here. So avoid this by generating our own - temporary file name. */ -# define FNAME_PREFIX "GMfifo" + temporary file name. The template in misc.c uses 6 X's so be sure this + name cannot conflict with that. */ +# define FNAME_PREFIX "GmFIFO" const char *tmpdir = get_tmpdir (); fifo_name = xmalloc (strlen (tmpdir) + CSTRLEN (FNAME_PREFIX) + INTSTR_LENGTH + 2); - sprintf (fifo_name, "%s/" FNAME_PREFIX "%" MK_PRI64_PREFIX "d", + sprintf (fifo_name, "%s/" FNAME_PREFIX "%03" MK_PRI64_PREFIX "d", tmpdir, (long long)make_pid ()); EINTRLOOP (r, mkfifo (fifo_name, 0600)); diff --git a/src/w32/w32os.c b/src/w32/w32os.c index ac8fc59c..af02621e 100644 --- a/src/w32/w32os.c +++ b/src/w32/w32os.c @@ -129,7 +129,7 @@ os_anontmp () static unsigned uniq = 0; static int second_loop = 0; - const char base[] = "gmake_tmpf"; + const char base[] = "GmTMPF"; const unsigned sizemax = sizeof (base) - 1 + 4 + 10 + 10; unsigned pid = GetCurrentProcessId ();