The Linux Programming Interface

(nextflipdebug5) #1

1314 Chapter 62


sigemptyset(&sa.sa_mask); /* Reestablish handler */
sa.sa_flags = SA_RESTART;
sa.sa_handler = tstpHandler;
if (sigaction(SIGTSTP, &sa, NULL) == -1)
errExit("sigaction");

/* The user may have changed the terminal settings while we were
stopped; save the settings so we can restore them later */

y if (tcgetattr(STDIN_FILENO, &userTermios) == -1)
errExit("tcgetattr");

/* Restore our terminal settings */

u if (tcsetattr(STDIN_FILENO, TCSAFLUSH, &ourTermios) == -1)
errExit("tcsetattr");

errno = savedErrno;
}

int
main(int argc, char *argv[])
{
char ch;
struct sigaction sa, prev;
ssize_t n;

sigemptyset(&sa.sa_mask);
sa.sa_flags = SA_RESTART;

i if (argc > 1) { /* Use cbreak mode */
o if (ttySetCbreak(STDIN_FILENO, &userTermios) == -1)
errExit("ttySetCbreak");

/* Terminal special characters can generate signals in cbreak
mode. Catch them so that we can adjust the terminal mode.
We establish handlers only if the signals are not being ignored. */

a sa.sa_handler = handler;

if (sigaction(SIGQUIT, NULL, &prev) == -1)
errExit("sigaction");
if (prev.sa_handler != SIG_IGN)
if (sigaction(SIGQUIT, &sa, NULL) == -1)
errExit("sigaction");

if (sigaction(SIGINT, NULL, &prev) == -1)
errExit("sigaction");
if (prev.sa_handler != SIG_IGN)
if (sigaction(SIGINT, &sa, NULL) == -1)
errExit("sigaction");

s sa.sa_handler = tstpHandler;
Free download pdf