1994-05-26 06:18:55 +00:00
|
|
|
/*-
|
|
|
|
* Copyright (c) 1991, 1993
|
|
|
|
* The Regents of the University of California. All rights reserved.
|
|
|
|
*
|
|
|
|
* This code is derived from software contributed to Berkeley by
|
|
|
|
* Kenneth Almquist.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
* 3. All advertising materials mentioning features or use of this software
|
|
|
|
* must display the following acknowledgement:
|
|
|
|
* This product includes software developed by the University of
|
|
|
|
* California, Berkeley and its contributors.
|
|
|
|
* 4. Neither the name of the University nor the names of its contributors
|
|
|
|
* may be used to endorse or promote products derived from this software
|
|
|
|
* without specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
|
|
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
|
|
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
|
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
|
|
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
|
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
|
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
|
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
|
|
* SUCH DAMAGE.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef lint
|
1998-05-18 06:44:24 +00:00
|
|
|
#if 0
|
|
|
|
static char sccsid[] = "@(#)trap.c 8.5 (Berkeley) 6/5/95";
|
|
|
|
#endif
|
|
|
|
static const char rcsid[] =
|
1999-05-08 10:22:15 +00:00
|
|
|
"$Id: trap.c,v 1.18 1999/04/01 13:27:36 cracauer Exp $";
|
1994-05-26 06:18:55 +00:00
|
|
|
#endif /* not lint */
|
|
|
|
|
1996-09-01 10:22:36 +00:00
|
|
|
#include <signal.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
1994-05-26 06:18:55 +00:00
|
|
|
#include "shell.h"
|
|
|
|
#include "main.h"
|
|
|
|
#include "nodes.h" /* for other headers */
|
|
|
|
#include "eval.h"
|
|
|
|
#include "jobs.h"
|
1996-09-01 10:22:36 +00:00
|
|
|
#include "show.h"
|
1994-05-26 06:18:55 +00:00
|
|
|
#include "options.h"
|
|
|
|
#include "syntax.h"
|
|
|
|
#include "output.h"
|
|
|
|
#include "memalloc.h"
|
|
|
|
#include "error.h"
|
|
|
|
#include "trap.h"
|
|
|
|
#include "mystring.h"
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Sigmode records the current value of the signal handlers for the various
|
|
|
|
* modes. A value of zero means that the current handler is not known.
|
|
|
|
* S_HARD_IGN indicates that the signal was ignored on entry to the shell,
|
|
|
|
*/
|
|
|
|
|
|
|
|
#define S_DFL 1 /* default signal handling (SIG_DFL) */
|
|
|
|
#define S_CATCH 2 /* signal is caught */
|
|
|
|
#define S_IGN 3 /* signal is ignored (SIG_IGN) */
|
1999-05-08 10:22:15 +00:00
|
|
|
#define S_HARD_IGN 4 /* signal is ignored permanently */
|
1994-05-26 06:18:55 +00:00
|
|
|
#define S_RESET 5 /* temporary - to reset a hard ignored sig */
|
|
|
|
|
|
|
|
|
1996-09-01 10:22:36 +00:00
|
|
|
MKINIT char sigmode[NSIG]; /* current value of signal */
|
1998-08-24 10:20:37 +00:00
|
|
|
int pendingsigs; /* indicates some signal received */
|
1998-08-25 09:33:34 +00:00
|
|
|
int in_dotrap; /* do we execute in a trap handler? */
|
1998-09-08 13:16:52 +00:00
|
|
|
static char *volatile trap[NSIG]; /* trap handler commands */
|
1998-08-24 10:20:37 +00:00
|
|
|
static volatile sig_atomic_t gotsig[NSIG];
|
|
|
|
/* indicates specified signal received */
|
1996-12-24 23:59:53 +00:00
|
|
|
static int ignore_sigchld; /* Used while handling SIGCHLD traps. */
|
1994-05-26 06:18:55 +00:00
|
|
|
|
1996-09-01 10:22:36 +00:00
|
|
|
static int getsigaction __P((int, sig_t *));
|
|
|
|
|
1996-12-24 23:59:53 +00:00
|
|
|
|
1994-05-26 06:18:55 +00:00
|
|
|
/*
|
1996-12-24 23:59:53 +00:00
|
|
|
* Map a string to a signal number.
|
1994-05-26 06:18:55 +00:00
|
|
|
*/
|
1996-12-24 23:59:53 +00:00
|
|
|
static int
|
|
|
|
sigstring_to_signum(sig)
|
|
|
|
char *sig;
|
|
|
|
{
|
|
|
|
|
|
|
|
if (is_number(sig)) {
|
|
|
|
int signo;
|
|
|
|
|
|
|
|
signo = atoi(sig);
|
|
|
|
return ((signo >= 0 && signo < NSIG) ? signo : (-1));
|
|
|
|
} else if (strcasecmp(sig, "exit") == 0) {
|
|
|
|
return (0);
|
|
|
|
} else {
|
|
|
|
int n;
|
|
|
|
|
|
|
|
if (strncasecmp(sig, "sig", 3) == 0)
|
|
|
|
sig += 3;
|
|
|
|
for (n = 1; n < NSIG; n++)
|
|
|
|
if (strcasecmp(sys_signame[n], sig) == 0)
|
|
|
|
return (n);
|
|
|
|
}
|
|
|
|
return (-1);
|
|
|
|
}
|
|
|
|
|
1994-05-26 06:18:55 +00:00
|
|
|
|
1996-12-24 23:59:53 +00:00
|
|
|
/*
|
|
|
|
* Print a list of valid signal names.
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
printsignals()
|
|
|
|
{
|
|
|
|
int n;
|
|
|
|
|
|
|
|
for (n = 1; n < NSIG; n++) {
|
|
|
|
out1fmt("%s", sys_signame[n]);
|
|
|
|
if (n == (NSIG / 2) || n == (NSIG - 1))
|
|
|
|
out1str("\n");
|
|
|
|
else
|
|
|
|
out1c(' ');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* The trap builtin.
|
|
|
|
*/
|
1996-09-01 10:22:36 +00:00
|
|
|
int
|
|
|
|
trapcmd(argc, argv)
|
|
|
|
int argc;
|
1996-12-14 06:20:03 +00:00
|
|
|
char **argv;
|
1996-09-01 10:22:36 +00:00
|
|
|
{
|
1994-05-26 06:18:55 +00:00
|
|
|
char *action;
|
|
|
|
int signo;
|
|
|
|
|
|
|
|
if (argc <= 1) {
|
1996-12-24 23:59:53 +00:00
|
|
|
for (signo = 0 ; signo < NSIG ; signo++) {
|
1994-05-26 06:18:55 +00:00
|
|
|
if (trap[signo] != NULL)
|
1996-12-24 23:59:53 +00:00
|
|
|
out1fmt("trap -- '%s' %s\n", trap[signo],
|
|
|
|
(signo) ? sys_signame[signo] : "exit");
|
1994-05-26 06:18:55 +00:00
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
1996-12-24 23:59:53 +00:00
|
|
|
action = NULL;
|
|
|
|
if (*++argv && strcmp(*argv, "--") == 0)
|
|
|
|
argv++;
|
|
|
|
if (*argv && sigstring_to_signum(*argv) == -1) {
|
|
|
|
if ((*argv)[0] != '-') {
|
|
|
|
action = *argv;
|
|
|
|
argv++;
|
|
|
|
} else if ((*argv)[1] == '\0') {
|
|
|
|
argv++;
|
|
|
|
} else if ((*argv)[1] == 'l' && (*argv)[2] == '\0') {
|
|
|
|
printsignals();
|
|
|
|
return 0;
|
|
|
|
} else {
|
|
|
|
error("bad option %s", *argv);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
while (*argv) {
|
|
|
|
if ((signo = sigstring_to_signum(*argv)) == -1)
|
|
|
|
error("bad signal %s", *argv);
|
1994-05-26 06:18:55 +00:00
|
|
|
INTOFF;
|
|
|
|
if (action)
|
|
|
|
action = savestr(action);
|
|
|
|
if (trap[signo])
|
|
|
|
ckfree(trap[signo]);
|
|
|
|
trap[signo] = action;
|
|
|
|
if (signo != 0)
|
|
|
|
setsignal(signo);
|
|
|
|
INTON;
|
1996-12-24 23:59:53 +00:00
|
|
|
argv++;
|
1994-05-26 06:18:55 +00:00
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Clear traps on a fork.
|
|
|
|
*/
|
|
|
|
void
|
1996-12-24 23:59:53 +00:00
|
|
|
clear_traps()
|
|
|
|
{
|
1998-09-08 13:16:52 +00:00
|
|
|
char *volatile *tp;
|
1994-05-26 06:18:55 +00:00
|
|
|
|
1996-12-24 23:59:53 +00:00
|
|
|
for (tp = trap ; tp <= &trap[NSIG - 1] ; tp++) {
|
1994-05-26 06:18:55 +00:00
|
|
|
if (*tp && **tp) { /* trap not NULL or SIG_IGN */
|
|
|
|
INTOFF;
|
|
|
|
ckfree(*tp);
|
|
|
|
*tp = NULL;
|
|
|
|
if (tp != &trap[0])
|
|
|
|
setsignal(tp - trap);
|
|
|
|
INTON;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Set the signal handler for the specified signal. The routine figures
|
|
|
|
* out what it should be set to.
|
|
|
|
*/
|
1997-11-10 11:32:24 +00:00
|
|
|
void
|
1996-12-14 06:20:03 +00:00
|
|
|
setsignal(signo)
|
1996-09-01 10:22:36 +00:00
|
|
|
int signo;
|
|
|
|
{
|
1994-05-26 06:18:55 +00:00
|
|
|
int action;
|
1997-11-10 11:32:24 +00:00
|
|
|
sig_t sig, sigact = SIG_DFL;
|
1994-05-26 06:18:55 +00:00
|
|
|
char *t;
|
|
|
|
|
|
|
|
if ((t = trap[signo]) == NULL)
|
|
|
|
action = S_DFL;
|
|
|
|
else if (*t != '\0')
|
|
|
|
action = S_CATCH;
|
|
|
|
else
|
|
|
|
action = S_IGN;
|
1998-08-24 10:20:37 +00:00
|
|
|
if (action == S_DFL) {
|
1994-05-26 06:18:55 +00:00
|
|
|
switch (signo) {
|
|
|
|
case SIGINT:
|
1998-08-24 10:20:37 +00:00
|
|
|
action = S_CATCH;
|
1994-05-26 06:18:55 +00:00
|
|
|
break;
|
|
|
|
case SIGQUIT:
|
|
|
|
#ifdef DEBUG
|
|
|
|
{
|
|
|
|
extern int debug;
|
|
|
|
|
|
|
|
if (debug)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
#endif
|
1998-08-25 08:49:47 +00:00
|
|
|
action = S_CATCH;
|
1998-08-24 10:20:37 +00:00
|
|
|
break;
|
1994-05-26 06:18:55 +00:00
|
|
|
case SIGTERM:
|
1998-08-24 10:20:37 +00:00
|
|
|
if (rootshell && iflag)
|
1994-05-26 06:18:55 +00:00
|
|
|
action = S_IGN;
|
|
|
|
break;
|
|
|
|
#if JOBS
|
|
|
|
case SIGTSTP:
|
|
|
|
case SIGTTOU:
|
1998-08-24 10:20:37 +00:00
|
|
|
if (rootshell && mflag)
|
1994-05-26 06:18:55 +00:00
|
|
|
action = S_IGN;
|
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
}
|
1996-09-01 10:22:36 +00:00
|
|
|
|
1996-12-24 23:59:53 +00:00
|
|
|
t = &sigmode[signo];
|
1995-05-30 00:07:29 +00:00
|
|
|
if (*t == 0) {
|
|
|
|
/*
|
|
|
|
* current setting unknown
|
1994-05-26 06:18:55 +00:00
|
|
|
*/
|
1996-09-01 10:22:36 +00:00
|
|
|
if (!getsigaction(signo, &sigact)) {
|
|
|
|
/*
|
|
|
|
* Pretend it worked; maybe we should give a warning
|
|
|
|
* here, but other shells don't. We don't alter
|
|
|
|
* sigmode, so that we retry every time.
|
|
|
|
*/
|
1997-11-10 11:32:24 +00:00
|
|
|
return;
|
1996-09-01 10:22:36 +00:00
|
|
|
}
|
1994-05-26 06:18:55 +00:00
|
|
|
if (sigact == SIG_IGN) {
|
1995-05-30 00:07:29 +00:00
|
|
|
if (mflag && (signo == SIGTSTP ||
|
1994-05-26 06:18:55 +00:00
|
|
|
signo == SIGTTIN || signo == SIGTTOU)) {
|
|
|
|
*t = S_IGN; /* don't hard ignore these */
|
|
|
|
} else
|
|
|
|
*t = S_HARD_IGN;
|
|
|
|
} else {
|
|
|
|
*t = S_RESET; /* force to be set */
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (*t == S_HARD_IGN || *t == action)
|
1997-11-10 11:32:24 +00:00
|
|
|
return;
|
1994-05-26 06:18:55 +00:00
|
|
|
switch (action) {
|
|
|
|
case S_DFL: sigact = SIG_DFL; break;
|
|
|
|
case S_CATCH: sigact = onsig; break;
|
|
|
|
case S_IGN: sigact = SIG_IGN; break;
|
|
|
|
}
|
|
|
|
*t = action;
|
1997-11-10 11:32:24 +00:00
|
|
|
sig = signal(signo, sigact);
|
1997-11-05 23:33:58 +00:00
|
|
|
#ifdef BSD
|
1997-11-10 11:32:24 +00:00
|
|
|
if (sig != SIG_ERR && action == S_CATCH)
|
|
|
|
siginterrupt(signo, 1);
|
1997-11-05 23:33:58 +00:00
|
|
|
#endif
|
1994-05-26 06:18:55 +00:00
|
|
|
}
|
|
|
|
|
1996-12-24 23:59:53 +00:00
|
|
|
|
1994-05-26 06:18:55 +00:00
|
|
|
/*
|
|
|
|
* Return the current setting for sig w/o changing it.
|
|
|
|
*/
|
1996-09-01 10:22:36 +00:00
|
|
|
static int
|
1996-12-14 06:20:03 +00:00
|
|
|
getsigaction(signo, sigact)
|
1996-09-01 10:22:36 +00:00
|
|
|
int signo;
|
|
|
|
sig_t *sigact;
|
|
|
|
{
|
1994-05-26 06:18:55 +00:00
|
|
|
struct sigaction sa;
|
|
|
|
|
|
|
|
if (sigaction(signo, (struct sigaction *)0, &sa) == -1)
|
1996-09-01 10:22:36 +00:00
|
|
|
return 0;
|
|
|
|
*sigact = (sig_t) sa.sa_handler;
|
|
|
|
return 1;
|
1994-05-26 06:18:55 +00:00
|
|
|
}
|
|
|
|
|
1996-12-24 23:59:53 +00:00
|
|
|
|
1994-05-26 06:18:55 +00:00
|
|
|
/*
|
|
|
|
* Ignore a signal.
|
|
|
|
*/
|
|
|
|
void
|
1996-12-14 06:20:03 +00:00
|
|
|
ignoresig(signo)
|
1996-09-01 10:22:36 +00:00
|
|
|
int signo;
|
|
|
|
{
|
1996-12-24 23:59:53 +00:00
|
|
|
|
|
|
|
if (sigmode[signo] != S_IGN && sigmode[signo] != S_HARD_IGN) {
|
1994-05-26 06:18:55 +00:00
|
|
|
signal(signo, SIG_IGN);
|
|
|
|
}
|
1996-12-24 23:59:53 +00:00
|
|
|
sigmode[signo] = S_HARD_IGN;
|
1994-05-26 06:18:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#ifdef mkinit
|
1996-09-01 10:22:36 +00:00
|
|
|
INCLUDE <signal.h>
|
1994-05-26 06:18:55 +00:00
|
|
|
INCLUDE "trap.h"
|
|
|
|
|
|
|
|
SHELLPROC {
|
|
|
|
char *sm;
|
|
|
|
|
|
|
|
clear_traps();
|
1996-09-01 10:22:36 +00:00
|
|
|
for (sm = sigmode ; sm < sigmode + NSIG ; sm++) {
|
1994-05-26 06:18:55 +00:00
|
|
|
if (*sm == S_IGN)
|
|
|
|
*sm = S_HARD_IGN;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Signal handler.
|
|
|
|
*/
|
|
|
|
void
|
1996-12-14 06:20:03 +00:00
|
|
|
onsig(signo)
|
1996-09-01 10:22:36 +00:00
|
|
|
int signo;
|
|
|
|
{
|
1997-11-10 11:32:24 +00:00
|
|
|
|
1997-11-05 23:33:58 +00:00
|
|
|
#ifndef BSD
|
1994-05-26 06:18:55 +00:00
|
|
|
signal(signo, onsig);
|
1997-11-05 23:33:58 +00:00
|
|
|
#endif
|
1994-05-26 06:18:55 +00:00
|
|
|
if (signo == SIGINT && trap[SIGINT] == NULL) {
|
|
|
|
onint();
|
|
|
|
return;
|
|
|
|
}
|
1998-09-08 13:16:52 +00:00
|
|
|
|
1996-12-24 23:59:53 +00:00
|
|
|
if (signo != SIGCHLD || !ignore_sigchld)
|
|
|
|
gotsig[signo] = 1;
|
1994-05-26 06:18:55 +00:00
|
|
|
pendingsigs++;
|
1998-09-08 13:16:52 +00:00
|
|
|
|
|
|
|
/* If we are currently in a wait builtin, prepare to break it */
|
|
|
|
if ((signo == SIGINT || signo == SIGQUIT) && in_waitcmd != 0)
|
1998-08-24 10:20:37 +00:00
|
|
|
breakwaitcmd = 1;
|
1998-09-08 13:16:52 +00:00
|
|
|
/*
|
1998-09-10 22:09:11 +00:00
|
|
|
* If a trap is set, not ignored and not the null command, we need
|
|
|
|
* to make sure traps are executed even when a child blocks signals.
|
1998-09-08 13:16:52 +00:00
|
|
|
*/
|
1999-04-01 13:27:36 +00:00
|
|
|
if (Tflag &&
|
|
|
|
trap[signo] != NULL &&
|
1998-09-10 22:09:11 +00:00
|
|
|
! trap[signo][0] == '\0' &&
|
1998-09-10 14:51:06 +00:00
|
|
|
! (trap[signo][0] == ':' && trap[signo][1] == '\0'))
|
|
|
|
breakwaitcmd = 1;
|
1994-05-26 06:18:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Called to execute a trap. Perhaps we should avoid entering new trap
|
|
|
|
* handlers while we are executing a trap handler.
|
|
|
|
*/
|
|
|
|
void
|
1996-12-24 23:59:53 +00:00
|
|
|
dotrap()
|
|
|
|
{
|
1994-05-26 06:18:55 +00:00
|
|
|
int i;
|
|
|
|
int savestatus;
|
|
|
|
|
1998-08-24 10:20:37 +00:00
|
|
|
in_dotrap++;
|
1994-05-26 06:18:55 +00:00
|
|
|
for (;;) {
|
1996-12-24 23:59:53 +00:00
|
|
|
for (i = 1; i < NSIG; i++) {
|
|
|
|
if (gotsig[i]) {
|
|
|
|
gotsig[i] = 0;
|
|
|
|
if (trap[i]) {
|
|
|
|
/*
|
|
|
|
* Ignore SIGCHLD to avoid infinite recursion
|
|
|
|
* if the trap action does a fork.
|
|
|
|
*/
|
|
|
|
if (i == SIGCHLD)
|
|
|
|
ignore_sigchld++;
|
|
|
|
savestatus = exitstatus;
|
|
|
|
evalstring(trap[i]);
|
|
|
|
exitstatus = savestatus;
|
|
|
|
if (i == SIGCHLD)
|
|
|
|
ignore_sigchld--;
|
|
|
|
}
|
1994-05-26 06:18:55 +00:00
|
|
|
break;
|
1996-12-24 23:59:53 +00:00
|
|
|
}
|
1994-05-26 06:18:55 +00:00
|
|
|
}
|
1996-12-24 23:59:53 +00:00
|
|
|
if (i >= NSIG)
|
|
|
|
break;
|
1994-05-26 06:18:55 +00:00
|
|
|
}
|
1998-08-24 10:20:37 +00:00
|
|
|
in_dotrap--;
|
1994-05-26 06:18:55 +00:00
|
|
|
pendingsigs = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Controls whether the shell is interactive or not.
|
|
|
|
*/
|
|
|
|
void
|
1996-09-01 10:22:36 +00:00
|
|
|
setinteractive(on)
|
|
|
|
int on;
|
|
|
|
{
|
1998-08-24 10:20:37 +00:00
|
|
|
static int is_interactive = -1;
|
1994-05-26 06:18:55 +00:00
|
|
|
|
|
|
|
if (on == is_interactive)
|
|
|
|
return;
|
|
|
|
setsignal(SIGINT);
|
|
|
|
setsignal(SIGQUIT);
|
|
|
|
setsignal(SIGTERM);
|
|
|
|
is_interactive = on;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Called to exit the shell.
|
|
|
|
*/
|
|
|
|
void
|
1996-12-14 06:20:03 +00:00
|
|
|
exitshell(status)
|
1996-09-01 10:22:36 +00:00
|
|
|
int status;
|
|
|
|
{
|
1994-05-26 06:18:55 +00:00
|
|
|
struct jmploc loc1, loc2;
|
|
|
|
char *p;
|
|
|
|
|
|
|
|
TRACE(("exitshell(%d) pid=%d\n", status, getpid()));
|
|
|
|
if (setjmp(loc1.loc)) {
|
|
|
|
goto l1;
|
|
|
|
}
|
|
|
|
if (setjmp(loc2.loc)) {
|
|
|
|
goto l2;
|
|
|
|
}
|
|
|
|
handler = &loc1;
|
|
|
|
if ((p = trap[0]) != NULL && *p != '\0') {
|
|
|
|
trap[0] = NULL;
|
|
|
|
evalstring(p);
|
|
|
|
}
|
|
|
|
l1: handler = &loc2; /* probably unnecessary */
|
|
|
|
flushall();
|
|
|
|
#if JOBS
|
|
|
|
setjobctl(0);
|
|
|
|
#endif
|
|
|
|
l2: _exit(status);
|
|
|
|
}
|