version 1.87, 2007/09/23 12:53:21 |
version 1.88, 2007/09/23 14:58:50 |
|
|
#include "memory.h" |
#include "memory.h" |
#include "make.h" |
#include "make.h" |
|
|
#define TMPPAT "/tmp/makeXXXXXXXXXX" |
|
|
|
/* |
/* |
* The SEL_ constants determine the maximum amount of time spent in select |
* The SEL_ constants determine the maximum amount of time spent in select |
* before coming out to see if a child has finished. SEL_SEC is the number of |
* before coming out to see if a child has finished. SEL_SEC is the number of |
|
|
#define JOB_FINISHED 2 /* The job is already finished */ |
#define JOB_FINISHED 2 /* The job is already finished */ |
#define JOB_STOPPED 3 /* The job is stopped */ |
#define JOB_STOPPED 3 /* The job is stopped */ |
|
|
/* |
|
* tfile is the name of a file into which all shell commands are put. It is |
|
* used over by removing it before the child shell is executed. The XXXXXXXXXX |
|
* in the string are replaced by mkstemp(3). |
|
*/ |
|
static char tfile[sizeof(TMPPAT)]; |
|
|
|
|
|
#define SHELL_ECHO_OFF "set -" |
#define SHELL_ECHO_OFF "set -" |
#define SHELL_ECHO_ON "set -v" |
#define SHELL_ECHO_ON "set -v" |
#define SHELL_ERROR_ON "set -e" |
#define SHELL_ERROR_ON "set -e" |
|
|
static void JobRestartJobs(void); |
static void JobRestartJobs(void); |
static void DBPRINTF(Job *, const char *, ...); |
static void DBPRINTF(Job *, const char *, ...); |
static void debug_printf(const char *, ...); |
static void debug_printf(const char *, ...); |
|
static FILE *new_command_file(void); |
|
|
static volatile sig_atomic_t got_SIGINT, got_SIGHUP, got_SIGQUIT, |
static volatile sig_atomic_t got_SIGINT, got_SIGHUP, got_SIGQUIT, |
got_SIGTERM; |
got_SIGTERM; |
|
|
got_SIGWINCH; |
got_SIGWINCH; |
#endif |
#endif |
|
|
|
#define TMPPAT "/tmp/makeXXXXXXXXXX" |
|
|
|
static FILE * |
|
new_command_file() |
|
{ |
|
int fd; |
|
FILE *f; |
|
char tmp[] = TMPPAT; |
|
|
|
fd = mkstemp(tmp); |
|
if (fd == -1) |
|
return NULL; |
|
f = fdopen(fd, "w"); |
|
if (f == NULL) |
|
close(fd); |
|
eunlink(tmp); |
|
return f; |
|
} |
|
|
static void |
static void |
SigHandler(int sig) |
SigHandler(int sig) |
{ |
{ |
|
|
/* |
/* |
* If we are aborting and the job table is now empty, we finish. |
* If we are aborting and the job table is now empty, we finish. |
*/ |
*/ |
(void)eunlink(tfile); |
|
Finish(errors); |
Finish(errors); |
} |
} |
} |
} |
|
|
DieHorribly(); |
DieHorribly(); |
} |
} |
|
|
job->cmdFILE = fopen(tfile, "w+"); |
job->cmdFILE = new_command_file(); |
if (job->cmdFILE == NULL) { |
if (job->cmdFILE == NULL) { |
Punt("Could not open %s", tfile); |
Punt("Error creating command file"); |
} |
} |
(void)fcntl(fileno(job->cmdFILE), F_SETFD, 1); |
(void)fcntl(fileno(job->cmdFILE), F_SETFD, 1); |
/* |
/* |
|
|
* Unlink and close the command file if we opened one |
* Unlink and close the command file if we opened one |
*/ |
*/ |
if (job->cmdFILE != stdout) { |
if (job->cmdFILE != stdout) { |
(void)eunlink(tfile); |
|
if (job->cmdFILE != NULL) |
if (job->cmdFILE != NULL) |
(void)fclose(job->cmdFILE); |
(void)fclose(job->cmdFILE); |
} else { |
} else { |
|
|
} |
} |
} else { |
} else { |
(void)fflush(job->cmdFILE); |
(void)fflush(job->cmdFILE); |
(void)eunlink(tfile); |
|
} |
} |
|
|
/* |
/* |
|
|
void |
void |
Job_Init(int maxproc) |
Job_Init(int maxproc) |
{ |
{ |
int tfd; |
|
|
|
(void)strlcpy(tfile, TMPPAT, sizeof(tfile)); |
|
if ((tfd = mkstemp(tfile)) == -1) |
|
Punt("Cannot create temp file: %s", strerror(errno)); |
|
else |
|
(void)close(tfd); |
|
|
|
Static_Lst_Init(&jobs); |
Static_Lst_Init(&jobs); |
Static_Lst_Init(&stoppedJobs); |
Static_Lst_Init(&stoppedJobs); |
maxJobs = maxproc; |
maxJobs = maxproc; |
|
|
} |
} |
} |
} |
} |
} |
(void)eunlink(tfile); |
|
exit(signo); |
exit(signo); |
} |
} |
|
|
|
|
* Results: |
* Results: |
* Number of errors reported. |
* Number of errors reported. |
* |
* |
* Side Effects: |
|
* The process' temporary file (tfile) is removed if it still |
|
* existed. |
|
*----------------------------------------------------------------------- |
*----------------------------------------------------------------------- |
*/ |
*/ |
int |
int |
|
|
} |
} |
} |
} |
} |
} |
(void)eunlink(tfile); |
|
return errors; |
return errors; |
} |
} |
|
|
|
|
*/ |
*/ |
while (waitpid(-1, &foo, WNOHANG) > 0) |
while (waitpid(-1, &foo, WNOHANG) > 0) |
continue; |
continue; |
(void)eunlink(tfile); |
|
} |
} |
|
|
/*- |
/*- |