From f8b8054be989c6064bb1dfddd3ee11eeb8792d89 Mon Sep 17 00:00:00 2001 From: Kern Sibbald Date: Tue, 2 Nov 2010 16:42:46 +0100 Subject: [PATCH] Fix bug #1655 Quitting bconsole with ctrl+d doesn't save history --- bacula/src/console/console.c | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/bacula/src/console/console.c b/bacula/src/console/console.c index 9f6360cf8e..ca1ee1b1dd 100644 --- a/bacula/src/console/console.c +++ b/bacula/src/console/console.c @@ -675,6 +675,11 @@ static int eolcmd(FILE *input, BSOCK *UA_sock) return 1; } +/* + * Return 1 if OK + * 0 if no input + * -1 error (must stop) + */ int get_cmd(FILE *input, const char *prompt, BSOCK *sock, int sec) { @@ -691,7 +696,7 @@ get_cmd(FILE *input, const char *prompt, BSOCK *sock, int sec) */ line = readline((char *)prompt); /* cast needed for old readlines */ if (!line) { - exit(1); + return -1; /* error return and exit */ } strip_trailing_junk(line); command = line; @@ -701,7 +706,7 @@ get_cmd(FILE *input, const char *prompt, BSOCK *sock, int sec) sendit(_("Command logic problem\n")); sock->msglen = 0; sock->msg[0] = 0; - return 0; + return 0; /* No input */ } /* @@ -732,7 +737,7 @@ get_cmd(FILE *input, const char *prompt, BSOCK *sock, int sec) actuallyfree(line); /* allocated by readline() malloc */ line = NULL; } - return 1; + return 1; /* OK */ } #else /* no readline, do it ourselves */ @@ -845,8 +850,9 @@ static int console_update_history(const char *histfile) int ret=0; #ifdef HAVE_READLINE -/* first, try to truncate the history file, and if it - * fail, the file is probably not present, and we +/* + * first, try to truncate the history file, and if it + * fails, the file is probably not present, and we * can use write_history to create it */ @@ -855,7 +861,6 @@ static int console_update_history(const char *histfile) } else { ret = write_history(histfile); } - #endif return ret; @@ -866,7 +871,6 @@ static int console_init_history(const char *histfile) int ret=0; #ifdef HAVE_READLINE - using_history(); ret = read_history(histfile); /* Tell the completer that we want a complete . */ -- 2.39.5