From dae3fc672db5f25bccabaea9f693abda9737004b Mon Sep 17 00:00:00 2001 From: kris Date: Sun, 19 Nov 2000 12:04:12 +0000 Subject: Unlink the temporary file immediately so it is removed on exit. Obtained from: OpenBSD --- usr.bin/make/job.c | 34 +++++++++++++++------------------- 1 file changed, 15 insertions(+), 19 deletions(-) (limited to 'usr.bin/make') diff --git a/usr.bin/make/job.c b/usr.bin/make/job.c index 1908475..16c29be 100644 --- a/usr.bin/make/job.c +++ b/usr.bin/make/job.c @@ -161,6 +161,13 @@ static int numCommands; /* The number of commands actually printed #define JOB_STOPPED 3 /* The job is stopped */ /* + * tfile is used to build temp file names to store shell commands to + * execute. + */ +static char tfile[sizeof(TMPPAT)]; + + +/* * Descriptions for various shells. */ static Shell shells[] = { @@ -989,13 +996,11 @@ JobFinish(job, status) aborting = ABORT_ERROR; } - if ((aborting == ABORT_ERROR) && Job_Empty()) { + if ((aborting == ABORT_ERROR) && Job_Empty()) /* * If we are aborting and the job table is now empty, we finish. */ - (void) eunlink(job->tfile); Finish(errors); - } } /*- @@ -1698,12 +1703,6 @@ JobStart(gn, flags, previous) } job->flags |= flags; - (void) strcpy(job->tfile, TMPPAT); - if ((tfd = mkstemp(job->tfile)) == -1) - Punt("cannot create temp file: %s", strerror(errno)); - else - (void) close(tfd); - /* * Check the commands now so any attributes from .DEFAULT have a chance * to migrate to the node @@ -1729,9 +1728,14 @@ JobStart(gn, flags, previous) DieHorribly(); } - job->cmdFILE = fopen(job->tfile, "w+"); + (void) strcpy(tfile, TMPPAT); + if ((tfd = mkstemp(tfile)) == -1) + Punt("Cannot create temp file: %s", strerror(errno)); + job->cmdFILE = fdopen(tfd, "w+"); + eunlink(tfile); if (job->cmdFILE == NULL) { - Punt("Could not open %s", job->tfile); + close(tfd); + Punt("Could not open %s", tfile); } (void) fcntl(FILENO(job->cmdFILE), F_SETFD, 1); /* @@ -1837,7 +1841,6 @@ JobStart(gn, flags, previous) * Unlink and close the command file if we opened one */ if (job->cmdFILE != stdout) { - (void) eunlink(job->tfile); if (job->cmdFILE != NULL) (void) fclose(job->cmdFILE); } else { @@ -1866,7 +1869,6 @@ JobStart(gn, flags, previous) } } else { (void) fflush(job->cmdFILE); - (void) eunlink(job->tfile); } /* @@ -2909,7 +2911,6 @@ JobInterrupt(runINTERRUPT, signo) } } } - (void) eunlink(job->tfile); } /* @@ -2920,10 +2921,6 @@ JobInterrupt(runINTERRUPT, signo) * * Results: * Number of errors reported. - * - * Side Effects: - * The process' temporary file (tfile) is removed if it still - * existed. *----------------------------------------------------------------------- */ int @@ -3018,7 +3015,6 @@ Job_AbortAll() KILL(job->pid, SIGINT); KILL(job->pid, SIGKILL); #endif /* RMT_WANTS_SIGNALS */ - (void) eunlink(job->tfile); } } -- cgit v1.1