static void stop(char cmdc) { mode(0); (void) sigset(SIGCHLD, SIG_IGN); (void) kill(cmdc == defltc.t_suspc ? 0 : getpid(), SIGTSTP); (void) sigset(SIGCHLD, catchild); mode(1); sigwinch(0); /* check for size changes */ }
static void stop(char cmdc) { mode(0); (void)signal(SIGCHLD, SIG_IGN); (void)kill(CCEQ(deftty.c_cc[VSUSP], cmdc) ? 0 : getpid(), SIGTSTP); (void)signal(SIGCHLD, catch_child); mode(1); sigwinch(0); /* check for size changes */ }
/* ** Inits the terminal with specific caracteristics */ struct termios get_next_init(t_caps_str *vars) { struct termios backup_st; backup_st = get_conf(0); modify_conf(vars); signal(SIGWINCH, sigwinch); signal(SIGTSTP, sigsuspend_redir); sigwinch(); return (backup_st); }
int main() { struct sigaction sa; sa.sa_handler=sigwinch; sigemptyset(&sa.sa_mask); sa.sa_flags=0; if(sigaction(SIGWINCH, &sa, NULL)<0) { perror("sigaction"); return -1; } sigwinch(0); while(1) { sleep(10); } return 0; }
int main(int argc, char **argv) { bool blink = false; int sig; sigset_t sigset; struct itimerspec its = {{0, interval_nsec}, {0, interval_nsec}}; struct sigaction sigact = {.sa_handler = sigwinch}; timer_t timerid; struct sigevent sev = {.sigev_notify = SIGEV_SIGNAL, .sigev_signo = SIGRTMIN, .sigev_value.sival_ptr = &timerid}; unsigned long long total_seconds = 0; if (!isatty(STDOUT_FILENO)) error(1, 0, "Error: stdout is not a tty"); if (argc < 2) error(1, 0, "Not enough arguments.\nUsage:\n" "\t%s <n>{s,m,h,D,M,Y} ...", argv[0]); for (int i = 1; i < argc; i++) total_seconds += get_seconds(argv[i]); if (sigaction(SIGWINCH, &sigact, NULL) != 0) error(1, errno, "Unable to set SIGWINCH signal action"); if (timer_create(CLOCK_MONOTONIC, &sev, &timerid) != 0) error(1, errno, "Could not create timer"); if (sigemptyset(&sigset) != 0) error(1, errno, "Could not empty signal set"); if (sigaddset(&sigset, SIGRTMIN) != 0) error(1, errno, "Could not add SIGRTMIN to signal set"); if (sigprocmask(SIG_BLOCK, &sigset, NULL) != 0) error(1, errno, "Could not block SIGRTMIN"); if (timer_settime(timerid, 0, &its, NULL) != 0) error(1, errno, "Could not set timer"); sigwinch(SIGWINCH); for (unsigned long long i = 0; i < total_seconds; i++) for (int ii = 0; ii < 4; ii++) { if (sigwait(&sigset, &sig), sig != SIGRTMIN) error(1, 0, "sigwait returned unexpected signal %d", sig); if (sigaddset(&sigset, SIGRTMIN) != 0) error(1, errno, "Could not add SIGRTMIN to signal set"); clear_line(); print_time(total_seconds - i, ii < 2); } if (sigaddset(&sigset, SIGINT) != 0) error(1, errno, "Could not add SIGINT to signal set"); while (true) { blink = !blink; sigwait(&sigset, &sig); if (sig != SIGRTMIN) break; if (sigaddset(&sigset, SIGRTMIN) != 0) error(1, errno, "Could not add SIGRTMIN to signal set"); clear_line(); if (blink) printf(" -- BEEP -- \a\r"); if (fflush(stdout) != 0) error(1, errno, "Failed to flush stdout"); } timer_delete(timerid); clear_line(); return 0; }