File:  [ELWIX - Embedded LightWeight unIX -] / embedaddon / freevrrpd / vrrp_signal.c
Revision 1.1.1.1 (vendor branch): download - view: text, annotated - select for diffs - revision graph
Wed Jun 14 12:01:54 2017 UTC (6 years, 11 months ago) by misho
Branches: freevrrpd, MAIN
CVS tags: v1_1, HEAD
freevrrpd 1.1

    1: /*
    2:  * Copyright (c) 2001,2002 Sebastien Petit <spe@bsdfr.org>
    3:  *
    4:  * Redistribution and use in source forms, with and without modification,
    5:  * are permitted provided that the following conditions are met:
    6:  * 1. Redistributions of source code must retain the above copyright notice,
    7:  *    this list of conditions and the following disclaimer.
    8:  * 2. Redistributions in binary form must reproduce the above copyright notice,
    9:  *    this list of conditions and the following disclaimer in the documentation
   10:  *    and/or other materials provided with the distribution. Obviously, it
   11:  *    would be nice if you gave credit where credit is due but requiring it
   12:  *    would be too onerous.
   13:  * 3. All advertising materials mentioning features or use of this software
   14:  *    must display the following acknowledgement:
   15:  *      This product includes software developed by Sebastien Petit.
   16:  * 4. Neither the name of its contributors may be used to endorse or promote
   17:  *    products derived from this software without specific prior written
   18:  *    permission.
   19:  *
   20:  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
   21:  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
   22:  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
   23:  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
   24:  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
   25:  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
   26:  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
   27:  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
   28:  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
   29:  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   30:  * SUCH DAMAGE.
   31:  *
   32:  * $Id: vrrp_signal.c,v 1.1.1.1 2017/06/14 12:01:54 misho Exp $
   33:  */
   34: 
   35: #include <string.h>
   36: #include "vrrp_signal.h"
   37: 
   38: /*
   39:  * On detourne les signaux SIGHUP et SIGSTOP, ainsi que le signal SIGINT.
   40:  */
   41: void 
   42: vrrp_signal_initialize(void)
   43: {
   44: 	signal(SIGINT, vrrp_signal_quit);
   45: 	signal(SIGABRT, vrrp_signal_quit);
   46: 	signal(SIGTERM, vrrp_signal_quit);
   47: 	signal(SIGHUP, vrrp_signal_shutdown);
   48: 	signal(SIGSTOP, vrrp_signal_shutdown);
   49: 
   50: 	return;
   51: }
   52: 
   53: /*
   54:  * On quitte gentiment
   55:  */
   56: void 
   57: vrrp_signal_quit(int sig)
   58: {
   59: 	int             cpt = 0;
   60: 	struct ether_addr ethaddr;
   61: 
   62: 	vrrp_thread_mutex_lock();
   63: 	vrrp_netgraph_shutdown_allnodes();
   64: 	while (vr_ptr[cpt]) {
   65: 		ethaddr = vrrp_list_get_first(vr_ptr[cpt]);
   66: 		vrrp_interface_vripaddr_delete(vr_ptr[cpt]);
   67: 		close(vr_ptr[cpt]->sd);
   68: 		close(vr_ptr[cpt]->ioctl_sd);
   69: 		cpt++;
   70: 	}
   71: 	vrrp_thread_mutex_unlock();
   72: 
   73: 	exit(0);
   74: }
   75: 
   76: /*
   77:  * Shutdown A REGARDER DE PLUS PRES PAR RAPPORT A LA RFC A QUOI CA SERT CE
   78:  * TRUC ???
   79:  */
   80: void 
   81: vrrp_signal_shutdown(int sig)
   82: {
   83: 	int             cpt = 0;
   84: 
   85: 	while (vr_ptr[cpt]) {
   86: 		switch (vr_ptr[cpt]->state) {
   87: 		case VRRP_STATE_MASTER:
   88: 			vr_ptr[cpt]->priority = 0;
   89: 			vrrp_network_send_advertisement(vr_ptr[cpt]);
   90: 		case VRRP_STATE_BACKUP:
   91: 			vrrp_state_initialize(vr_ptr[cpt]);
   92: 		}
   93: 		cpt++;
   94: 	}
   95: 
   96: 	return;
   97: }

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>