mirror of
https://https.git.savannah.gnu.org/git/bash.git
synced 2026-07-13 07:00:49 +02:00
commit bash-20150206 snapshot
This commit is contained in:
+21
-2
@@ -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
@@ -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
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user