cli: terminate when the input terminal goes away
Readline treats I/O errors on stdin as a newline, thus if the terminal disappears with SIGHUP masked we just loop until the end of times and beyond.
This commit is contained in:
@@ -24,6 +24,8 @@
|
|||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
|
#include <termios.h>
|
||||||
|
#include <sys/ioctl.h>
|
||||||
|
|
||||||
#include <readline/readline.h>
|
#include <readline/readline.h>
|
||||||
#include <readline/history.h>
|
#include <readline/history.h>
|
||||||
@@ -1068,6 +1070,7 @@ nmc_readline (const char *prompt_fmt, ...)
|
|||||||
{
|
{
|
||||||
va_list args;
|
va_list args;
|
||||||
char *prompt, *str;
|
char *prompt, *str;
|
||||||
|
int b;
|
||||||
|
|
||||||
va_start (args, prompt_fmt);
|
va_start (args, prompt_fmt);
|
||||||
prompt = g_strdup_vprintf (prompt_fmt, args);
|
prompt = g_strdup_vprintf (prompt_fmt, args);
|
||||||
@@ -1080,6 +1083,13 @@ readline_mark:
|
|||||||
/* We are outside readline -> Ctrl-C should quit nmcli */
|
/* We are outside readline -> Ctrl-C should quit nmcli */
|
||||||
nmc_set_in_readline (FALSE);
|
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 */
|
/* Add string to the history */
|
||||||
if (str && *str)
|
if (str && *str)
|
||||||
add_history (str);
|
add_history (str);
|
||||||
|
Reference in New Issue
Block a user