]> git.ipfire.org Git - thirdparty/bash.git/blobdiff - bashhist.c
Bash-5.0 patch 1: fix pathname expansion of directory names containing backslashes
[thirdparty/bash.git] / bashhist.c
index 809026687c686a9a741fe4a1734d63ff0e60b32d..7912cce311871da3766979ffe60178a4d03ce06d 100644 (file)
@@ -1,22 +1,22 @@
 /* bashhist.c -- bash interface to the GNU history library. */
 
-/* Copyright (C) 1993 Free Software Foundation, Inc.
+/* Copyright (C) 1993-2015 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. */
+   You should have received a copy of the GNU General Public License
+   along with Bash.  If not, see <http://www.gnu.org/licenses/>.
+*/
 
 #include "config.h"
 
@@ -24,7 +24,7 @@
 
 #if defined (HAVE_UNISTD_H)
 #  ifdef _MINIX
-#    include <sys/types.h>
+ #    include <sys/types.h>
 #  endif
 #  include <unistd.h>
 #endif
 #include "posixstat.h"
 #include "filecntl.h"
 
+#include "bashintl.h"
+
+#if defined (SYSLOG_HISTORY)
+#  include <syslog.h>
+#endif
+
 #include "shell.h"
 #include "flags.h"
+#include "parser.h"
 #include "input.h"
 #include "parser.h"    /* for the struct dstack stuff. */
 #include "pathexp.h"   /* for the struct ignorevar stuff */
 
 #if defined (READLINE)
 #  include "bashline.h"
+extern int rl_done, rl_dispatching;    /* should really include readline.h */
+#endif
+
+#ifndef HISTSIZE_DEFAULT
+#  define HISTSIZE_DEFAULT "500"
 #endif
 
 #if !defined (errno)
@@ -58,6 +70,7 @@ extern int errno;
 
 static int histignore_item_func __P((struct ign *));
 static int check_history_control __P((char *));
+static void hc_erasedups __P((char *));
 static void really_add_history __P((char *));
 
 static struct ignorevar histignore =
@@ -75,9 +88,13 @@ static struct ignorevar histignore =
 /* Non-zero means to remember lines typed to the shell on the history
    list.  This is different than the user-controlled behaviour; this
    becomes zero when we read lines from a file, for example. */
-int remember_on_history = 1;
+int remember_on_history = 0;
+int enable_history_list = 0;   /* value for `set -o history' */
 
-/* The number of lines that Bash has added to this history session. */
+/* The number of lines that Bash has added to this history session.  The
+   difference between the number of the top element in the history list
+   (offset from history_base) and the number of lines in the history file.
+   Appending this session's history to the history file resets this to 0. */
 int history_lines_this_session;
 
 /* The number of lines that Bash has read from the history file. */
@@ -87,6 +104,8 @@ int history_lines_in_file;
 /* Non-zero means do no history expansion on this line, regardless
    of what history_expansion says. */
 int history_expansion_inhibited;
+/* If non-zero, double quotes can quote the history expansion character. */
+int double_quotes_inhibit_history_expansion = 0;
 #endif
 
 /* With the old default, every line was saved in the history individually.
@@ -126,6 +145,11 @@ int command_oriented_history = 1;
    the history-manipluating builtins can see it. */
 int current_command_first_line_saved = 0;
 
+/* Set to the number of the most recent line of a possibly-multi-line command
+   that contains a shell comment.  Used by bash_add_history() to determine
+   whether to add a newline or a semicolon. */
+int current_command_line_comment = 0;
+
 /* Non-zero means to store newlines in the history list when using
    command_oriented_history rather than trying to use semicolons. */
 int literal_history;
@@ -134,10 +158,14 @@ int literal_history;
    exit, even if the history has been stifled. */
 int force_append_history;
 
-/* A nit for picking at history saving.
-   Value of 0 means save all lines parsed by the shell on the history.
-   Value of 1 means save all lines that do not start with a space.
-   Value of 2 means save all lines that do not match the last line saved. */
+/* A nit for picking at history saving.  Flags have the following values:
+
+   Value == 0 means save all lines parsed by the shell on the history.
+   Value & HC_IGNSPACE means save all lines that do not start with a space.
+   Value & HC_IGNDUPS means save all lines that do not match the last
+   line saved.
+   Value & HC_ERASEDUPS means to remove all other matching lines from the
+   history list before saving the latest line. */
 int history_control;
 
 /* Set to 1 if the last command was added to the history list successfully
@@ -145,6 +173,10 @@ int history_control;
    to a previous entry as part of command-oriented-history processing. */
 int hist_last_line_added;
 
