From 2f2a064994b149267b4e6f2e4e3643377de981dc Mon Sep 17 00:00:00 2001 From: Sam Leffler Date: Sat, 11 Jun 1983 23:50:05 -0800 Subject: [PATCH] different approach, try signal compatibility package SCCS-vsn: bin/csh/Makefile 4.3 SCCS-vsn: bin/csh/csh.c 4.12 SCCS-vsn: bin/csh/exec.c 4.7 SCCS-vsn: bin/csh/func.c 4.10 SCCS-vsn: bin/csh/csh.h 4.9 SCCS-vsn: bin/csh/hist.c 4.6 SCCS-vsn: bin/csh/proc.c 4.10 SCCS-vsn: bin/csh/sem.c 4.3 --- usr/src/bin/csh/Makefile | 12 +++---- usr/src/bin/csh/csh.c | 32 +++++++++--------- usr/src/bin/csh/csh.h | 8 ++++- usr/src/bin/csh/exec.c | 8 +++-- usr/src/bin/csh/func.c | 32 +++++++++--------- usr/src/bin/csh/hist.c | 4 +-- usr/src/bin/csh/proc.c | 71 +++++++++++++++++----------------------- usr/src/bin/csh/sem.c | 28 ++++++++-------- 8 files changed, 96 insertions(+), 99 deletions(-) diff --git a/usr/src/bin/csh/Makefile b/usr/src/bin/csh/Makefile index b23c51431e..2d226b75c8 100644 --- a/usr/src/bin/csh/Makefile +++ b/usr/src/bin/csh/Makefile @@ -1,5 +1,5 @@ # -# Makefile 4.2 %G% +# Makefile 4.3 %G% # # C Shell with process control; VM/UNIX VAX Makefile # Bill Joy UC Berkeley; Jim Kulp IIASA, Austria @@ -16,10 +16,10 @@ LIBES= SCCS= /usr/local/sccs # strings.o must be last in OBJS since it can change when previous files compile -OBJS= sh.o sh.dol.o sh.err.o sh.exec.o sh.exp.o sh.func.o sh.glob.o \ - sh.hist.o sh.lex.o sh.misc.o sh.parse.o sh.print.o sh.sem.o sh.set.o \ - sh.proc.o sh.dir.o sh.time.o alloc.o sh.init.o printf.o \ - strings.o doprnt.o +OBJS= alloc.o doprnt.o printf.o sh.o sh.dir.o sh.dol.o sh.err.o sh.exec.o \ + sh.exp.o sh.func.o sh.glob.o sh.hist.o sh.init.o sh.lex.o sh.misc.o \ + sh.parse.o sh.print.o sh.proc.o sh.sem.o sh.set.o sh.sig.o sh.time.o \ + strings.o # Special massaging of C files for sharing of strings .c.o: @@ -89,7 +89,7 @@ install: csh sh.local.h install -s csh ${DESTDIR}/bin/csh clean: - ${RM} -f a.out strings x.c xs.c csh + ${RM} -f a.out strings x.c xs.c csh errs ${RM} -f *.o sh.prof.c tags: /tmp diff --git a/usr/src/bin/csh/csh.c b/usr/src/bin/csh/csh.c index 660bd360fb..0fc95acb4d 100644 --- a/usr/src/bin/csh/csh.c +++ b/usr/src/bin/csh/csh.c @@ -1,4 +1,4 @@ -static char *sccsid = "@(#)csh.c 4.11 %G%"; +static char *sccsid = "@(#)csh.c 4.12 %G%"; #include "sh.h" #include @@ -111,7 +111,7 @@ main(c, av) * We catch it only if we are the login shell. */ parintr = signal(SIGINT, SIG_IGN); /* parents interruptibility */ - signal(SIGINT, parintr); /* ... restore */ + sigset(SIGINT, parintr); /* ... restore */ parterm = signal(SIGTERM, SIG_IGN); /* parents terminability */ signal(SIGTERM, parterm); /* ... restore */ if (loginsh) { @@ -258,8 +258,8 @@ main(c, av) **av = '-'; if (!quitit) /* Wary! */ signal(SIGQUIT, SIG_IGN); - sigblock(mask(SIGINT)); - signal(SIGINT, pintr); + sigset(SIGINT, pintr); + sighold(SIGINT); signal(SIGTERM, SIG_IGN); if (quitit == 0 && arginp == 0) { signal(SIGTSTP, SIG_IGN); @@ -283,9 +283,9 @@ retry: if (ioctl(f, TIOCGPGRP, &tpgrp) == 0 && tpgrp != -1) { int ldisc; if (tpgrp != shpgrp) { - int (*old)() = signal(SIGTTIN, SIG_DFL); + int (*old)() = sigsys(SIGTTIN, SIG_DFL); kill(0, SIGTTIN); - signal(SIGTTIN, old); + sigsys(SIGTTIN, old); goto retry; } if (ioctl(f, TIOCGETD, &oldisc) != 0) @@ -314,7 +314,7 @@ notty: } if (setintr == 0 && parintr == SIG_DFL) setintr++; - signal(SIGCHLD, pchild); /* while signals not ready */ + sigset(SIGCHLD, pchild); /* while signals not ready */ /* * Set an exit here in case of an interrupt or error reading @@ -488,7 +488,7 @@ srcunit(unit, onlyown, hflg) getexit(oldexit); reenter = 0; if (setintr) - (void) sigblock(mask(SIGINT)); + sighold(SIGINT); setexit(); reenter++; if (reenter == 1) { @@ -507,14 +507,14 @@ srcunit(unit, onlyown, hflg) * we let ourselves be interrupted. */ if (setintr) - (void) sigrelse(mask(SIGINT)); + sigrelse(SIGINT); #ifdef TELL settell(); #endif process(0); /* 0 -> blow away on errors */ } if (setintr) - (void) sigrelse(mask(SIGINT)); + sigrelse(SIGINT); if (oSHIN >= 0) { register int i; @@ -578,7 +578,7 @@ goodbye() { if (loginsh) { signal(SIGQUIT, SIG_IGN); - signal(SIGINT, SIG_IGN); + sigset(SIGINT, SIG_IGN); signal(SIGTERM, SIG_IGN); setintr = 0; /* No interrupts after "logout" */ if (adrof("home")) @@ -628,7 +628,7 @@ pintr1(wantnl) register char **v; if (setintr) { - (void) sigrelse(mask(SIGINT)); + sigrelse(SIGINT); if (pjobs) { pjobs = 0; printf("\n"); @@ -637,8 +637,8 @@ pintr1(wantnl) } } if (setintr) - sigblock(mask(SIGINT)); - sigrelse(mask(SIGCHLD)); + sighold(SIGINT); + sigrelse(SIGCHLD); draino(); /* @@ -693,7 +693,7 @@ process(catch) * Interruptible during interactive reads */ if (setintr) - (void) sigrelse(mask(SIGINT)); + sigrelse(SIGINT); /* * For the sake of reset() @@ -771,7 +771,7 @@ process(catch) * The parser may lose space if interrupted. */ if (setintr) - sigblock(mask(SIGINT)); + sighold(SIGINT); /* * Save input text on the history list if diff --git a/usr/src/bin/csh/csh.h b/usr/src/bin/csh/csh.h index 5cf79bd1d1..ae02fde488 100644 --- a/usr/src/bin/csh/csh.h +++ b/usr/src/bin/csh/csh.h @@ -1,4 +1,4 @@ -/* csh.h 4.8 83/06/11 */ +/* csh.h 4.9 83/06/11 */ #include "sh.local.h" #include @@ -26,7 +26,13 @@ typedef char bool; #define eq(a, b) (strcmp(a, b) == 0) + +/* + * For 4.2bsd signals. + */ #define mask(s) (1 << ((s)-1)) +#define sigsys(s, a) signal(s, a) +#define sighold(s) sigblock(mask(s)) /* * Global flags diff --git a/usr/src/bin/csh/exec.c b/usr/src/bin/csh/exec.c index f6189209d2..560006e8e6 100644 --- a/usr/src/bin/csh/exec.c +++ b/usr/src/bin/csh/exec.c @@ -1,4 +1,4 @@ -static char *sccsid = "@(#)exec.c 4.6 %G%"; +static char *sccsid = "@(#)exec.c 4.7 %G%"; #include "sh.h" #include @@ -93,8 +93,10 @@ doexec(t) * We must do this AFTER any possible forking (like `foo` * in glob) so that this shell can still do subprocesses. */ - signal(SIGCHLD, SIG_IGN); - sigsetmask(0); /* sanity */ +#ifdef notdef + sigsys(SIGCHLD, SIG_IGN); /* sigsys for vforks sake */ +#endif + sigsetmask(0); /* * If no path, no words in path, or a / in the filename diff --git a/usr/src/bin/csh/func.c b/usr/src/bin/csh/func.c index 7f9f8a6d2d..15b16af5bf 100644 --- a/usr/src/bin/csh/func.c +++ b/usr/src/bin/csh/func.c @@ -1,4 +1,4 @@ -static char *sccsid = "@(#)func.c 4.9 83/06/10"; +static char *sccsid = "@(#)func.c 4.10 83/06/11"; #include "sh.h" #include @@ -75,16 +75,16 @@ doonintr(v) cp = gointr, gointr = 0, xfree(cp); if (vv == 0) { if (setintr) - (void) sigblock(mask(SIGINT)); + sighold(SIGINT); else - signal(SIGINT, SIG_DFL); + sigset(SIGINT, SIG_DFL); gointr = 0; } else if (eq((vv = strip(vv)), "-")) { - signal(SIGINT, SIG_IGN); + sigset(SIGINT, SIG_IGN); gointr = "-"; } else { gointr = savestr(vv); - signal(SIGINT, pintr); + sigset(SIGINT, pintr); } } @@ -400,10 +400,10 @@ preread() whyles->w_end = -1; if (setintr) - (void) sigrelse(mask(SIGINT)); + sigrelse(SIGINT); search(ZBREAK, 0); if (setintr) - sigblock(mask(SIGINT)); + sighold(SIGINT); whyles->w_end = btell(); } @@ -453,17 +453,17 @@ dorepeat(v, kp) i = getn(v[1]); if (setintr) - (void) sigblock(mask(SIGINT)); + sighold(SIGINT); lshift(v, 2); while (i > 0) { if (setintr) - (void) sigrelse(mask(SIGINT)); + sigrelse(SIGINT); reexecute(kp); --i; } donefds(); if (setintr) - (void) sigrelse(mask(SIGINT)); + sigrelse(SIGINT); } doswbrk() @@ -699,7 +699,7 @@ echo(sep, v) int nonl = 0; if (setintr) - (void) sigrelse(mask(SIGINT)); + sigrelse(SIGINT); v++; if (*v == 0) return; @@ -725,7 +725,7 @@ echo(sep, v) else flush(); if (setintr) - (void) sigblock(mask(SIGINT)); + sighold(SIGINT); if (gargv) blkfree(gargv), gargv = 0; } @@ -1008,17 +1008,17 @@ dosuspend() if (loginsh) error("Can't suspend a login shell (yet)"); untty(); - old = signal(SIGTSTP, SIG_DFL); + old = sigsys(SIGTSTP, SIG_DFL); kill(0, SIGTSTP); /* the shell stops here */ - signal(SIGTSTP, old); + sigsys(SIGTSTP, old); if (tpgrp != -1) { retry: ioctl(FSHTTY, TIOCGPGRP, &ctpgrp); if (ctpgrp != opgrp) { - old = signal(SIGTTIN, SIG_DFL); + old = sigsys(SIGTTIN, SIG_DFL); kill(0, SIGTTIN); - signal(SIGTTIN, old); + sigsys(SIGTTIN, old); goto retry; } ioctl(FSHTTY, TIOCSPGRP, &shpgrp); diff --git a/usr/src/bin/csh/hist.c b/usr/src/bin/csh/hist.c index 774e1cc251..64ed6ae787 100644 --- a/usr/src/bin/csh/hist.c +++ b/usr/src/bin/csh/hist.c @@ -1,4 +1,4 @@ -static char *sccsid = "@(#)hist.c 4.5 %G%"; +static char *sccsid = "@(#)hist.c 4.6 %G%"; #include "sh.h" @@ -73,7 +73,7 @@ dohist(vp) if (getn(value("history")) == 0) return; if (setintr) - (void) sigrelse(mask(SIGINT)); + sigrelse(SIGINT); vp++; while (*vp && *vp[0] == '-') { if (*vp && eq(*vp, "-h")) { diff --git a/usr/src/bin/csh/proc.c b/usr/src/bin/csh/proc.c index 8a64ea1f1b..3ad725fd97 100644 --- a/usr/src/bin/csh/proc.c +++ b/usr/src/bin/csh/proc.c @@ -1,4 +1,4 @@ -static char *sccsid = "@(#)proc.c 4.9 (Berkeley) 83/06/10"; +static char *sccsid = "@(#)proc.c 4.10 (Berkeley) 83/06/11"; #include "sh.h" #include "sh.dir.h" @@ -144,12 +144,12 @@ pnote() neednote = 0; for (pp = proclist.p_next; pp != PNULL; pp = pp->p_next) { if (pp->p_flags & PNEEDNOTE) { - (void) sigblock(mask(SIGCHLD)); + sighold(SIGCHLD); pp->p_flags &= ~PNEEDNOTE; flags = pprint(pp, NUMBER|NAME|REASON); if ((flags&(PRUNNING|PSTOPPED)) == 0) pflush(pp); - (void) sigrelse(mask(SIGCHLD)); + sigrelse(SIGCHLD); } } } @@ -165,7 +165,7 @@ pwait() /* * Here's where dead procs get flushed. */ - (void) sigblock(mask(SIGCHLD)); + sighold(SIGCHLD); for (pp = (fp = &proclist)->p_next; pp != PNULL; pp = (fp = pp)->p_next) if (pp->p_pid == 0) { fp->p_next = pp->p_next; @@ -176,11 +176,9 @@ pwait() xfree((char *)pp); pp = fp; } - (void) sigrelse(mask(SIGCHLD)); -#ifdef notdef + sigrelse(SIGCHLD); if (setintr) - signal(SIGINT, SIG_IGN); -#endif + sigignore(SIGINT); pjwait(pcurrjob); } @@ -192,7 +190,7 @@ pjwait(pp) register struct process *pp; { register struct process *fp; - int jobflags, reason, omask; + int jobflags, reason; fp = pp; do { @@ -204,17 +202,17 @@ pjwait(pp) * and the target process, or any of its friends, are running */ fp = pp; - omask = sigblock(mask(SIGCHLD)); for (;;) { + sighold(SIGCHLD); jobflags = 0; do jobflags |= fp->p_flags; while((fp = (fp->p_friends)) != pp); if ((jobflags & PRUNNING) == 0) break; - sigpause(omask &~ mask(SIGCHLD)); + sigpause(sigblock(0) &~ mask(SIGCHLD)); } - sigsetmask(omask); + sigrelse(SIGCHLD); if (tpgrp > 0) ioctl(FSHTTY, TIOCSPGRP, &tpgrp); /* get tty back */ if ((jobflags&(PSIGNALED|PSTOPPED|PTIME)) || @@ -249,20 +247,19 @@ pjwait(pp) dowait() { register struct process *pp; - int omask; pjobs++; if (setintr) - (void) sigrelse(mask(SIGINT)); - omask = sigblock(mask(SIGCHLD)); + sigrelse(SIGINT); loop: + sighold(SIGCHLD); for (pp = proclist.p_next; pp; pp = pp->p_next) if (pp->p_pid && pp->p_pid == pp->p_jobid && pp->p_flags&PRUNNING) { - sigpause(omask &~ mask(SIGCHLD)); + sigpause(sigblock(0) &~ mask(SIGCHLD)); goto loop; } - sigsetmask(omask); + sigrelse(SIGCHLD); pjobs = 0; } @@ -707,7 +704,7 @@ dofg(v) pp = pfind(*v); pstart(pp, 1); if (setintr) - signal(SIGINT, SIG_IGN); + sigignore(SIGINT); pjwait(pp); } while (*v && *++v); } @@ -724,7 +721,7 @@ dofg1(v) pp = pfind(v[0]); pstart(pp, 1); if (setintr) - signal(SIGINT, SIG_IGN); + sigignore(SIGINT); pjwait(pp); } @@ -815,12 +812,11 @@ pkill(v, signum) register int jobflags = 0; int pid; extern char *sys_errlist[]; - int err = 0, omask = 0; + int err = 0; if (setintr) - omask |= mask(SIGINT); - omask |= mask(SIGCHLD); - omask = sigblock(omask); + sighold(SIGINT); + sighold(SIGCHLD); while (*v) { if (**v == '%') { np = pp = pfind(*v); @@ -858,7 +854,9 @@ pkill(v, signum) cont: v++; } - sigsetmask(omask); + sigrelse(SIGCHLD); + if (setintr) + sigrelse(SIGINT); if (err) error(NOSTR); } @@ -873,7 +871,7 @@ pstart(pp, foregnd) register struct process *np; int jobflags = 0; - (void) sigblock(mask(SIGCHLD)); + sighold(SIGCHLD); np = pp; do { jobflags |= np->p_flags; @@ -893,7 +891,7 @@ pstart(pp, foregnd) ioctl(FSHTTY, TIOCSPGRP, &pp->p_jobid); if (jobflags&PSTOPPED) killpg(pp->p_jobid, SIGCONT); - (void) sigrelse(mask(SIGCHLD)); + sigrelse(SIGCHLD); } panystop(neednl) @@ -1005,7 +1003,7 @@ pfork(t, wanttty) { register int pid; bool ignint = 0; - int pgrp, omask; + int pgrp; /* * A child will be uninterruptible only under very special @@ -1022,12 +1020,13 @@ pfork(t, wanttty) /* * Hold SIGCHLD until we have the process installed in our table. */ - (void) sigblock(mask(SIGCHLD)); + sighold(SIGCHLD); while ((pid = fork()) < 0) if (setintr == 0) sleep(FORKSLEEP); else { - (void) sigrelse(mask(SIGINT)|mask(SIGCHLD)); + sigrelse(SIGINT); + sigrelse(SIGCHLD); error("No more processes"); } if (pid == 0) { @@ -1039,7 +1038,7 @@ pfork(t, wanttty) child++; if (setintr) { setintr = 0; /* until I think otherwise */ - (void) sigrelse(mask(SIGCHLD)); + sigrelse(SIGCHLD); /* * Children just get blown away on SIGINT, SIGQUIT * unless "onintr -" seen. @@ -1077,11 +1076,10 @@ pfork(t, wanttty) */ nice(t->t_nice); } - sigrelse(mask(SIGINT)); } else { palloc(pid, t); - (void) sigrelse(mask(SIGCHLD)); + sigrelse(SIGCHLD); } return (pid); @@ -1095,12 +1093,3 @@ okpcntl() if (tpgrp == 0) error("No job control in subshells"); } - -/* - * For "compatibility". - */ -sigrelse(m) -{ - - return (sigsetmask(sigblock(0) &~ m)); -} diff --git a/usr/src/bin/csh/sem.c b/usr/src/bin/csh/sem.c index 08b88cbd48..53b77f293a 100644 --- a/usr/src/bin/csh/sem.c +++ b/usr/src/bin/csh/sem.c @@ -1,4 +1,4 @@ -static char *sccsid = "@(#)sem.c 4.2 %G%"; +static char *sccsid = "@(#)sem.c 4.3 %G%"; #include "sh.h" #include "sh.proc.h" @@ -114,7 +114,7 @@ execute(t, wanttty, pipein, pipeout) int ochild, osetintr, ohaderr, odidfds, odidcch; int oSHIN, oSHOUT, oSHDIAG, oOLDSTD, otpgrp; - (void) sigblock(mask(SIGCHLD)); + sighold(SIGCHLD); ochild = child; osetintr = setintr; ohaderr = haderr; odidfds = didfds; odidcch = didcch; oSHIN = SHIN; oSHOUT = SHOUT; @@ -122,7 +122,7 @@ execute(t, wanttty, pipein, pipeout) Vsav = Vdp = 0; Vav = 0; pid = vfork(); if (pid < 0) { - (void) sigrelse(mask(SIGCHLD)); + sigrelse(SIGCHLD); error("No more processes"); } forked++; @@ -137,7 +137,7 @@ execute(t, wanttty, pipein, pipeout) xfree(Vav); Vav = 0; /* this is from pfork() */ palloc(pid, t); - (void) sigrelse(mask(SIGCHLD)); + sigrelse(SIGCHLD); } else { /* this is from pfork() */ int pgrp; @@ -152,21 +152,21 @@ execute(t, wanttty, pipein, pipeout) if (setintr) { setintr = 0; #ifdef notdef - signal(SIGCHLD, SIG_DFL); + sigsys(SIGCHLD, SIG_DFL); #endif - signal(SIGINT, + sigsys(SIGINT, ignint ? SIG_IGN : vffree); - signal(SIGQUIT, + sigsys(SIGQUIT, ignint ? SIG_IGN : SIG_DFL); if (wanttty >= 0) { - signal(SIGTSTP, SIG_DFL); - signal(SIGTTIN, SIG_DFL); - signal(SIGTTOU, SIG_DFL); + sigsys(SIGTSTP, SIG_DFL); + sigsys(SIGTTIN, SIG_DFL); + sigsys(SIGTTOU, SIG_DFL); } - signal(SIGTERM, parterm); + sigsys(SIGTERM, parterm); } else if (tpgrp == -1 && (t->t_dflg&FINT)) { - signal(SIGINT, SIG_IGN); - signal(SIGQUIT, SIG_IGN); + sigsys(SIGINT, SIG_IGN); + sigsys(SIGQUIT, SIG_IGN); } if (wanttty > 0) ioctl(FSHTTY, TIOCSPGRP, &pgrp); @@ -175,7 +175,7 @@ execute(t, wanttty, pipein, pipeout) if (tpgrp > 0) tpgrp = 0; if (t->t_dflg & FNOHUP) - signal(SIGHUP, SIG_IGN); + sigsys(SIGHUP, SIG_IGN); if (t->t_dflg & FNICE) nice(t->t_nice); } -- 2.20.1