Unlink the temporary file immediately so it is removed on exit.
Obtained from: OpenBSD
This commit is contained in:
parent
b05092e25a
commit
29ac114aae
@ -160,6 +160,13 @@ static int numCommands; /* The number of commands actually printed
|
||||
#define JOB_FINISHED 2 /* The job is already finished */
|
||||
#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.
|
||||
*/
|
||||
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user