+/* Set to 1 if builtins/history.def:push_history added the last history
+   entry. */
+int hist_last_line_pushed;
+
 #if defined (READLINE)
 /* If non-zero, and readline is being used, the user is offered the
    chance to re-edit a failed history expansion. */
@@ -160,12 +192,9 @@ int hist_verify;
 /* Non-zero means to not save function definitions in the history list. */
 int dont_save_function_defs;
 
-/* Variables declared in other files used here. */
-extern int current_command_line_count;
-
-extern struct dstack dstack;
-
+#if defined (BANG_HISTORY)
 static int bash_history_inhibit_expansion __P((char *, int));
+#endif
 #if defined (READLINE)
 static void re_edit __P((char *));
 #endif
@@ -176,6 +205,7 @@ static HIST_ENTRY *last_history_entry __P((void));
 static char *expand_histignore_pattern __P((char *));
 static int history_should_ignore __P((char *));
 
+#if defined (BANG_HISTORY)
 /* Is the history expansion starting at string[i] one that should not
    be expanded? */
 static int
@@ -183,6 +213,12 @@ bash_history_inhibit_expansion (string, i)
      char *string;
      int i;
 {
+  int t, si;
+  char hx[2];
+
+  hx[0] = history_expansion_char;
+  hx[1] = '\0';
+
   /* The shell uses ! as a pattern negation character in globbing [...]
      expressions, so let those pass without expansion. */
   if (i > 0 && (string[i - 1] == '[') && member (']', string + i + 1))
@@ -192,20 +228,53 @@ bash_history_inhibit_expansion (string, i)
   else if (i > 1 && string[i - 1] == '{' && string[i - 2] == '$' &&
             member ('}', string + i + 1))
     return (1);
+  /* The shell uses $! as a defined parameter expansion. */
+  else if (i > 1 && string[i - 1] == '$' && string[i] == '!')
+    return (1);
 #if defined (EXTENDED_GLOB)
   else if (extended_glob && i > 1 && string[i+1] == '(' && member (')', string + i + 2))
     return (1);
 #endif
+
+  si = 0;
+  /* If we're supposed to be in single-quoted string, skip over the
+     single-quoted part and then look at what's left. */
+  if (history_quoting_state == '\'')
+    {
+      si = skip_to_delim (string, 0, "'", SD_NOJMP|SD_HISTEXP);
+      if (string[si] == 0 || si >= i)
+       return (1);
+      si++;
+    }
+
+  /* Make sure the history expansion should not be skipped by quoting or
+     command/process substitution. */
+  if ((t = skip_to_histexp (string, si, hx, SD_NOJMP|SD_HISTEXP)) > 0)
+    {
+      /* Skip instances of history expansion appearing on the line before
+        this one. */
+      while (t < i)
+       {
+         t = skip_to_histexp (string, t+1, hx, SD_NOJMP|SD_HISTEXP);
+         if (t <= 0)
+           return 0;
+       }
+      return (t > i);
+    }
   else
     return (0);
 }
+#endif
 
 void
 bash_initialize_history ()
 {
   history_quotes_inhibit_expansion = 1;
   history_search_delimiter_chars = ";&()|<>";
+#if defined (BANG_HISTORY)
   history_inhibit_expansion_function = bash_history_inhibit_expansion;
+  sv_histchars ("histchars");
+#endif
 }
 
 void
@@ -213,11 +282,11 @@ bash_history_reinit (interact)
      int interact;
 {
 #if defined (BANG_HISTORY)
-  history_expansion = interact != 0;
-  history_expansion_inhibited = 1;
-#endif
-  remember_on_history = interact != 0;
+  history_expansion = (interact == 0) ? histexp_flag : HISTEXPAND_DEFAULT;
+  history_expansion_inhibited = (interact == 0) ? 1 - histexp_flag : 0;        /* changed in bash_history_enable() */
   history_inhibit_expansion_function = bash_history_inhibit_expansion;
+#endif
+  remember_on_history = enable_history_list;
 }
 
 void
