commit bash-20150206 snapshot

This commit is contained in:
Chet Ramey
2015-02-09 11:03:36 -05:00
parent f8b90b7bdd
commit de6081912c
21 changed files with 507 additions and 595 deletions
+54
View File
@@ -7945,3 +7945,57 @@ lib/readline/histfile.c
original. Report from Jonathan Hankins <jhankins@homewood.k12.al.us>
- history_do_write: don't attempt to back up non-regular files.
Report from Jonathan Hankins <jhankins@homewood.k12.al.us>
2/2
---
trap.c
- run_interrupt_trap: now takes an argument indicating whether or not
it was called just before a longjmp to top_level; change callers
- run_interrupt_trap: if running a trap and we are being called before
a longjmp to top_level, call run_trap_cleanup on running trap so
a QUIT call while running a DEBUG trap, for instance, doesn't leave
sigmodes[DEBUG_TRAP] including SIG_INPROGRESS. Fixes bug reported
by Chih-Chieh Chou <ccchou@gmail.com>
sig.c
- throw_to_top_level: change call to run_interrupt_trap to pass arg 1
- termsig_handler: change call to run_interrupt_trap
trap.h
- run_interrupt_trap: update extern prototype declaration
2/4
---
lib/readline/histfile.c
- histfile_backup, histfile_restore: new functions to back up and restore
history file to `filename-', following (one level of) symlinks through
so we don't rename the symlink itself. From a suggestion by
Jonathan Hankins <jhankins@homewood.k12.al.us>
assoc.c
- assoc_to_assign: if an index happens to be `@' or `*', make sure it's
double-quoted. Bug report from Greg Wooledge <wooledg@eeg.ccf.org>
2/5
---
lib/readline/bind.c
- rl_bind_key: if we are rebinding a key that is not bound to a
function or a macro, construct a key sequence and pass it to
rl_bind_keyseq. Make sure that '\' when it is used as a key is
changed to "\\" so it can survive rl_translate_keyseq. Fixes
https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=776743
2/8
---
include/posixjmp.h
- _rl_longjmp, sh_longjmp: new defines, expand to siglongjmp or longjmp
depending on autoconf results, used to avoid redefining longjmp,
remove _OPENNT conditional code. Report from Eric Blake
<eblake@redhat.com>
{bashjmp,quit}.h,{execute_cmd,expr,jobs,sig,trap}.c,builtins/{evalstring.c,return.def}
- change calls to longjmp to use sh_longjmp
lib/readline/util.c
- change calls to longjmp to use _rl_longjmp
+2
View File
@@ -439,6 +439,8 @@ assoc_to_assign (hash, quoted)
#if 1
if (sh_contains_shell_metas (tlist->key))
istr = sh_double_quote (tlist->key);
else if (ALL_ELEMENT_SUB (tlist->key[0]) && tlist->key[1] == '\0')
istr = sh_double_quote (tlist->key);
else
istr = tlist->key;
#else
+1 -1
View File
@@ -27,7 +27,7 @@ extern procenv_t top_level;
extern procenv_t subshell_top_level;
extern procenv_t return_catch; /* used by `return' builtin */
#define SHFUNC_RETURN() longjmp (return_catch, 1)
#define SHFUNC_RETURN() sh_longjmp (return_catch, 1)
#define COPY_PROCENV(old, save) \
xbcopy ((char *)old, (char *)save, sizeof (procenv_t));
+2 -2
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.
@@ -644,7 +644,7 @@ evalstring (string, from_file, flags)
if (rcatch && return_catch_flag)
{
return_catch_value = r;
longjmp (return_catch, 1);
sh_longjmp (return_catch, 1);
}
}
+2 -2
View File
@@ -1,7 +1,7 @@
This file is return.def, from which is created return.c.
It implements the builtin "return" in Bash.
Copyright (C) 1987-2009 Free Software Foundation, Inc.
Copyright (C) 1987-2015 Free Software Foundation, Inc.
This file is part of GNU Bash, the Bourne Again SHell.
@@ -65,7 +65,7 @@ return_builtin (list)
return_catch_value = get_exitstat (list);
if (return_catch_flag)
longjmp (return_catch, 1);
sh_longjmp (return_catch, 1);
else
{
builtin_error (_("can only `return' from a function or sourced script"));
+2 -1
View File
@@ -87,7 +87,8 @@ reader_loop ()
unlink_fifo_list ();
#endif /* PROCESS_SUBSTITUTION */
/* XXX - why do we set this every time through the loop? */
/* XXX - why do we set this every time through the loop? And why do
it if SIGINT is trapped in an interactive shell? */
if (interactive_shell && signal_is_ignored (SIGINT) == 0)
set_signal_handler (SIGINT, sigint_sighandler);
+2 -2
View File
@@ -1,6 +1,6 @@
/* execute_cmd.c -- Execute a COMMAND structure. */
/* Copyright (C) 1987-2013 Free Software Foundation, Inc.
/* Copyright (C) 1987-2015 Free Software Foundation, Inc.
This file is part of GNU Bash, the Bourne Again SHell.
@@ -5495,7 +5495,7 @@ shell_execve (command, args, env)
clear_fifo_list (); /* pipe fds are what they are now */
#endif
longjmp (subshell_top_level, 1);
sh_longjmp (subshell_top_level, 1);
/*NOTREACHED*/
}
+3 -3
View File
@@ -1,6 +1,6 @@
/* expr.c -- arithmetic expression evaluation. */
/* Copyright (C) 1990-2013 Free Software Foundation, Inc.
/* Copyright (C) 1990-2015 Free Software Foundation, Inc.
This file is part of GNU Bash, the Bourne Again SHell.
@@ -316,7 +316,7 @@ expr_bind_variable (lhs, rhs)
v = bind_int_variable (lhs, rhs);
if (v && (readonly_p (v) || noassign_p (v)))
longjmp (evalbuf, 1); /* variable assignment error */
sh_longjmp (evalbuf, 1); /* variable assignment error */
stupidly_hack_special_variables (lhs);
}
@@ -1416,7 +1416,7 @@ evalerror (msg)
internal_error (_("%s%s%s: %s (error token is \"%s\")"),
name ? name : "", name ? ": " : "", t,
msg, (lasttp && *lasttp) ? lasttp : "");
longjmp (evalbuf, 1);
sh_longjmp (evalbuf, 1);
}
/* Convert a string to an intmax_t integer, with an arbitrary base.
+12 -8
View File
@@ -27,16 +27,20 @@
#if defined (HAVE_POSIX_SIGSETJMP)
# define procenv_t sigjmp_buf
# if !defined (__OPENNT)
# define setjmp_nosigs(x) sigsetjmp((x), 0)
# define setjmp_sigs(x) sigsetjmp((x), 1)
# undef longjmp
# define longjmp(x, n) siglongjmp((x), (n))
# endif /* !__OPENNT */
# define setjmp_nosigs(x) sigsetjmp((x), 0)
# define setjmp_sigs(x) sigsetjmp((x), 1)
# define _rl_longjmp(x, n) siglongjmp((x), (n))
# define sh_longjmp(x, n) siglongjmp((x), (n))
#else
# define procenv_t jmp_buf
# define setjmp_nosigs setjmp
# define setjmp_sigs setjmp
# define setjmp_nosigs setjmp
# define setjmp_sigs setjmp
# define _rl_longjmp(x, n) longjmp((x), (n))
# define sh_longjmp(x, n) longjmp((x), (n))
#endif
#endif /* _POSIXJMP_H_ */
+3 -3
View File
@@ -3,7 +3,7 @@
/* This file works with both POSIX and BSD systems. It implements job
control. */
/* Copyright (C) 1989-2013 Free Software Foundation, Inc.
/* Copyright (C) 1989-2015 Free Software Foundation, Inc.
This file is part of GNU Bash, the Bourne Again SHell.
@@ -2299,7 +2299,7 @@ wait_sigint_handler (sig)
if (interrupt_immediately)
{
interrupt_immediately = 0;
longjmp (wait_intr_buf, 1);
sh_longjmp (wait_intr_buf, 1);
}
else
/* Let CHECK_WAIT_INTR handle it in wait_for/waitchld */
@@ -3391,7 +3391,7 @@ itrace("waitchld: waitpid returns %d block = %d children_exited = %d", pid, bloc
/* If we're in a signal handler, let CHECK_WAIT_INTR pick it up;
run_pending_traps will call run_sigchld_trap later */
if (sigchld == 0)
longjmp (wait_intr_buf, 1);
sh_longjmp (wait_intr_buf, 1);
}
/* If not in posix mode and not executing the wait builtin, queue the
signal for later handling. Run the trap immediately if we are
+21 -2
View File
@@ -117,6 +117,9 @@ rl_bind_key (key, function)
int key;
rl_command_func_t *function;
{
char keyseq[3];
int l;
if (key < 0)
return (key);
@@ -135,8 +138,24 @@ rl_bind_key (key, function)
return (key);
}
_rl_keymap[key].type = ISFUNC;
_rl_keymap[key].function = function;
/* If it's bound to a function or macro, just overwrite. Otherwise we have
to treat it as a key sequence so rl_generic_bind handles shadow keymaps
for us. If we are binding '\' make sure to escape it so it makes it
through the call to rl_translate_keyseq. */
if (_rl_keymap[key].type != ISKMAP)
{
_rl_keymap[key].type = ISFUNC;
_rl_keymap[key].function = function;
}
else
{
l = 0;
if (key == '\\')
keyseq[l++] = '\\';
keyseq[l++] = key;
keyseq[l] = '\0';
rl_bind_keyseq (keyseq, function);
}
rl_binding_keymap = _rl_keymap;
return (0);
}
+51 -20
View File
@@ -116,6 +116,10 @@ int history_lines_written_to_file = 0;
for more extensive tests. */
#define HIST_TIMESTAMP_START(s) (*(s) == history_comment_char && isdigit ((unsigned char)(s)[1]) )
static char *history_backupfile __P((const char *));
static int histfile_backup __P((const char *, const char *));
static int histfile_restore __P((const char *, const char *));
/* Return the string that should be used in the place of this
filename. This only matters when you don't specify the
filename to read_history (), or write_history (). */
@@ -165,17 +169,14 @@ history_backupfile (filename)
ssize_t n;
struct stat fs;
fn = filename;
#if defined (HAVE_LSTAT)
if (lstat (filename, &fs) == 0 && S_ISLNK (fs.st_mode))
fn = filename;
#if defined (HAVE_READLINK)
/* Follow symlink to avoid backing up symlink itself; call will fail if
not a symlink */
if ((n = readlink (filename, linkbuf, sizeof (linkbuf) - 1)) > 0)
{
if ((n = readlink (filename, linkbuf, sizeof (linkbuf) - 1)) > 0)
{
linkbuf[n] = '\0';
fn = linkbuf;
}
else
fn = filename;
linkbuf[n] = '\0';
fn = linkbuf;
}
#endif
@@ -347,11 +348,41 @@ read_history_range (filename, from, to)
}
static int
backup (fn, back)
const char *fn;
histfile_backup (filename, back)
const char *filename;
const char *back;
{
return (rename (fn, back));
#if defined (HAVE_READLINK)
char linkbuf[PATH_MAX+1];
ssize_t n;
/* Follow to target of symlink to avoid renaming symlink itself */
if ((n = readlink (filename, linkbuf, sizeof (linkbuf) - 1)) > 0)
{
linkbuf[n] = '\0';
return (rename (linkbuf, back));
}
#endif
return (rename (filename, back));
}
static int
histfile_restore (backup, orig)
const char *backup;
const char *orig;
{
#if defined (HAVE_READLINK)
char linkbuf[PATH_MAX+1];
ssize_t n;
/* Follow to target of symlink to avoid renaming symlink itself */
if ((n = readlink (orig, linkbuf, sizeof (linkbuf) - 1)) > 0)
{
linkbuf[n] = '\0';
return (rename (backup, linkbuf));
}
#endif
return (rename (backup, orig));
}
/* Truncate the history file FNAME, leaving only LINES trailing lines.
@@ -470,7 +501,7 @@ history_truncate_file (fname, lines)
if (filename && bakname)
{
/* XXX - need to check case where filename is a symlink */
if (rename (filename, bakname) < 0)
if (histfile_backup (filename, bakname) < 0)
{
free (bakname); /* no backups if rename fails */
bakname = 0;
@@ -499,7 +530,7 @@ history_truncate_file (fname, lines)
history_lines_written_to_file = orig_lines - lines;
if (rv != 0 && filename && bakname)
rename (bakname, filename);
histfile_restore (bakname, filename);
else if (rv == 0 && bakname)
unlink (bakname);
@@ -551,7 +582,7 @@ history_do_write (filename, nelements, overwrite)
if (output && bakname)
{
/* XXX - need to check case where output is a symlink */
if (rename (output, bakname) < 0) /* no backups if rename fails */
if (histfile_backup (output, bakname) < 0) /* no backups if rename fails */
{
free (bakname);
bakname = 0;
@@ -565,7 +596,7 @@ history_do_write (filename, nelements, overwrite)
{
rv = errno;
if (output && bakname)
rename (bakname, output);
histfile_restore (bakname, output);
FREE (output);
FREE (bakname);
return (rv);
@@ -610,7 +641,7 @@ mmap_error:
rv = errno;
close (file);
if (output && bakname)
rename (bakname, output);
histfile_restore (bakname, output);
FREE (output);
FREE (bakname);
return rv;
@@ -622,7 +653,7 @@ mmap_error:
rv = errno;
close (file);
if (output && bakname)
rename (bakname, output);
histfile_restore (bakname, output);
FREE (output);
FREE (bakname);
return rv;
@@ -658,7 +689,7 @@ mmap_error:
rv = errno;
if (rv != 0 && output && bakname)
rename (bakname, output);
histfile_restore (bakname, output);
else if (rv == 0 && bakname)
unlink (bakname);
+2 -5
View File
@@ -111,11 +111,8 @@ _rl_abort_internal ()
RL_UNSETSTATE (RL_STATE_MULTIKEY); /* XXX */
rl_last_func = (rl_command_func_t *)NULL;
#if defined (HAVE_POSIX_SIGSETJMP)
siglongjmp (_rl_top_level, 1);
#else
longjmp (_rl_top_level, 1);
#endif
_rl_longjmp (_rl_top_level, 1);
return (0);
}
BIN
View File
Binary file not shown.
BIN
View File
Binary file not shown.
+329 -527
View File
File diff suppressed because it is too large Load Diff
+2 -2
View File
@@ -41,7 +41,7 @@ extern volatile sig_atomic_t terminating_signal;
#define CHECK_ALRM \
do { \
if (sigalrm_seen) \
longjmp (alrmbuf, 1); \
sh_longjmp (alrmbuf, 1); \
} while (0)
#define SETINTERRUPT interrupt_state = 1
@@ -64,7 +64,7 @@ extern volatile sig_atomic_t terminating_signal;
#define CHECK_WAIT_INTR \
do { \
if (wait_signal_received && this_shell_builtin && (this_shell_builtin == wait_builtin)) \
longjmp (wait_intr_buf, 1); \
sh_longjmp (wait_intr_buf, 1); \
} while (0)
#define RESET_SIGTERM \
+6 -6
View File
@@ -1,6 +1,6 @@
/* sig.c - interface for shell signal handlers and signal initialization. */
/* Copyright (C) 1994-2013 Free Software Foundation, Inc.
/* Copyright (C) 1994-2015 Free Software Foundation, Inc.
This file is part of GNU Bash, the Bourne Again SHell.
@@ -413,15 +413,15 @@ throw_to_top_level ()
(last_command_exit_value - 128) : 0;
last_command_exit_value |= 128;
/* Run any traps set on SIGINT. */
/* Run any traps set on SIGINT, mostly for interactive shells */
if (signal_is_trapped (SIGINT))
run_interrupt_trap ();
run_interrupt_trap (1);
/* Clean up string parser environment. */
while (parse_and_execute_level)
parse_and_execute_cleanup ();
if (running_trap)
if (running_trap > 0)
run_trap_cleanup (running_trap - 1);
#if defined (JOB_CONTROL)
@@ -469,7 +469,7 @@ void
jump_to_top_level (value)
int value;
{
longjmp (top_level, value);
sh_longjmp (top_level, value);
}
sighandler
@@ -563,7 +563,7 @@ termsig_handler (sig)
/* I don't believe this condition ever tests true. */
if (sig == SIGINT && signal_is_trapped (SIGINT))
run_interrupt_trap ();
run_interrupt_trap (0);
#if defined (HISTORY)
/* If we don't do something like this, the history will not be saved when
+1 -1
View File
@@ -101,7 +101,7 @@ extern int errno;
static procenv_t test_exit_buf;
static int test_error_return;
#define test_exit(val) \
do { test_error_return = val; longjmp (test_exit_buf, 1); } while (0)
do { test_error_return = val; sh_longjmp (test_exit_buf, 1); } while (0)
extern int sh_stat __P((const char *, struct stat *));
+11 -9
View File
@@ -1,7 +1,7 @@
/* trap.c -- Not the trap command, but useful functions for manipulating
those objects. The trap command is in builtins/trap.def. */
/* Copyright (C) 1987-2013 Free Software Foundation, Inc.
/* Copyright (C) 1987-2015 Free Software Foundation, Inc.
This file is part of GNU Bash, the Bourne Again SHell.
@@ -325,7 +325,7 @@ run_pending_traps ()
if (sig == SIGINT)
{
pending_traps[sig] = 0; /* XXX */
run_interrupt_trap ();
run_interrupt_trap (0);
CLRINTERRUPT;
}
#if defined (JOB_CONTROL) && defined (SIGCHLD)
@@ -442,14 +442,13 @@ trap_handler (sig)
catch_flag = 1;
pending_traps[sig]++;
trapped_signal_received = sig;
if (this_shell_builtin && (this_shell_builtin == wait_builtin))
{
wait_signal_received = sig;
if (interrupt_immediately)
longjmp (wait_intr_buf, 1);
sh_longjmp (wait_intr_buf, 1);
}
#if defined (READLINE)
@@ -964,8 +963,8 @@ _run_trap_internal (sig, tag)
restore_pipestatus_array (ps);
#endif
running_trap = 0;
sigmodes[sig] &= ~SIG_INPROGRESS;
running_trap = 0;
interrupt_state = old_int;
if (sigmodes[sig] & SIG_CHANGED)
@@ -990,7 +989,7 @@ _run_trap_internal (sig, tag)
#if 0
from_return_trap = sig == RETURN_TRAP;
#endif
longjmp (return_catch, 1);
sh_longjmp (return_catch, 1);
}
}
}
@@ -1039,7 +1038,7 @@ run_debug_trap ()
if (debugging_mode && trap_exit_value == 2 && return_catch_flag)
{
return_catch_value = trap_exit_value;
longjmp (return_catch, 1);
sh_longjmp (return_catch, 1);
}
#endif
}
@@ -1074,8 +1073,11 @@ 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. */
void
run_interrupt_trap ()
run_interrupt_trap (will_throw)
int will_throw; /* from throw_to_top_level? */
{
if (will_throw && running_trap > 0)
run_trap_cleanup (running_trap - 1);
_run_trap_internal (SIGINT, "interrupt trap");
}
@@ -1204,7 +1206,7 @@ maybe_call_trap_handler (sig)
switch (sig)
{
case SIGINT:
run_interrupt_trap ();
run_interrupt_trap (0);
break;
case EXIT_TRAP:
run_exit_trap ();
+1 -1
View File
@@ -95,7 +95,7 @@ extern void get_all_original_signals __P((void));
extern char *signal_name __P((int));
extern int decode_signal __P((char *, int));
extern void run_interrupt_trap __P((void));
extern void run_interrupt_trap __P((int));
extern int maybe_call_trap_handler __P((int));
extern int signal_is_special __P((int));
extern int signal_is_trapped __P((int));