From 90b5364b29a65d141b7f260a2be5ece5db140b36 Mon Sep 17 00:00:00 2001 From: Přemysl Janouch
Date: Mon, 23 Sep 2019 23:01:30 +0200 Subject: Fix running helper programs A bug was introduced in 5c38087. --- json-rpc-shell.c | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/json-rpc-shell.c b/json-rpc-shell.c index 47ef3b8..e8bf9fb 100644 --- a/json-rpc-shell.c +++ b/json-rpc-shell.c @@ -3184,8 +3184,6 @@ process_edited_input (struct app_context *ctx) print_error ("could not unlink `%s': %s", ctx->editor_filename, strerror (errno)); - free (ctx->editor_filename); - ctx->editor_filename = NULL; str_free (&input); } @@ -3203,7 +3201,7 @@ on_child (EV_P_ ev_child *handle, int revents) kill (-handle->rpid, SIGKILL); return; } - // I don't recognize this child (we should also check PID) + // I don't recognize this child (we should also check its PID) if (!ctx->editor_filename) return; @@ -3216,6 +3214,9 @@ on_child (EV_P_ ev_child *handle, int revents) print_error ("editor returned status %d", WEXITSTATUS (status)); else process_edited_input (ctx); + + free (ctx->editor_filename); + ctx->editor_filename = NULL; } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -3250,8 +3251,14 @@ on_tty_readable (EV_P_ ev_io *handle, int revents) { // rl_callback_read_char() is not reentrant, may happen on EOF ev_io_stop (EV_DEFAULT_ &ctx->tty_watcher); + ctx->input->vtable->on_tty_readable (ctx->input); - ev_io_start (EV_DEFAULT_ &ctx->tty_watcher); + + // Don't make ourselves receive a SIGTTIN. Ideally we'd prevent + // reentrancy without inciting conflicts with + // {suspend,resume}_terminal() but I can't figure anything out. + if (!ctx->editor_filename) + ev_io_start (EV_DEFAULT_ &ctx->tty_watcher); } } -- cgit v1.2.3-70-g09d2