bash-5.1 distribution sources and documentation

This commit is contained in:
Chet Ramey
2020-12-06 15:51:17 -05:00
parent 36f2c406ff
commit 8868edaf22
828 changed files with 94641 additions and 56509 deletions
+83 -28
View File
@@ -1,6 +1,6 @@
/* shell.c -- GNU's idea of the POSIX shell specification. */
/* Copyright (C) 1987-2017 Free Software Foundation, Inc.
/* Copyright (C) 1987-2019 Free Software Foundation, Inc.
This file is part of GNU Bash, the Bourne Again SHell.
@@ -62,8 +62,8 @@
#include "jobs.h"
#else
extern int running_in_background;
extern int initialize_job_control __P((int));
extern int get_tty_state __P((void));
extern int initialize_job_control PARAMS((int));
extern int get_tty_state PARAMS((void));
#endif /* JOB_CONTROL */
#include "input.h"
@@ -179,6 +179,7 @@ char *shell_name = (char *)NULL;
/* time in seconds when the shell was started */
time_t shell_start_time;
struct timeval shellstart;
/* Are we running in an emacs shell window? */
int running_under_emacs;
@@ -303,35 +304,38 @@ static FILE *default_input;
static STRING_INT_ALIST *shopt_alist;
static int shopt_ind = 0, shopt_len = 0;
static int parse_long_options __P((char **, int, int));
static int parse_shell_options __P((char **, int, int));
static int bind_args __P((char **, int, int, int));
static int parse_long_options PARAMS((char **, int, int));
static int parse_shell_options PARAMS((char **, int, int));
static int bind_args PARAMS((char **, int, int, int));
static void start_debugger __P((void));
static void start_debugger PARAMS((void));
static void add_shopt_to_alist __P((char *, int));
static void run_shopt_alist __P((void));
static void add_shopt_to_alist PARAMS((char *, int));
static void run_shopt_alist PARAMS((void));
static void execute_env_file __P((char *));
static void run_startup_files __P((void));
static int open_shell_script __P((char *));
static void set_bash_input __P((void));
static int run_one_command __P((char *));
static void execute_env_file PARAMS((char *));
static void run_startup_files PARAMS((void));
static int open_shell_script PARAMS((char *));
static void set_bash_input PARAMS((void));
static int run_one_command PARAMS((char *));
#if defined (WORDEXP_OPTION)
static int run_wordexp __P((char *));
static int run_wordexp PARAMS((char *));
#endif
static int uidget __P((void));
static int uidget PARAMS((void));
static void init_interactive __P((void));
static void init_noninteractive __P((void));
static void init_interactive_script __P((void));
static void set_option_defaults PARAMS((void));
static void reset_option_defaults PARAMS((void));
static void set_shell_name __P((char *));
static void shell_initialize __P((void));
static void shell_reinitialize __P((void));
static void init_interactive PARAMS((void));
static void init_noninteractive PARAMS((void));
static void init_interactive_script PARAMS((void));
static void show_shell_usage __P((FILE *, int));
static void set_shell_name PARAMS((char *));
static void shell_initialize PARAMS((void));
static void shell_reinitialize PARAMS((void));
static void show_shell_usage PARAMS((FILE *, int));
#ifdef __CYGWIN__
static void
@@ -455,7 +459,9 @@ main (argc, argv, env)
shell_environment = env;
set_shell_name (argv[0]);
shell_start_time = NOW; /* NOW now defined in general.h */
gettimeofday (&shellstart, 0);
shell_start_time = shellstart.tv_sec;
/* Parse argument flags from the input line. */
@@ -907,7 +913,9 @@ parse_shell_options (argv, arg_start, arg_end)
o_option = argv[next_arg];
if (o_option == 0)
{
set_option_defaults ();
list_minus_o_opts (-1, (on_or_off == '-') ? 0 : 1);
reset_option_defaults ();
break;
}
if (set_minus_o_option (on_or_off, o_option) != EXECUTION_SUCCESS)
@@ -973,7 +981,7 @@ exit_shell (s)
s = run_exit_trap ();
#if defined (PROCESS_SUBSTITUTION)
unlink_fifo_list ();
unlink_all_fifos ();
#endif /* PROCESS_SUBSTITUTION */
#if defined (HISTORY)
@@ -1038,6 +1046,13 @@ subshell_exit (s)
sh_exit (s);
}
void
set_exit_status (s)
int s;
{
set_pipestatus_from_exit (last_command_exit_value = s);
}
/* Source the bash startup files. If POSIXLY_CORRECT is non-zero, we obey
the Posix.2 startup file rules: $ENV is expanded, and if the file it
names exists, that file is sourced. The Posix.2 rules are in effect
@@ -1257,6 +1272,7 @@ maybe_make_restricted (name)
set_var_read_only ("SHELL");
set_var_read_only ("ENV");
set_var_read_only ("BASH_ENV");
set_var_read_only ("HISTFILE");
restricted = 1;
}
return (restricted);
@@ -1293,7 +1309,11 @@ disable_priv_mode ()
{
int e;
#if HAVE_SETRESUID
if (setresuid (current_user.uid, current_user.uid, current_user.uid) < 0)
#else
if (setuid (current_user.uid) < 0)
#endif
{
e = errno;
sys_error (_("cannot set uid to %d: effective uid %d"), current_user.uid, current_user.euid);
@@ -1302,7 +1322,11 @@ disable_priv_mode ()
exit (e);
#endif
}
#if HAVE_SETRESGID
if (setresgid (current_user.gid, current_user.gid, current_user.gid) < 0)
#else
if (setgid (current_user.gid) < 0)
#endif
sys_error (_("cannot set gid to %d: effective gid %d"), current_user.gid, current_user.egid);
current_user.euid = current_user.uid;
@@ -1413,7 +1437,7 @@ run_one_command (command)
command_error ("run_one_command", CMDERR_BADJUMP, code, 0);
}
}
return (parse_and_execute (savestring (command), "-c", SEVAL_NOHIST));
return (parse_and_execute (savestring (command), "-c", SEVAL_NOHIST|SEVAL_RESETLINE));
}
#endif /* ONESHOT */
@@ -1763,14 +1787,39 @@ set_shell_name (argv0)
shell_name = PROGRAM;
}
/* Some options are initialized to -1 so we have a way to determine whether
they were set on the command line. This is an issue when listing the option
values at invocation (`bash -o'), so we set the defaults here and reset
them after the call to list_minus_o_options (). */
/* XXX - could also do this for histexp_flag, jobs_m_flag */
static void
set_option_defaults ()
{
#if defined (HISTORY)
enable_history_list = 0;
#endif
}
static void
reset_option_defaults ()
{
#if defined (HISTORY)
enable_history_list = -1;
#endif
}
static void
init_interactive ()
{
expand_aliases = interactive_shell = startup_state = 1;
interactive = 1;
#if defined (HISTORY)
remember_on_history = enable_history_list = 1; /* XXX */
if (enable_history_list == -1)
enable_history_list = 1; /* set default */
remember_on_history = enable_history_list;
# if defined (BANG_HISTORY)
histexp_flag = history_expansion; /* XXX */
# endif
#endif
}
@@ -1778,6 +1827,8 @@ static void
init_noninteractive ()
{
#if defined (HISTORY)
if (enable_history_list == -1) /* set default */
enable_history_list = 0;
bash_history_reinit (0);
#endif /* HISTORY */
interactive_shell = startup_state = interactive = 0;
@@ -1793,10 +1844,14 @@ init_noninteractive ()
static void
init_interactive_script ()
{
#if defined (HISTORY)
if (enable_history_list == -1)
enable_history_list = 1;
#endif
init_noninteractive ();
expand_aliases = interactive_shell = startup_state = 1;
#if defined (HISTORY)
remember_on_history = enable_history_list = 1; /* XXX */
remember_on_history = enable_history_list; /* XXX */
#endif
}