From: Eric Bollengier Date: Fri, 7 Feb 2020 09:25:50 +0000 (+0100) Subject: Fix #5944 about incorrect bconsole history size X-Git-Tag: Release-9.6.0~3 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=8135b9d21d0fb92e12f5bc8c7e6efd1adff2c042;p=thirdparty%2Fbacula.git Fix #5944 about incorrect bconsole history size --- diff --git a/bacula/src/console/console.c b/bacula/src/console/console.c index 02cb61e18..22d1faf0e 100644 --- a/bacula/src/console/console.c +++ b/bacula/src/console/console.c @@ -409,6 +409,8 @@ static int tls_pem_callback(char *buf, int size, const void *userdata) #include "readline.h" #include "history.h" +static int history_lines_added=0; /* Number of lines added to the history file */ + /* Get the first keyword of the line */ static char * get_first_keyword() @@ -789,6 +791,10 @@ get_cmd(FILE *input, const char *prompt, BSOCK *sock, int sec) if (!next) { if (do_history) { add_history(line); + /* Count the number of lines added, we use it to truncate the history + * file correctly + */ + history_lines_added++; } actuallyfree(line); /* allocated by readline() malloc */ line = NULL; @@ -938,9 +944,10 @@ static int console_update_history(const char *histfile) * fails, the file is probably not present, and we * can use write_history to create it */ - - if (history_truncate_file(histfile, 100) == 0) { - ret = append_history(history_length, histfile); + int nlines = MAX(histfile_size - history_lines_added, 0); + if (history_truncate_file(histfile, nlines) == 0) { + nlines = MIN(histfile_size, history_lines_added); + ret = append_history(nlines, histfile); } else { ret = write_history(histfile); }