=================================================================== RCS file: /cvsrepo/anoncvs/cvs/src/usr.bin/top/top.c,v retrieving revision 1.6 retrieving revision 1.7 diff -c -r1.6 -r1.7 *** src/usr.bin/top/top.c 2000/12/22 22:46:57 1.6 --- src/usr.bin/top/top.c 2001/01/18 07:29:28 1.7 *************** *** 1,4 **** ! /* $OpenBSD: top.c,v 1.6 2000/12/22 22:46:57 deraadt Exp $ */ const char copyright[] = "Copyright (c) 1984 through 1996, William LeFebvre"; --- 1,4 ---- ! /* $OpenBSD: top.c,v 1.7 2001/01/18 07:29:28 deraadt Exp $ */ const char copyright[] = "Copyright (c) 1984 through 1996, William LeFebvre"; *************** *** 70,75 **** --- 70,79 ---- static void winch __P((int)); #endif + sig_atomic_t leaveflag; + sig_atomic_t tstopflag; + sig_atomic_t winchflag; + static void reset_display __P((void)); /* values which need to be accessed by signal handlers */ *************** *** 483,494 **** fputc('\n', stderr); } ! /* setup the jump buffer for stops */ ! if (setjmp(jmp_int) != 0) ! { ! /* control ends up here after an interrupt */ ! reset_display(); ! } /* * main loop -- repeat while display count is positive or while it --- 487,493 ---- fputc('\n', stderr); } ! restart: /* * main loop -- repeat while display count is positive or while it *************** *** 626,631 **** --- 625,676 ---- timeout.tv_sec = delay; timeout.tv_usec = 0; + if (leaveflag) { + end_screen(); + exit(0); + } + + if (tstopflag) { + /* move to the lower left */ + end_screen(); + fflush(stdout); + + /* default the signal handler action */ + (void) signal(SIGTSTP, SIG_DFL); + + /* unblock the signal and send ourselves one */ + #ifdef SIGRELSE + sigrelse(SIGTSTP); + #else + (void) sigsetmask(sigblock(0) & ~(1 << (SIGTSTP - 1))); + #endif + (void) kill(0, SIGTSTP); + + /* reset the signal handler */ + (void) signal(SIGTSTP, tstop); + + /* reinit screen */ + reinit_screen(); + reset_display(); + tstopflag = 0; + goto restart; + } + + if (winchflag) { + /* reascertain the screen dimensions */ + get_screensize(); + + /* tell display to resize */ + max_topn = display_resize(); + + /* reset the signal handler */ + (void) signal(SIGWINCH, winch); + + reset_display(); + winchflag = 0; + goto restart; + } + /* wait for either input or the end of the delay period */ if (select(32, &readfds, (fd_set *)NULL, (fd_set *)NULL, &timeout) > 0) { *************** *** 900,907 **** int unused; { ! end_screen(); ! exit(0); } void tstop(i) /* SIGTSTP handler */ --- 945,951 ---- int unused; { ! leaveflag = 1; } void tstop(i) /* SIGTSTP handler */ *************** *** 909,943 **** int i; { ! int save_errno = errno; ! ! /* move to the lower left */ ! end_screen(); ! fflush(stdout); ! ! /* default the signal handler action */ ! (void) signal(SIGTSTP, SIG_DFL); ! ! /* unblock the signal and send ourselves one */ ! #ifdef SIGRELSE ! sigrelse(SIGTSTP); ! #else ! (void) sigsetmask(sigblock(0) & ~(1 << (SIGTSTP - 1))); ! #endif ! (void) kill(0, SIGTSTP); ! ! /* reset the signal handler */ ! (void) signal(SIGTSTP, tstop); ! ! /* reinit screen */ ! reinit_screen(); ! ! errno = save_errno; ! ! /* jump to appropriate place */ ! longjmp(jmp_int, 1); ! ! /*NOTREACHED*/ } #ifdef SIGWINCH --- 953,959 ---- int i; { ! tstopflag = 1; } #ifdef SIGWINCH *************** *** 946,966 **** int i; { ! int save_errno = errno; ! ! /* reascertain the screen dimensions */ ! get_screensize(); ! ! /* tell display to resize */ ! max_topn = display_resize(); ! ! /* reset the signal handler */ ! (void) signal(SIGWINCH, winch); ! ! errno = save_errno; ! ! /* jump to appropriate place */ ! longjmp(jmp_int, 1); } #endif --- 962,968 ---- int i; { ! winchflag = 1; } #endif