diff --git a/tools/virsh.c b/tools/virsh.c index 50ca50f..a4371c2 100644 --- a/tools/virsh.c +++ b/tools/virsh.c @@ -246,6 +246,9 @@ static void vshOpenLogFile(vshControl *ctl); static void vshOutputLogFile(vshControl *ctl, int log_level, const char *format, va_list ap); static void vshCloseLogFile(vshControl *ctl); +static char *vshReadlineNoReadline (vshControl *, const char *); +static char *(*vshReadline)(vshControl *, const char *) = vshReadlineNoReadline; + static int vshParseArgv(vshControl *ctl, int argc, char **argv); static const char *vshCmddefGetInfo(const vshCmdDef *cmd, const char *info); @@ -12105,6 +12108,12 @@ vshReadlineCompletion(const char *text, int start, return matches; } +static char * +vshReadlineReadline (vshControl *ctl ATTRIBUTE_UNUSED, const char *prompt) +{ + return readline (prompt); +} + static int vshReadlineInit(vshControl *ctl) @@ -12141,6 +12150,7 @@ vshReadlineInit(vshControl *ctl) VIR_FREE(userdir); read_history(ctl->historyfile); + vshReadline = vshReadlineReadline; return 0; } @@ -12161,12 +12171,6 @@ vshReadlineDeinit (vshControl *ctl) VIR_FREE(ctl->historyfile); } -static char * -vshReadline (vshControl *ctl ATTRIBUTE_UNUSED, const char *prompt) -{ - return readline (prompt); -} - #else /* !USE_READLINE */ static int @@ -12182,8 +12186,10 @@ vshReadlineDeinit (vshControl *ctl ATTRIBUTE_UNUSED) /* empty */ } +#endif /* !USE_READLINE */ + static char * -vshReadline (vshControl *ctl, const char *prompt) +vshReadlineNoReadline (vshControl *ctl, const char *prompt) { char line[1024]; char *r; @@ -12201,8 +12207,6 @@ vshReadline (vshControl *ctl, const char *prompt) return vshStrdup (ctl, r); } -#endif /* !USE_READLINE */ - /* * Deinitialize virsh */ @@ -12531,9 +12535,8 @@ main(int argc, char **argv) " 'quit' to quit\n\n")); } - if (vshReadlineInit(ctl) < 0) { - vshDeinit(ctl); - exit(EXIT_FAILURE); + if (isatty(STDIN_FILENO)) { + vshReadlineInit(ctl); } do {