int main(int argc, char *argv[]) { int n, num_secs; sigset_t pending_mask, blocking_mask, empty_mask; printf("%s: PID is %ld\n", argv[0], (long) getpid()); for (n = 1; n < NSIG; ++n) { (void) signal(n, handler); } /* If a sleep time was specified, temporarily block all signals, * sleep (while another process sends us signals), and then * display the mask of pending signals and unblock all signals */ if (argc > 1) { num_secs = atoi(argv[1]); if (num_secs < 0) { fprintf(stderr, "num-secs %s > 0\n", argv[1]); exit(EXIT_FAILURE); } sigfillset(&blocking_mask); if (sigprocmask(SIG_SETMASK, &blocking_mask, NULL) == -1) { perror("sigprocmask"); exit(EXIT_FAILURE); } printf("%s: sleeping for %d seconds\n", argv[0], num_secs); sleep(num_secs); if (sigpending(&pending_mask) == -1) { perror("sigpending"); exit(EXIT_FAILURE); } printf("%s: pending signals are: \n", argv[0]); print_sigset(stdout, "\t\t", &pending_mask); sigemptyset(&empty_mask); if (sigprocmask(SIG_SETMASK, &empty_mask, NULL) == -1) { perror("sigprocmask"); exit(EXIT_FAILURE); } } while (!got_sigint) { /* Loop until SIGINT caught */ continue; } for (n = 1; n < NSIG; ++n) { if (sig_cnt[n] != 0) { printf("%s: signal %d caught %d times%s\n", argv[0], n, sig_cnt[n], (sig_cnt[n] == 1) ? " " : "s"); } } exit(EXIT_SUCCESS); }
int sys_epoll_pwait(struct tcb *tcp) { epoll_wait_common(tcp); if (exiting(tcp)) print_sigset(tcp, tcp->u_arg[4], 0); return 0; }
int sys_sigprocmask(struct tcb *tcp) { #ifdef ALPHA sigset_t ss; if (entering(tcp)) { /* * Alpha/OSF is different: it doesn't pass in two pointers, * but rather passes in the new bitmask as an argument and * then returns the old bitmask. This "works" because we * only have 64 signals to worry about. If you want more, * use of the rt_sigprocmask syscall is required. * Alpha: * old = osf_sigprocmask(how, new); * Everyone else: * ret = sigprocmask(how, &new, &old, ...); */ memcpy(&ss, &tcp->u_arg[1], sizeof(long)); printxval(sigprocmaskcmds, tcp->u_arg[0], "SIG_???"); tprints(", "); printsigmask(&ss, 0); } else if (!syserror(tcp)) { memcpy(&ss, &tcp->u_rval, sizeof(long)); tcp->auxstr = sprintsigmask("old mask ", &ss, 0); return RVAL_HEX | RVAL_STR; } #else /* !ALPHA */ if (entering(tcp)) { printxval(sigprocmaskcmds, tcp->u_arg[0], "SIG_???"); tprints(", "); print_sigset(tcp, tcp->u_arg[1], 0); tprints(", "); } else { if (!tcp->u_arg[2]) tprints("NULL"); else if (syserror(tcp)) tprintf("%#lx", tcp->u_arg[2]); else print_sigset(tcp, tcp->u_arg[2], 0); } #endif /* !ALPHA */ return 0; }
int sys_ppoll(struct tcb *tcp) { int rc = decode_poll(tcp, tcp->u_arg[2]); if (entering(tcp)) { print_timespec(tcp, tcp->u_arg[2]); tprints(", "); print_sigset(tcp, tcp->u_arg[3], 0); tprintf(", %lu", tcp->u_arg[4]); } return rc; }
static int do_signalfd(struct tcb *tcp, int flags_arg) { if (entering(tcp)) { printfd(tcp, tcp->u_arg[0]); tprints(", "); print_sigset(tcp, tcp->u_arg[1], 1); tprintf(", %lu", tcp->u_arg[2]); if (flags_arg >= 0) { tprints(", "); printflags(open_mode_flags, tcp->u_arg[flags_arg], "O_???"); } } return 0; }
int print_sigmask(FILE *of, const char *msg) { sigset_t currMask; if(msg != NULL) fprintf(of, "%s\n", msg); if(sigprocmask(SIG_BLOCK, NULL, &currMask)==-1) // 获取当前进程的信号掩码,并存放在currMask中 { return -1; } print_sigset(of, "\t\t", &currMask); return 0; }
int sys_pselect6(struct tcb *tcp) { int rc = decode_select(tcp, tcp->u_arg, BITNESS_CURRENT); if (entering(tcp)) { struct { void *ss; unsigned long len; } data; if (umove(tcp, tcp->u_arg[5], &data) < 0) tprintf(", %#lx", tcp->u_arg[5]); else { tprintf(", {"); if (data.len < sizeof(long)) tprintf("%#lx", (long)data.ss); else print_sigset(tcp, (long)data.ss, 0); tprintf(", %lu}", data.len); } } return rc; }