home *** CD-ROM | disk | FTP | other *** search
- /*
- * signals.c
- */
-
- #include <stdio.h>
- #include <signal.h>
- #include "snapshot.h"
-
- #ifndef BADSIG
- #define BADSIG (int (*)()) -1
- #endif
-
- /* pointers to functions returning int */
- static int (*oldint) (); /* Old value of SIGINT. */
-
- #ifdef SIGTTIN
- static int (*oldttin) (); /* Old value of SIGTTIN. */
- static int (*oldttou) (); /* Old value of SIGTTOU. */
- #endif
-
- /*
- * Interrupt signal handler.
- */
-
- static int
- int_handler()
- {
- fprintf(stderr, "Interrupted\n");
- longjmp(sjbuf, -1);
- }
-
- /*
- * Set up signal handlers. Return 0 if ok, -1 if error.
- */
- handlesigs()
- {
- #ifdef SIGTTIN
- /*
- * Ignore the signals sent if someone in our process group tries a
- * background read from/write to the tty.
- */
- if ((oldttin = signal(SIGTTIN, SIG_IGN)) == BADSIG ||
- (oldttou = signal(SIGTTOU, SIG_IGN)) == BADSIG) {
- return -1;
- }
- #endif
-
- /* if interrupts were being ignored, don't catch them */
- if ((oldint = signal(SIGINT, SIG_IGN)) != SIG_IGN)
- if (signal(SIGINT, int_handler) == BADSIG) {
- return -1;
- }
- return 0;
- }
-
- /*
- * Restore original signal values. Return 0 if ok, -1 if error.
- */
- restoresigs()
- {
- int status = 0;
-
- #ifdef SIGTTIN
- if (signal(SIGTTIN, oldttin) == BADSIG || signal(SIGTTOU, oldttou) ==
- BADSIG) {
- status = -1;
- }
- #endif
- if (signal(SIGINT, oldint) == BADSIG) {
- status = -1;
- }
- return status;
- }
-