Bash-4.4 distribution sources and documentation

This commit is contained in:
Chet Ramey 2016-09-15 16:59:08 -04:00
commit a0c0a00fc4
588 changed files with 130746 additions and 80164 deletions

View file

@ -1,6 +1,6 @@
/* evalstring.c - evaluate a string as one or more shell commands. */
/* Copyright (C) 1996-2012 Free Software Foundation, Inc.
/* Copyright (C) 1996-2015 Free Software Foundation, Inc.
This file is part of GNU Bash, the Bourne Again SHell.
@ -96,6 +96,38 @@ restore_lastcom (x)
the_printed_command_except_trap = x;
}
int
should_suppress_fork (command)
COMMAND *command;
{
return (startup_state == 2 && parse_and_execute_level == 1 &&
running_trap == 0 &&
*bash_input.location.string == '\0' &&
command->type == cm_simple &&
#if 0
signal_is_trapped (EXIT_TRAP) == 0 &&
signal_is_trapped (ERROR_TRAP) == 0 &&
#else
any_signals_trapped () < 0 &&
#endif
command->redirects == 0 && command->value.Simple->redirects == 0 &&
((command->flags & CMD_TIME_PIPELINE) == 0) &&
((command->flags & CMD_INVERT_RETURN) == 0));
}
void
optimize_fork (command)
COMMAND *command;
{
if (command->type == cm_connection &&
(command->value.Connection->connector == AND_AND || command->value.Connection->connector == OR_OR) &&
should_suppress_fork (command->value.Connection->second))
{
command->value.Connection->second->flags |= CMD_NO_FORK;
command->value.Connection->second->value.Simple->flags |= CMD_NO_FORK;
}
}
/* How to force parse_and_execute () to clean up after itself. */
void
parse_and_execute_cleanup ()
@ -141,8 +173,7 @@ parse_prologue (string, flags, tag)
else
unwind_protect_int (remember_on_history); /* can be used in scripts */
# if defined (BANG_HISTORY)
if (interactive_shell)
unwind_protect_int (history_expansion_inhibited);
unwind_protect_int (history_expansion_inhibited);
# endif /* BANG_HISTORY */
#endif /* HISTORY */
@ -172,6 +203,10 @@ parse_prologue (string, flags, tag)
#if defined (HISTORY)
if (flags & SEVAL_NOHIST)
bash_history_disable ();
# if defined (BANG_HISTORY)
if (flags & SEVAL_NOHISTEXP)
history_expansion_inhibited = 1;
# endif /* BANG_HISTORY */
#endif /* HISTORY */
}
@ -184,6 +219,7 @@ parse_prologue (string, flags, tag)
(flags & SEVAL_NOHIST) -> call bash_history_disable ()
(flags & SEVAL_NOFREE) -> don't free STRING when finished
(flags & SEVAL_RESETLINE) -> reset line_number to 1
(flags & SEVAL_NOHISTEXP) -> history_expansion_inhibited -> 1
*/
int
@ -205,8 +241,8 @@ parse_and_execute (string, from_file, flags)
#if defined (HAVE_POSIX_SIGNALS)
/* If we longjmp and are going to go on, use this to restore signal mask */
sigemptyset (&pe_sigmask);
sigprocmask (SIG_BLOCK, (sigset_t *)NULL, &pe_sigmask);
sigemptyset ((sigset_t *)&pe_sigmask);
sigprocmask (SIG_BLOCK, (sigset_t *)NULL, (sigset_t *)&pe_sigmask);
#endif
/* Reset the line number if the caller wants us to. If we don't reset the
@ -226,7 +262,12 @@ parse_and_execute (string, from_file, flags)
code = should_jump_to_top_level = 0;
last_result = EXECUTION_SUCCESS;
/* We need to reset enough of the token state so we can start fresh. */
if (current_token == yacc_EOF)
current_token = '\n'; /* reset_parser() ? */
with_input_from_string (string, from_file);
clear_shell_input_line ();
while (*(bash_input.location.string))
{
command = (COMMAND *)NULL;
@ -285,7 +326,7 @@ parse_and_execute (string, from_file, flags)
dispose_command (command); /* pe_dispose does this */
#endif
#if defined (HAVE_POSIX_SIGNALS)
sigprocmask (SIG_SETMASK, &pe_sigmask, (sigset_t *)NULL);
sigprocmask (SIG_SETMASK, (sigset_t *)&pe_sigmask, (sigset_t *)NULL);
#endif
continue;
}
@ -349,22 +390,18 @@ parse_and_execute (string, from_file, flags)
* we're not going to run the exit trap AND
* we have a simple command without redirections AND
* the command is not being timed AND
* the command's return status is not being inverted
* the command's return status is not being inverted AND
* there aren't any traps in effect
* THEN
* tell the execution code that we don't need to fork
*/
if (startup_state == 2 && parse_and_execute_level == 1 &&
running_trap == 0 &&
*bash_input.location.string == '\0' &&
command->type == cm_simple &&
signal_is_trapped (EXIT_TRAP) == 0 &&
command->redirects == 0 && command->value.Simple->redirects == 0 &&
((command->flags & CMD_TIME_PIPELINE) == 0) &&
((command->flags & CMD_INVERT_RETURN) == 0))
if (should_suppress_fork (command))
{
command->flags |= CMD_NO_FORK;
command->value.Simple->flags |= CMD_NO_FORK;
}
else if (command->type == cm_connection)
optimize_fork (command);
#endif /* ONESHOT */
/* See if this is a candidate for $( <file ). */
@ -457,11 +494,11 @@ parse_string (string, from_file, flags, endp)
#if defined (HAVE_POSIX_SIGNALS)
/* If we longjmp and are going to go on, use this to restore signal mask */
sigemptyset (&ps_sigmask);
sigprocmask (SIG_BLOCK, (sigset_t *)NULL, &ps_sigmask);
sigemptyset ((sigset_t *)&ps_sigmask);
sigprocmask (SIG_BLOCK, (sigset_t *)NULL, (sigset_t *)&ps_sigmask);
#endif
/* itrace("parse_string: `%s'", string); */
/*itrace("parse_string: `%s'", string);*/
/* Reset the line number if the caller wants us to. If we don't reset the
line number, we have to subtract one, because we will add one just
before executing the next command (resetting the line number sets it to
@ -510,7 +547,7 @@ itrace("parse_string: longjmp executed: code = %d", code);
default:
#if defined (HAVE_POSIX_SIGNALS)
sigprocmask (SIG_SETMASK, &ps_sigmask, (sigset_t *)NULL);
sigprocmask (SIG_SETMASK, (sigset_t *)&ps_sigmask, (sigset_t *)NULL);
#endif
command_error ("parse_string", CMDERR_BADJUMP, code, 0);
break;
@ -547,8 +584,16 @@ itrace("parse_string: longjmp executed: code = %d", code);
run_unwind_frame (PS_TAG);
/* If we return < 0, the caller (xparse_dolparen) will jump_to_top_level for
us, after doing cleanup */
if (should_jump_to_top_level)
jump_to_top_level (code);
{
if (parse_and_execute_level == 0)
top_level_cleanup ();
if (code == DISCARD)
return -DISCARD;
jump_to_top_level (code);
}
return (nc);
}
@ -634,7 +679,7 @@ evalstring (string, from_file, flags)
if (rcatch && return_catch_flag)
{
return_catch_value = r;
longjmp (return_catch, 1);
sh_longjmp (return_catch, 1);
}
}