Exemple #1
0
void sighup_cb(struct ev_loop *loop, struct ev_signal *w, int revents)
{
	g_warning("%s loop %p w %p revents %i",__PRETTY_FUNCTION__, loop, w, revents);

	g_info("Reloading config");
	if( (g_dionaea->config.config = lcfg_new(g_dionaea->config.name)) == NULL )
	{
		g_critical("config not found");
	}

	if( lcfg_parse(g_dionaea->config.config) != lcfg_status_ok )
	{
		g_critical("lcfg error: %s\n", lcfg_error_get(g_dionaea->config.config));
	}

	g_dionaea->config.root = lcfgx_tree_new(g_dionaea->config.config);


	// modules ...
	modules_hup();

	// loggers hup
	for( GList *it = g_dionaea->logging->loggers; it != NULL; it = it->next )
	{
		struct logger *l = it->data;
		g_message("Logger %p hup %p", l, l->log);
		if( l->hup != NULL )
			l->hup(l, l->data);
	}
}
void main_config_hup(void)
{
	cached_config_t *cc;
	CONF_SECTION *cs;
	char buffer[1024];

	INFO("HUP - Re-reading configuration files");

	/* Read the configuration file */
	snprintf(buffer, sizeof(buffer), "%.200s/%.50s.conf",
		 radius_dir, main_config.name);
	if ((cs = cf_file_read(buffer)) == NULL) {
		ERROR("Failed to re-read or parse %s", buffer);
		return;
	}

	cc = talloc_zero(cs_cache, cached_config_t);
	if (!cc) {
		ERROR("Out of memory");
		return;
	}

	/*
	 *	Save the current configuration.  Note that we do NOT
	 *	free older ones.  We should probably do so at some
	 *	point.  Doing so will require us to mark which modules
	 *	are still in use, and which aren't.  Modules that
	 *	can't be HUPed always use the original configuration.
	 *	Modules that can be HUPed use one of the newer
	 *	configurations.
	 */
	cc->created = time(NULL);
	cc->cs = talloc_steal(cc, cs);
	cc->next = cs_cache;
	cs_cache = cc;

	/*
	 *	Re-open the log file.  If we can't, then keep logging
	 *	to the old log file.
	 *
	 *	The "open log file" code is here rather than in log.c,
	 *	because it makes that function MUCH simpler.
	 */
	hup_logfile();

	INFO("HUP - loading modules");

	/*
	 *	Prefer the new module configuration.
	 */
	modules_hup(cf_section_sub_find(cs, "modules"));

	/*
	 *	Load new servers BEFORE freeing old ones.
	 */
	virtual_servers_load(cs);

	virtual_servers_free(cc->created - main_config.max_request_time * 4);
}