@@ -232,11 +301,11 @@ bash_history_disable ()
 void
 bash_history_enable ()
 {
-  remember_on_history = 1;
+  remember_on_history = enable_history_list = 1;
 #if defined (BANG_HISTORY)
   history_expansion_inhibited = 0;
-#endif
   history_inhibit_expansion_function = bash_history_inhibit_expansion;
+#endif
   sv_history_control ("HISTCONTROL");
   sv_histignore ("HISTIGNORE");
 }
@@ -246,46 +315,118 @@ void
 load_history ()
 {
   char *hf;
-  struct stat buf;
 
   /* Truncate history file for interactive shells which desire it.
      Note that the history file is automatically truncated to the
      size of HISTSIZE if the user does not explicitly set the size
      differently. */
+  set_if_not ("HISTSIZE", HISTSIZE_DEFAULT);
+  sv_histsize ("HISTSIZE");
+
   set_if_not ("HISTFILESIZE", get_string_value ("HISTSIZE"));
   sv_histsize ("HISTFILESIZE");
 
   /* Read the history in HISTFILE into the history list. */
   hf = get_string_value ("HISTFILE");
 
-  if (hf && *hf && stat (hf, &buf) == 0)
+  if (hf && *hf && file_exists (hf))
     {
       read_history (hf);
+      /* We have read all of the lines from the history file, even if we
+        read more lines than $HISTSIZE.  Remember the total number of lines
+        we read so we don't count the last N lines as new over and over
+        again. */
+      history_lines_in_file = history_lines_read_from_file;
       using_history ();
-      history_lines_in_file = where_history ();
+      /* history_lines_in_file = where_history () + history_base - 1; */
     }
 }
 
+void
+bash_clear_history ()
+{
+  clear_history ();
+  history_lines_this_session = 0;
+  /* XXX - reset history_lines_read_from_file? */
+}
+
+/* Delete and free the history list entry at offset I. */
+int
+bash_delete_histent (i)
+     int i;
+{
+  HIST_ENTRY *discard;
+
+  discard = remove_history (i);
+  if (discard)
+    free_history_entry (discard);
+  history_lines_this_session--;
+
+  return 1;
+}
+
+int
+bash_delete_history_range (first, last)
+     int first, last;
+{
+  register int i;
+  HIST_ENTRY **discard_list;
+
+  discard_list = remove_history_range (first, last);
+  for (i = 0; discard_list && discard_list[i]; i++)
+    free_history_entry (discard_list[i]);
+  history_lines_this_session -= i;
+
+  return 1;
+}
+
+int
+bash_delete_last_history ()
+{
+  register int i;
+  HIST_ENTRY **hlist, *histent;
+  int r;
+
+  hlist = history_list ();
+  if (hlist == NULL)
+    return 0;
+
+  for (i = 0; hlist[i]; i++)
+    ;
+  i--;
+
+  /* History_get () takes a parameter that must be offset by history_base. */
+  histent = history_get (history_base + i);    /* Don't free this */
+  if (histent == NULL)
+    return 0;
+
+  r = bash_delete_histent (i);
+
+  if (where_history () > history_length)
+    history_set_pos (history_length);
+
+  return r;
+}
+
 #ifdef INCLUDE_UNUSED
 /* Write the existing history out to the history file. */
 void
 save_history ()
 {
   char *hf;
-  struct stat buf;
+  int r;
 
   hf = get_string_value ("HISTFILE");
-  if (hf && *hf && stat (hf, &buf) == 0)
+  if (hf && *hf && file_exists (hf))
     {
       /* Append only the lines that occurred this session to
         the history file. */
       using_history ();
 
-      if (history_lines_this_session < where_history () || force_append_history)
-       append_history (history_lines_this_session, hf);
+      if (history_lines_this_session <= where_history () || force_append_history)
+       r = append_history (history_lines_this_session, hf);
       else
-       write_history (hf);
-
+       r = write_history (hf);
       sv_histsize ("HISTFILESIZE");
     }
 }
@@ -299,7 +440,7 @@ maybe_append_history (filename)
   struct stat buf;
 
   result = EXECUTION_SUCCESS;
