From 47dcc84c94021c1e6decf85a7b36520458faa13c Mon Sep 17 00:00:00 2001 From: Chris Allegretta Date: Thu, 28 Jun 2001 16:52:52 +0000 Subject: [PATCH] rewrote suspend handler, added sigfillset before setting up handler with sigaction, allows nano to suspend properly with mutt git-svn-id: svn://svn.savannah.gnu.org/nano/branches/nano_1_0_branch/nano@699 35c25a1d-7b9e-4130-9fde-d3aeb78583b8 --- ChangeLog | 11 +++++++++++ nano.c | 45 +++++++++++++++++++++++++-------------------- 2 files changed, 36 insertions(+), 20 deletions(-) diff --git a/ChangeLog b/ChangeLog index 276a9ab0..3758fdca 100644 --- a/ChangeLog +++ b/ChangeLog @@ -24,6 +24,17 @@ CVS code - do_alt_speller() - Try to go to the same line we were on before before spell check (Rocco). + signal_init() + - Reorder sigaction calls, use sigfillset() to stop SIGTSTP and + SIGCONT from being interrupted, allows suspending nano + to work more reliably, esp. with mutt, etc. + do_suspend() + - Don't try to play with the handler inside the handler. Just + raise a SIGSTOP. We also now write the "use "fg"" message to + stdout instead of stderr. + do_cont() + - Now just does a refresh call instead of playing with the SIGTSTP + handler. - utils.c: strcasestr() - Replaced by mutt's mutt_stristr function, because the thought diff --git a/nano.c b/nano.c index 34e69026..0780aa73 100644 --- a/nano.c +++ b/nano.c @@ -1602,25 +1602,27 @@ RETSIGTYPE handle_hup(int signal) /* What do we do when we catch the suspend signal */ RETSIGTYPE do_suspend(int signal) { - - act.sa_handler = SIG_DFL; - sigemptyset(&act.sa_mask); - sigaction(SIGTSTP, &act, NULL); - endwin(); - fprintf(stderr, "\n\n\n\n\nUse \"fg\" to return to nano\n"); - raise(SIGTSTP); + printf("\n\n\n\n\nUse \"fg\" to return to nano\n"); + fflush(stdout); + + /* We used to re-enable the default SIG_DFL and raise SIGTSTP, but + then we could be (and were) interrupted in the middle of the call. + So we do it the mutt way instead */ + kill(0, SIGSTOP); } /* Restore the suspend handler when we come back into the prog */ RETSIGTYPE do_cont(int signal) { - act.sa_handler = do_suspend; - sigemptyset(&act.sa_mask); - sigaction(SIGTSTP, &act, NULL); - initscr(); - total_refresh(); + /* Now we just update the screen instead of having to reenable the + SIGTSTP handler */ + + wnoutrefresh(edit); + wnoutrefresh(bottomwin); + wnoutrefresh(topwin); + doupdate(); } void handle_sigwinch(int s) @@ -1705,9 +1707,20 @@ void signal_init(void) act.sa_handler = SIG_IGN; sigaction(SIGINT, &act, NULL); + /* Trap SIGHUP cuz we want to write the file out. */ + act.sa_handler = handle_hup; + sigaction(SIGHUP, &act, NULL); + + act.sa_handler = handle_sigwinch; + sigaction(SIGWINCH, &act, NULL); + if (!ISSET(SUSPEND)) { sigaction(SIGTSTP, &act, NULL); } else { + /* if we don't do this, it seems other stuff interrupts the + suspend handler! Try using nano with mutt without this line */ + sigfillset(&act.sa_mask); + act.sa_handler = do_suspend; sigaction(SIGTSTP, &act, NULL); @@ -1715,14 +1728,6 @@ void signal_init(void) sigaction(SIGCONT, &act, NULL); } - - /* Trap SIGHUP cuz we want to write the file out. */ - act.sa_handler = handle_hup; - sigaction(SIGHUP, &act, NULL); - - act.sa_handler = handle_sigwinch; - sigaction(SIGWINCH, &act, NULL); - } void window_init(void) -- 2.39.5