OpenDNSSEC-signer
1.3.8
|
00001 /* 00002 * $Id: signal.c 4349 2011-02-01 10:42:53Z matthijs $ 00003 * 00004 * Copyright (c) 2009 NLNet Labs. All rights reserved. 00005 * 00006 * Redistribution and use in source and binary forms, with or without 00007 * modification, are permitted provided that the following conditions 00008 * are met: 00009 * 1. Redistributions of source code must retain the above copyright 00010 * notice, this list of conditions and the following disclaimer. 00011 * 2. Redistributions in binary form must reproduce the above copyright 00012 * notice, this list of conditions and the following disclaimer in the 00013 * documentation and/or other materials provided with the distribution. 00014 * 00015 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 00016 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 00017 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 00018 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY 00019 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 00020 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE 00021 * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 00022 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER 00023 * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 00024 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN 00025 * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00026 * 00027 */ 00028 00034 #include "config.h" 00035 #include "daemon/engine.h" 00036 #include "daemon/signal.h" 00037 #include "shared/locks.h" 00038 #include "shared/log.h" 00039 00040 #include <signal.h> 00041 00042 static int signal_hup_recvd = 0; 00043 static int signal_term_recvd = 0; 00044 static engine_type* signal_engine = NULL; 00045 static const char* signal_str = "signal"; 00046 00047 00052 void 00053 signal_set_engine(struct engine_struct* engine) 00054 { 00055 signal_engine = (engine_type*) engine; 00056 } 00057 00058 00063 void 00064 signal_handler(sig_atomic_t sig) 00065 { 00066 switch (sig) { 00067 case SIGHUP: 00068 ods_log_debug("[%s] SIGHUP received", signal_str); 00069 signal_hup_recvd++; 00070 if (signal_engine) { 00071 lock_basic_lock(&signal_engine->signal_lock); 00072 /* [LOCK] signal */ 00073 lock_basic_alarm(&signal_engine->signal_cond); 00074 /* [UNLOCK] signal */ 00075 lock_basic_unlock(&signal_engine->signal_lock); 00076 } 00077 break; 00078 case SIGTERM: 00079 ods_log_debug("[%s] SIGTERM received", signal_str); 00080 signal_term_recvd++; 00081 if (signal_engine) { 00082 lock_basic_lock(&signal_engine->signal_lock); 00083 /* [LOCK] signal */ 00084 lock_basic_alarm(&signal_engine->signal_cond); 00085 /* [UNLOCK] signal */ 00086 lock_basic_unlock(&signal_engine->signal_lock); 00087 } 00088 break; 00089 default: 00090 break; 00091 } 00092 return; 00093 } 00094 00095 00100 sig_atomic_t 00101 signal_capture(sig_atomic_t dflsig) 00102 { 00103 if (signal_term_recvd) { 00104 signal_term_recvd = 0; 00105 return SIGNAL_SHUTDOWN; 00106 } else if (signal_hup_recvd) { 00107 signal_hup_recvd = 0; 00108 return SIGNAL_RELOAD; 00109 } 00110 return dflsig; 00111 }