Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/lib/libcurses Change TSTP handler back to using signal().



details:   https://anonhg.NetBSD.org/src/rev/c49f88a9ab49
branches:  trunk
changeset: 559876:c49f88a9ab49
user:      jdc <jdc%NetBSD.org@localhost>
date:      Thu Mar 25 07:35:40 2004 +0000

description:
Change TSTP handler back to using signal().
This fixes a problem where vi would not suspend.
Also, make sure that the signal handlers aren't set or removed multiple times.
Finally, add debug output when the signal handlers are set and removed.

diffstat:

 lib/libcurses/tstp.c |  61 +++++++++++++++++++++++++++++++++++++--------------
 1 files changed, 44 insertions(+), 17 deletions(-)

diffs (117 lines):

diff -r 84ee6d7a2fdf -r c49f88a9ab49 lib/libcurses/tstp.c
--- a/lib/libcurses/tstp.c      Thu Mar 25 06:17:51 2004 +0000
+++ b/lib/libcurses/tstp.c      Thu Mar 25 07:35:40 2004 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: tstp.c,v 1.31 2004/03/22 18:57:10 jdc Exp $    */
+/*     $NetBSD: tstp.c,v 1.32 2004/03/25 07:35:40 jdc Exp $    */
 
 /*
  * Copyright (c) 1981, 1993, 1994
@@ -34,7 +34,7 @@
 #if 0
 static char sccsid[] = "@(#)tstp.c     8.3 (Berkeley) 5/4/94";
 #else
-__RCSID("$NetBSD: tstp.c,v 1.31 2004/03/22 18:57:10 jdc Exp $");
+__RCSID("$NetBSD: tstp.c,v 1.32 2004/03/25 07:35:40 jdc Exp $");
 #endif
 #endif                         /* not lint */
 
@@ -48,7 +48,13 @@
 #include "curses.h"
 #include "curses_private.h"
 
-static struct sigaction        otsa, owsa;
+static int tstp_set = 0;
+static int winch_set = 0;
+
+static void (*otstpfn)
+__P((int)) = SIG_DFL;
+
+static struct sigaction        owsa;
 
 /*
  * stop_signal_handler --
@@ -97,11 +103,13 @@
 void
 __set_stophandler(void)
 {
-       struct sigaction sa;
-       sa.sa_handler = __stop_signal_handler;
-       sa.sa_flags = SA_RESTART;
-       sigemptyset(&sa.sa_mask);
-       sigaction(SIGTSTP, &sa, &otsa);
+#ifdef DEBUG
+       __CTRACE("__set_stophandler: %d\n", tstp_set);
+#endif
+       if (!tstp_set) {
+               otstpfn = signal(SIGTSTP, __stop_signal_handler);
+               tstp_set = 1;
+       }
 }
 
 /*
@@ -110,7 +118,13 @@
 void
 __restore_stophandler(void)
 {
-       sigaction(SIGTSTP, &otsa, NULL);
+#ifdef DEBUG
+       __CTRACE("__restore_stophandler: %d\n", tstp_set);
+#endif
+       if (tstp_set) {
+               (void) signal(SIGTSTP, otstpfn);
+               tstp_set = 0;
+       }
 }
 
 /*
@@ -131,7 +145,7 @@
         * If there was a previous handler, call that,
         * otherwise tell getch() to send KEY_RESIZE.
         */
-       if (owsa.sa_handler != __winch_signal_handler)
+       if (owsa.sa_handler !=  NULL)
                owsa.sa_handler(signo);
        else
                _cursesi_screen->resized = 1;
@@ -143,20 +157,33 @@
 void
 __set_winchhandler(void)
 {
-       struct sigaction sa;
-       sa.sa_handler = __winch_signal_handler;
-       sa.sa_flags = 0;
-       sigemptyset(&sa.sa_mask);
-       sigaction(SIGWINCH, &sa, &owsa);
+#ifdef DEBUG
+       __CTRACE("__set_winchhandler: %d\n", winch_set);
+#endif
+       if (!winch_set) {
+               struct sigaction sa;
+
+               sa.sa_handler = __winch_signal_handler;
+               sa.sa_flags = 0;
+               sigemptyset(&sa.sa_mask);
+               sigaction(SIGWINCH, &sa, &owsa);
+               winch_set = 1;
+       }
 }
 
 /*
- * Restore the TSTP handler.
+ * Restore the WINCH handler.
  */
 void
 __restore_winchhandler(void)
 {
-       sigaction(SIGTSTP, &owsa, NULL);
+#ifdef DEBUG
+       __CTRACE("__restore_winchhandler: %d\n", winch_set);
+#endif
+       if (winch_set) {
+               sigaction(SIGWINCH, &owsa, NULL);
+               winch_set = 0;
+       }
 }
 
 /* To allow both SIGTSTP and endwin() to come back nicely, we provide



Home | Main Index | Thread Index | Old Index