From 8ec698bf0995df45844991503d03aacac00b9246 Mon Sep 17 00:00:00 2001 From: Philip Withnall Date: Fri, 22 Nov 2013 12:47:42 +0000 Subject: [PATCH] client: Fix handling of (G_IO_IN | G_IO_HUP) input case MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit If running bluetoothctl as a subprocess from another process, and piping input to it, it’s possible for the stdin pipe to be closed by the parent process while there’s still data pending in its buffer. This results in input handler callbacks with condition (G_IO_IN | G_IO_HUP). All of the pending input should be handled before closing bluetoothctl. --- client/main.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/client/main.c b/client/main.c index 0dd151072..0ec40c778 100644 --- a/client/main.c +++ b/client/main.c @@ -1197,12 +1197,16 @@ done: static gboolean input_handler(GIOChannel *channel, GIOCondition condition, gpointer user_data) { + if (condition & G_IO_IN) { + rl_callback_read_char(); + return TRUE; + } + if (condition & (G_IO_HUP | G_IO_ERR | G_IO_NVAL)) { g_main_loop_quit(main_loop); return FALSE; } - rl_callback_read_char(); return TRUE; } -- 2.47.3