summaryrefslogtreecommitdiff
path: root/shell.c
diff options
context:
space:
mode:
authorStephen Hemminger <stephen.hemminger@vyatta.com>2010-10-11 14:49:26 -0700
committerStephen Hemminger <stephen.hemminger@vyatta.com>2010-10-11 15:19:40 -0700
commit011c1d1c0766c65517ebd495465c99e86edb63ec (patch)
tree30d8f6a13235af90897c3223554871ef52225462 /shell.c
parent40cfaccf7b178b6239b5cd0013ef80b7ff8e503e (diff)
downloadvyatta-bash-011c1d1c0766c65517ebd495465c99e86edb63ec.tar.gz
vyatta-bash-011c1d1c0766c65517ebd495465c99e86edb63ec.zip
Update to bash-4.1
Diffstat (limited to 'shell.c')
-rw-r--r--shell.c117
1 files changed, 88 insertions, 29 deletions
diff --git a/shell.c b/shell.c
index 09b3cfd..4dd0cb7 100644
--- a/shell.c
+++ b/shell.c
@@ -1,23 +1,24 @@
/* shell.c -- GNU's idea of the POSIX shell specification. */
-/* Copyright (C) 1987-2005 Free Software Foundation, Inc.
+/* Copyright (C) 1987-2009 Free Software Foundation, Inc.
This file is part of GNU Bash, the Bourne Again SHell.
- Bash is free software; you can redistribute it and/or modify it
- under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 2, or (at your option)
- any later version.
+ Bash is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
- Bash is distributed in the hope that it will be useful, but WITHOUT
- ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
- License for more details.
+ Bash is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
You should have received a copy of the GNU General Public License
- along with Bash; see the file COPYING. If not, write to the Free
- Software Foundation, 59 Temple Place, Suite 330, Boston, MA 02111 USA.
+ along with Bash. If not, see <http://www.gnu.org/licenses/>.
+*/
+/*
Birthdate:
Sunday, January 10th, 1988.
Initial author: Brian Fox
@@ -71,6 +72,10 @@
# include <readline/history.h>
#endif
+#if defined (READLINE)
+# include "bashline.h"
+#endif
+
#include <tilde/tilde.h>
#include <glob/strmatch.h>
@@ -139,6 +144,12 @@ int interactive_shell = 0;
shell exits. */
int hup_on_exit = 0;
+/* Non-zero means to list status of running and stopped jobs at shell exit */
+int check_jobs_at_exit = 0;
+
+/* Non-zero means to change to a directory name supplied as a command name */
+int autocd = 0;
+
/* Tells what state the shell was in when it started:
0 = non-interactive shell script
1 = interactive
@@ -172,6 +183,13 @@ time_t shell_start_time;
/* Are we running in an emacs shell window? */
int running_under_emacs;
+/* Do we have /dev/fd? */
+#ifdef HAVE_DEV_FD
+int have_devfd = HAVE_DEV_FD;
+#else
+int have_devfd = 0;
+#endif
+
/* The name of the .(shell)rc file. */
static char *bashrc_file = "~/.bashrc";
@@ -212,8 +230,8 @@ int posixly_correct = 0; /* Non-zero means posix.2 superset. */
/* Some long-winded argument names. These are obviously new. */
#define Int 1
#define Charp 2
-struct {
- char *name;
+static const struct {
+ const char *name;
int type;
int *int_value;
char **char_value;
@@ -238,7 +256,9 @@ struct {
#endif
{ "verbose", Int, &echo_input_at_read, (char **)0x0 },
{ "version", Int, &do_version, (char **)0x0 },
+#if defined (WORDEXP_OPTION)
{ "wordexp", Int, &wordexp_only, (char **)0x0 },
+#endif
{ (char *)0x0, Int, (int *)0x0, (char **)0x0 }
};
@@ -286,12 +306,15 @@ 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 *));
+#if defined (WORDEXP_OPTION)
static int run_wordexp __P((char *));
+#endif
static int uidget __P((void));
static void init_interactive __P((void));
static void init_noninteractive __P((void));
+static void init_interactive_script __P((void));
static void set_shell_name __P((char *));
static void shell_initialize __P((void));
@@ -355,6 +378,8 @@ main (argc, argv, env)
if (code)
exit (2);
+ xtrace_init ();
+
#if defined (USING_BASH_MALLOC) && defined (DEBUG) && !defined (DISABLE_MALLOC_WRAPPERS)
# if 1
malloc_set_register (1);
@@ -452,7 +477,7 @@ main (argc, argv, env)
login_shell = -login_shell;
}
- set_login_shell (login_shell != 0);
+ set_login_shell ("login_shell", login_shell != 0);
if (dump_po_strings)
dump_translatable_strings = 1;
@@ -535,19 +560,26 @@ main (argc, argv, env)
set_default_lang ();
set_default_locale_vars ();
+ /*
+ * M-x term -> TERM=eterm EMACS=22.1 (term:0.96) (eterm)
+ * M-x shell -> TERM=dumb EMACS=t (no line editing)
+ * M-x terminal -> TERM=emacs-em7955 EMACS= (line editing)
+ */
if (interactive_shell)
{
char *term, *emacs;
term = get_string_value ("TERM");
- no_line_editing |= term && (STREQ (term, "emacs"));
emacs = get_string_value ("EMACS");
- running_under_emacs = emacs ? ((strstr (emacs, "term") != 0) ? 2 : 1) : 0;
-#if 0
- no_line_editing |= emacs && emacs[0] == 't' && emacs[1] == '\0';
-#else
+
+ /* Not sure any emacs terminal emulator sets TERM=emacs any more */
+ no_line_editing |= term && (STREQ (term, "emacs"));
no_line_editing |= emacs && emacs[0] == 't' && emacs[1] == '\0' && STREQ (term, "dumb");
-#endif
+
+ /* running_under_emacs == 2 for `eterm' */
+ running_under_emacs = (emacs != 0) || (term && STREQN (term, "emacs", 5));
+ running_under_emacs += term && STREQN (term, "eterm", 5) && emacs && strstr (emacs, "term");
+
if (running_under_emacs)
gnu_error_format = 1;
}
@@ -634,12 +666,14 @@ main (argc, argv, env)
maybe_make_restricted (shell_name);
#endif /* RESTRICTED_SHELL */
+#if defined (WORDEXP_OPTION)
if (wordexp_only)
{
startup_state = 3;
last_command_exit_value = run_wordexp (argv[arg_index]);
exit_shell (last_command_exit_value);
}
+#endif
if (command_execution_string)
{
@@ -687,8 +721,8 @@ main (argc, argv, env)
if (interactive_shell)
{
/* Set up for checking for presence of mail. */
- remember_mail_dates ();
reset_mail_timer ();
+ init_mail_dates ();
#if defined (HISTORY)
/* Initialize the interactive history stuff. */
@@ -868,6 +902,9 @@ void
exit_shell (s)
int s;
{
+ fflush (stdout); /* XXX */
+ fflush (stderr);
+
/* Do trap[0] if defined. Allow it to override the exit status
passed to us. */
if (signal_is_trapped (0))
@@ -882,6 +919,10 @@ exit_shell (s)
maybe_save_shell_history ();
#endif /* HISTORY */
+#if defined (COPROCESS_SUPPORT)
+ coproc_flush ();
+#endif
+
#if defined (JOB_CONTROL)
/* If the user has run `shopt -s huponexit', hangup all jobs when we exit
an interactive login shell. ksh does this unconditionally. */
@@ -1169,6 +1210,7 @@ disable_priv_mode ()
current_user.egid = current_user.gid;
}
+#if defined (WORDEXP_OPTION)
static int
run_wordexp (words)
char *words;
@@ -1240,6 +1282,7 @@ run_wordexp (words)
return (0);
}
+#endif
#if defined (ONESHOT)
/* Run one command, given as the argument to the -c option. Tell
@@ -1418,7 +1461,7 @@ open_shell_script (script_name)
}
else if (sample_len > 0 && (check_binary_file (sample, sample_len)))
{
- internal_error ("%s: cannot execute binary file", filename);
+ internal_error (_("%s: cannot execute binary file"), filename);
exit (EX_BINARY_FILE);
}
/* Now rewind the file back to the beginning. */
@@ -1428,7 +1471,7 @@ open_shell_script (script_name)
/* Open the script. But try to move the file descriptor to a randomly
large one, in the hopes that any descriptors used by the script will
not match with ours. */
- fd = move_to_high_fd (fd, 0, -1);
+ fd = move_to_high_fd (fd, 1, -1);
#if defined (__CYGWIN__) && defined (O_TEXT)
setmode (fd, O_TEXT);
@@ -1469,7 +1512,7 @@ open_shell_script (script_name)
/* But if a script is called with something like `bash -i scriptname',
we need to do a non-interactive setup here, since we didn't do it
before. */
- init_noninteractive ();
+ init_interactive_script ();
free (filename);
return (fd);
@@ -1513,6 +1556,7 @@ unset_bash_input (check_zero)
{
close_buffered_fd (default_buffered_input);
default_buffered_input = bash_input.location.buffered_fd = -1;
+ bash_input.type = st_none; /* XXX */
}
#else /* !BUFFERED_INPUT */
if (default_input)
@@ -1562,8 +1606,8 @@ set_shell_name (argv0)
static void
init_interactive ()
{
- interactive_shell = startup_state = interactive = 1;
- expand_aliases = 1;
+ expand_aliases = interactive_shell = startup_state = 1;
+ interactive = 1;
}
static void
@@ -1580,6 +1624,13 @@ init_noninteractive ()
#endif /* JOB_CONTROL */
}
+static void
+init_interactive_script ()
+{
+ init_noninteractive ();
+ expand_aliases = interactive_shell = startup_state = 1;
+}
+
void
get_current_user_info ()
{
@@ -1674,8 +1725,10 @@ shell_initialize ()
privileged or restricted mode or if the shell is running setuid. */
#if defined (RESTRICTED_SHELL)
initialize_shell_options (privileged_mode||restricted||running_setuid);
+ initialize_bashopts (privileged_mode||restricted||running_setuid);
#else
initialize_shell_options (privileged_mode||running_setuid);
+ initialize_bashopts (privileged_mode||running_setuid);
#endif
}
@@ -1721,6 +1774,12 @@ shell_reinitialize ()
delete_all_contexts (shell_variables);
delete_all_variables (shell_functions);
+ reinit_special_variables ();
+
+#if defined (READLINE)
+ bashline_reinitialize ();
+#endif
+
shell_reinitialized = 1;
}
@@ -1733,7 +1792,7 @@ show_shell_usage (fp, extra)
char *set_opts, *s, *t;
if (extra)
- fprintf (fp, "GNU bash, version %s-(%s)\n", shell_version_string (), MACHTYPE);
+ fprintf (fp, _("GNU bash, version %s-(%s)\n"), shell_version_string (), MACHTYPE);
fprintf (fp, _("Usage:\t%s [GNU long option] [option] ...\n\t%s [GNU long option] [option] script-file ...\n"),
shell_name, shell_name);
fputs (_("GNU long options:\n"), fp);
@@ -1748,12 +1807,12 @@ show_shell_usage (fp, extra)
set_opts = savestring (shell_builtins[i].short_doc);
if (set_opts)
{
- s = xstrchr (set_opts, '[');
+ s = strchr (set_opts, '[');
if (s == 0)
s = set_opts;
while (*++s == '-')
;
- t = xstrchr (s, ']');
+ t = strchr (s, ']');
if (t)
*t = '\0';
fprintf (fp, _("\t-%s or -o option\n"), s);