1 | /********************************************************************************************************* |
---|
2 | * Software License Agreement (BSD License) * |
---|
3 | * Author: Sebastien Decugis <sdecugis@nict.go.jp> * |
---|
4 | * * |
---|
5 | * Copyright (c) 2009, WIDE Project and NICT * |
---|
6 | * All rights reserved. * |
---|
7 | * * |
---|
8 | * Redistribution and use of this software in source and binary forms, with or without modification, are * |
---|
9 | * permitted provided that the following conditions are met: * |
---|
10 | * * |
---|
11 | * * Redistributions of source code must retain the above * |
---|
12 | * copyright notice, this list of conditions and the * |
---|
13 | * following disclaimer. * |
---|
14 | * * |
---|
15 | * * Redistributions in binary form must reproduce the above * |
---|
16 | * copyright notice, this list of conditions and the * |
---|
17 | * following disclaimer in the documentation and/or other * |
---|
18 | * materials provided with the distribution. * |
---|
19 | * * |
---|
20 | * * Neither the name of the WIDE Project or NICT nor the * |
---|
21 | * names of its contributors may be used to endorse or * |
---|
22 | * promote products derived from this software without * |
---|
23 | * specific prior written permission of WIDE Project and * |
---|
24 | * NICT. * |
---|
25 | * * |
---|
26 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED * |
---|
27 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A * |
---|
28 | * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR * |
---|
29 | * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * |
---|
30 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS * |
---|
31 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR * |
---|
32 | * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF * |
---|
33 | * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * |
---|
34 | *********************************************************************************************************/ |
---|
35 | |
---|
36 | /* Monitoring extension: |
---|
37 | - periodically display queues and peers information |
---|
38 | - upon SIGUSR1, display additional debug information |
---|
39 | */ |
---|
40 | |
---|
41 | #include <freeDiameter/extension.h> |
---|
42 | #include <signal.h> |
---|
43 | |
---|
44 | static int monitor_main(char * conffile); |
---|
45 | |
---|
46 | EXTENSION_ENTRY("monitor", monitor_main); |
---|
47 | |
---|
48 | /* Function called on receipt of SIGUSR1 */ |
---|
49 | static void got_sig(int signal) |
---|
50 | { |
---|
51 | CHECK_FCT_DO(fd_event_send(fd_g_config->cnf_main_ev, FDEV_DUMP_DICT, 0, NULL), /* continue */); |
---|
52 | CHECK_FCT_DO(fd_event_send(fd_g_config->cnf_main_ev, FDEV_DUMP_CONFIG, 0, NULL), /* continue */); |
---|
53 | CHECK_FCT_DO(fd_event_send(fd_g_config->cnf_main_ev, FDEV_DUMP_EXT, 0, NULL), /* continue */); |
---|
54 | } |
---|
55 | /* Thread to display periodical debug information */ |
---|
56 | static pthread_t thr; |
---|
57 | static void * mn_thr(void * arg) |
---|
58 | { |
---|
59 | sigset_t sig; |
---|
60 | struct sigaction act; |
---|
61 | fd_log_threadname("Monitor thread"); |
---|
62 | |
---|
63 | /* Catch signal SIGUSR1 */ |
---|
64 | memset(&act, 0, sizeof(act)); |
---|
65 | act.sa_handler = got_sig; |
---|
66 | CHECK_SYS_DO( sigaction(SIGUSR1, &act, NULL), /* conitnue */ ); |
---|
67 | sigemptyset(&sig); |
---|
68 | sigaddset(&sig, SIGUSR1); |
---|
69 | CHECK_POSIX_DO( pthread_sigmask(SIG_UNBLOCK, &sig, NULL), /* conitnue */ ); |
---|
70 | |
---|
71 | /* Loop */ |
---|
72 | while (1) { |
---|
73 | #ifdef DEBUG |
---|
74 | sleep(30); |
---|
75 | #else /* DEBUG */ |
---|
76 | sleep(3600); /* 1 hour */ |
---|
77 | #endif /* DEBUG */ |
---|
78 | TRACE_DEBUG(NONE, "Monitor information"); |
---|
79 | CHECK_FCT_DO(fd_event_send(fd_g_config->cnf_main_ev, FDEV_DUMP_QUEUES, 0, NULL), /* continue */); |
---|
80 | CHECK_FCT_DO(fd_event_send(fd_g_config->cnf_main_ev, FDEV_DUMP_SERV, 0, NULL), /* continue */); |
---|
81 | CHECK_FCT_DO(fd_event_send(fd_g_config->cnf_main_ev, FDEV_DUMP_PEERS, 0, NULL), /* continue */); |
---|
82 | pthread_testcancel(); |
---|
83 | } |
---|
84 | |
---|
85 | return NULL; |
---|
86 | } |
---|
87 | |
---|
88 | static int monitor_main(char * conffile) |
---|
89 | { |
---|
90 | TRACE_ENTRY("%p", conffile); |
---|
91 | CHECK_POSIX( pthread_create( &thr, NULL, mn_thr, NULL ) ); |
---|
92 | return 0; |
---|
93 | } |
---|
94 | |
---|
95 | void fd_ext_fini(void) |
---|
96 | { |
---|
97 | TRACE_ENTRY(); |
---|
98 | CHECK_FCT_DO( fd_thr_term(&thr), /* continue */ ); |
---|
99 | return ; |
---|
100 | } |
---|
101 | |
---|