From e0334e861d6869863ff544f970e583adf55ba190 Mon Sep 17 00:00:00 2001 From: Benno Schulenberg Date: Tue, 28 Sep 2021 18:05:15 +0200 Subject: [PATCH] shutdown: when dying, do not install/restore a handler for Ctrl+C First, we don't want the writing of an emergency file to be interrupted by the user. But more important: the routine for restoring the handler also disables SIGINT, which would leave the terminal with a non-working Ctrl+C. Saving an emergency file calls write_file() in a unique manner: with thefile == NULL, fullbuffer == FALSE (even though the entire buffer will be saved, of course) and tmp == TRUE (even though it is not a temporary file, as it will persist after nano exits). But in fact we want the handler for Ctrl+C installed only for normal files, not for temporary files and not for emergency files -- the user should not be able to interrupt the writing of those. This fixes https://savannah.gnu.org/bugs/?61237. Bug existed since version 4.3, commit 8550c6bd. --- src/files.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/files.c b/src/files.c index 60db3f74..76040488 100644 --- a/src/files.c +++ b/src/files.c @@ -1848,7 +1848,8 @@ bool write_file(const char *name, FILE *thefile, bool tmp, #ifndef NANO_TINY block_sigwinch(TRUE); - install_handler_for_Ctrl_C(); + if (!tmp) + install_handler_for_Ctrl_C(); #endif /* Now open the file. Use O_EXCL for an emergency file. */ @@ -1856,7 +1857,8 @@ bool write_file(const char *name, FILE *thefile, bool tmp, O_APPEND : (tmp ? O_EXCL : O_TRUNC)), permissions); #ifndef NANO_TINY - restore_handler_for_Ctrl_C(); + if (!tmp) + restore_handler_for_Ctrl_C(); block_sigwinch(FALSE); #endif