mirror of
https://https.git.savannah.gnu.org/git/bash.git
synced 2026-07-06 20:00:49 +02:00
second set of ANSI C changes: C89-style function declarations, more inline functions, remove register keyword
This commit is contained in:
@@ -150,7 +150,7 @@ int suppress_debug_trap_verbose = 0;
|
||||
GETORIGSIG(sig)
|
||||
|
||||
void
|
||||
initialize_traps ()
|
||||
initialize_traps (void)
|
||||
{
|
||||
register int i;
|
||||
|
||||
@@ -198,8 +198,7 @@ initialize_traps ()
|
||||
#ifdef DEBUG
|
||||
/* Return a printable representation of the trap handler for SIG. */
|
||||
static char *
|
||||
trap_handler_string (sig)
|
||||
int sig;
|
||||
trap_handler_string (int sig)
|
||||
{
|
||||
if (trap_list[sig] == (char *)DEFAULT_SIG)
|
||||
return "DEFAULT_SIG";
|
||||
@@ -216,8 +215,7 @@ trap_handler_string (sig)
|
||||
|
||||
/* Return the print name of this signal. */
|
||||
char *
|
||||
signal_name (sig)
|
||||
int sig;
|
||||
signal_name (int sig)
|
||||
{
|
||||
char *ret;
|
||||
|
||||
@@ -234,9 +232,7 @@ signal_name (sig)
|
||||
then (int)2 is returned. Return NO_SIG if STRING doesn't
|
||||
contain a valid signal descriptor. */
|
||||
int
|
||||
decode_signal (string, flags)
|
||||
char *string;
|
||||
int flags;
|
||||
decode_signal (char *string, int flags)
|
||||
{
|
||||
intmax_t sig;
|
||||
char *name;
|
||||
@@ -300,7 +296,7 @@ decode_signal (string, flags)
|
||||
static int catch_flag;
|
||||
|
||||
void
|
||||
run_pending_traps ()
|
||||
run_pending_traps (void)
|
||||
{
|
||||
register int sig;
|
||||
int x;
|
||||
@@ -501,8 +497,7 @@ run_pending_traps ()
|
||||
/* Set the private state variables noting that we received a signal SIG
|
||||
for which we have a trap set. */
|
||||
void
|
||||
set_trap_state (sig)
|
||||
int sig;
|
||||
set_trap_state (int sig)
|
||||
{
|
||||
catch_flag = 1;
|
||||
pending_traps[sig]++;
|
||||
@@ -510,8 +505,7 @@ set_trap_state (sig)
|
||||
}
|
||||
|
||||
sighandler
|
||||
trap_handler (sig)
|
||||
int sig;
|
||||
trap_handler (int sig)
|
||||
{
|
||||
int oerrno;
|
||||
|
||||
@@ -585,8 +579,7 @@ trap_handler (sig)
|
||||
}
|
||||
|
||||
int
|
||||
next_pending_trap (start)
|
||||
int start;
|
||||
next_pending_trap (int start)
|
||||
{
|
||||
register int i;
|
||||
|
||||
@@ -597,7 +590,7 @@ next_pending_trap (start)
|
||||
}
|
||||
|
||||
int
|
||||
first_pending_trap ()
|
||||
first_pending_trap (void)
|
||||
{
|
||||
return (next_pending_trap (1));
|
||||
}
|
||||
@@ -605,7 +598,7 @@ first_pending_trap ()
|
||||
/* Return > 0 if any of the "real" signals (not fake signals like EXIT) are
|
||||
trapped. */
|
||||
int
|
||||
any_signals_trapped ()
|
||||
any_signals_trapped (void)
|
||||
{
|
||||
register int i;
|
||||
|
||||
@@ -616,7 +609,7 @@ any_signals_trapped ()
|
||||
}
|
||||
|
||||
void
|
||||
clear_pending_traps ()
|
||||
clear_pending_traps (void)
|
||||
{
|
||||
register int i;
|
||||
|
||||
@@ -625,7 +618,7 @@ clear_pending_traps ()
|
||||
}
|
||||
|
||||
void
|
||||
check_signals ()
|
||||
check_signals (void)
|
||||
{
|
||||
/* Add any other shell timeouts here */
|
||||
check_read_timeout (); /* set by the read builtin */
|
||||
@@ -634,7 +627,7 @@ check_signals ()
|
||||
|
||||
/* Convenience functions the rest of the shell can use */
|
||||
void
|
||||
check_signals_and_traps ()
|
||||
check_signals_and_traps (void)
|
||||
{
|
||||
check_signals ();
|
||||
|
||||
@@ -646,8 +639,7 @@ check_signals_and_traps ()
|
||||
#ifdef INCLUDE_UNUSED
|
||||
/* Make COMMAND_STRING be executed when SIGCHLD is caught. */
|
||||
void
|
||||
set_sigchld_trap (command_string)
|
||||
char *command_string;
|
||||
set_sigchld_trap (char *command_string)
|
||||
{
|
||||
set_signal (SIGCHLD, command_string);
|
||||
}
|
||||
@@ -659,8 +651,7 @@ set_sigchld_trap (command_string)
|
||||
reset the disposition to the default and not have the original signal
|
||||
accidentally restored, undoing the user's command. */
|
||||
void
|
||||
maybe_set_sigchld_trap (command_string)
|
||||
char *command_string;
|
||||
maybe_set_sigchld_trap (char *command_string)
|
||||
{
|
||||
if ((sigmodes[SIGCHLD] & SIG_TRAPPED) == 0 && trap_list[SIGCHLD] == (char *)IMPOSSIBLE_TRAP_HANDLER)
|
||||
set_signal (SIGCHLD, command_string);
|
||||
@@ -670,7 +661,7 @@ maybe_set_sigchld_trap (command_string)
|
||||
as a sentinel in run_sigchld_trap and maybe_set_sigchld_trap to see whether
|
||||
or not a SIGCHLD trap handler reset SIGCHLD disposition to the default. */
|
||||
void
|
||||
set_impossible_sigchld_trap ()
|
||||
set_impossible_sigchld_trap (void)
|
||||
{
|
||||
restore_default_signal (SIGCHLD);
|
||||
change_signal (SIGCHLD, (char *)IMPOSSIBLE_TRAP_HANDLER);
|
||||
@@ -681,8 +672,7 @@ set_impossible_sigchld_trap ()
|
||||
pending_traps[SIGCHLD] by that amount. This allows us to still run the
|
||||
SIGCHLD trap once for each exited child. */
|
||||
void
|
||||
queue_sigchld_trap (nchild)
|
||||
int nchild;
|
||||
queue_sigchld_trap (int nchild)
|
||||
{
|
||||
if (nchild > 0)
|
||||
{
|
||||
@@ -695,17 +685,14 @@ queue_sigchld_trap (nchild)
|
||||
|
||||
/* Set a trap for SIG only if SIG is not already trapped. */
|
||||
static inline void
|
||||
trap_if_untrapped (sig, command)
|
||||
int sig;
|
||||
char *command;
|
||||
trap_if_untrapped (int sig, char *command)
|
||||
{
|
||||
if ((sigmodes[sig] & SIG_TRAPPED) == 0)
|
||||
set_signal (sig, command);
|
||||
}
|
||||
|
||||
void
|
||||
set_debug_trap (command)
|
||||
char *command;
|
||||
set_debug_trap (char *command)
|
||||
{
|
||||
set_signal (DEBUG_TRAP, command);
|
||||
}
|
||||
@@ -717,44 +704,38 @@ set_debug_trap (command)
|
||||
SIG_TRAPPED will be set and we don't bother restoring the original trap string.
|
||||
This is used by both functions and the source builtin. */
|
||||
void
|
||||
maybe_set_debug_trap (command)
|
||||
char *command;
|
||||
maybe_set_debug_trap (char *command)
|
||||
{
|
||||
trap_if_untrapped (DEBUG_TRAP, command);
|
||||
}
|
||||
|
||||
void
|
||||
set_error_trap (command)
|
||||
char *command;
|
||||
set_error_trap (char *command)
|
||||
{
|
||||
set_signal (ERROR_TRAP, command);
|
||||
}
|
||||
|
||||
void
|
||||
maybe_set_error_trap (command)
|
||||
char *command;
|
||||
maybe_set_error_trap (char *command)
|
||||
{
|
||||
trap_if_untrapped (ERROR_TRAP, command);
|
||||
}
|
||||
|
||||
void
|
||||
set_return_trap (command)
|
||||
char *command;
|
||||
set_return_trap (char *command)
|
||||
{
|
||||
set_signal (RETURN_TRAP, command);
|
||||
}
|
||||
|
||||
void
|
||||
maybe_set_return_trap (command)
|
||||
char *command;
|
||||
maybe_set_return_trap (char *command)
|
||||
{
|
||||
trap_if_untrapped (RETURN_TRAP, command);
|
||||
}
|
||||
|
||||
#ifdef INCLUDE_UNUSED
|
||||
void
|
||||
set_sigint_trap (command)
|
||||
char *command;
|
||||
set_sigint_trap (char *command)
|
||||
{
|
||||
set_signal (SIGINT, command);
|
||||
}
|
||||
@@ -764,7 +745,7 @@ set_sigint_trap (command)
|
||||
things, like waiting for command substitution or executing commands
|
||||
in explicit subshells ( ( cmd ) ), can catch interrupts properly. */
|
||||
SigHandler *
|
||||
set_sigint_handler ()
|
||||
set_sigint_handler (void)
|
||||
{
|
||||
if (sigmodes[SIGINT] & SIG_HARD_IGNORE)
|
||||
return ((SigHandler *)SIG_IGN);
|
||||
@@ -776,7 +757,8 @@ set_sigint_handler ()
|
||||
return ((SigHandler *)set_signal_handler (SIGINT, trap_handler));
|
||||
|
||||
/* The signal is not trapped, so set the handler to the shell's special
|
||||
interrupt handler. */
|
||||
interrupt handler. Make sure this agrees with code in sig.c and
|
||||
builtins/trap.def */
|
||||
else if (interactive) /* XXX - was interactive_shell */
|
||||
return (set_signal_handler (SIGINT, sigint_sighandler));
|
||||
else
|
||||
@@ -786,8 +768,7 @@ set_sigint_handler ()
|
||||
/* Return the correct handler for signal SIG according to the values in
|
||||
sigmodes[SIG]. */
|
||||
SigHandler *
|
||||
trap_to_sighandler (sig)
|
||||
int sig;
|
||||
trap_to_sighandler (int sig)
|
||||
{
|
||||
if (sigmodes[sig] & (SIG_IGNORED|SIG_HARD_IGNORE))
|
||||
return (SIG_IGN);
|
||||
@@ -799,9 +780,7 @@ trap_to_sighandler (sig)
|
||||
|
||||
/* Set SIG to call STRING as a command. */
|
||||
void
|
||||
set_signal (sig, string)
|
||||
int sig;
|
||||
char *string;
|
||||
set_signal (int sig, char *string)
|
||||
{
|
||||
sigset_t set, oset;
|
||||
|
||||
@@ -845,8 +824,7 @@ set_signal (sig, string)
|
||||
}
|
||||
|
||||
static void
|
||||
free_trap_command (sig)
|
||||
int sig;
|
||||
free_trap_command (int sig)
|
||||
{
|
||||
if ((sigmodes[sig] & SIG_TRAPPED) && trap_list[sig] &&
|
||||
(trap_list[sig] != (char *)IGNORE_SIG) &&
|
||||
@@ -858,9 +836,7 @@ free_trap_command (sig)
|
||||
/* If SIG has a string assigned to it, get rid of it. Then give it
|
||||
VALUE. */
|
||||
static void
|
||||
change_signal (sig, value)
|
||||
int sig;
|
||||
char *value;
|
||||
change_signal (int sig, char *value)
|
||||
{
|
||||
if ((sigmodes[sig] & SIG_INPROGRESS) == 0)
|
||||
free_trap_command (sig);
|
||||
@@ -876,8 +852,7 @@ change_signal (sig, value)
|
||||
}
|
||||
|
||||
void
|
||||
get_original_signal (sig)
|
||||
int sig;
|
||||
get_original_signal (int sig)
|
||||
{
|
||||
/* If we aren't sure the of the original value, then get it. */
|
||||
if (sig > 0 && sig < NSIG && original_signals[sig] == (SigHandler *)IMPOSSIBLE_TRAP_HANDLER)
|
||||
@@ -885,7 +860,7 @@ get_original_signal (sig)
|
||||
}
|
||||
|
||||
void
|
||||
get_all_original_signals ()
|
||||
get_all_original_signals (void)
|
||||
{
|
||||
register int i;
|
||||
|
||||
@@ -894,9 +869,7 @@ get_all_original_signals ()
|
||||
}
|
||||
|
||||
void
|
||||
set_original_signal (sig, handler)
|
||||
int sig;
|
||||
SigHandler *handler;
|
||||
set_original_signal (int sig, SigHandler *handler)
|
||||
{
|
||||
if (sig > 0 && sig < NSIG && original_signals[sig] == (SigHandler *)IMPOSSIBLE_TRAP_HANDLER)
|
||||
SETORIGSIG (sig, handler);
|
||||
@@ -907,8 +880,7 @@ set_original_signal (sig, handler)
|
||||
from trap_builtin (), which takes care to restore the handlers for
|
||||
the signals the shell treats specially. */
|
||||
void
|
||||
restore_default_signal (sig)
|
||||
int sig;
|
||||
restore_default_signal (int sig)
|
||||
{
|
||||
if (SPECIAL_TRAP (sig))
|
||||
{
|
||||
@@ -950,8 +922,7 @@ restore_default_signal (sig)
|
||||
|
||||
/* Make this signal be ignored. */
|
||||
void
|
||||
ignore_signal (sig)
|
||||
int sig;
|
||||
ignore_signal (int sig)
|
||||
{
|
||||
if (SPECIAL_TRAP (sig) && ((sigmodes[sig] & SIG_IGNORED) == 0))
|
||||
{
|
||||
@@ -982,7 +953,7 @@ ignore_signal (sig)
|
||||
the command to be executed includes an "exit". This is why we have
|
||||
to provide our own place for top_level to jump to. */
|
||||
int
|
||||
run_exit_trap ()
|
||||
run_exit_trap (void)
|
||||
{
|
||||
char *trap_command;
|
||||
int code, function_code, retval;
|
||||
@@ -1045,8 +1016,7 @@ run_exit_trap ()
|
||||
}
|
||||
|
||||
void
|
||||
run_trap_cleanup (sig)
|
||||
int sig;
|
||||
run_trap_cleanup (int sig)
|
||||
{
|
||||
/* XXX - should we clean up trap_list[sig] == IMPOSSIBLE_TRAP_HANDLER? */
|
||||
sigmodes[sig] &= ~(SIG_INPROGRESS|SIG_CHANGED);
|
||||
@@ -1057,9 +1027,7 @@ run_trap_cleanup (sig)
|
||||
/* Run a trap command for SIG. SIG is one of the signals the shell treats
|
||||
specially. Returns the exit status of the executed trap command list. */
|
||||
static int
|
||||
_run_trap_internal (sig, tag)
|
||||
int sig;
|
||||
char *tag;
|
||||
_run_trap_internal (int sig, char *tag)
|
||||
{
|
||||
char *trap_command, *old_trap;
|
||||
int trap_exit_value;
|
||||
@@ -1198,7 +1166,7 @@ _run_trap_internal (sig, tag)
|
||||
}
|
||||
|
||||
int
|
||||
run_debug_trap ()
|
||||
run_debug_trap (void)
|
||||
{
|
||||
int trap_exit_value, old_verbose;
|
||||
pid_t save_pgrp;
|
||||
@@ -1254,14 +1222,14 @@ run_debug_trap ()
|
||||
}
|
||||
|
||||
void
|
||||
run_error_trap ()
|
||||
run_error_trap (void)
|
||||
{
|
||||
if ((sigmodes[ERROR_TRAP] & SIG_TRAPPED) && ((sigmodes[ERROR_TRAP] & SIG_IGNORED) == 0) && (sigmodes[ERROR_TRAP] & SIG_INPROGRESS) == 0)
|
||||
_run_trap_internal (ERROR_TRAP, "error trap");
|
||||
}
|
||||
|
||||
void
|
||||
run_return_trap ()
|
||||
run_return_trap (void)
|
||||
{
|
||||
int old_exit_value;
|
||||
|
||||
@@ -1280,9 +1248,9 @@ run_return_trap ()
|
||||
|
||||
/* Run a trap set on SIGINT. This is called from throw_to_top_level (), and
|
||||
declared here to localize the trap functions. */
|
||||
/* WILL_THROW indicates whether we're run from throw_to_top_level */
|
||||
void
|
||||
run_interrupt_trap (will_throw)
|
||||
int will_throw; /* from throw_to_top_level? */
|
||||
run_interrupt_trap (int will_throw)
|
||||
{
|
||||
if (will_throw && running_trap > 0)
|
||||
run_trap_cleanup (running_trap - 1);
|
||||
@@ -1299,7 +1267,7 @@ run_interrupt_trap (will_throw)
|
||||
reset_or_restore_signal_handlers and not change the disposition of signals
|
||||
that are set to be ignored. */
|
||||
void
|
||||
free_trap_strings ()
|
||||
free_trap_strings (void)
|
||||
{
|
||||
register int i;
|
||||
|
||||
@@ -1322,8 +1290,7 @@ free_trap_strings ()
|
||||
/* Free a trap command string associated with SIG without changing signal
|
||||
disposition. Intended to be called from free_trap_strings() */
|
||||
static void
|
||||
free_trap_string (sig)
|
||||
int sig;
|
||||
free_trap_string (int sig)
|
||||
{
|
||||
change_signal (sig, (char *)DEFAULT_SIG);
|
||||
sigmodes[sig] &= ~SIG_TRAPPED; /* XXX - SIG_INPROGRESS? */
|
||||
@@ -1332,8 +1299,7 @@ free_trap_string (sig)
|
||||
/* Reset the handler for SIG to the original value but leave the trap string
|
||||
in place. */
|
||||
static void
|
||||
reset_signal (sig)
|
||||
int sig;
|
||||
reset_signal (int sig)
|
||||
{
|
||||
set_signal_handler (sig, original_signals[sig]);
|
||||
sigmodes[sig] &= ~SIG_TRAPPED; /* XXX - SIG_INPROGRESS? */
|
||||
@@ -1342,8 +1308,7 @@ reset_signal (sig)
|
||||
/* Set the handler signal SIG to the original and free any trap
|
||||
command associated with it. */
|
||||
static void
|
||||
restore_signal (sig)
|
||||
int sig;
|
||||
restore_signal (int sig)
|
||||
{
|
||||
set_signal_handler (sig, original_signals[sig]);
|
||||
change_signal (sig, (char *)DEFAULT_SIG);
|
||||
@@ -1351,8 +1316,7 @@ restore_signal (sig)
|
||||
}
|
||||
|
||||
static void
|
||||
reset_or_restore_signal_handlers (reset)
|
||||
sh_resetsig_func_t *reset;
|
||||
reset_or_restore_signal_handlers (sh_resetsig_func_t *reset)
|
||||
{
|
||||
register int i;
|
||||
|
||||
@@ -1399,7 +1363,7 @@ reset_or_restore_signal_handlers (reset)
|
||||
trap strings. Called by the command substitution code and other places
|
||||
that create a "subshell environment". */
|
||||
void
|
||||
reset_signal_handlers ()
|
||||
reset_signal_handlers (void)
|
||||
{
|
||||
reset_or_restore_signal_handlers (reset_signal);
|
||||
}
|
||||
@@ -1408,7 +1372,7 @@ reset_signal_handlers ()
|
||||
ignored with trap '' SIGNAL should be ignored, so we make sure that they
|
||||
are. Called by child processes after they are forked. */
|
||||
void
|
||||
restore_original_signals ()
|
||||
restore_original_signals (void)
|
||||
{
|
||||
reset_or_restore_signal_handlers (restore_signal);
|
||||
}
|
||||
@@ -1416,8 +1380,7 @@ restore_original_signals ()
|
||||
/* Change the flags associated with signal SIG without changing the trap
|
||||
string. The string is TRAP_LIST[SIG] if we need it. */
|
||||
static void
|
||||
reinit_trap (sig)
|
||||
int sig;
|
||||
reinit_trap (int sig)
|
||||
{
|
||||
sigmodes[sig] |= SIG_TRAPPED;
|
||||
if (trap_list[sig] == (char *)IGNORE_SIG)
|
||||
@@ -1432,7 +1395,7 @@ reinit_trap (sig)
|
||||
leaves the trap strings in place. This understands how reset_signal_handlers
|
||||
works. */
|
||||
void
|
||||
restore_traps ()
|
||||
restore_traps (void)
|
||||
{
|
||||
char *trapstr;
|
||||
int i;
|
||||
@@ -1487,8 +1450,7 @@ restore_traps ()
|
||||
/* If a trap handler exists for signal SIG, then call it; otherwise just
|
||||
return failure. Returns 1 if it called the trap handler. */
|
||||
int
|
||||
maybe_call_trap_handler (sig)
|
||||
int sig;
|
||||
maybe_call_trap_handler (int sig)
|
||||
{
|
||||
/* Call the trap handler for SIG if the signal is trapped and not ignored. */
|
||||
if ((sigmodes[sig] & SIG_TRAPPED) && ((sigmodes[sig] & SIG_IGNORED) == 0))
|
||||
@@ -1518,67 +1480,57 @@ maybe_call_trap_handler (sig)
|
||||
}
|
||||
|
||||
int
|
||||
signal_is_trapped (sig)
|
||||
int sig;
|
||||
signal_is_trapped (int sig)
|
||||
{
|
||||
return (sigmodes[sig] & SIG_TRAPPED);
|
||||
}
|
||||
|
||||
int
|
||||
signal_is_pending (sig)
|
||||
int sig;
|
||||
signal_is_pending (int sig)
|
||||
{
|
||||
return (pending_traps[sig]);
|
||||
}
|
||||
|
||||
int
|
||||
signal_is_special (sig)
|
||||
int sig;
|
||||
signal_is_special (int sig)
|
||||
{
|
||||
return (sigmodes[sig] & SIG_SPECIAL);
|
||||
}
|
||||
|
||||
int
|
||||
signal_is_ignored (sig)
|
||||
int sig;
|
||||
signal_is_ignored (int sig)
|
||||
{
|
||||
return (sigmodes[sig] & SIG_IGNORED);
|
||||
}
|
||||
|
||||
int
|
||||
signal_is_hard_ignored (sig)
|
||||
int sig;
|
||||
signal_is_hard_ignored (int sig)
|
||||
{
|
||||
return (sigmodes[sig] & SIG_HARD_IGNORE);
|
||||
}
|
||||
|
||||
void
|
||||
set_signal_hard_ignored (sig)
|
||||
int sig;
|
||||
set_signal_hard_ignored (int sig)
|
||||
{
|
||||
sigmodes[sig] |= SIG_HARD_IGNORE;
|
||||
original_signals[sig] = SIG_IGN;
|
||||
}
|
||||
|
||||
void
|
||||
set_signal_ignored (sig)
|
||||
int sig;
|
||||
set_signal_ignored (int sig)
|
||||
{
|
||||
original_signals[sig] = SIG_IGN;
|
||||
}
|
||||
|
||||
int
|
||||
signal_in_progress (sig)
|
||||
int sig;
|
||||
signal_in_progress (int sig)
|
||||
{
|
||||
return (sigmodes[sig] & SIG_INPROGRESS);
|
||||
}
|
||||
|
||||
#if 0 /* unused */
|
||||
int
|
||||
block_trapped_signals (maskp, omaskp)
|
||||
sigset_t *maskp;
|
||||
sigset_t *omaskp;
|
||||
block_trapped_signals (sigset_t *maskp, sigset_t *omaskp)
|
||||
{
|
||||
int i;
|
||||
|
||||
@@ -1590,8 +1542,7 @@ block_trapped_signals (maskp, omaskp)
|
||||
}
|
||||
|
||||
int
|
||||
unblock_trapped_signals (maskp)
|
||||
sigset_t *maskp;
|
||||
unblock_trapped_signals (sigset_t *maskp)
|
||||
{
|
||||
return (sigprocmask (SIG_SETMASK, maskp, 0));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user