summaryrefslogtreecommitdiffstats
path: root/usr.bin/make
diff options
context:
space:
mode:
authorkris <kris@FreeBSD.org>2000-11-19 12:04:12 +0000
committerkris <kris@FreeBSD.org>2000-11-19 12:04:12 +0000
commitdae3fc672db5f25bccabaea9f693abda9737004b (patch)
treea3eed8ca9da2af0d27eef5faa4b7b404f6ef3f9c /usr.bin/make
parent21ab1b113eabff15807530dd724789f4efa36213 (diff)
downloadFreeBSD-src-dae3fc672db5f25bccabaea9f693abda9737004b.zip
FreeBSD-src-dae3fc672db5f25bccabaea9f693abda9737004b.tar.gz
Unlink the temporary file immediately so it is removed on exit.
Obtained from: OpenBSD
Diffstat (limited to 'usr.bin/make')
-rw-r--r--usr.bin/make/job.c34
1 files changed, 15 insertions, 19 deletions
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);
}
}
OpenPOWER on IntegriCloud