diff --git a/clients/cli/common.c b/clients/cli/common.c index e7d7e1322..e17f02123 100644 --- a/clients/cli/common.c +++ b/clients/cli/common.c @@ -24,6 +24,8 @@ #include #include #include +#include +#include #include #include @@ -1068,6 +1070,7 @@ nmc_readline (const char *prompt_fmt, ...) { va_list args; char *prompt, *str; + int b; va_start (args, prompt_fmt); prompt = g_strdup_vprintf (prompt_fmt, args); @@ -1080,6 +1083,13 @@ readline_mark: /* We are outside readline -> Ctrl-C should quit nmcli */ nmc_set_in_readline (FALSE); + /* Check for an I/O error by attempting to peek into the input buffer. + * Readline just inserts newlines when errors occur so we need to check ourselves. */ + if (ioctl (0, FIONREAD, &b) == -1) { + g_free (str); + str = NULL; + } + /* Add string to the history */ if (str && *str) add_history (str);