Main Page   Modules   Alphabetical List   Data Structures   File List   Data Fields   Globals  

signal.c

00001  /*
00002   * plint/misc/signal.c : signals' handling
00003   * 
00004   * Time-stamp: <2002-09-26 01:32:45 gseba>
00005   * 
00006   * Copyright (C) Sebastian Glita, email: gseba@users.sourceforge.net
00007   * 
00008   * This file is part of plint.
00009   * 
00010   * plint is free software; you can  redistribute it and/or modify it under the
00011   * terms of the  GNU General Public License as published  by the Free Software
00012   * Foundation; either version 2, or (at your option) any later version.
00013   *
00014   * plint  is distributed  in the  hope  that it  will be  useful, but  WITHOUT
00015   * ANY  WARRANTY; without  even  the implied  warranty  of MERCHANTABILITY  or
00016   * FITNESS FOR A  PARTICULAR PURPOSE.  See the GNU  General Public License for
00017   * more details.
00018   * 
00019   * You should  have received a  copy of the  GNU General Public  License along
00020   * with  plint; see  the file  COPYING.  If  not, write  to the  Free Software
00021   * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA USA.
00022   *
00023   */
00024 
00025 #include "plint.h"
00026 #include "error.h"
00027 
00028 #include "signal.h"
00029 #include "sys.h"
00030 
00031 
00032 static void signal_handler(int s)
00033 {
00034   signal(s, signal_handler);
00035 
00036   switch (s)
00037     {
00038     case SIGCHLD: eprintf("\n%s%sa child has left me !\n", PLINT_PLINT, PLINT_SIGN); wait(0); return;
00039     case SIGTSTP: eprintf("\n%s%sOk, I'll take a break to rest a while...\n", PLINT_PLINT, PLINT_SIGN); raise(SIGSTOP); return;
00040     case SIGPIPE OR SIGINT: eprintf("\n%s%swhat do you want ?\n", PLINT_PLINT, PLINT_SIGN); break;
00041     case SIGTERM: eprintf("\n%s%si follow your order!\n", PLINT_PLINT, PLINT_SIGN); break;
00042     case SIGQUIT: eprintf("\n%s%scowardly quitting...\n", PLINT_PLINT, PLINT_SIGN); break;
00043     case SIGSTKFLT OR SIGFPE : PLINT_ERROR(PLINT_ERR_MATH);
00044     case SIGSEGV: PLINT_ERROR(PLINT_ERR_MEM);
00045     default:
00046       assert(0);
00047     }
00048 
00049   exit(0);
00050 }
00051 
00052 static void signal_fatal_handler(int s)
00053 {
00054   plint->flag.jmp = 1;
00055   switch (s)
00056     {
00057     case SIGABRT OR SIGSYS OR SIGBUS:
00058       eprintf("\n%s%sbug!!!\n%s\n", PLINT_PLINT, PLINT_SIGN, PLINT_MAIL);
00059       PLINT_ERROR(PLINT_ERR_BUG);
00060       break;
00061     case SIGKILL:
00062       eprintf("\n%s%soh, no... shot from the backhhhaaooo.. ahhh...\n", PLINT_PLINT, PLINT_SIGN);
00063       break;
00064     default:
00065     }
00066   signal(s, SIG_DFL); /* maybe not necessary */
00067   signal(SIGABRT, SIG_DFL);
00068 
00069   abort();
00070 }
00071 
00072 void plint_sig_init()
00073 {
00074   sigfillset(&plint->ctx.sigblk);
00075   sigprocmask(SIG_SETMASK, &plint->ctx.sigblk, 0);
00076 
00077   sigemptyset(&plint->ctx.sigblk);
00078 
00079 #define PLINT_SIGNAL(__sig__) signal((__sig__), signal_handler), sigaddset(&plint->ctx.sigblk, (__sig__))
00080   PLINT_SIGNAL(SIGINT);
00081   PLINT_SIGNAL(SIGQUIT);
00082   PLINT_SIGNAL(SIGTERM);
00083   PLINT_SIGNAL(SIGSEGV);
00084   PLINT_SIGNAL(SIGFPE);
00085   PLINT_SIGNAL(SIGSTKFLT);
00086   PLINT_SIGNAL(SIGPIPE);
00087   PLINT_SIGNAL(SIGCHLD);
00088   PLINT_SIGNAL(SIGTSTP);
00089 #undef PLINT_SIGNAL
00090 
00091 #define PLINT_FATAL_SIGNAL(__sig__) signal((__sig__), signal_fatal_handler)
00092   PLINT_FATAL_SIGNAL(SIGABRT);
00093   PLINT_FATAL_SIGNAL(SIGSYS);
00094   PLINT_FATAL_SIGNAL(SIGBUS);
00095   PLINT_FATAL_SIGNAL(SIGKILL);
00096 #undef PLINT_FATAL_SIGNAL
00097 
00098   sigprocmask(SIG_SETMASK, &plint->ctx.sigblk, 0);
00099 
00100 }
00101 
00102 void plint_sig_finish()
00103 {
00104   sigprocmask(SIG_UNBLOCK, &plint->ctx.sigblk, 0);
00105 }

Generated on Thu Jan 9 19:02:39 2003 for plint by doxygen1.2.14 written by Dimitri van Heesch, © 1997-2002