=================================================================== RCS file: /cvsrepo/anoncvs/cvs/src/usr.bin/make/job.c,v retrieving revision 1.56 retrieving revision 1.57 diff -c -r1.56 -r1.57 *** src/usr.bin/make/job.c 2004/04/07 13:11:36 1.56 --- src/usr.bin/make/job.c 2004/07/19 02:10:47 1.57 *************** *** 1,5 **** /* $OpenPackages$ */ ! /* $OpenBSD: job.c,v 1.56 2004/04/07 13:11:36 espie Exp $ */ /* $NetBSD: job.c,v 1.16 1996/11/06 17:59:08 christos Exp $ */ /* --- 1,5 ---- /* $OpenPackages$ */ ! /* $OpenBSD: job.c,v 1.57 2004/07/19 02:10:47 espie Exp $ */ /* $NetBSD: job.c,v 1.16 1996/11/06 17:59:08 christos Exp $ */ /* *************** *** 430,435 **** --- 430,437 ---- static void JobCondPassSig(void *, void *); + static void SigHandler(int); + static void HandleSigs(void); static void JobPassSig(int); static int JobCmpPid(void *, void *); static int JobPrintCommand(void *, void *); *************** *** 446,451 **** --- 448,532 ---- static void JobInterrupt(int, int); static void JobRestartJobs(void); + static volatile sig_atomic_t got_SIGINT, got_SIGHUP, got_SIGQUIT, + got_SIGTERM; + #if defined(USE_PGRP) + static volatile sig_atomic_t got_SIGTSTP, got_SIGTTOU, got_SIGTTIN, + got_SIGWINCH; + #endif + + static void + SigHandler(int sig) + { + switch(sig) { + case SIGINT: + got_SIGINT++; + break; + case SIGHUP: + got_SIGHUP++; + break; + case SIGQUIT: + got_SIGQUIT++; + break; + case SIGTERM: + got_SIGTERM++; + break; + #if defined(USE_PGRGP) + case SIGTSTP: + got_SIGTSTP++; + break; + case SIGTTOU: + got_SIGTTOU++; + break; + case SIGTTIN: + got_SIGTTIN++; + break; + case SIGWINCH: + got_SIGWINCH++; + break; + #endif + } + } + + static void + HandleSigs() + { + if (got_SIGINT) { + got_SIGINT=0; + JobPassSig(SIGINT); + } + if (got_SIGHUP) { + got_SIGHUP=0; + JobPassSig(SIGHUP); + } + if (got_SIGQUIT) { + got_SIGQUIT=0; + JobPassSig(SIGQUIT); + } + if (got_SIGTERM) { + got_SIGTERM=0; + JobPassSig(SIGTERM); + } + #if defined(USE_PGRP) + if (got_SIGTSTP) { + got_SIGTSTP=0; + JobPassSig(SIGTSTP); + } + if (got_SIGTTOU) { + got_SIGTTOU=0; + JobPassSig(SIGTTOU); + } + if (got_SIGTTIN) { + got_SIGTTIN=0; + JobPassSig(SIGTTIN); + } + if (got_SIGWINCH) { + got_SIGWINCH=0; + JobPassSig(SIGWINCH); + } + #endif + } + /*- *----------------------------------------------------------------------- * JobCondPassSig -- *************** *** 484,490 **** static void JobPassSig(int signo) /* The signal number we've received */ { - int save_errno = errno; sigset_t nmask, omask; struct sigaction act; --- 565,570 ---- *************** *** 542,550 **** (void)sigprocmask(SIG_SETMASK, &omask, NULL); sigprocmask(SIG_SETMASK, &omask, NULL); ! act.sa_handler = JobPassSig; sigaction(signo, &act, NULL); - errno = save_errno; } /*- --- 622,629 ---- (void)sigprocmask(SIG_SETMASK, &omask, NULL); sigprocmask(SIG_SETMASK, &omask, NULL); ! act.sa_handler = SigHandler; sigaction(signo, &act, NULL); } /*- *************** *** 2034,2039 **** --- 2113,2119 ---- while ((pid = waitpid((pid_t) -1, &status, (block?0:WNOHANG)|WUNTRACED)) > 0) { + HandleSigs(); if (DEBUG(JOB)) { (void)fprintf(stdout, "Process %ld exited or stopped.\n", (long)pid); (void)fflush(stdout); *************** *** 2105,2113 **** --- 2185,2195 ---- if ((nfds = select(outputsn+1, readfdsp, (fd_set *) 0, (fd_set *) 0, &timeout)) <= 0) { + HandleSigs(); free(readfdsp); return; } else { + HandleSigs(); for (ln = Lst_First(&jobs); nfds && ln != NULL; ln = Lst_Adv(ln)) { job = (Job *)Lst_Datum(ln); if (FD_ISSET(job->inPipe, readfdsp)) { *************** *** 2207,2222 **** * JobPassSig will take care of calling JobInterrupt if appropriate. */ if (signal(SIGINT, SIG_IGN) != SIG_IGN) { ! (void)signal(SIGINT, JobPassSig); } if (signal(SIGHUP, SIG_IGN) != SIG_IGN) { ! (void)signal(SIGHUP, JobPassSig); } if (signal(SIGQUIT, SIG_IGN) != SIG_IGN) { ! (void)signal(SIGQUIT, JobPassSig); } if (signal(SIGTERM, SIG_IGN) != SIG_IGN) { ! (void)signal(SIGTERM, JobPassSig); } /* * There are additional signals that need to be caught and passed if --- 2289,2304 ---- * JobPassSig will take care of calling JobInterrupt if appropriate. */ if (signal(SIGINT, SIG_IGN) != SIG_IGN) { ! (void)signal(SIGINT, SigHandler); } if (signal(SIGHUP, SIG_IGN) != SIG_IGN) { ! (void)signal(SIGHUP, SigHandler); } if (signal(SIGQUIT, SIG_IGN) != SIG_IGN) { ! (void)signal(SIGQUIT, SigHandler); } if (signal(SIGTERM, SIG_IGN) != SIG_IGN) { ! (void)signal(SIGTERM, SigHandler); } /* * There are additional signals that need to be caught and passed if *************** *** 2226,2241 **** */ #if defined(USE_PGRP) if (signal(SIGTSTP, SIG_IGN) != SIG_IGN) { ! (void)signal(SIGTSTP, JobPassSig); } if (signal(SIGTTOU, SIG_IGN) != SIG_IGN) { ! (void)signal(SIGTTOU, JobPassSig); } if (signal(SIGTTIN, SIG_IGN) != SIG_IGN) { ! (void)signal(SIGTTIN, JobPassSig); } if (signal(SIGWINCH, SIG_IGN) != SIG_IGN) { ! (void)signal(SIGWINCH, JobPassSig); } #endif --- 2308,2323 ---- */ #if defined(USE_PGRP) if (signal(SIGTSTP, SIG_IGN) != SIG_IGN) { ! (void)signal(SIGTSTP, SigHandler); } if (signal(SIGTTOU, SIG_IGN) != SIG_IGN) { ! (void)signal(SIGTTOU, SigHandler); } if (signal(SIGTTIN, SIG_IGN) != SIG_IGN) { ! (void)signal(SIGTTIN, SigHandler); } if (signal(SIGWINCH, SIG_IGN) != SIG_IGN) { ! (void)signal(SIGWINCH, SigHandler); } #endif