Stop using mktemp() --- on Haiku, it always generates the same filenames,

pretty much guaranteeing temporary file overwrites on parallel builds. Use
mkstemp() instead which creates the files atomically.
This commit is contained in:
David Given 2017-08-06 13:22:05 +02:00
parent 789f79b369
commit 64f2fa9d46
11 changed files with 30 additions and 35 deletions

View file

@ -363,7 +363,8 @@ char *path, *tail;
if ((dir = getenv("TMPDIR")) == NULL) if ((dir = getenv("TMPDIR")) == NULL)
dir = tmp_dir; dir = tmp_dir;
sprintf(path, "%s/%s", dir, tail); sprintf(path, "%s/%s", dir, tail);
return(ffcreat(mktemp(path))); close(mkstemp(path));
return(ffcreat(path));
} }
/* ---------- Error handling ---------- */ /* ---------- Error handling ---------- */

View file

@ -145,7 +145,8 @@ swttmp()
strcpy(p, C_tmpdir); strcpy(p, C_tmpdir);
strcat(p, "/CodeXXXXXX"); strcat(p, "/CodeXXXXXX");
C_tmpfile = mktemp(p); close(mkstemp(p));
C_tmpfile = p;
if (! sys_open(p, OP_WRITE, &C_old_ofp)) { if (! sys_open(p, OP_WRITE, &C_old_ofp)) {
C_failed(); C_failed();
} }

View file

@ -4,6 +4,8 @@
*/ */
/* $Id$ */ /* $Id$ */
#include <string.h>
#include <stdlib.h>
#include "system.h" #include "system.h"
int int
@ -12,7 +14,6 @@ sys_lock(path)
{ {
char buf[1024]; char buf[1024];
char *tmpf = ".lockXXXXXX"; char *tmpf = ".lockXXXXXX";
char *strrchr(), *strcpy(), *mktemp();
char *p; char *p;
int ok, fd; int ok, fd;
@ -23,8 +24,7 @@ sys_lock(path)
} }
else else
strcpy(buf, tmpf); strcpy(buf, tmpf);
mktemp(buf); if ((fd = mkstemp(buf)) < 0)
if ((fd = creat(buf, 0)) < 0)
return 0; return 0;
close(fd); close(fd);
ok = (link(buf, path) == 0); ok = (link(buf, path) == 0);

View file

@ -37,7 +37,6 @@ extern fatal();
extern comfatal(); extern comfatal();
extern copyfile(); extern copyfile();
extern void install(); extern void install();
extern char *mktemp();
extern char *sbrk(); extern char *sbrk();
main(argc,argv) register string argv[]; { main(argc,argv) register string argv[]; {
@ -164,8 +163,8 @@ main(argc,argv) register string argv[]; {
nc_rec_file = libpath ("nc_rec"); nc_rec_file = libpath ("nc_rec");
} }
#endif #endif
mktemp(f_temp); close(mkstemp(f_temp));
mktemp(f_pars); close(mkstemp(f_pars));
if ((fact = fopen(f_temp,"w")) == NULL) { if ((fact = fopen(f_temp,"w")) == NULL) {
fputs("Cannot create temporary\n",stderr); fputs("Cannot create temporary\n",stderr);
exit(1); exit(1);

View file

@ -17,8 +17,6 @@
char temp_name[] = "/tmp/sXXXXXX"; char temp_name[] = "/tmp/sXXXXXX";
char *tname; char *tname;
char *mktemp();
FILE *fopen();
FILE *tf; FILE *tf;
struct outhead buf; struct outhead buf;
int readerror, writeerror; int readerror, writeerror;
@ -31,12 +29,12 @@ char **argv;
signal(SIGHUP, SIG_IGN); signal(SIGHUP, SIG_IGN);
signal(SIGINT, SIG_IGN); signal(SIGINT, SIG_IGN);
signal(SIGQUIT, SIG_IGN); signal(SIGQUIT, SIG_IGN);
tname = mktemp(temp_name); close(mkstemp(temp_name));
while(--argc) { while(--argc) {
if ((status = strip(argv[argc])) > 1) if ((status = strip(argv[argc])) > 1)
break; break;
} }
unlink(tname); unlink(temp_name);
exit(status); exit(status);
} }

View file

@ -106,7 +106,6 @@ char *progname;
char temp_buf[32]; char temp_buf[32];
char *temp_arch = &temp_buf[0]; char *temp_arch = &temp_buf[0];
extern char *mktemp();
extern char *ctime(); extern char *ctime();
void do_object(int f, long size); void do_object(int f, long size);
@ -277,7 +276,7 @@ char *argv[];
|| app_fl || app_fl
#endif #endif
) { ) {
mktemp(temp_arch); close(mkstemp(temp_arch));
} }
#ifdef AAL #ifdef AAL
tab = (struct ranlib *) malloc(512 * sizeof(struct ranlib)); tab = (struct ranlib *) malloc(512 * sizeof(struct ranlib));

