=================================================================== RCS file: /cvsrepo/anoncvs/cvs/src/usr.bin/make/job.c,v retrieving revision 1.87 retrieving revision 1.88 diff -c -r1.87 -r1.88 *** src/usr.bin/make/job.c 2007/09/23 12:53:21 1.87 --- src/usr.bin/make/job.c 2007/09/23 14:58:50 1.88 *************** *** 1,5 **** /* $OpenPackages$ */ ! /* $OpenBSD: job.c,v 1.87 2007/09/23 12:53:21 espie Exp $ */ /* $NetBSD: job.c,v 1.16 1996/11/06 17:59:08 christos Exp $ */ /* --- 1,5 ---- /* $OpenPackages$ */ ! /* $OpenBSD: job.c,v 1.88 2007/09/23 14:58:50 espie Exp $ */ /* $NetBSD: job.c,v 1.16 1996/11/06 17:59:08 christos Exp $ */ /* *************** *** 108,115 **** #include "memory.h" #include "make.h" - #define TMPPAT "/tmp/makeXXXXXXXXXX" - /* * 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 --- 108,113 ---- *************** *** 201,214 **** #define JOB_FINISHED 2 /* The job is already finished */ #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_ON "set -v" #define SHELL_ERROR_ON "set -e" --- 199,204 ---- *************** *** 297,302 **** --- 287,293 ---- static void JobRestartJobs(void); static void DBPRINTF(Job *, 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, got_SIGTERM; *************** *** 305,310 **** --- 296,320 ---- got_SIGWINCH; #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 SigHandler(int sig) { *************** *** 890,896 **** /* * If we are aborting and the job table is now empty, we finish. */ - (void)eunlink(tfile); Finish(errors); } } --- 900,905 ---- *************** *** 1224,1232 **** DieHorribly(); } ! job->cmdFILE = fopen(tfile, "w+"); if (job->cmdFILE == NULL) { ! Punt("Could not open %s", tfile); } (void)fcntl(fileno(job->cmdFILE), F_SETFD, 1); /* --- 1233,1241 ---- DieHorribly(); } ! job->cmdFILE = new_command_file(); if (job->cmdFILE == NULL) { ! Punt("Error creating command file"); } (void)fcntl(fileno(job->cmdFILE), F_SETFD, 1); /* *************** *** 1296,1302 **** * Unlink and close the command file if we opened one */ if (job->cmdFILE != stdout) { - (void)eunlink(tfile); if (job->cmdFILE != NULL) (void)fclose(job->cmdFILE); } else { --- 1305,1310 ---- *************** *** 1321,1327 **** } } else { (void)fflush(job->cmdFILE); - (void)eunlink(tfile); } /* --- 1329,1334 ---- *************** *** 1711,1724 **** void 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(&stoppedJobs); maxJobs = maxproc; --- 1718,1723 ---- *************** *** 1884,1890 **** } } } - (void)eunlink(tfile); exit(signo); } --- 1883,1888 ---- *************** *** 1897,1905 **** * Results: * Number of errors reported. * - * Side Effects: - * The process' temporary file (tfile) is removed if it still - * existed. *----------------------------------------------------------------------- */ int --- 1895,1900 ---- *************** *** 1917,1923 **** } } } - (void)eunlink(tfile); return errors; } --- 1912,1917 ---- *************** *** 1988,1994 **** */ while (waitpid(-1, &foo, WNOHANG) > 0) continue; - (void)eunlink(tfile); } /*- --- 1982,1987 ----