annotate extensions/dbg_loglevel/dbg_loglevel.c @ 1345:51a0521cd065

dbg_loglevel: new extension that allows changing the log level at runtime
author Thomas Klausner <tk@giga.or.at>
date Sun, 12 May 2019 10:35:46 +0200
parents
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1345
51a0521cd065 dbg_loglevel: new extension that allows changing the log level at runtime
Thomas Klausner <tk@giga.or.at>
parents:
diff changeset
1 /*********************************************************************************************************
51a0521cd065 dbg_loglevel: new extension that allows changing the log level at runtime
Thomas Klausner <tk@giga.or.at>
parents:
diff changeset
2 * Software License Agreement (BSD License) *
51a0521cd065 dbg_loglevel: new extension that allows changing the log level at runtime
Thomas Klausner <tk@giga.or.at>
parents:
diff changeset
3 * Author: Thomas Klausner <tk@giga.or.at> *
51a0521cd065 dbg_loglevel: new extension that allows changing the log level at runtime
Thomas Klausner <tk@giga.or.at>
parents:
diff changeset
4 * *
51a0521cd065 dbg_loglevel: new extension that allows changing the log level at runtime
Thomas Klausner <tk@giga.or.at>
parents:
diff changeset
5 * Copyright (c) 2019, Thomas Klausner *
51a0521cd065 dbg_loglevel: new extension that allows changing the log level at runtime
Thomas Klausner <tk@giga.or.at>
parents:
diff changeset
6 * All rights reserved. *
51a0521cd065 dbg_loglevel: new extension that allows changing the log level at runtime
Thomas Klausner <tk@giga.or.at>
parents:
diff changeset
7 * *
51a0521cd065 dbg_loglevel: new extension that allows changing the log level at runtime
Thomas Klausner <tk@giga.or.at>
parents:
diff changeset
8 * Written under contract by Effortel Technologies SA, http://effortel.com/ *
51a0521cd065 dbg_loglevel: new extension that allows changing the log level at runtime
Thomas Klausner <tk@giga.or.at>
parents:
diff changeset
9 * *
51a0521cd065 dbg_loglevel: new extension that allows changing the log level at runtime
Thomas Klausner <tk@giga.or.at>
parents:
diff changeset
10 * Redistribution and use of this software in source and binary forms, with or without modification, are *
51a0521cd065 dbg_loglevel: new extension that allows changing the log level at runtime
Thomas Klausner <tk@giga.or.at>
parents:
diff changeset
11 * permitted provided that the following conditions are met: *
51a0521cd065 dbg_loglevel: new extension that allows changing the log level at runtime
Thomas Klausner <tk@giga.or.at>
parents:
diff changeset
12 * *
51a0521cd065 dbg_loglevel: new extension that allows changing the log level at runtime
Thomas Klausner <tk@giga.or.at>
parents:
diff changeset
13 * * Redistributions of source code must retain the above *
51a0521cd065 dbg_loglevel: new extension that allows changing the log level at runtime
Thomas Klausner <tk@giga.or.at>
parents:
diff changeset
14 * copyright notice, this list of conditions and the *
51a0521cd065 dbg_loglevel: new extension that allows changing the log level at runtime
Thomas Klausner <tk@giga.or.at>
parents:
diff changeset
15 * following disclaimer. *
51a0521cd065 dbg_loglevel: new extension that allows changing the log level at runtime
Thomas Klausner <tk@giga.or.at>
parents:
diff changeset
16 * *
51a0521cd065 dbg_loglevel: new extension that allows changing the log level at runtime
Thomas Klausner <tk@giga.or.at>
parents:
diff changeset
17 * * Redistributions in binary form must reproduce the above *
51a0521cd065 dbg_loglevel: new extension that allows changing the log level at runtime
Thomas Klausner <tk@giga.or.at>
parents:
diff changeset
18 * copyright notice, this list of conditions and the *
51a0521cd065 dbg_loglevel: new extension that allows changing the log level at runtime
Thomas Klausner <tk@giga.or.at>
parents:
diff changeset
19 * following disclaimer in the documentation and/or other *
51a0521cd065 dbg_loglevel: new extension that allows changing the log level at runtime
Thomas Klausner <tk@giga.or.at>
parents:
diff changeset
20 * materials provided with the distribution. *
51a0521cd065 dbg_loglevel: new extension that allows changing the log level at runtime
Thomas Klausner <tk@giga.or.at>
parents:
diff changeset
21 * *
51a0521cd065 dbg_loglevel: new extension that allows changing the log level at runtime
Thomas Klausner <tk@giga.or.at>
parents:
diff changeset
22 * * Neither the name of the WIDE Project or NICT nor the *
51a0521cd065 dbg_loglevel: new extension that allows changing the log level at runtime
Thomas Klausner <tk@giga.or.at>
parents:
diff changeset
23 * names of its contributors may be used to endorse or *
51a0521cd065 dbg_loglevel: new extension that allows changing the log level at runtime
Thomas Klausner <tk@giga.or.at>
parents:
diff changeset
24 * promote products derived from this software without *
51a0521cd065 dbg_loglevel: new extension that allows changing the log level at runtime
Thomas Klausner <tk@giga.or.at>
parents:
diff changeset
25 * specific prior written permission of WIDE Project and *
51a0521cd065 dbg_loglevel: new extension that allows changing the log level at runtime
Thomas Klausner <tk@giga.or.at>
parents:
diff changeset
26 * NICT. *
51a0521cd065 dbg_loglevel: new extension that allows changing the log level at runtime
Thomas Klausner <tk@giga.or.at>
parents:
diff changeset
27 * *
51a0521cd065 dbg_loglevel: new extension that allows changing the log level at runtime
Thomas Klausner <tk@giga.or.at>
parents:
diff changeset
28 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED *
51a0521cd065 dbg_loglevel: new extension that allows changing the log level at runtime
Thomas Klausner <tk@giga.or.at>
parents:
diff changeset
29 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A *
51a0521cd065 dbg_loglevel: new extension that allows changing the log level at runtime
Thomas Klausner <tk@giga.or.at>
parents:
diff changeset
30 * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR *
51a0521cd065 dbg_loglevel: new extension that allows changing the log level at runtime
Thomas Klausner <tk@giga.or.at>
parents:
diff changeset
31 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT *
51a0521cd065 dbg_loglevel: new extension that allows changing the log level at runtime
Thomas Klausner <tk@giga.or.at>
parents:
diff changeset
32 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS *
51a0521cd065 dbg_loglevel: new extension that allows changing the log level at runtime
Thomas Klausner <tk@giga.or.at>
parents:
diff changeset
33 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR *
51a0521cd065 dbg_loglevel: new extension that allows changing the log level at runtime
Thomas Klausner <tk@giga.or.at>
parents:
diff changeset
34 * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF *
51a0521cd065 dbg_loglevel: new extension that allows changing the log level at runtime
Thomas Klausner <tk@giga.or.at>
parents:
diff changeset
35 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. *
51a0521cd065 dbg_loglevel: new extension that allows changing the log level at runtime
Thomas Klausner <tk@giga.or.at>
parents:
diff changeset
36 *********************************************************************************************************/
51a0521cd065 dbg_loglevel: new extension that allows changing the log level at runtime
Thomas Klausner <tk@giga.or.at>
parents:
diff changeset
37
51a0521cd065 dbg_loglevel: new extension that allows changing the log level at runtime
Thomas Klausner <tk@giga.or.at>
parents:
diff changeset
38 #include <signal.h>
51a0521cd065 dbg_loglevel: new extension that allows changing the log level at runtime
Thomas Klausner <tk@giga.or.at>
parents:
diff changeset
39
51a0521cd065 dbg_loglevel: new extension that allows changing the log level at runtime
Thomas Klausner <tk@giga.or.at>
parents:
diff changeset
40 /* See doc/dbg_loglevel.conf.sample for more details about the features of this extension */
51a0521cd065 dbg_loglevel: new extension that allows changing the log level at runtime
Thomas Klausner <tk@giga.or.at>
parents:
diff changeset
41 #include "dbg_loglevel.h"
51a0521cd065 dbg_loglevel: new extension that allows changing the log level at runtime
Thomas Klausner <tk@giga.or.at>
parents:
diff changeset
42
51a0521cd065 dbg_loglevel: new extension that allows changing the log level at runtime
Thomas Klausner <tk@giga.or.at>
parents:
diff changeset
43 static char *config_file = NULL;
51a0521cd065 dbg_loglevel: new extension that allows changing the log level at runtime
Thomas Klausner <tk@giga.or.at>
parents:
diff changeset
44 #define MODULE_NAME "dbg_loglevel"
51a0521cd065 dbg_loglevel: new extension that allows changing the log level at runtime
Thomas Klausner <tk@giga.or.at>
parents:
diff changeset
45
51a0521cd065 dbg_loglevel: new extension that allows changing the log level at runtime
Thomas Klausner <tk@giga.or.at>
parents:
diff changeset
46 static void sig_hdlr(void)
51a0521cd065 dbg_loglevel: new extension that allows changing the log level at runtime
Thomas Klausner <tk@giga.or.at>
parents:
diff changeset
47 {
51a0521cd065 dbg_loglevel: new extension that allows changing the log level at runtime
Thomas Klausner <tk@giga.or.at>
parents:
diff changeset
48 int old_log_level;
51a0521cd065 dbg_loglevel: new extension that allows changing the log level at runtime
Thomas Klausner <tk@giga.or.at>
parents:
diff changeset
49
51a0521cd065 dbg_loglevel: new extension that allows changing the log level at runtime
Thomas Klausner <tk@giga.or.at>
parents:
diff changeset
50 old_log_level = fd_g_debug_lvl;
51a0521cd065 dbg_loglevel: new extension that allows changing the log level at runtime
Thomas Klausner <tk@giga.or.at>
parents:
diff changeset
51 if (dbg_loglevel_conf_handle(config_file) != 0) {
51a0521cd065 dbg_loglevel: new extension that allows changing the log level at runtime
Thomas Klausner <tk@giga.or.at>
parents:
diff changeset
52 fd_log_error("%s: error during config file reload, restoring previous value", MODULE_NAME);
51a0521cd065 dbg_loglevel: new extension that allows changing the log level at runtime
Thomas Klausner <tk@giga.or.at>
parents:
diff changeset
53 fd_g_debug_lvl = old_log_level;
51a0521cd065 dbg_loglevel: new extension that allows changing the log level at runtime
Thomas Klausner <tk@giga.or.at>
parents:
diff changeset
54 }
51a0521cd065 dbg_loglevel: new extension that allows changing the log level at runtime
Thomas Klausner <tk@giga.or.at>
parents:
diff changeset
55 fd_log_notice("%s: reloaded configuration, log level now %d", MODULE_NAME, fd_g_debug_lvl);
51a0521cd065 dbg_loglevel: new extension that allows changing the log level at runtime
Thomas Klausner <tk@giga.or.at>
parents:
diff changeset
56 }
51a0521cd065 dbg_loglevel: new extension that allows changing the log level at runtime
Thomas Klausner <tk@giga.or.at>
parents:
diff changeset
57
51a0521cd065 dbg_loglevel: new extension that allows changing the log level at runtime
Thomas Klausner <tk@giga.or.at>
parents:
diff changeset
58 /* entry point */
51a0521cd065 dbg_loglevel: new extension that allows changing the log level at runtime
Thomas Klausner <tk@giga.or.at>
parents:
diff changeset
59 static int dbg_loglevel_entry(char * conffile)
51a0521cd065 dbg_loglevel: new extension that allows changing the log level at runtime
Thomas Klausner <tk@giga.or.at>
parents:
diff changeset
60 {
51a0521cd065 dbg_loglevel: new extension that allows changing the log level at runtime
Thomas Klausner <tk@giga.or.at>
parents:
diff changeset
61 TRACE_ENTRY("%p", conffile);
51a0521cd065 dbg_loglevel: new extension that allows changing the log level at runtime
Thomas Klausner <tk@giga.or.at>
parents:
diff changeset
62
51a0521cd065 dbg_loglevel: new extension that allows changing the log level at runtime
Thomas Klausner <tk@giga.or.at>
parents:
diff changeset
63 config_file = conffile;
51a0521cd065 dbg_loglevel: new extension that allows changing the log level at runtime
Thomas Klausner <tk@giga.or.at>
parents:
diff changeset
64
51a0521cd065 dbg_loglevel: new extension that allows changing the log level at runtime
Thomas Klausner <tk@giga.or.at>
parents:
diff changeset
65 /* default set by main program */
51a0521cd065 dbg_loglevel: new extension that allows changing the log level at runtime
Thomas Klausner <tk@giga.or.at>
parents:
diff changeset
66 /* fd_g_debug_lvl = FD_LOG_NOTICE; */
51a0521cd065 dbg_loglevel: new extension that allows changing the log level at runtime
Thomas Klausner <tk@giga.or.at>
parents:
diff changeset
67
51a0521cd065 dbg_loglevel: new extension that allows changing the log level at runtime
Thomas Klausner <tk@giga.or.at>
parents:
diff changeset
68 /* Parse the configuration file */
51a0521cd065 dbg_loglevel: new extension that allows changing the log level at runtime
Thomas Klausner <tk@giga.or.at>
parents:
diff changeset
69 CHECK_FCT(dbg_loglevel_conf_handle(config_file));
51a0521cd065 dbg_loglevel: new extension that allows changing the log level at runtime
Thomas Klausner <tk@giga.or.at>
parents:
diff changeset
70
51a0521cd065 dbg_loglevel: new extension that allows changing the log level at runtime
Thomas Klausner <tk@giga.or.at>
parents:
diff changeset
71 /* Register reload callback */
51a0521cd065 dbg_loglevel: new extension that allows changing the log level at runtime
Thomas Klausner <tk@giga.or.at>
parents:
diff changeset
72 CHECK_FCT(fd_event_trig_regcb(SIGUSR1, MODULE_NAME, sig_hdlr));
51a0521cd065 dbg_loglevel: new extension that allows changing the log level at runtime
Thomas Klausner <tk@giga.or.at>
parents:
diff changeset
73
51a0521cd065 dbg_loglevel: new extension that allows changing the log level at runtime
Thomas Klausner <tk@giga.or.at>
parents:
diff changeset
74 fd_log_notice("Extension 'Loglevel' initialized with log level %d", fd_g_debug_lvl);
51a0521cd065 dbg_loglevel: new extension that allows changing the log level at runtime
Thomas Klausner <tk@giga.or.at>
parents:
diff changeset
75
51a0521cd065 dbg_loglevel: new extension that allows changing the log level at runtime
Thomas Klausner <tk@giga.or.at>
parents:
diff changeset
76 /* We're done */
51a0521cd065 dbg_loglevel: new extension that allows changing the log level at runtime
Thomas Klausner <tk@giga.or.at>
parents:
diff changeset
77 return 0;
51a0521cd065 dbg_loglevel: new extension that allows changing the log level at runtime
Thomas Klausner <tk@giga.or.at>
parents:
diff changeset
78 }
51a0521cd065 dbg_loglevel: new extension that allows changing the log level at runtime
Thomas Klausner <tk@giga.or.at>
parents:
diff changeset
79
51a0521cd065 dbg_loglevel: new extension that allows changing the log level at runtime
Thomas Klausner <tk@giga.or.at>
parents:
diff changeset
80 /* Unload */
51a0521cd065 dbg_loglevel: new extension that allows changing the log level at runtime
Thomas Klausner <tk@giga.or.at>
parents:
diff changeset
81 void fd_ext_fini(void)
51a0521cd065 dbg_loglevel: new extension that allows changing the log level at runtime
Thomas Klausner <tk@giga.or.at>
parents:
diff changeset
82 {
51a0521cd065 dbg_loglevel: new extension that allows changing the log level at runtime
Thomas Klausner <tk@giga.or.at>
parents:
diff changeset
83 TRACE_ENTRY();
51a0521cd065 dbg_loglevel: new extension that allows changing the log level at runtime
Thomas Klausner <tk@giga.or.at>
parents:
diff changeset
84
51a0521cd065 dbg_loglevel: new extension that allows changing the log level at runtime
Thomas Klausner <tk@giga.or.at>
parents:
diff changeset
85 /* Nothing to do */
51a0521cd065 dbg_loglevel: new extension that allows changing the log level at runtime
Thomas Klausner <tk@giga.or.at>
parents:
diff changeset
86 return ;
51a0521cd065 dbg_loglevel: new extension that allows changing the log level at runtime
Thomas Klausner <tk@giga.or.at>
parents:
diff changeset
87 }
51a0521cd065 dbg_loglevel: new extension that allows changing the log level at runtime
Thomas Klausner <tk@giga.or.at>
parents:
diff changeset
88
51a0521cd065 dbg_loglevel: new extension that allows changing the log level at runtime
Thomas Klausner <tk@giga.or.at>
parents:
diff changeset
89 EXTENSION_ENTRY(MODULE_NAME, dbg_loglevel_entry);
"Welcome to our mercurial repository"