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.
This commit is contained in:
Benno Schulenberg 2020-07-31 19:45:03 +02:00
parent 40b03162c3
commit 3eff34b075
1 changed files with 10 additions and 4 deletions

View File

@ -2098,7 +2098,7 @@ const char *treat(char *tempfile_name, char *theprogram, bool spelling)
long timestamp_nsec = 0; long timestamp_nsec = 0;
static char **arguments = NULL; static char **arguments = NULL;
pid_t thepid; pid_t thepid;
int program_status; int program_status, errornumber;
bool replaced = FALSE; bool replaced = FALSE;
/* Stat the temporary file. If that succeeds and its size is zero, /* 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. */ /* Terminate the child if the program is not found. */
exit(9); exit(9);
} else if (thepid < 0) } else if (thepid > 0) {
return _("Could not fork");
/* Block SIGWINCHes while waiting for the program to end, /* Block SIGWINCHes while waiting for the program to end,
* so nano doesn't get pushed past the wait(). */ * so nano doesn't get pushed past the wait(). */
block_sigwinch(TRUE); block_sigwinch(TRUE);
wait(&program_status); wait(&program_status);
block_sigwinch(FALSE); block_sigwinch(FALSE);
}
errornumber = errno;
/* Restore the terminal state and reenter curses mode. */ /* Restore the terminal state and reenter curses mode. */
terminal_init(); terminal_init();
doupdate(); doupdate();
if (thepid < 0) {
statusline(ALERT, _("Could not fork: %s"), strerror(errornumber));
return NULL;
}
if (!WIFEXITED(program_status) || WEXITSTATUS(program_status) > 2) { if (!WIFEXITED(program_status) || WEXITSTATUS(program_status) > 2) {
statusline(ALERT, _("Error invoking '%s'"), arguments[0]); statusline(ALERT, _("Error invoking '%s'"), arguments[0]);
return NULL; return NULL;