/* trap.c -- Not the trap command, but useful functions for manipulating
those objects. The trap command is in builtins/trap.def. */
-/* Copyright (C) 1987, 1991 Free Software Foundation, Inc.
+/* Copyright (C) 1987-2002 Free Software Foundation, Inc.
This file is part of GNU Bash, the Bourne Again SHell.
#include "shell.h"
#include "input.h" /* for save_token_state, restore_token_state */
#include "signames.h"
+#include "builtins.h"
#include "builtins/common.h"
+#include "builtins/builtext.h"
#ifndef errno
extern int errno;
extern int last_command_exit_value;
extern int line_number;
+extern sh_builtin_func_t *this_shell_builtin;
+extern procenv_t wait_intr_buf;
+
/* The list of things to do originally, before we started trapping. */
SigHandler *original_signals[NSIG];
it. */
int trap_line_number;
+/* The (trapped) signal received while executing in the `wait' builtin */
+int wait_signal_received;
+
/* A value which can never be the target of a trap handler. */
#define IMPOSSIBLE_TRAP_HANDLER (SigHandler *)initialize_traps
char *ret;
/* on cygwin32, signal_names[sig] could be null */
- ret = (sig > NSIG || sig < 0) ? "bad signal number" : signal_names[sig];
+ ret = (sig >= BASH_NSIG || sig < 0) ? "bad signal number" : signal_names[sig];
if (ret == NULL)
ret = "unrecognized signal number";
return ret;
decode_signal (string)
char *string;
{
- long sig;
+ intmax_t sig;
if (legal_number (string, &sig))
return ((sig >= 0 && sig < NSIG) ? (int)sig : NO_SIG);
catch_flag = 1;
pending_traps[sig]++;
+ if (interrupt_immediately && this_shell_builtin && (this_shell_builtin == wait_builtin))
+ {
+ wait_signal_received = sig;
+ longjmp (wait_intr_buf, 1);
+ }
+
if (interrupt_immediately)
run_pending_traps ();
void
run_debug_trap ()
{
- if ((sigmodes[DEBUG_TRAP] & SIG_TRAPPED) && (sigmodes[DEBUG_TRAP] & SIG_INPROGRESS) == 0)
+ if ((sigmodes[DEBUG_TRAP] & SIG_TRAPPED) && ((sigmodes[DEBUG_TRAP] & SIG_INPROGRESS) == 0))
_run_trap_internal (DEBUG_TRAP, "debug trap");
}
int sig;
{
set_signal_handler (sig, original_signals[sig]);
+ sigmodes[sig] &= ~SIG_TRAPPED;
}
/* Set the handler signal SIG to the original and free any trap