From: Kern Sibbald Date: Tue, 2 Nov 2010 15:42:46 +0000 (+0100) Subject: Fix bug #1655 Quitting bconsole with ctrl+d doesn't save history X-Git-Tag: Release-7.0.0~1443 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=224227ad0c487fa707327b59fcf325c29a606663;p=bacula%2Fbacula Fix bug #1655 Quitting bconsole with ctrl+d doesn't save history --- 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 . */