Signal Handling
Shut down cleanly if the system signals an error to the program.
Notes
This appears to also support an extended concern to use
the SA_INTERRUPT (sigaction) model of signal handling.
- Import <signal.h>
-
Imported definition
- Segment Source
- 28: #include <signal.h>
- Define sighandler()
-
Function definition
- Segment Source
-
1641: /* Handle interrupts and hangups. */
1642:
1643: static void
1644: sighandler (int sig)
1645: {
1646: #ifdef SA_INTERRUPT
1647: struct sigaction sigact;
1648:
1649: sigact.sa_handler = SIG_DFL;
1650: sigemptyset (&sigact.sa_mask);
1651: sigact.sa_flags = 0;
1652: sigaction (sig, &sigact, NULL);
1653: #else /* !SA_INTERRUPT */
1654: signal (sig, SIG_DFL);
1655: #endif /* SA_INTERRUPT */
1656: cleanup ();
1657: kill (getpid (), sig);
1658: }
1659:
- Activate signal handler
Segment Element
Variable declaration
- 1724: #ifdef SA_INTERRUPT
1725: struct sigaction oldact, newact;
1726: #endif /* SA_INTERRUPT */
1727:
Segment Element
Code insertion
- 1742: #ifdef SA_INTERRUPT
1743: newact.sa_handler = sighandler;
1744: sigemptyset (&newact.sa_mask);
1745: newact.sa_flags = 0;
1746:
1747: sigaction (SIGINT, NULL, &oldact);
1748: if (oldact.sa_handler != SIG_IGN)
1749: sigaction (SIGINT, &newact, NULL);
1750: sigaction (SIGHUP, NULL, &oldact);
1751: if (oldact.sa_handler != SIG_IGN)
1752: sigaction (SIGHUP, &newact, NULL);
1753: sigaction (SIGPIPE, NULL, &oldact);
1754: if (oldact.sa_handler != SIG_IGN)
1755: sigaction (SIGPIPE, &newact, NULL);
1756: sigaction (SIGTERM, NULL, &oldact);
1757: if (oldact.sa_handler != SIG_IGN)
1758: sigaction (SIGTERM, &newact, NULL);
1759: #else /* !SA_INTERRUPT */
1760: if (signal (SIGINT, SIG_IGN) != SIG_IGN)
1761: signal (SIGINT, sighandler);
1762: if (signal (SIGHUP, SIG_IGN) != SIG_IGN)
1763: signal (SIGHUP, sighandler);
1764: if (signal (SIGPIPE, SIG_IGN) != SIG_IGN)
1765: signal (SIGPIPE, sighandler);
1766: if (signal (SIGTERM, SIG_IGN) != SIG_IGN)
1767: signal (SIGTERM, sighandler);
1768: #endif /* !SA_INTERRUPT */
1769: