rewrite tstp as __stop_signal_handler: new implementation
authorKeith Bostic <bostic@ucbvax.Berkeley.EDU>
Mon, 25 Jan 1993 12:14:13 +0000 (04:14 -0800)
committerKeith Bostic <bostic@ucbvax.Berkeley.EDU>
Mon, 25 Jan 1993 12:14:13 +0000 (04:14 -0800)
SCCS-vsn: lib/libcurses/tstp.c 5.8

usr/src/lib/libcurses/tstp.c

index a05c9e9..c79f6aa 100644 (file)
@@ -6,7 +6,7 @@
  */
 
 #ifndef lint
  */
 
 #ifndef lint
-static char sccsid[] = "@(#)tstp.c     5.7 (Berkeley) %G%";
+static char sccsid[] = "@(#)tstp.c     5.8 (Berkeley) %G%";
 #endif /* not lint */
 
 #include <curses.h>
 #endif /* not lint */
 
 #include <curses.h>
@@ -16,41 +16,57 @@ static char sccsid[] = "@(#)tstp.c  5.7 (Berkeley) %G%";
 #include <unistd.h>
 
 /*
 #include <unistd.h>
 
 /*
- * tstp --
- *     Handle stop and start signals.
+ * stop_signal_handler --
+ *     Handle stop signals.
  */
 void
  */
 void
-tstp(signo)
+__stop_signal_handler(signo)
        int signo;
 {
        struct termios save;
        int signo;
 {
        struct termios save;
-       sigset_t set;
+       sigset_t oset, set;
 
        /* Get the current terminal state. */
        if (tcgetattr(STDIN_FILENO, &save))
                return;
 
 
        /* Get the current terminal state. */
        if (tcgetattr(STDIN_FILENO, &save))
                return;
 
-       /* Move the cursor to the end of the screen. */
-       mvcur(0, COLS - 1, LINES - 1, 0);
-
-       /* End the window. */
+       /*
+        * Block every signal we can get our hands on.  This is because
+        * applications have timers going off that want to repaint the
+        * screen.
+        */
+       (void)sigfillset(&set);
+       (void)sigprocmask(SIG_BLOCK, &set, &oset);
+       
+       /*
+        * End the window, which also resets the terminal state to the
+        * original modes.
+        */
        endwin();
 
        endwin();
 
-       /* Stop ourselves. */
+       /* Unblock SIGTSTP. */
        (void)sigemptyset(&set);
        (void)sigaddset(&set, SIGTSTP);
        (void)sigprocmask(SIG_UNBLOCK, &set, NULL);
        (void)sigemptyset(&set);
        (void)sigaddset(&set, SIGTSTP);
        (void)sigprocmask(SIG_UNBLOCK, &set, NULL);
+
+       /* Stop ourselves. */
        (void)signal(SIGTSTP, SIG_DFL);
        (void)kill(0, SIGTSTP);
 
        /* Time passes ... */
 
        (void)signal(SIGTSTP, SIG_DFL);
        (void)kill(0, SIGTSTP);
 
        /* Time passes ... */
 
-       /* Reset the signal handler. */
-       (void)signal(SIGTSTP, tstp);
+       /* Reset the curses SIGTSTP signal handler. */
+       (void)signal(SIGTSTP, __stop_signal_handler);
 
 
-       /* Reset the terminal state. */
+       /* Reset the terminal state its mode when we stopped. */
        (void)tcsetattr(STDIN_FILENO, TCSADRAIN, &save);
 
        /* Restart the screen. */
        (void)tcsetattr(STDIN_FILENO, TCSADRAIN, &save);
 
        /* Restart the screen. */
+       __startwin();
+
+       /* Repaint the screen. */
        wrefresh(curscr);
        wrefresh(curscr);
+
+       /* Reset the signals. */
+       (void)sigprocmask(SIG_SETMASK, &oset, NULL);
 }
 }