From f864e10c5fc9a4d134bda8be463578d63f85c7b1 Mon Sep 17 00:00:00 2001 From: thorpej Date: Fri, 27 Sep 1996 03:07:05 +0000 Subject: [PATCH] Make unique temporary file names. From Luke Mewburn , PR #2544. --- sbin/restore/dirs.c | 27 ++++++++++++++++++++------- 1 file changed, 20 insertions(+), 7 deletions(-) diff --git a/sbin/restore/dirs.c b/sbin/restore/dirs.c index ddb70c4c2087..8d66c3b1e965 100644 --- a/sbin/restore/dirs.c +++ b/sbin/restore/dirs.c @@ -1,4 +1,4 @@ -/* $NetBSD: dirs.c,v 1.16 1995/06/19 00:20:11 cgd Exp $ */ +/* $NetBSD: dirs.c,v 1.17 1996/09/27 03:07:05 thorpej Exp $ */ /* * Copyright (c) 1983, 1993 @@ -42,7 +42,7 @@ #if 0 static char sccsid[] = "@(#)dirs.c 8.5 (Berkeley) 8/31/94"; #else -static char rcsid[] = "$NetBSD: dirs.c,v 1.16 1995/06/19 00:20:11 cgd Exp $"; +static char rcsid[] = "$NetBSD: dirs.c,v 1.17 1996/09/27 03:07:05 thorpej Exp $"; #endif #endif /* not lint */ @@ -111,9 +111,9 @@ struct rstdirdesc { static long seekpt; static FILE *df, *mf; static RST_DIR *dirp; -static char dirfile[32] = "#"; /* No file */ -static char modefile[32] = "#"; /* No file */ -static char dot[2] = "."; /* So it can be modified */ +static char dirfile[MAXPATHLEN] = "#"; /* No file */ +static char modefile[MAXPATHLEN] = "#"; /* No file */ +static char dot[2] = "."; /* So it can be modified */ /* * Format of old style directories. @@ -151,7 +151,13 @@ extractdirs(genmode) struct direct nulldir; vprintf(stdout, "Extract directories from tape\n"); - (void) sprintf(dirfile, "%s/rstdir%d", _PATH_TMP, dumpdate); + (void) sprintf(dirfile, "%s/rstdir%d-XXXXXX", _PATH_TMP, dumpdate); + if (mktemp(dirfile) == NULL) { + fprintf(stderr, + "restore: %s - cannot generate directory temporary\n", + dirfile); + exit(1); + } df = fopen(dirfile, "w"); if (df == NULL) { fprintf(stderr, @@ -161,7 +167,14 @@ extractdirs(genmode) exit(1); } if (genmode != 0) { - (void) sprintf(modefile, "%s/rstmode%d", _PATH_TMP, dumpdate); + (void) sprintf(modefile, "%s/rstmode%d-XXXXXX", _PATH_TMP, + dumpdate); + if (mktemp(modefile) == NULL) { + fprintf(stderr, + "restore: %s - cannot generate modefile\n", + modefile); + exit(1); + } mf = fopen(modefile, "w"); if (mf == NULL) { fprintf(stderr,