From 3eff34b07576ed72941956358f9b3031bac75add Mon Sep 17 00:00:00 2001 From: Benno Schulenberg Date: Fri, 31 Jul 2020 19:45:03 +0200 Subject: [PATCH] speller: re-enter curses mode before trying to report an error If forking fails, we must first return to curses mode before we can show an error message on the status bar. (This additionally requires storing the error number, because doupdate() apparently sets it to zero.) This fixes https://savannah.gnu.org/bugs/?58864. Bug existed since version 4.8, commit 61197563. --- src/text.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/src/text.c b/src/text.c index c6154e70..0639e932 100644 --- a/src/text.c +++ b/src/text.c @@ -2098,7 +2098,7 @@ const char *treat(char *tempfile_name, char *theprogram, bool spelling) long timestamp_nsec = 0; static char **arguments = NULL; pid_t thepid; - int program_status; + int program_status, errornumber; bool replaced = FALSE; /* Stat the temporary file. If that succeeds and its size is zero, @@ -2122,19 +2122,25 @@ const char *treat(char *tempfile_name, char *theprogram, bool spelling) /* Terminate the child if the program is not found. */ exit(9); - } else if (thepid < 0) - return _("Could not fork"); - + } else if (thepid > 0) { /* Block SIGWINCHes while waiting for the program to end, * so nano doesn't get pushed past the wait(). */ block_sigwinch(TRUE); wait(&program_status); block_sigwinch(FALSE); + } + + errornumber = errno; /* Restore the terminal state and reenter curses mode. */ terminal_init(); doupdate(); + if (thepid < 0) { + statusline(ALERT, _("Could not fork: %s"), strerror(errornumber)); + return NULL; + } + if (!WIFEXITED(program_status) || WEXITSTATUS(program_status) > 2) { statusline(ALERT, _("Error invoking '%s'"), arguments[0]); return NULL;