1 /* 2 * Copyright (c) 1981 Regents of the University of California. 3 * All rights reserved. 4 * 5 * %sccs.include.redist.c% 6 */ 7 8 #ifndef lint 9 static char sccsid[] = "@(#)tstp.c 5.8 (Berkeley) 01/24/93"; 10 #endif /* not lint */ 11 12 #include <curses.h> 13 #include <errno.h> 14 #include <signal.h> 15 #include <termios.h> 16 #include <unistd.h> 17 18 /* 19 * stop_signal_handler -- 20 * Handle stop signals. 21 */ 22 void 23 __stop_signal_handler(signo) 24 int signo; 25 { 26 struct termios save; 27 sigset_t oset, set; 28 29 /* Get the current terminal state. */ 30 if (tcgetattr(STDIN_FILENO, &save)) 31 return; 32 33 /* 34 * Block every signal we can get our hands on. This is because 35 * applications have timers going off that want to repaint the 36 * screen. 37 */ 38 (void)sigfillset(&set); 39 (void)sigprocmask(SIG_BLOCK, &set, &oset); 40 41 /* 42 * End the window, which also resets the terminal state to the 43 * original modes. 44 */ 45 endwin(); 46 47 /* Unblock SIGTSTP. */ 48 (void)sigemptyset(&set); 49 (void)sigaddset(&set, SIGTSTP); 50 (void)sigprocmask(SIG_UNBLOCK, &set, NULL); 51 52 /* Stop ourselves. */ 53 (void)signal(SIGTSTP, SIG_DFL); 54 (void)kill(0, SIGTSTP); 55 56 /* Time passes ... */ 57 58 /* Reset the curses SIGTSTP signal handler. */ 59 (void)signal(SIGTSTP, __stop_signal_handler); 60 61 /* Reset the terminal state its mode when we stopped. */ 62 (void)tcsetattr(STDIN_FILENO, TCSADRAIN, &save); 63 64 /* Restart the screen. */ 65 __startwin(); 66 67 /* Repaint the screen. */ 68 wrefresh(curscr); 69 70 /* Reset the signals. */ 71 (void)sigprocmask(SIG_SETMASK, &oset, NULL); 72 } 73