signal.c

Go to the documentation of this file.
00001 /*
00002  * Copyright (C), 2000-2002 by Contributors to the monit codebase. 
00003  * All Rights Reserved.
00004  *
00005  * This program is free software; you can redistribute it and/or
00006  * modify it under the terms of the GNU General Public License as
00007  * published by the Free Software Foundation; either version 2 of the
00008  * License, or (at your option) any later version.
00009  *
00010  * This program is distributed in the hope that it will be useful, but
00011  * WITHOUT ANY WARRANTY; without even the implied warranty of
00012  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013  * General Public License for more details.
00014  * 
00015  * You should have received a copy of the GNU General Public License
00016  * along with this program; if not, write to the Free Software Foundation,
00017  * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
00018  */
00019 
00020 #include <config.h>
00021 
00022 #include <stdio.h>
00023 #include <signal.h>
00024 
00025 #include "monitor.h"
00026 
00039 /* ------------------------------------------------------------------ Public */
00040 
00041 
00047 Sigfunc *signal(int signo, Sigfunc *func) {
00048   
00049   struct sigaction act, oact;
00050 
00051   act.sa_handler = func;
00052   sigemptyset(&act.sa_mask);
00053   act.sa_flags = 0;
00054   if (signo == SIGALRM) {
00055 #ifdef  SA_INTERRUPT
00056     act.sa_flags |= SA_INTERRUPT;   /* SunOS */
00057 #endif
00058   } else {
00059 #ifdef  SA_RESTART
00060     act.sa_flags |= SA_RESTART;             /* SVR4, 44BSD */
00061 #endif
00062   }
00063   if (sigaction(signo, &act, &oact) < 0)
00064       return(SIG_ERR);
00065   
00066   return(oact.sa_handler);
00067   
00068 }
00069 
00070 
00075 void set_alarm_handler(void *func) {
00076 
00077   struct sigaction sa;
00078 
00079   sa.sa_handler= func;
00080   sa.sa_flags= 0;
00081   sigemptyset(&sa.sa_mask);
00082   sigaction(SIGALRM, &sa, NULL);
00083   
00084 }