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)
dir = tmp_dir;
sprintf(path, "%s/%s", dir, tail);
return(ffcreat(mktemp(path)));
close(mkstemp(path));
return(ffcreat(path));
}
/* ---------- Error handling ---------- */

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

@ -38,6 +38,7 @@ static char rcsid[] =
#endif
#include <stdlib.h>
#include "flexdef.h"
static char flex_version[] = "2.3";
@ -394,7 +395,7 @@ char **argv;
{
int i, sawcmpflag;
char *arg, *flex_gettime(), *mktemp();
char *arg, *flex_gettime();
printstats = syntaxerror = trace = spprdflt = interactive = caseins = 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
(void) strcpy( temp_action_file_name, "flexXXXXXX.tmp" );
#endif
(void) mktemp( temp_action_file_name );
close(mkstemp(temp_action_file_name));
action_file_name = temp_action_file_name;
}

View file

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