home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / unix / volume25 / listserv5.31 / part01 / src / signals.c < prev    next >
Encoding:
C/C++ Source or Header  |  1991-12-12  |  2.9 KB  |  85 lines

  1. /*
  2.   ----------------------------------------------------------------------------
  3.   |                            SIGNAL FUNCTIONS                              |
  4.   |                                                                          |
  5.   |                              Version 2.0                                 |
  6.   |                                                                          |
  7.   |                (or, when Computer Science gets to you)                   |
  8.   |                                                                          |
  9.   |                    Written by Anastasios Kotsikonas                      |
  10.   |                           (tasos@cs.bu.edu)                              |
  11.   |                                                                          |
  12.   | AGREEMENT: This software can be used and distributed freely as long      |
  13.   | as you do not remove or alter the Copyright notice in the file defs.h;   |
  14.   | this notice is #define'd in the symbol VERSION. Although you may alter   |
  15.   | the code provided, you may not alter the functions create_header()       |
  16.   | and create_multi_recipient_header() in list.c and listserv.c.            |
  17.   | By using this software you are bound by this agreement.                  |
  18.   | This software comes with no warranties and cannot be sold for profit.    |
  19.   | The AGREEMENT and COPYRIGHT notices should be included in all source     |
  20.   | files when distributing this software.                                   |
  21.   | COPYRIGHT: Copyright (c) 1991, Anastasios C. Kotsikonas                  |
  22.   ----------------------------------------------------------------------------
  23. */
  24.  
  25. #include <stdio.h>
  26. #include <signal.h>
  27. #include "defs.h"
  28. #include "struct.h"
  29.  
  30. extern void report_progress (FILE *, char *, int);
  31.  
  32. void   init_signals (void);
  33. void   catch_signals (void);
  34. void   my_abort (int);
  35.  
  36. static char *signals[MAX_SIGNAL + 1];   /* Signal names */
  37.  
  38. /*
  39.   Initialize the signals[].
  40. */
  41.  
  42. void init_signals ()
  43. {
  44.   signals[SIGHUP] = "SIGHUP";
  45.   signals[SIGINT] = "SIGINT";
  46.   signals[SIGQUIT] = "SIGQUIT";
  47.   signals[SIGTERM] = "SIGTERM";
  48.   signals[SIGBUS] = "SIGBUS";
  49.   signals[SIGSEGV] = "SIGSEGV";
  50. }
  51.  
  52. /*
  53.   Catch signals to print messages before aborting.
  54. */
  55.  
  56. void catch_signals ()
  57. {
  58.   signal (SIGHUP, my_abort);
  59.   signal (SIGQUIT, my_abort);
  60.   signal (SIGTERM, my_abort);
  61.   signal (SIGSEGV, my_abort);
  62.   signal (SIGBUS, my_abort);
  63.   signal (SIGKILL, my_abort); /* Can't be caught, but why not try? */
  64. }
  65.  
  66. /*
  67.   Kill program after sending message to MANAGER that this is
  68.   about to happen (message is sent only when using UCB mail).
  69. */
  70.  
  71. void my_abort (int sig)
  72. {
  73.   extern SYS sys;
  74.  
  75.   if (sig == SIGHUP) { /* Damn AIX passes signals from children to parents */
  76.     signal (SIGHUP, my_abort);
  77.     return;
  78.   }
  79.   printf ("\n*** Received %s signal ***\n", signals[sig]);
  80.   if (sys.options & BSD_MAIL)
  81.     syscom ("%s -s \"SERVERD/SERVER/LIST received %s\" %s &", UCB_MAIL,
  82.         signals[sig], sys.manager);
  83.   exit (8);
  84. }
  85.