mirror of
https://github.com/servalproject/serval-dna.git
synced 2024-12-18 20:57:56 +00:00
Replace cf_on_config_change() with "config_change" trigger
This is required to support feature-driven linking, in which the exact list of which functions to call in response to a configuration re-load is not known until link time. The "config_change_log" trigger is called before "config_change", so that the logger can respond to the change before other subsystems.
This commit is contained in:
parent
6dd823a9e8
commit
8cb3afa7dc
19
conf.c
19
conf.c
@ -236,12 +236,27 @@ static int reload_and_parse(int permissive, int strict)
|
||||
cf_limbo = 0; // let log messages out
|
||||
logFlush();
|
||||
if (changed) {
|
||||
logConfigChanged();
|
||||
cf_on_config_change();
|
||||
CALL_TRIGGER(config_change_log);
|
||||
CALL_TRIGGER(config_change);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
// Put a dummy no-op trigger callback into the "config_change" and "config_change_log" trigger
|
||||
// sections, otherwise if no other object provides one, the link will fail with errors like:
|
||||
// undefined reference to `__start_tr_config_change'
|
||||
// undefined reference to `__stop_tr_config_change'
|
||||
|
||||
static void __dummy_on_config_change_log();
|
||||
DEFINE_TRIGGER(config_change_log, __dummy_on_config_change_log);
|
||||
static void __dummy_on_config_change_log() {}
|
||||
|
||||
static void __dummy_on_config_change();
|
||||
DEFINE_TRIGGER(config_change, __dummy_on_config_change);
|
||||
static void __dummy_on_config_change() {}
|
||||
|
||||
// The configuration API entry points.
|
||||
|
||||
int cf_load()
|
||||
{
|
||||
conffile_meta = config_meta = FILE_META_UNKNOWN;
|
||||
|
4
conf.h
4
conf.h
@ -233,6 +233,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
#include "rhizome_types.h"
|
||||
#include "strbuf.h"
|
||||
#include "httpd.h"
|
||||
#include "trigger.h"
|
||||
|
||||
#define CONFIG_FILE_MAX_SIZE (32 * 1024)
|
||||
#define INTERFACE_NAME_STRLEN 40
|
||||
@ -713,6 +714,7 @@ int cf_reload(void);
|
||||
int cf_reload_strict(void);
|
||||
int cf_reload_permissive(void);
|
||||
|
||||
void cf_on_config_change(void);
|
||||
DECLARE_TRIGGER(config_change_log);
|
||||
DECLARE_TRIGGER(config_change);
|
||||
|
||||
#endif //__SERVAL_DNA__CONF_H
|
||||
|
@ -191,10 +191,6 @@ static void resolve_request(){
|
||||
}
|
||||
}
|
||||
|
||||
void cf_on_config_change()
|
||||
{
|
||||
}
|
||||
|
||||
int main(void){
|
||||
struct pollfd fds[2];
|
||||
int mdp_sockfd;
|
||||
|
@ -60,8 +60,6 @@ struct radio_state {
|
||||
#define STATE_PLUSPLUSPLUS 3
|
||||
#define STATE_COMMAND 4
|
||||
|
||||
void cf_on_config_change(){}
|
||||
|
||||
void log_time(){
|
||||
struct timeval tv;
|
||||
struct tm tm;
|
||||
|
4
log.c
4
log.c
@ -669,7 +669,9 @@ void vlogMessage(int level, struct __sourceloc whence, const char *fmt, va_list
|
||||
}
|
||||
}
|
||||
|
||||
void logConfigChanged()
|
||||
static void logConfigChanged();
|
||||
DEFINE_TRIGGER(config_change_log, logConfigChanged);
|
||||
static void logConfigChanged()
|
||||
{
|
||||
_log_iterator it;
|
||||
_log_iterator_start(&it);
|
||||
|
3
log.h
3
log.h
@ -1,4 +1,6 @@
|
||||
/*
|
||||
Serval DNA logging
|
||||
Copyright (C) 2016 Flinders University
|
||||
Copyright (C) 2012-2015 Serval Project Inc.
|
||||
|
||||
This program is free software; you can redistribute it and/or
|
||||
@ -52,7 +54,6 @@ extern int logLevel_NoLogFileConfigured;
|
||||
void close_log_file();
|
||||
void redirect_stderr_to_log();
|
||||
void logFlush();
|
||||
void logConfigChanged();
|
||||
|
||||
// Logging context string.
|
||||
struct strbuf;
|
||||
|
@ -1,25 +0,0 @@
|
||||
/*
|
||||
Serval DNA logging
|
||||
Copyright 2016 Flinders University
|
||||
|
||||
This program is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU General Public License
|
||||
as published by the Free Software Foundation; either version 2
|
||||
of the License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
// This compilation unit provides an on_log_config_change() function for
|
||||
// clients that do not define their own.
|
||||
|
||||
#include "log.h"
|
||||
|
||||
void cf_on_config_change() {}
|
@ -88,7 +88,3 @@ void logFlush()
|
||||
{
|
||||
fflush(stderr);
|
||||
}
|
||||
|
||||
void logConfigChanged()
|
||||
{
|
||||
}
|
||||
|
9
server.c
9
server.c
@ -36,6 +36,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
#include "server.h"
|
||||
#include "serval.h"
|
||||
#include "conf.h"
|
||||
#include "log.h"
|
||||
#include "str.h"
|
||||
#include "numeric_str.h"
|
||||
#include "strbuf.h"
|
||||
@ -273,7 +274,7 @@ int server_bind()
|
||||
|
||||
void server_loop(time_ms_t (*waiting)(time_ms_t, time_ms_t, time_ms_t), void (*wokeup)())
|
||||
{
|
||||
cf_on_config_change();
|
||||
CALL_TRIGGER(config_change);
|
||||
|
||||
// This log message is used by tests to wait for the server to start.
|
||||
INFOF("Server initialised, entering main loop");
|
||||
@ -512,7 +513,11 @@ void rhizome_clean_db(struct sched_ent *alarm)
|
||||
RESCHEDULE(alarm, now + 30*60*1000, TIME_MS_NEVER_WILL, TIME_MS_NEVER_WILL);
|
||||
}
|
||||
|
||||
void cf_on_config_change()
|
||||
static void server_on_config_change();
|
||||
|
||||
DEFINE_TRIGGER(config_change, server_on_config_change);
|
||||
|
||||
static void server_on_config_change()
|
||||
{
|
||||
if (!serverMode)
|
||||
return;
|
||||
|
@ -109,10 +109,6 @@ struct command_state *stdin_state;
|
||||
struct network *networks=NULL;
|
||||
static void unicast_alarm(struct sched_ent *alarm);
|
||||
|
||||
void cf_on_config_change()
|
||||
{
|
||||
}
|
||||
|
||||
static void recv_packet(int fd, struct network *network, struct peer *destination)
|
||||
{
|
||||
struct socket_address addr;
|
||||
|
Loading…
Reference in New Issue
Block a user