Use POSIX signals.

This commit is contained in:
mycroft 1995-03-21 18:35:32 +00:00
parent 04446336b4
commit 7b38403c89
8 changed files with 196 additions and 113 deletions

View File

@ -1,4 +1,4 @@
/* $NetBSD: csh.c,v 1.12 1995/03/21 09:02:38 cgd Exp $ */
/* $NetBSD: csh.c,v 1.13 1995/03/21 18:35:32 mycroft Exp $ */
/*-
* Copyright (c) 1980, 1991, 1993
@ -43,7 +43,7 @@ static char copyright[] =
#if 0
static char sccsid[] = "@(#)csh.c 8.2 (Berkeley) 10/12/93";
#else
static char rcsid[] = "$NetBSD: csh.c,v 1.12 1995/03/21 09:02:38 cgd Exp $";
static char rcsid[] = "$NetBSD: csh.c,v 1.13 1995/03/21 18:35:32 mycroft Exp $";
#endif
#endif /* not lint */
@ -122,7 +122,8 @@ main(argc, argv)
register char *tcp;
register int f;
register char **tempv;
struct sigvec osv;
struct sigaction oact;
sigset_t sigset;
cshin = stdin;
cshout = stdout;
@ -272,10 +273,10 @@ main(argc, argv)
* only if we are the login shell.
*/
/* parents interruptibility */
(void) sigvec(SIGINT, NULL, &osv);
parintr = (void (*) ()) osv.sv_handler;
(void) sigvec(SIGTERM, NULL, &osv);
parterm = (void (*) ()) osv.sv_handler;
(void) sigaction(SIGINT, NULL, &oact);
parintr = oact.sa_handler;
(void) sigaction(SIGTERM, NULL, &oact);
parterm = oact.sa_handler;
/* catch these all, login shell or not */
(void) signal(SIGHUP, phup); /* exit processing on HUP */
@ -455,7 +456,9 @@ main(argc, argv)
if (!quitit) /* Wary! */
(void) signal(SIGQUIT, SIG_IGN);
(void) signal(SIGINT, pintr);
(void) sigblock(sigmask(SIGINT));
sigemptyset(&sigset);
sigaddset(&sigset, SIGINT);
sigprocmask(SIG_BLOCK, &sigset, NULL);
(void) signal(SIGTERM, SIG_IGN);
if (quitit == 0 && arginp == 0) {
(void) signal(SIGTSTP, SIG_IGN);
@ -523,7 +526,11 @@ notty:
{
int osetintr = setintr;
sig_t oparintr = parintr;
sigset_t omask = sigblock(sigmask(SIGINT));
sigset_t osigset;
sigemptyset(&sigset);
sigaddset(&sigset, SIGINT);
sigprocmask(SIG_BLOCK, &sigset, &osigset);
setintr = 0;
parintr = SIG_IGN; /* Disable onintr */
@ -536,7 +543,7 @@ notty:
if (loginsh)
(void) srcfile(_PATH_DOTLOGIN, 0, 0);
#endif
(void) sigsetmask(omask);
sigprocmask(SIG_SETMASK, &osigset, NULL);
setintr = osetintr;
parintr = oparintr;
}
@ -690,7 +697,7 @@ srcunit(unit, onlyown, hflg)
bool otell = cantell;
struct Bin saveB;
volatile sigset_t omask;
sigset_t sigset, osigset;
jmp_buf oldexit;
/* The (few) real local variables */
@ -721,10 +728,12 @@ srcunit(unit, onlyown, hflg)
*/
insource = 1;
getexit(oldexit);
omask = 0;
if (setintr)
omask = sigblock(sigmask(SIGINT));
if (setintr) {
sigemptyset(&sigset);
sigaddset(&sigset, SIGINT);
sigprocmask(SIG_BLOCK, &sigset, &osigset);
}
/* Setup the new values of the state stuff saved above */
memcpy(&saveB, &B, sizeof(B));
fbuf = NULL;
@ -742,14 +751,14 @@ srcunit(unit, onlyown, hflg)
* interrupted.
*/
if (setintr)
(void) sigsetmask(omask);
sigprocmask(SIG_SETMASK, &osigset, NULL);
settell();
if ((my_reenter = setexit()) == 0)
process(0); /* 0 -> blow away on errors */
if (setintr)
(void) sigsetmask(omask);
sigprocmask(SIG_SETMASK, &osigset, NULL);
if (oSHIN >= 0) {
register int i;
@ -927,11 +936,14 @@ pintr1(wantnl)
bool wantnl;
{
Char **v;
sigset_t omask;
sigset_t sigset, osigset;
omask = sigblock((sigset_t) 0);
sigemptyset(&sigset);
sigprocmask(SIG_BLOCK, &sigset, &osigset);
if (setintr) {
(void) sigsetmask(omask & ~sigmask(SIGINT));
sigset = osigset;
sigdelset(&sigset, SIGINT);
sigprocmask(SIG_SETMASK, &sigset, NULL);
if (pjobs) {
pjobs = 0;
(void) fprintf(cshout, "\n");
@ -939,7 +951,8 @@ pintr1(wantnl)
stderror(ERR_NAME | ERR_INTR);
}
}
(void) sigsetmask(omask & ~sigmask(SIGCHLD));
sigdelset(&osigset, SIGCHLD);
sigprocmask(SIG_SETMASK, &osigset, NULL);
(void) fpurge(cshout);
(void) endpwent();
@ -985,6 +998,7 @@ process(catch)
{
jmp_buf osetexit;
struct command *t = savet;
sigset_t sigset;
savet = NULL;
getexit(osetexit);
@ -998,8 +1012,11 @@ process(catch)
/*
* Interruptible during interactive reads
*/
if (setintr)
(void) sigsetmask(sigblock((sigset_t) 0) & ~sigmask(SIGINT));
if (setintr) {
sigemptyset(&sigset);
sigaddset(&sigset, SIGINT);
sigprocmask(SIG_UNBLOCK, &sigset, NULL);
}
/*
* For the sake of reset()
@ -1063,7 +1080,7 @@ process(catch)
* The parser may lose space if interrupted.
*/
if (setintr)
(void) sigblock(sigmask(SIGINT));
sigprocmask(SIG_BLOCK, &sigset, NULL);
/*
* Save input text on the history list if reading in old history, or it

View File

@ -1,4 +1,4 @@
/* $NetBSD: exec.c,v 1.6 1995/03/21 09:02:49 cgd Exp $ */
/* $NetBSD: exec.c,v 1.7 1995/03/21 18:35:36 mycroft Exp $ */
/*-
* Copyright (c) 1980, 1991, 1993
@ -37,7 +37,7 @@
#if 0
static char sccsid[] = "@(#)exec.c 8.1 (Berkeley) 5/31/93";
#else
static char rcsid[] = "$NetBSD: exec.c,v 1.6 1995/03/21 09:02:49 cgd Exp $";
static char rcsid[] = "$NetBSD: exec.c,v 1.7 1995/03/21 18:35:36 mycroft Exp $";
#endif
#endif /* not lint */
@ -122,6 +122,7 @@ doexec(v, t)
register bool slash;
register int hashval = 0, hashval1, i;
Char *blk[2];
sigset_t sigset;
/*
* Glob the command name. We will search $path even if this does something,
@ -197,7 +198,8 @@ doexec(v, t)
* We must do this AFTER any possible forking (like `foo` in glob) so that
* this shell can still do subprocesses.
*/
(void) sigsetmask((sigset_t) 0);
sigemptyset(&sigset);
sigprocmask(SIG_SETMASK, &sigset, NULL);
/*
* If no path, no words in path, or a / in the filename then restrict the
* command search.

View File

@ -1,4 +1,4 @@
/* $NetBSD: file.c,v 1.9 1995/03/21 09:02:56 cgd Exp $ */
/* $NetBSD: file.c,v 1.10 1995/03/21 18:35:39 mycroft Exp $ */
/*-
* Copyright (c) 1980, 1991, 1993
@ -37,7 +37,7 @@
#if 0
static char sccsid[] = "@(#)file.c 8.2 (Berkeley) 3/19/94";
#else
static char rcsid[] = "$NetBSD: file.c,v 1.9 1995/03/21 09:02:56 cgd Exp $";
static char rcsid[] = "$NetBSD: file.c,v 1.10 1995/03/21 18:35:39 mycroft Exp $";
#endif
#endif /* not lint */
@ -144,9 +144,11 @@ static void
back_to_col_1()
{
struct termios tty, tty_normal;
int omask;
sigset_t sigset, osigset;
omask = sigblock(sigmask(SIGINT));
sigemptyset(&sigset);
sigaddset(&sigset, SIGINT);
sigprocmask(SIG_BLOCK, &sigset, &osigset);
(void) tcgetattr(SHOUT, &tty);
tty_normal = tty;
tty.c_iflag &= ~INLCR;
@ -154,7 +156,7 @@ back_to_col_1()
(void) tcsetattr(SHOUT, TCSANOW, &tty);
(void) write(SHOUT, "\r", 1);
(void) tcsetattr(SHOUT, TCSANOW, &tty_normal);
(void) sigsetmask(omask);
sigprocmask(SIG_SETMASK, &osigset, NULL);
}
/*
@ -166,10 +168,12 @@ pushback(string)
{
register Char *p;
struct termios tty, tty_normal;
int omask;
sigset_t sigset, osigset;
char c;
omask = sigblock(sigmask(SIGINT));
sigemptyset(&sigset);
sigaddset(&sigset, SIGINT);
sigprocmask(SIG_BLOCK, &sigset, &osigset);
(void) tcgetattr(SHOUT, &tty);
tty_normal = tty;
tty.c_lflag &= ~(ECHOKE | ECHO | ECHOE | ECHOK | ECHONL | ECHOPRT | ECHOCTL);
@ -178,7 +182,7 @@ pushback(string)
for (p = string; (c = *p) != '\0'; p++)
(void) ioctl(SHOUT, TIOCSTI, (ioctl_t) & c);
(void) tcsetattr(SHOUT, TCSANOW, &tty_normal);
(void) sigsetmask(omask);
sigprocmask(SIG_SETMASK, &osigset, NULL);
}
/*
@ -422,12 +426,14 @@ free_items(items)
}
#define FREE_ITEMS(items) { \
int omask;\
sigset_t sigset, osigset;\
\
omask = sigblock(sigmask(SIGINT));\
sigemptyset(&sigset);\
sigaddset(&sigset, SIGINT);\
sigprocmask(SIG_BLOCK, &sigset, &osigset);\
free_items(items);\
items = NULL;\
(void) sigsetmask(omask);\
sigprocmask(SIG_SETMASK, &osigset, NULL);\
}
/*

View File

@ -1,4 +1,4 @@
/* $NetBSD: func.c,v 1.9 1995/03/21 09:02:59 cgd Exp $ */
/* $NetBSD: func.c,v 1.10 1995/03/21 18:35:42 mycroft Exp $ */
/*-
* Copyright (c) 1980, 1991, 1993
@ -37,7 +37,7 @@
#if 0
static char sccsid[] = "@(#)func.c 8.1 (Berkeley) 5/31/93";
#else
static char rcsid[] = "$NetBSD: func.c,v 1.9 1995/03/21 09:02:59 cgd Exp $";
static char rcsid[] = "$NetBSD: func.c,v 1.10 1995/03/21 18:35:42 mycroft Exp $";
#endif
#endif /* not lint */
@ -139,6 +139,7 @@ doonintr(v, t)
{
register Char *cp;
register Char *vv = v[1];
sigset_t sigset;
if (parintr == SIG_IGN)
return;
@ -148,9 +149,11 @@ doonintr(v, t)
gointr = 0;
xfree((ptr_t) cp);
if (vv == 0) {
if (setintr)
(void) sigblock(sigmask(SIGINT));
else
if (setintr) {
sigemptyset(&sigset);
sigaddset(&sigset, SIGINT);
sigprocmask(SIG_BLOCK, &sigset, NULL);
} else
(void) signal(SIGINT, SIG_DFL);
gointr = 0;
}
@ -509,13 +512,18 @@ dowhile(v, t)
static void
preread()
{
sigset_t sigset;
whyles->w_end.type = I_SEEK;
if (setintr)
(void) sigsetmask(sigblock((sigset_t) 0) & ~sigmask(SIGINT));
if (setintr) {
sigemptyset(&sigset);
sigaddset(&sigset, SIGINT);
sigprocmask(SIG_UNBLOCK, &sigset, NULL);
}
search(T_BREAK, 0, NULL); /* read the expression in */
if (setintr)
(void) sigblock(sigmask(SIGINT));
sigprocmask(SIG_BLOCK, &sigset, NULL);
btell(&whyles->w_end);
}
@ -569,21 +577,24 @@ dorepeat(v, kp)
struct command *kp;
{
register int i;
register sigset_t omask = 0;
sigset_t sigset;
i = getn(v[1]);
if (setintr)
omask = sigblock(sigmask(SIGINT)) & ~sigmask(SIGINT);
if (setintr) {
sigemptyset(&sigset);
sigaddset(&sigset, SIGINT);
sigprocmask(SIG_BLOCK, &sigset, NULL);
}
lshift(v, 2);
while (i > 0) {
if (setintr)
(void) sigsetmask(omask);
sigprocmask(SIG_UNBLOCK, &sigset, NULL);
reexecute(kp);
--i;
}
donefds();
if (setintr)
(void) sigsetmask(omask);
sigprocmask(SIG_UNBLOCK, &sigset, NULL);
}
void
@ -909,9 +920,13 @@ xecho(sep, v)
{
register Char *cp;
int nonl = 0;
sigset_t sigset;
if (setintr)
(void) sigsetmask(sigblock((sigset_t) 0) & ~sigmask(SIGINT));
if (setintr) {
sigemptyset(&sigset);
sigaddset(&sigset, SIGINT);
sigprocmask(SIG_UNBLOCK, &sigset, NULL);
}
v++;
if (*v == 0)
return;
@ -941,7 +956,7 @@ xecho(sep, v)
else
(void) fflush(cshout);
if (setintr)
(void) sigblock(sigmask(SIGINT));
sigprocmask(SIG_BLOCK, &sigset, NULL);
if (gargv)
blkfree(gargv), gargv = 0;
}
@ -953,13 +968,17 @@ dosetenv(v, t)
struct command *t;
{
Char *vp, *lp;
sigset_t sigset;
v++;
if ((vp = *v++) == 0) {
register Char **ep;
if (setintr)
(void) sigsetmask(sigblock((sigset_t) 0) & ~sigmask(SIGINT));
if (setintr) {
sigemptyset(&sigset);
sigaddset(&sigset, SIGINT);
sigprocmask(SIG_UNBLOCK, &sigset, NULL);
}
for (ep = STR_environ; *ep; ep++)
(void) fprintf(cshout, "%s\n", vis_str(*ep));
return;

View File

@ -1,4 +1,4 @@
/* $NetBSD: hist.c,v 1.6 1995/03/21 09:03:04 cgd Exp $ */
/* $NetBSD: hist.c,v 1.7 1995/03/21 18:35:44 mycroft Exp $ */
/*-
* Copyright (c) 1980, 1991, 1993
@ -37,7 +37,7 @@
#if 0
static char sccsid[] = "@(#)hist.c 8.1 (Berkeley) 5/31/93";
#else
static char rcsid[] = "$NetBSD: hist.c,v 1.6 1995/03/21 09:03:04 cgd Exp $";
static char rcsid[] = "$NetBSD: hist.c,v 1.7 1995/03/21 18:35:44 mycroft Exp $";
#endif
#endif /* not lint */
@ -127,11 +127,15 @@ dohist(v, t)
struct command *t;
{
int n, rflg = 0, hflg = 0;
sigset_t sigset;
if (getn(value(STRhistory)) == 0)
return;
if (setintr)
(void) sigsetmask(sigblock((sigset_t) 0) & ~sigmask(SIGINT));
if (setintr) {
sigemptyset(&sigset);
sigaddset(&sigset, SIGINT);
sigprocmask(SIG_UNBLOCK, &sigset, NULL);
}
while (*++v && **v == '-') {
Char *vp = *v;

View File

@ -1,4 +1,4 @@
/* $NetBSD: proc.c,v 1.7 1995/03/21 13:55:23 mycroft Exp $ */
/* $NetBSD: proc.c,v 1.8 1995/03/21 18:35:46 mycroft Exp $ */
/*-
* Copyright (c) 1980, 1991, 1993
@ -37,7 +37,7 @@
#if 0
static char sccsid[] = "@(#)proc.c 8.1 (Berkeley) 5/31/93";
#else
static char rcsid[] = "$NetBSD: proc.c,v 1.7 1995/03/21 13:55:23 mycroft Exp $";
static char rcsid[] = "$NetBSD: proc.c,v 1.8 1995/03/21 18:35:46 mycroft Exp $";
#endif
#endif /* not lint */
@ -207,17 +207,19 @@ pnote()
{
register struct process *pp;
int flags;
sigset_t omask;
sigset_t sigset, osigset;
neednote = 0;
sigemptyset(&sigset);
sigaddset(&sigset, SIGCHLD);
for (pp = proclist.p_next; pp != NULL; pp = pp->p_next) {
if (pp->p_flags & PNEEDNOTE) {
omask = sigblock(sigmask(SIGCHLD));
sigprocmask(SIG_BLOCK, &sigset, &osigset);
pp->p_flags &= ~PNEEDNOTE;
flags = pprint(pp, NUMBER | NAME | REASON);
if ((flags & (PRUNNING | PSTOPPED)) == 0)
pflush(pp);
(void) sigsetmask(omask);
sigprocmask(SIG_SETMASK, &osigset, NULL);
}
}
}
@ -230,12 +232,14 @@ void
pwait()
{
register struct process *fp, *pp;
sigset_t omask;
sigset_t sigset, osigset;
/*
* Here's where dead procs get flushed.
*/
omask = sigblock(sigmask(SIGCHLD));
sigemptyset(&sigset);
sigaddset(&sigset, SIGCHLD);
sigprocmask(SIG_BLOCK, &sigset, &osigset);
for (pp = (fp = &proclist)->p_next; pp != NULL; pp = (fp = pp)->p_next)
if (pp->p_pid == 0) {
fp->p_next = pp->p_next;
@ -246,7 +250,7 @@ pwait()
xfree((ptr_t) pp);
pp = fp;
}
(void) sigsetmask(omask);
sigprocmask(SIG_SETMASK, &osigset, NULL);
pjwait(pcurrjob);
}
@ -261,7 +265,7 @@ pjwait(pp)
{
register struct process *fp;
int jobflags, reason;
sigset_t omask;
sigset_t sigset, osigset;
while (pp->p_pid != pp->p_jobid)
pp = pp->p_friends;
@ -276,9 +280,13 @@ pjwait(pp)
* target process, or any of its friends, are running
*/
fp = pp;
omask = sigblock(sigmask(SIGCHLD));
sigemptyset(&sigset);
sigaddset(&sigset, SIGCHLD);
sigprocmask(SIG_BLOCK, &sigset, &osigset);
for (;;) {
(void) sigblock(sigmask(SIGCHLD));
sigemptyset(&sigset);
sigaddset(&sigset, SIGCHLD);
sigprocmask(SIG_BLOCK, &sigset, NULL);
jobflags = 0;
do
jobflags |= fp->p_flags;
@ -286,12 +294,14 @@ pjwait(pp)
if ((jobflags & PRUNNING) == 0)
break;
#ifdef JOBDEBUG
(void) fprintf(csherr, "starting to sigpause for SIGCHLD on %d\n",
(void) fprintf(csherr, "starting to sigsuspend for SIGCHLD on %d\n",
fp->p_pid);
#endif /* JOBDEBUG */
(void) sigpause(omask & ~sigmask(SIGCHLD));
sigset = osigset;
sigdelset(&sigset, SIGCHLD);
sigsuspend(&sigset);
}
(void) sigsetmask(omask);
sigprocmask(SIG_SETMASK, &osigset, NULL);
if (tpgrp > 0) /* get tty back */
(void) tcsetpgrp(FSHTTY, tpgrp);
if ((jobflags & (PSIGNALED | PSTOPPED | PTIME)) ||
@ -350,18 +360,21 @@ dowait(v, t)
struct command *t;
{
register struct process *pp;
sigset_t omask;
sigset_t sigset, osigset;
pjobs++;
omask = sigblock(sigmask(SIGCHLD));
sigemptyset(&sigset);
sigaddset(&sigset, SIGCHLD);
sigprocmask(SIG_BLOCK, &sigset, &osigset);
loop:
for (pp = proclist.p_next; pp; pp = pp->p_next)
if (pp->p_pid && /* pp->p_pid == pp->p_jobid && */
pp->p_flags & PRUNNING) {
(void) sigpause((sigset_t) 0);
sigemptyset(&sigset);
sigsuspend(&sigset);
goto loop;
}
(void) sigsetmask(omask);
sigprocmask(SIG_SETMASK, &osigset, NULL);
pjobs = 0;
}
@ -1005,13 +1018,14 @@ pkill(v, signum)
register struct process *pp, *np;
register int jobflags = 0;
int pid, err1 = 0;
sigset_t omask;
sigset_t sigset;
Char *cp;
omask = sigmask(SIGCHLD);
sigemptyset(&sigset);
sigaddset(&sigset, SIGCHLD);
if (setintr)
omask |= sigmask(SIGINT);
omask = sigblock(omask) & ~omask;
sigaddset(&sigset, SIGINT);
sigprocmask(SIG_BLOCK, &sigset, NULL);
gflag = 0, tglob(v);
if (gflag) {
v = globall(v);
@ -1075,7 +1089,7 @@ cont:
}
if (gargv)
blkfree(gargv), gargv = 0;
(void) sigsetmask(omask);
sigprocmask(SIG_UNBLOCK, &sigset, NULL);
if (err1)
stderror(ERR_SILENT);
}
@ -1089,10 +1103,12 @@ pstart(pp, foregnd)
int foregnd;
{
register struct process *np;
sigset_t omask;
sigset_t sigset, osigset;
long jobflags = 0;
omask = sigblock(sigmask(SIGCHLD));
sigemptyset(&sigset);
sigaddset(&sigset, SIGCHLD);
sigprocmask(SIG_BLOCK, &sigset, &osigset);
np = pp;
do {
jobflags |= np->p_flags;
@ -1112,7 +1128,7 @@ pstart(pp, foregnd)
(void) tcsetpgrp(FSHTTY, pp->p_jobid);
if (jobflags & PSTOPPED)
(void) killpg((pid_t) pp->p_jobid, SIGCONT);
(void) sigsetmask(omask);
sigprocmask(SIG_SETMASK, &osigset, NULL);
}
void
@ -1235,7 +1251,7 @@ pfork(t, wanttty)
register int pid;
bool ignint = 0;
int pgrp;
sigset_t omask;
sigset_t sigset, osigset;
/*
* A child will be uninterruptible only under very special conditions.
@ -1256,12 +1272,14 @@ pfork(t, wanttty)
/*
* Hold SIGCHLD until we have the process installed in our table.
*/
omask = sigblock(sigmask(SIGCHLD));
sigemptyset(&sigset);
sigaddset(&sigset, SIGCHLD);
sigprocmask(SIG_BLOCK, &sigset, &osigset);
while ((pid = fork()) < 0)
if (setintr == 0)
(void) sleep(FORKSLEEP);
else {
(void) sigsetmask(omask);
sigprocmask(SIG_SETMASK, &osigset, NULL);
stderror(ERR_NOPROC);
}
if (pid == 0) {
@ -1305,7 +1323,7 @@ pfork(t, wanttty)
if (wanttty >= 0)
(void) setpgid(pid, pcurrjob ? pcurrjob->p_jobid : pid);
palloc(pid, t);
(void) sigsetmask(omask);
sigprocmask(SIG_SETMASK, &osigset, NULL);
}
return (pid);
@ -1332,14 +1350,19 @@ void
pgetty(wanttty, pgrp)
int wanttty, pgrp;
{
sigset_t omask = 0;
sigset_t sigset, osigset;
/*
* christos: I am blocking the tty signals till I've set things
* correctly....
*/
if (wanttty > 0)
omask = sigblock(sigmask(SIGTSTP)|sigmask(SIGTTIN)|sigmask(SIGTTOU));
if (wanttty > 0) {
sigemptyset(&sigset);
sigaddset(&sigset, SIGTSTP);
sigaddset(&sigset, SIGTTIN);
sigaddset(&sigset, SIGTTOU);
sigprocmask(SIG_BLOCK, &sigset, &osigset);
}
/*
* From: Michael Schroeder <mlschroe@immd4.informatik.uni-erlangen.de>
* Don't check for tpgrp >= 0 so even non-interactive shells give
@ -1354,7 +1377,7 @@ pgetty(wanttty, pgrp)
if (wanttty > 0) {
(void) tcsetpgrp(FSHTTY, pgrp);
(void) sigsetmask(omask);
sigprocmask(SIG_SETMASK, &osigset, NULL);
}
if (tpgrp > 0)

View File

@ -1,4 +1,4 @@
/* $NetBSD: sem.c,v 1.7 1995/03/21 09:03:20 cgd Exp $ */
/* $NetBSD: sem.c,v 1.8 1995/03/21 18:35:48 mycroft Exp $ */
/*-
* Copyright (c) 1980, 1991, 1993
@ -37,7 +37,7 @@
#if 0
static char sccsid[] = "@(#)sem.c 8.1 (Berkeley) 5/31/93";
#else
static char rcsid[] = "$NetBSD: sem.c,v 1.7 1995/03/21 09:03:20 cgd Exp $";
static char rcsid[] = "$NetBSD: sem.c,v 1.8 1995/03/21 18:35:48 mycroft Exp $";
#endif
#endif /* not lint */
@ -73,10 +73,11 @@ execute(t, wanttty, pipein, pipeout)
struct biltins *bifunc;
int pid = 0;
int pv[2];
sigset_t sigset;
static sigset_t csigmask;
static sigset_t csigset;
static sigset_t ocsigmask;
static sigset_t ocsigset;
static int onosigchld = 0;
static int nosigchld = 0;
@ -214,13 +215,15 @@ execute(t, wanttty, pipein, pipeout)
* not die before we can set the process group
*/
if (wanttty >= 0 && !nosigchld) {
csigmask = sigblock(sigmask(SIGCHLD));
sigemptyset(&sigset);
sigaddset(&sigset, SIGCHLD);
sigprocmask(SIG_BLOCK, &sigset, &csigset);
nosigchld = 1;
}
pid = pfork(t, wanttty);
if (pid == 0 && nosigchld) {
(void) sigsetmask(csigmask);
sigprocmask(SIG_SETMASK, &csigset, NULL);
nosigchld = 0;
}
else if (pid != 0 && (t->t_dflg & F_AMPERSAND))
@ -230,21 +233,26 @@ execute(t, wanttty, pipein, pipeout)
else {
int ochild, osetintr, ohaderr, odidfds;
int oSHIN, oSHOUT, oSHERR, oOLDSTD, otpgrp;
sigset_t omask;
sigset_t osigset;
/*
* Prepare for the vfork by saving everything that the child
* corrupts before it exec's. Note that in some signal
* implementations which keep the signal info in user space
* (e.g. Sun's) it will also be necessary to save and restore
* the current sigvec's for the signals the child touches
* the current sigaction's for the signals the child touches
* before it exec's.
*/
if (wanttty >= 0 && !nosigchld && !noexec) {
csigmask = sigblock(sigmask(SIGCHLD));
sigemptyset(&sigset);
sigaddset(&sigset, SIGCHLD);
sigprocmask(SIG_BLOCK, &sigset, &csigset);
nosigchld = 1;
}
omask = sigblock(sigmask(SIGCHLD) | sigmask(SIGINT));
sigemptyset(&sigset);
sigaddset(&sigset, SIGCHLD);
sigaddset(&sigset, SIGINT);
sigprocmask(SIG_BLOCK, &sigset, &osigset);
ochild = child;
osetintr = setintr;
ohaderr = haderr;
@ -254,7 +262,7 @@ execute(t, wanttty, pipein, pipeout)
oSHERR = SHERR;
oOLDSTD = OLDSTD;
otpgrp = tpgrp;
ocsigmask = csigmask;
ocsigset = csigset;
onosigchld = nosigchld;
Vsav = Vdp = 0;
Vexpath = 0;
@ -262,7 +270,7 @@ execute(t, wanttty, pipein, pipeout)
pid = vfork();
if (pid < 0) {
(void) sigsetmask(omask);
sigprocmask(SIG_SETMASK, &osigset, NULL);
stderror(ERR_NOPROC);
}
forked++;
@ -276,7 +284,7 @@ execute(t, wanttty, pipein, pipeout)
SHERR = oSHERR;
OLDSTD = oOLDSTD;
tpgrp = otpgrp;
csigmask = ocsigmask;
csigset = ocsigset;
nosigchld = onosigchld;
xfree((ptr_t) Vsav);
@ -289,7 +297,7 @@ execute(t, wanttty, pipein, pipeout)
Vt = 0;
/* this is from pfork() */
palloc(pid, t);
(void) sigsetmask(omask);
sigprocmask(SIG_SETMASK, &osigset, NULL);
}
else { /* child */
/* this is from pfork() */
@ -297,7 +305,7 @@ execute(t, wanttty, pipein, pipeout)
bool ignint = 0;
if (nosigchld) {
(void) sigsetmask(csigmask);
sigprocmask(SIG_SETMASK, &csigset, NULL);
nosigchld = 0;
}
@ -354,7 +362,7 @@ execute(t, wanttty, pipein, pipeout)
}
if ((t->t_dflg & F_PIPEOUT) == 0) {
if (nosigchld) {
(void) sigsetmask(csigmask);
sigprocmask(SIG_SETMASK, &csigset, NULL);
nosigchld = 0;
}
if ((t->t_dflg & F_AMPERSAND) == 0)

View File

@ -1,4 +1,4 @@
/* $NetBSD: set.c,v 1.7 1995/03/21 09:03:22 cgd Exp $ */
/* $NetBSD: set.c,v 1.8 1995/03/21 18:35:52 mycroft Exp $ */
/*-
* Copyright (c) 1980, 1991, 1993
@ -37,7 +37,7 @@
#if 0
static char sccsid[] = "@(#)set.c 8.1 (Berkeley) 5/31/93";
#else
static char rcsid[] = "$NetBSD: set.c,v 1.7 1995/03/21 09:03:22 cgd Exp $";
static char rcsid[] = "$NetBSD: set.c,v 1.8 1995/03/21 18:35:52 mycroft Exp $";
#endif
#endif /* not lint */
@ -816,9 +816,13 @@ plist(p)
{
register struct varent *c;
register len;
sigset_t sigset;
if (setintr)
(void) sigsetmask(sigblock((sigset_t) 0) & ~sigmask(SIGINT));
if (setintr) {
sigemptyset(&sigset);
sigaddset(&sigset, SIGINT);
sigprocmask(SIG_UNBLOCK, &sigset, NULL);
}
for (;;) {
while (p->v_left)