| OLD | NEW |
| 1 #include <signal.h> | 1 #include <signal.h> |
| 2 | 2 |
| 3 void (*sigset(int sig, void (*handler)(int)))(int) | 3 void (*sigset(int sig, void (*handler)(int)))(int) { |
| 4 { | 4 struct sigaction sa, sa_old; |
| 5 » struct sigaction sa, sa_old; | 5 sigset_t mask; |
| 6 » sigset_t mask; | |
| 7 | 6 |
| 8 » sigemptyset(&mask); | 7 sigemptyset(&mask); |
| 9 » if (sigaddset(&mask, sig) < 0) | 8 if (sigaddset(&mask, sig) < 0) |
| 10 » » return SIG_ERR; | 9 return SIG_ERR; |
| 11 » | 10 |
| 12 » if (handler == SIG_HOLD) { | 11 if (handler == SIG_HOLD) { |
| 13 » » if (sigaction(sig, 0, &sa_old) < 0) | 12 if (sigaction(sig, 0, &sa_old) < 0) |
| 14 » » » return SIG_ERR; | 13 return SIG_ERR; |
| 15 » » if (sigprocmask(SIG_BLOCK, &mask, &mask) < 0) | 14 if (sigprocmask(SIG_BLOCK, &mask, &mask) < 0) |
| 16 » » » return SIG_ERR; | 15 return SIG_ERR; |
| 17 » } else { | 16 } else { |
| 18 » » sa.sa_handler = handler; | 17 sa.sa_handler = handler; |
| 19 » » sa.sa_flags = 0; | 18 sa.sa_flags = 0; |
| 20 » » sigemptyset(&sa.sa_mask); | 19 sigemptyset(&sa.sa_mask); |
| 21 » » if (sigaction(sig, &sa, &sa_old) < 0) | 20 if (sigaction(sig, &sa, &sa_old) < 0) |
| 22 » » » return SIG_ERR; | 21 return SIG_ERR; |
| 23 » » if (sigprocmask(SIG_UNBLOCK, &mask, &mask) < 0) | 22 if (sigprocmask(SIG_UNBLOCK, &mask, &mask) < 0) |
| 24 » » » return SIG_ERR; | 23 return SIG_ERR; |
| 25 » } | 24 } |
| 26 » return sigismember(&mask, sig) ? SIG_HOLD : sa_old.sa_handler; | 25 return sigismember(&mask, sig) ? SIG_HOLD : sa_old.sa_handler; |
| 27 } | 26 } |
| OLD | NEW |