| 1584 | otherwise restore to the default. */ |
| 1585 | |
| 1586 | static void |
| 1587 | signal_setup (bool init) |
| 1588 | { |
| 1589 | /* The signals that are trapped, and the number of such signals. */ |
| 1590 | static int const stop_sig[] = |
| 1591 | { |
| 1592 | /* This one is handled specially. */ |
| 1593 | SIGTSTP, |
| 1594 | }; |
| 1595 | |
| 1596 | enum { nsigs = countof (term_sig), nstop = countof (stop_sig) }; |
| 1597 | |
| 1598 | if (init) |
| 1599 | { |
| 1600 | struct sigaction act; |
| 1601 | |
| 1602 | sigemptyset (&caught_signals); |
| 1603 | for (int j = 0; j < nsigs + nstop; j++) |
| 1604 | { |
| 1605 | int sig = j < nsigs ? term_sig[j]: stop_sig[j - nsigs]; |
| 1606 | sigaction (sig, NULL, &act); |
| 1607 | if (act.sa_handler != SIG_IGN) |
| 1608 | sigaddset (&caught_signals, sig); |
| 1609 | } |
| 1610 | |
| 1611 | act.sa_mask = caught_signals; |
| 1612 | act.sa_flags = SA_RESTART; |
| 1613 | |
| 1614 | for (int j = 0; j < nsigs + nstop; j++) |
| 1615 | { |
| 1616 | int sig = j < nsigs ? term_sig[j]: stop_sig[j - nsigs]; |
| 1617 | if (sigismember (&caught_signals, sig)) |
| 1618 | { |
| 1619 | act.sa_handler = j < nsigs ? sighandler : stophandler; |
| 1620 | sigaction (sig, &act, NULL); |
| 1621 | } |
| 1622 | } |
| 1623 | } |
| 1624 | else /* restore. */ |
| 1625 | { |
| 1626 | for (int j = 0; j < nsigs + nstop; j++) |
| 1627 | { |
| 1628 | int sig = j < nsigs ? term_sig[j]: stop_sig[j - nsigs]; |
| 1629 | if (sigismember (&caught_signals, sig)) |
| 1630 | signal (sig, SIG_DFL); |
| 1631 | } |
| 1632 | } |
| 1633 | } |
| 1634 | |
| 1635 | static void |
| 1636 | signal_init (void) |
no test coverage detected