View file

@ -1,3 +1,4 @@
#include <stdlib.h>
#include <signal.h> #include <signal.h>
#include "defs.h" #include "defs.h"
@ -56,10 +57,6 @@ char *rassoc;
short **derives; short **derives;
char *nullable; char *nullable;
extern char *mktemp();
extern char *getenv();
done(k) done(k)
int k; int k;
{ {
@ -253,9 +250,9 @@ create_file_names()
text_file_name[len + 5] = 't'; text_file_name[len + 5] = 't';
union_file_name[len + 5] = 'u'; union_file_name[len + 5] = 'u';
mktemp(action_file_name); close(mkstemp(action_file_name));
mktemp(text_file_name); close(mkstemp(text_file_name));
mktemp(union_file_name); close(mkstemp(union_file_name));
len = strlen(file_prefix); len = strlen(file_prefix);

View file

@ -410,12 +410,12 @@ int main(int argc, char* argv[])
(void)strcpy(tmpbufs[0], "."); (void)strcpy(tmpbufs[0], ".");
} }
(void)strcat(ddump, "/ego.dd.XXXXXX"); (void)strcat(ddump, "/ego.dd.XXXXXX");
(void)mktemp(ddump); close(mkstemp(ddump));
(void)strcat(pdump, "/ego.pd.XXXXXX"); (void)strcat(pdump, "/ego.pd.XXXXXX");
(void)mktemp(pdump); close(mkstemp(pdump));
(void)strcat(tmpbufs[0], "/ego.XXXXXX"); (void)strcat(tmpbufs[0], "/ego.XXXXXX");
(void)mktemp(tmpbufs[0]); close(mkstemp(tmpbufs[0]));
(void)strcat(tmpbufs[0], ".A.BB"); (void)strcat(tmpbufs[0], ".A.BB");
for (i = 2 * NTEMPS - 1; i >= 1; i--) for (i = 2 * NTEMPS - 1; i >= 1; i--)
{ {

View file

@ -334,10 +334,10 @@ char* argv[];
strcat(ccname, "/ego.i2.XXXXXX"); strcat(ccname, "/ego.i2.XXXXXX");
strcat(sname, "/ego.i3.XXXXXX"); strcat(sname, "/ego.i3.XXXXXX");
strcat(cname2, "/ego.i4.XXXXXX"); strcat(cname2, "/ego.i4.XXXXXX");
mktemp(cname); close(mkstemp(cname));
mktemp(ccname); close(mkstemp(ccname));
mktemp(sname); close(mkstemp(sname));
mktemp(cname2); close(mkstemp(cname2));
pass1(files->lname_in, files->bname_in, cname); /* grep calls, analyse procedures */ pass1(files->lname_in, files->bname_in, cname); /* grep calls, analyse procedures */
space = total_size * space / 100; space = total_size * space / 100;
pass2(cname, space); /* select calls to be expanded */ pass2(cname, space); /* select calls to be expanded */

View file

@ -38,6 +38,7 @@ static char rcsid[] =
#endif #endif
#include <stdlib.h>
#include "flexdef.h" #include "flexdef.h"
static char flex_version[] = "2.3"; static char flex_version[] = "2.3";
@ -394,7 +395,7 @@ char **argv;
{ {
int i, sawcmpflag; int i, sawcmpflag;
char *arg, *flex_gettime(), *mktemp(); char *arg, *flex_gettime();
printstats = syntaxerror = trace = spprdflt = interactive = caseins = false; printstats = syntaxerror = trace = spprdflt = interactive = caseins = false;
backtrack_report = performance_report = ddebug = fulltbl = fullspd = false; backtrack_report = performance_report = ddebug = fulltbl = fullspd = false;
@ -611,7 +612,7 @@ get_next_arg: /* used by -C and -S flags in lieu of a "continue 2" control */
#else #else
(void) strcpy( temp_action_file_name, "flexXXXXXX.tmp" ); (void) strcpy( temp_action_file_name, "flexXXXXXX.tmp" );
#endif #endif
(void) mktemp( temp_action_file_name ); close(mkstemp(temp_action_file_name));
action_file_name = temp_action_file_name; action_file_name = temp_action_file_name;
} }

View file

@ -57,13 +57,12 @@ flags(s) register char *s; {
} }
fileinit() { fileinit() {
char *mktemp();
short readshort(); short readshort();
if (readshort() != (short) sp_magic) if (readshort() != (short) sp_magic)
error("wrong input file"); error("wrong input file");
if (Lflag) { if (Lflag) {
outfile = fopen(mktemp(template),"w"); outfile = fdopen(mkstemp(template),"w");
if (outfile == NULL) if (outfile == NULL)
error("can't create %s",template); error("can't create %s",template);
} else { } else {