-  if (history_lines_this_session && (history_lines_this_session < where_history ()))
+  if (history_lines_this_session > 0 && (history_lines_this_session <= where_history ()))
     {
       /* If the filename was supplied, then create it if necessary. */
       if (stat (filename, &buf) == -1 && errno == ENOENT)
@@ -307,15 +448,20 @@ maybe_append_history (filename)
          fd = open (filename, O_WRONLY|O_CREAT, 0600);
          if (fd < 0)
            {
-             builtin_error ("%s: cannot create: %s", filename, strerror (errno));
+             builtin_error (_("%s: cannot create: %s"), filename, strerror (errno));
              return (EXECUTION_FAILURE);
            }
          close (fd);
        }
       result = append_history (history_lines_this_session, filename);
+      /* Pretend we already read these lines from the file because we just
+        added them */
       history_lines_in_file += history_lines_this_session;
       history_lines_this_session = 0;
     }
+  else
+    history_lines_this_session = 0;    /* reset if > where_history() */
+
   return (result);
 }
 
@@ -326,17 +472,16 @@ maybe_save_shell_history ()
 {
   int result;
   char *hf;
-  struct stat buf;
 
   result = 0;
-  if (history_lines_this_session)
+  if (history_lines_this_session > 0)
     {
       hf = get_string_value ("HISTFILE");
 
       if (hf && *hf)
        {
          /* If the file doesn't exist, then create it. */
-         if (stat (hf, &buf) == -1)
+         if (file_exists (hf) == 0)
            {
              int file;
              file = open (hf, O_CREAT | O_TRUNC | O_WRONLY, 0600);
@@ -356,7 +501,8 @@ maybe_save_shell_history ()
          else
            {
              result = write_history (hf);
-             history_lines_in_file = history_lines_this_session;
+             history_lines_in_file = history_lines_written_to_file;
+             /* history_lines_in_file = where_history () + history_base - 1; */
            }
          history_lines_this_session = 0;
 
@@ -414,7 +560,15 @@ pre_process_line (line, print_changes, addit)
      add that line to the history if ADDIT is non-zero. */
   if (!history_expansion_inhibited && history_expansion && history_expansion_p (line))
     {
+      /* If we are expanding the second or later line of a multi-line
+        command, decrease history_length so references to history expansions
+        in these lines refer to the previous history entry and not the
+        current command. */
+      if (history_length > 0 && command_oriented_history && current_command_first_line_saved && current_command_line_count > 1)
+        history_length--;
       expanded = history_expand (line, &history_value);
+      if (history_length >= 0 && command_oriented_history && current_command_first_line_saved && current_command_line_count > 1)
+        history_length++;
 
       if (expanded)
        {
@@ -433,12 +587,19 @@ pre_process_line (line, print_changes, addit)
          /* If there was an error, return NULL. */
          if (expanded < 0 || expanded == 2)    /* 2 == print only */
            {
+#    if defined (READLINE)
+             if (expanded == 2 && rl_dispatching == 0 && *history_value)
+#    else            
+             if (expanded == 2 && *history_value)
+#    endif /* !READLINE */
+               maybe_add_history (history_value);
+
              free (history_value);
 
 #    if defined (READLINE)
              /* New hack.  We can allow the user to edit the
                 failed history expansion. */
-             if (history_reediting && expanded < 0)
+             if (history_reediting && expanded < 0 && rl_done)
                re_edit (line);
 #    endif /* READLINE */
              return ((char *)NULL);
@@ -448,6 +609,7 @@ pre_process_line (line, print_changes, addit)
          if (hist_verify && expanded == 1)
            {
              re_edit (history_value);
+             free (history_value);
              return ((char *)NULL);
            }
 #    endif
@@ -473,16 +635,24 @@ pre_process_line (line, print_changes, addit)
 }
 
 /* Return 1 if the first non-whitespace character in LINE is a `#', indicating
- * that the line is a shell comment. */
+   that the line is a shell comment.  Return 2 if there is a comment after the
+   first non-whitespace character. Return 0 if the line does not contain a
+   comment. */
 static int
 shell_comment (line)
      char *line;
 {
   char *p;
+  int n;
 
+  if (line == 0)
+    return 0;
   for (p = line; p && *p && whitespace (*p); p++)
     ;
-  return (p && *p == '#');
+  if (p && *p == '#')
+    return 1;
+  n = skip_to_delim (line, p - line, "#", SD_NOJMP|SD_GLOB|SD_EXTGLOB|SD_COMPLETE);
+  return (line[n] == '#') ? 2 : 0;
 }
 
 #ifdef INCLUDE_UNUSED
@@ -511,27 +681,51 @@ check_history_control (line)
   HIST_ENTRY *temp;
   int r;
 
-  switch (history_control)
+  if (history_control == 0)
+    return 1;
+
+  /* ignorespace or ignoreboth */
+  if ((history_control & HC_IGNSPACE) && *line == ' ')
+    return 0;
+
+  /* ignoredups or ignoreboth */
+  if (history_control & HC_IGNDUPS)
     {
-    case 0:                    /* nothing */
-      return 1;
-    case 1:                    /* ignorespace */
-      return (*line != ' ');
-    case 3:                    /* ignoreboth */
-      if (*line == ' ')
-       return 0;
-      /* FALLTHROUGH if case == 3 (`ignoreboth') */
-    case 2:                    /* ignoredups */
       using_history ();
       temp = previous_history ();
 
       r = (temp == 0 || STREQ (temp->line, line) == 0);
 
       using_history ();
-      return r;
+
+      if (r == 0)
+       return r;
     }
 
-  return 0;
+  return 1;
+}
+
+/* Remove all entries matching LINE from the history list.  Triggered when
+   HISTCONTROL includes `erasedups'. */
+static void
+hc_erasedups (line)
+     char *line;
+{
+  HIST_ENTRY *temp;
+  int r;
+
+  using_history ();
+  while (temp = previous_history ())
+    {
+      if (STREQ (temp->line, line))
+       {
+         r = where_history ();
+         temp = remove_history (r);
+         if (temp)
+           free_history_entry (temp);
+       }
+    }
+  using_history ();
 }
 
 /* Add LINE to the history list, handling possibly multi-line compound
@@ -543,13 +737,19 @@ check_history_control (line)
    commenting out the rest of the command when the entire command is saved as
    a single history entry (when COMMAND_ORIENTED_HISTORY is enabled).  If
    LITERAL_HISTORY is set, we're saving lines in the history with embedded
-   newlines, so it's OK to save comment lines.  We also make sure to save
-   multiple-line quoted strings or other constructs. */
+   newlines, so it's OK to save comment lines.  If we're collecting the body
+   of a here-document, we should act as if literal_history is enabled, because
+   we want to save the entire contents of the here-document as it was
+   entered.  We also make sure to save multiple-line quoted strings or other
+   constructs. */
 void
 maybe_add_history (line)
      char *line;
 {
+  int is_comment;
+
   hist_last_line_added = 0;
+  is_comment = shell_comment (line);
 
   /* Don't use the value of history_control to affect the second
      and subsequent lines of a multi-line command (old code did
@@ -557,13 +757,15 @@ maybe_add_history (line)
   if (current_command_line_count > 1)
     {
       if (current_command_first_line_saved &&
-         (literal_history || dstack.delimiter_depth != 0 || shell_comment (line) == 0))
+         ((parser_state & PST_HEREDOC) || literal_history || dstack.delimiter_depth != 0 || is_comment != 1))
        bash_add_history (line);
+      current_command_line_comment = is_comment ? current_command_line_count : -2;
       return;
     }
 
   /* This is the first line of a (possible multi-line) command.  Note whether
      or not we should save the first line and remember it. */
+  current_command_line_comment = is_comment ? current_command_line_count : -2;
   current_command_first_line_saved = check_add_history (line, 0);
 }
 
@@ -577,6 +779,11 @@ check_add_history (line, force)
 {
   if (check_history_control (line) && history_should_ignore (line) == 0)
     {
+      /* We're committed to saving the line.  If the user has requested it,
+        remove other matching lines from the history. */
+      if (history_control & HC_ERASEDUPS)
+       hc_erasedups (line);
+        
       if (force)
        {
          really_add_history (line);
@@ -589,6 +796,43 @@ check_add_history (line, force)
   return 0;
 }
 
+#if defined (SYSLOG_HISTORY)
+#define SYSLOG_MAXLEN 600
+
+#ifndef OPENLOG_OPTS
+#define OPENLOG_OPTS 0
+#endif
+
+#if defined (SYSLOG_SHOPT)
+int syslog_history = SYSLOG_SHOPT;
+#else
+int syslog_history = 1;
+#endif
+
+void
+bash_syslog_history (line)
+     const char *line;
+{
+  char trunc[SYSLOG_MAXLEN];
+  static int first = 1;
+
+  if (first)
+    {
+      openlog (shell_name, OPENLOG_OPTS, SYSLOG_FACILITY);
+      first = 0;
+    }
+
+  if (strlen(line) < SYSLOG_MAXLEN)
+    syslog (SYSLOG_FACILITY|SYSLOG_LEVEL, "HISTORY: PID=%d UID=%d %s", getpid(), current_user.uid, line);
+  else
+    {
+      strncpy (trunc, line, SYSLOG_MAXLEN);
+      trunc[SYSLOG_MAXLEN - 1] = '\0';
+      syslog (SYSLOG_FACILITY|SYSLOG_LEVEL, "HISTORY (TRUNCATED): PID=%d UID=%d %s", getpid(), current_user.uid, trunc);
+    }
+}
+#endif
+       
 /* Add a line to the history list.
    The variable COMMAND_ORIENTED_HISTORY controls the style of history
    remembering;  when non-zero, and LINE is not the first line of a
@@ -605,11 +849,27 @@ bash_add_history (line)
   add_it = 1;
   if (command_oriented_history && current_command_line_count > 1)
     {
-      chars_to_add = literal_history ? "\n" : history_delimiting_chars ();
+      /* The second and subsequent lines of a here document have the trailing
+        newline preserved.  We don't want to add extra newlines here, but we
+        do want to add one after the first line (which is the command that
+        contains the here-doc specifier).  parse.y:history_delimiting_chars()
+        does the right thing to take care of this for us.  We don't want to
+        add extra newlines if the user chooses to enable literal_history,
+        so we have to duplicate some of what that function does here. */
+      if ((parser_state & PST_HEREDOC) && literal_history && current_command_line_count > 2 && line[strlen (line) - 1] == '\n')
+       chars_to_add = "";
+      else if (current_command_line_count == current_command_line_comment+1)
+       chars_to_add = "\n";
+      else if (literal_history)
+       chars_to_add = "\n";
+      else
+       chars_to_add = history_delimiting_chars (line);
 
       using_history ();
       current = previous_history ();
 
+      current_command_line_comment = shell_comment (line) ? current_command_line_count : -2;
+
       if (current)
        {
          /* If the previous line ended with an escaped newline (escaped
@@ -625,6 +885,13 @@ bash_add_history (line)
              chars_to_add = "";
            }
 
+         /* If we're not in some kind of quoted construct, the current history
+            entry ends with a newline, and we're going to add a semicolon,
+            don't.  In some cases, it results in a syntax error (e.g., before
+            a close brace), and it should not be needed. */
+         if (dstack.delimiter_depth == 0 && current->line[curlen - 1] == '\n' && *chars_to_add == ';')
+           chars_to_add++;
+
          new_line = (char *)xmalloc (1
                                      + curlen
                                      + strlen (line)
@@ -635,10 +902,8 @@ bash_add_history (line)
          free (new_line);
 
          if (old)
-           {
-             FREE (old->line);
-             free (old);
-           }
+           free_history_entry (old);
+
          add_it = 0;
        }
     }
@@ -646,6 +911,11 @@ bash_add_history (line)
   if (add_it)
     really_add_history (line);
 
+#if defined (SYSLOG_HISTORY)
+  if (syslog_history)
+    bash_syslog_history (line);
+#endif
+
   using_history ();
 }
 
@@ -654,6 +924,7 @@ really_add_history (line)
      char *line;
 {
   hist_last_line_added = 1;
+  hist_last_line_pushed = 0;
   add_history (line);
   history_lines_this_session++;
 }
@@ -662,7 +933,7 @@ int
 history_number ()
 {
   using_history ();
-  return (get_string_value ("HISTSIZE") ? history_base + where_history () : 1);
+  return (remember_on_history ? history_base + where_history () : 1);
 }
 
 static int