OpenDNSSEC-enforcer  2.0.3
signal.c
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2009 NLNet Labs. All rights reserved.
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions
6  * are met:
7  * 1. Redistributions of source code must retain the above copyright
8  * notice, this list of conditions and the following disclaimer.
9  * 2. Redistributions in binary form must reproduce the above copyright
10  * notice, this list of conditions and the following disclaimer in the
11  * documentation and/or other materials provided with the distribution.
12  *
13  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
14  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
15  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
16  * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
17  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
18  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
19  * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
20  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
21  * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
22  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
23  * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24  *
25  */
26 
32 #include "config.h"
33 
34 #include <pthread.h>
35 #include <signal.h>
36 
37 #include "daemon/engine.h"
38 #include "daemon/signal.h"
39 #include "log.h"
40 
41 #include "signal.h"
42 
43 static engine_type* signal_engine = NULL;
44 static const char* signal_str = "signal";
45 
46 
51 void
53 {
54  signal_engine = (engine_type*) engine;
55 }
56 
57 
62 void *
63 signal_handler(sig_atomic_t sig)
64 {
65  switch (sig) {
66  case SIGHUP:
67  ods_log_debug("[%s] SIGHUP received", signal_str);
68  if (signal_engine) {
69  signal_engine->need_to_reload = 1;
70  pthread_mutex_lock(&signal_engine->signal_lock);
71  pthread_cond_signal(&signal_engine->signal_cond);
72  pthread_mutex_unlock(&signal_engine->signal_lock);
73  }
74  break;
75  case SIGINT:
76  case SIGTERM:
77  ods_log_debug("[%s] SIGTERM received", signal_str);
78  if (signal_engine) {
79  signal_engine->need_to_exit = 1;
80  pthread_mutex_lock(&signal_engine->signal_lock);
81  pthread_cond_signal(&signal_engine->signal_cond);
82  pthread_mutex_unlock(&signal_engine->signal_lock);
83  }
84  break;
85  default:
86  ods_log_debug("[%s] Spurious signal %d received",
87  signal_str, (int)sig);
88  break;
89  }
90  return NULL;
91 }
void ods_log_debug(const char *format,...)
Definition: log.c:41
pthread_cond_t signal_cond
Definition: engine.h:69
void signal_set_engine(struct engine_struct *engine)
Definition: signal.c:52
pthread_mutex_t signal_lock
Definition: engine.h:70
void * signal_handler(sig_atomic_t sig)
Definition: signal.c:63
int need_to_exit
Definition: engine.h:65
int need_to_reload
Definition: engine.h:66