2005-04-21 16:53:53 +02:00
|
|
|
/*-
|
2006-05-23 14:59:34 +02:00
|
|
|
* Copyright (c) 1991, 1993
|
|
|
|
* The Regents of the University of California. All rights reserved.
|
2005-04-21 16:53:53 +02:00
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
* 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
|
2006-05-23 14:59:34 +02:00
|
|
|
#if 0
|
|
|
|
static char sccsid[] = "@(#)trap.c 8.5 (Berkeley) 6/5/95";
|
|
|
|
#endif
|
2005-04-21 16:53:53 +02:00
|
|
|
#endif /* not lint */
|
2006-05-23 14:59:34 +02:00
|
|
|
/*
|
|
|
|
#include <sys/cdefs.h>
|
|
|
|
__FBSDID("$FreeBSD: src/bin/sh/trap.c,v 1.29 2004/04/06 20:06:51 markm Exp $");
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <signal.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <stdlib.h>
|
2005-04-21 16:53:53 +02:00
|
|
|
|
|
|
|
#include "shell.h"
|
|
|
|
#include "main.h"
|
|
|
|
#include "nodes.h" /* for other headers */
|
|
|
|
#include "eval.h"
|
|
|
|
#include "jobs.h"
|
2006-05-23 14:59:34 +02:00
|
|
|
#include "show.h"
|
2005-04-21 16:53:53 +02:00
|
|
|
#include "options.h"
|
|
|
|
#include "syntax.h"
|
|
|
|
#include "output.h"
|
|
|
|
#include "memalloc.h"
|
|
|
|
#include "error.h"
|
|
|
|
#include "trap.h"
|
|
|
|
#include "mystring.h"
|
2006-05-23 14:59:34 +02:00
|
|
|
#if !defined(NO_HISTORY) && !defined(EDITLINE)
|
|
|
|
#include "myhistedit.h"
|
|
|
|
#endif
|
|
|
|
#include "builtins.h"
|
|
|
|
|
|
|
|
#ifdef __minix
|
|
|
|
#define NO_SIGINTERRUPT
|
|
|
|
#define NO_SYS_SIGNAME
|
|
|
|
#define NO_SYS_SIGLIST
|
|
|
|
|
|
|
|
#endif
|
2005-04-21 16:53:53 +02:00
|
|
|
|
2006-05-23 14:59:34 +02:00
|
|
|
typedef void (*sig_T)(int);
|
2005-04-21 16:53:53 +02:00
|
|
|
|
|
|
|
/*
|
|
|
|
* 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) */
|
2006-05-23 14:59:34 +02:00
|
|
|
#define S_HARD_IGN 4 /* signal is ignored permanently */
|
|
|
|
#define S_RESET 5 /* temporary - to reset a hard ignored sig */
|
|
|
|
|
|
|
|
|
|
|
|
MKINIT char sigmode[_NSIG]; /* current value of signal */
|
|
|
|
int pendingsigs; /* indicates some signal received */
|
|
|
|
int is_interactive= -1; /* Shell is interactive */
|
|
|
|
int in_dotrap; /* do we execute in a trap handler? */
|
|
|
|
static char *volatile trap[_NSIG]; /* trap handler commands */
|
|
|
|
static volatile sig_atomic_t gotsig[_NSIG];
|
|
|
|
/* indicates specified signal received */
|
|
|
|
static int ignore_sigchld; /* Used while handling SIGCHLD traps. */
|
|
|
|
volatile sig_atomic_t gotwinch;
|
|
|
|
|
|
|
|
static int sigstring_to_signum (char *);
|
|
|
|
static void printsignals (void);
|
|
|
|
static int getsigaction(int, sig_T *);
|
|
|
|
static void onsig (int);
|
|
|
|
#ifdef NO_SIGINTERRUPT
|
|
|
|
static int siginterrupt (int,int);
|
|
|
|
#endif
|
|
|
|
static char *strsigname (int);
|
2005-04-21 16:53:53 +02:00
|
|
|
|
|
|
|
|
2006-05-23 14:59:34 +02:00
|
|
|
/*
|
|
|
|
* Map a string to a signal number.
|
|
|
|
*/
|
|
|
|
static int
|
|
|
|
sigstring_to_signum(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(strsigname(n), sig) == 0)
|
|
|
|
return (n);
|
|
|
|
}
|
|
|
|
return (-1);
|
|
|
|
}
|
2005-04-21 16:53:53 +02:00
|
|
|
|
|
|
|
|
|
|
|
/*
|
2006-05-23 14:59:34 +02:00
|
|
|
* Print a list of valid signal names.
|
2005-04-21 16:53:53 +02:00
|
|
|
*/
|
2006-05-23 14:59:34 +02:00
|
|
|
static void
|
|
|
|
printsignals(void)
|
|
|
|
{
|
|
|
|
int n, outlen;
|
|
|
|
|
|
|
|
outlen = 0;
|
|
|
|
for (n = 1; n < _NSIG; n++) {
|
|
|
|
if (strsigname(n)) {
|
|
|
|
out1fmt("%s", strsigname(n));
|
|
|
|
outlen += strlen(strsigname(n));
|
|
|
|
} else {
|
|
|
|
out1fmt("%d", n);
|
|
|
|
outlen += 3; /* good enough */
|
|
|
|
}
|
|
|
|
++outlen;
|
|
|
|
if (outlen > 70 || n == _NSIG - 1) {
|
|
|
|
out1str("\n");
|
|
|
|
outlen = 0;
|
|
|
|
} else {
|
|
|
|
out1c(' ');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-04-21 16:53:53 +02:00
|
|
|
|
2006-05-23 14:59:34 +02:00
|
|
|
/*
|
|
|
|
* The trap builtin.
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
trapcmd(int argc, char **argv)
|
|
|
|
{
|
2005-04-21 16:53:53 +02:00
|
|
|
char *action;
|
|
|
|
int signo;
|
|
|
|
|
|
|
|
if (argc <= 1) {
|
2006-05-23 14:59:34 +02:00
|
|
|
for (signo = 0 ; signo < _NSIG ; signo++) {
|
|
|
|
if (trap[signo] != NULL) {
|
|
|
|
if (signo == 0) {
|
|
|
|
out1fmt("trap -- '%s' %s\n",
|
|
|
|
trap[signo], "exit");
|
|
|
|
} else if (strsigname(signo)) {
|
|
|
|
out1fmt("trap -- '%s' %s\n",
|
|
|
|
trap[signo], strsigname(signo));
|
|
|
|
} else {
|
|
|
|
out1fmt("trap -- '%s' %d\n",
|
|
|
|
trap[signo], signo);
|
|
|
|
}
|
|
|
|
}
|
2005-04-21 16:53:53 +02:00
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
2006-05-23 14:59:34 +02: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);
|
2005-04-21 16:53:53 +02:00
|
|
|
INTOFF;
|
|
|
|
if (action)
|
|
|
|
action = savestr(action);
|
|
|
|
if (trap[signo])
|
|
|
|
ckfree(trap[signo]);
|
|
|
|
trap[signo] = action;
|
|
|
|
if (signo != 0)
|
|
|
|
setsignal(signo);
|
|
|
|
INTON;
|
2006-05-23 14:59:34 +02:00
|
|
|
argv++;
|
2005-04-21 16:53:53 +02:00
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Clear traps on a fork.
|
|
|
|
*/
|
|
|
|
void
|
2006-05-23 14:59:34 +02:00
|
|
|
clear_traps(void)
|
|
|
|
{
|
|
|
|
char *volatile *tp;
|
2005-04-21 16:53:53 +02:00
|
|
|
|
2006-05-23 14:59:34 +02:00
|
|
|
for (tp = trap ; tp <= &trap[_NSIG - 1] ; tp++) {
|
2005-04-21 16:53:53 +02: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.
|
|
|
|
*/
|
2006-05-23 14:59:34 +02:00
|
|
|
void
|
|
|
|
setsignal(int signo)
|
|
|
|
{
|
2005-04-21 16:53:53 +02:00
|
|
|
int action;
|
2006-05-23 14:59:34 +02:00
|
|
|
sig_T sig, sigact = SIG_DFL;
|
2005-04-21 16:53:53 +02:00
|
|
|
char *t;
|
|
|
|
|
|
|
|
if ((t = trap[signo]) == NULL)
|
|
|
|
action = S_DFL;
|
|
|
|
else if (*t != '\0')
|
|
|
|
action = S_CATCH;
|
|
|
|
else
|
|
|
|
action = S_IGN;
|
2006-05-23 14:59:34 +02:00
|
|
|
if (action == S_DFL) {
|
2005-04-21 16:53:53 +02:00
|
|
|
switch (signo) {
|
|
|
|
case SIGINT:
|
2006-05-23 14:59:34 +02:00
|
|
|
action = S_CATCH;
|
2005-04-21 16:53:53 +02:00
|
|
|
break;
|
|
|
|
case SIGQUIT:
|
|
|
|
#if DEBUG
|
|
|
|
{
|
|
|
|
extern int debug;
|
|
|
|
|
|
|
|
if (debug)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
#endif
|
2006-05-23 14:59:34 +02:00
|
|
|
action = S_CATCH;
|
|
|
|
break;
|
2005-04-21 16:53:53 +02:00
|
|
|
case SIGTERM:
|
2006-05-23 14:59:34 +02:00
|
|
|
if (rootshell && iflag)
|
2005-04-21 16:53:53 +02:00
|
|
|
action = S_IGN;
|
|
|
|
break;
|
|
|
|
#if JOBS
|
|
|
|
case SIGTSTP:
|
|
|
|
case SIGTTOU:
|
2006-05-23 14:59:34 +02:00
|
|
|
if (rootshell && mflag)
|
2005-04-21 16:53:53 +02:00
|
|
|
action = S_IGN;
|
|
|
|
break;
|
2006-05-23 14:59:34 +02:00
|
|
|
#endif
|
|
|
|
#ifndef NO_HISTORY
|
|
|
|
case SIGWINCH:
|
|
|
|
if (rootshell && iflag)
|
|
|
|
action = S_CATCH;
|
|
|
|
break;
|
2005-04-21 16:53:53 +02:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
}
|
2006-05-23 14:59:34 +02:00
|
|
|
|
|
|
|
t = &sigmode[signo];
|
|
|
|
if (*t == 0) {
|
2005-04-21 16:53:53 +02:00
|
|
|
/*
|
2006-05-23 14:59:34 +02:00
|
|
|
* current setting unknown
|
2005-04-21 16:53:53 +02:00
|
|
|
*/
|
2006-05-23 14:59:34 +02: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.
|
|
|
|
*/
|
|
|
|
return;
|
|
|
|
}
|
2005-04-21 16:53:53 +02:00
|
|
|
if (sigact == SIG_IGN) {
|
2006-05-23 14:59:34 +02:00
|
|
|
if (mflag && (signo == SIGTSTP ||
|
|
|
|
signo == SIGTTIN || signo == SIGTTOU)) {
|
|
|
|
*t = S_IGN; /* don't hard ignore these */
|
|
|
|
} else
|
|
|
|
*t = S_HARD_IGN;
|
2005-04-21 16:53:53 +02:00
|
|
|
} else {
|
2006-05-23 14:59:34 +02:00
|
|
|
*t = S_RESET; /* force to be set */
|
2005-04-21 16:53:53 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if (*t == S_HARD_IGN || *t == action)
|
2006-05-23 14:59:34 +02:00
|
|
|
return;
|
2005-04-21 16:53:53 +02: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;
|
2006-05-23 14:59:34 +02:00
|
|
|
sig = signal(signo, sigact);
|
|
|
|
if (sig != SIG_ERR && action == S_CATCH)
|
|
|
|
siginterrupt(signo, 1);
|
2005-04-21 16:53:53 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
2006-05-23 14:59:34 +02:00
|
|
|
* Return the current setting for sig w/o changing it.
|
2005-04-21 16:53:53 +02:00
|
|
|
*/
|
2006-05-23 14:59:34 +02:00
|
|
|
static int
|
|
|
|
getsigaction(int signo, sig_T *sigact)
|
|
|
|
{
|
|
|
|
struct sigaction sa;
|
|
|
|
|
|
|
|
if (sigaction(signo, (struct sigaction *)0, &sa) == -1)
|
|
|
|
return 0;
|
|
|
|
*sigact = (sig_T) sa.sa_handler;
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2005-04-21 16:53:53 +02:00
|
|
|
|
2006-05-23 14:59:34 +02:00
|
|
|
/*
|
|
|
|
* Ignore a signal.
|
|
|
|
*/
|
2005-04-21 16:53:53 +02:00
|
|
|
void
|
2006-05-23 14:59:34 +02:00
|
|
|
ignoresig(int signo)
|
|
|
|
{
|
|
|
|
|
|
|
|
if (sigmode[signo] != S_IGN && sigmode[signo] != S_HARD_IGN) {
|
2005-04-21 16:53:53 +02:00
|
|
|
signal(signo, SIG_IGN);
|
|
|
|
}
|
2006-05-23 14:59:34 +02:00
|
|
|
sigmode[signo] = S_HARD_IGN;
|
2005-04-21 16:53:53 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#ifdef mkinit
|
2006-05-23 14:59:34 +02:00
|
|
|
INCLUDE <signal.h>
|
2005-04-21 16:53:53 +02:00
|
|
|
INCLUDE "trap.h"
|
|
|
|
|
|
|
|
SHELLPROC {
|
|
|
|
char *sm;
|
|
|
|
|
|
|
|
clear_traps();
|
2006-05-23 14:59:34 +02:00
|
|
|
for (sm = sigmode ; sm < sigmode + _NSIG ; sm++) {
|
2005-04-21 16:53:53 +02:00
|
|
|
if (*sm == S_IGN)
|
|
|
|
*sm = S_HARD_IGN;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Signal handler.
|
|
|
|
*/
|
2006-05-23 14:59:34 +02:00
|
|
|
static void
|
|
|
|
onsig(int signo)
|
|
|
|
{
|
2005-04-21 16:53:53 +02:00
|
|
|
|
2006-05-23 14:59:34 +02:00
|
|
|
#ifndef BSD
|
2005-04-21 16:53:53 +02:00
|
|
|
signal(signo, onsig);
|
2006-05-23 14:59:34 +02:00
|
|
|
#endif
|
2005-04-21 16:53:53 +02:00
|
|
|
if (signo == SIGINT && trap[SIGINT] == NULL) {
|
|
|
|
onint();
|
|
|
|
return;
|
|
|
|
}
|
2006-05-23 14:59:34 +02:00
|
|
|
|
|
|
|
if (signo != SIGCHLD || !ignore_sigchld)
|
|
|
|
gotsig[signo] = 1;
|
2005-04-21 16:53:53 +02:00
|
|
|
pendingsigs++;
|
|
|
|
|
2006-05-23 14:59:34 +02:00
|
|
|
/* If we are currently in a wait builtin, prepare to break it */
|
|
|
|
if ((signo == SIGINT || signo == SIGQUIT) && in_waitcmd != 0)
|
|
|
|
breakwaitcmd = 1;
|
|
|
|
/*
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
if (Tflag &&
|
|
|
|
trap[signo] != NULL &&
|
|
|
|
! trap[signo][0] == '\0' &&
|
|
|
|
! (trap[signo][0] == ':' && trap[signo][1] == '\0'))
|
|
|
|
breakwaitcmd = 1;
|
|
|
|
|
|
|
|
#ifndef NO_HISTORY
|
|
|
|
if (signo == SIGWINCH)
|
|
|
|
gotwinch = 1;
|
|
|
|
#endif
|
|
|
|
}
|
2005-04-21 16:53:53 +02:00
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Called to execute a trap. Perhaps we should avoid entering new trap
|
|
|
|
* handlers while we are executing a trap handler.
|
|
|
|
*/
|
|
|
|
void
|
2006-05-23 14:59:34 +02:00
|
|
|
dotrap(void)
|
|
|
|
{
|
2005-04-21 16:53:53 +02:00
|
|
|
int i;
|
|
|
|
int savestatus;
|
|
|
|
|
2006-05-23 14:59:34 +02:00
|
|
|
in_dotrap++;
|
2005-04-21 16:53:53 +02:00
|
|
|
for (;;) {
|
2006-05-23 14:59:34 +02: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--;
|
|
|
|
}
|
2005-04-21 16:53:53 +02:00
|
|
|
break;
|
2006-05-23 14:59:34 +02:00
|
|
|
}
|
2005-04-21 16:53:53 +02:00
|
|
|
}
|
2006-05-23 14:59:34 +02:00
|
|
|
if (i >= _NSIG)
|
|
|
|
break;
|
2005-04-21 16:53:53 +02:00
|
|
|
}
|
2006-05-23 14:59:34 +02:00
|
|
|
in_dotrap--;
|
2005-04-21 16:53:53 +02:00
|
|
|
pendingsigs = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Controls whether the shell is interactive or not.
|
|
|
|
*/
|
|
|
|
void
|
2006-05-23 14:59:34 +02:00
|
|
|
setinteractive(int on)
|
|
|
|
{
|
2005-04-21 16:53:53 +02:00
|
|
|
if (on == is_interactive)
|
|
|
|
return;
|
|
|
|
setsignal(SIGINT);
|
|
|
|
setsignal(SIGQUIT);
|
|
|
|
setsignal(SIGTERM);
|
2006-05-23 14:59:34 +02:00
|
|
|
#ifndef NO_HISTORY
|
|
|
|
setsignal(SIGWINCH);
|
|
|
|
#endif
|
2005-04-21 16:53:53 +02:00
|
|
|
is_interactive = on;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Called to exit the shell.
|
|
|
|
*/
|
|
|
|
void
|
2006-05-23 14:59:34 +02:00
|
|
|
exitshell(int status)
|
|
|
|
{
|
2005-04-21 16:53:53 +02:00
|
|
|
struct jmploc loc1, loc2;
|
|
|
|
char *p;
|
|
|
|
|
|
|
|
TRACE(("exitshell(%d) pid=%d\n", status, getpid()));
|
2006-05-23 14:59:34 +02:00
|
|
|
if (setjmp(loc1.loc)) {
|
|
|
|
goto l1;
|
|
|
|
}
|
|
|
|
if (setjmp(loc2.loc)) {
|
|
|
|
goto l2;
|
|
|
|
}
|
2005-04-21 16:53:53 +02:00
|
|
|
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);
|
|
|
|
}
|
2006-05-23 14:59:34 +02:00
|
|
|
|
|
|
|
#ifdef NO_SIGINTERRUPT
|
|
|
|
static int siginterrupt(sig, flag)
|
|
|
|
int sig;
|
|
|
|
int flag;
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef NO_SYS_SIGNAME
|
|
|
|
static char *strsigname(sig)
|
|
|
|
int sig;
|
|
|
|
{
|
|
|
|
switch(sig)
|
|
|
|
{
|
|
|
|
case 0: return "Signal 0"; /* 0 */
|
|
|
|
case SIGHUP: return "hup"; /* 1 */
|
|
|
|
case SIGINT: return "int"; /* 2 */
|
|
|
|
case SIGQUIT: return "quit"; /* 3 */
|
|
|
|
case SIGILL: return "ill"; /* 4 */
|
|
|
|
case SIGTRAP: return "trap"; /* 5 */
|
|
|
|
case SIGABRT: return "abrt"; /* 6 */
|
|
|
|
#ifdef __minix_vmd
|
|
|
|
case SIGEMT: return "emt"; /* 7 */
|
|
|
|
#else
|
|
|
|
case SIGBUS: return "bus"; /* 7 */
|
|
|
|
#endif
|
|
|
|
case SIGFPE: return "fpe"; /* 8 */
|
|
|
|
case SIGKILL: return "kill"; /* 9 */
|
|
|
|
case SIGUSR1: return "usr1"; /* 10 */
|
|
|
|
case SIGSEGV: return "segv"; /* 11 */
|
|
|
|
case SIGUSR2: return "usr2"; /* 12 */
|
|
|
|
case SIGPIPE: return "pipe"; /* 13 */
|
|
|
|
case SIGALRM: return "alrm"; /* 14 */
|
|
|
|
case SIGTERM: return "term"; /* 15 */
|
|
|
|
#ifdef __minix_vmd
|
|
|
|
case 16: return "Signal 16"; /* 16 */
|
|
|
|
#else
|
|
|
|
case SIGEMT: return "emt"; /* 16 */
|
|
|
|
#endif
|
|
|
|
case SIGCHLD: return "chld"; /* 17 */
|
|
|
|
case SIGCONT: return "cont"; /* 18 */
|
|
|
|
case SIGSTOP: return "stop"; /* 19 */
|
|
|
|
case SIGTSTP: return "tstp"; /* 20 */
|
|
|
|
case SIGTTIN: return "ttin"; /* 21 */
|
|
|
|
case SIGTTOU: return "ttou"; /* 22 */
|
|
|
|
case SIGWINCH: return "winch"; /* 23 */
|
2009-08-15 23:37:26 +02:00
|
|
|
case SIGVTALRM: return "vtalrm"; /* 24 */
|
|
|
|
case SIGPROF: return "prof"; /* 25 */
|
2006-05-23 14:59:34 +02:00
|
|
|
#ifdef __minix_vmd
|
|
|
|
case SIGFPEMU: return "fpemu"; /* 30 */
|
|
|
|
#endif
|
|
|
|
default: return "Signal n";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
static char *strsigname(sig)
|
|
|
|
int sig;
|
|
|
|
{
|
|
|
|
return sys_signame[sig];
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef NO_SYS_SIGLIST
|
|
|
|
#include "signames.h"
|
|
|
|
char *strsiglist(sig)
|
|
|
|
int sig;
|
|
|
|
{
|
|
|
|
if (sig > MAXSIG)
|
|
|
|
return NULL;
|
|
|
|
return sigmesg[sig];
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
char *strsiglist(sig)
|
|
|
|
int sig;
|
|
|
|
{
|
|
|
|
return sys_siglist[sig];
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/*
|
|
|
|
* $PchId: trap.c,v 1.7 2006/05/23 11:56:21 philip Exp $
|
|
|
|
*/
|