Exemplo n.º 1
0
/*-----------------------------------------------------------------------------------*/
LOADER_INIT_FUNC(config_init, arg)
{
  arg_free(arg);
  config_load();
  config_apply();
  LOADER_UNLOAD();
}
Exemplo n.º 2
0
void daemon_apply_cfg(struct daemon* daemon, struct config_file* cfg)
{
        daemon->cfg = cfg;
	config_apply(cfg);
	if(!slabhash_is_size(daemon->env->msg_cache, cfg->msg_cache_size,
	   	cfg->msg_cache_slabs)) {
		slabhash_delete(daemon->env->msg_cache);
		daemon->env->msg_cache = slabhash_create(cfg->msg_cache_slabs,
			HASH_DEFAULT_STARTARRAY, cfg->msg_cache_size,
			msgreply_sizefunc, query_info_compare,
			query_entry_delete, reply_info_delete, NULL);
		if(!daemon->env->msg_cache) {
			fatal_exit("malloc failure updating config settings");
		}
	}
	if((daemon->env->rrset_cache = rrset_cache_adjust(
		daemon->env->rrset_cache, cfg, &daemon->superalloc)) == 0)
		fatal_exit("malloc failure updating config settings");
	if((daemon->env->infra_cache = infra_adjust(daemon->env->infra_cache,
		cfg))==0)
		fatal_exit("malloc failure updating config settings");
}
Exemplo n.º 3
0
int 
context_finalize(struct ub_ctx* ctx)
{
	struct config_file* cfg = ctx->env->cfg;
	verbosity = cfg->verbosity;
	if(ctx->logfile_override)
		log_file(ctx->log_out);
	else	log_init(cfg->logfile, cfg->use_syslog, NULL);
	config_apply(cfg);
	if(!modstack_setup(&ctx->mods, cfg->module_conf, ctx->env))
		return UB_INITFAIL;
	ctx->local_zones = local_zones_create();
	if(!ctx->local_zones)
		return UB_NOMEM;
	if(!local_zones_apply_cfg(ctx->local_zones, cfg))
		return UB_INITFAIL;
	if(!ctx->env->msg_cache ||
	   cfg->msg_cache_size != slabhash_get_size(ctx->env->msg_cache) || 
	   cfg->msg_cache_slabs != ctx->env->msg_cache->size) {
		slabhash_delete(ctx->env->msg_cache);
		ctx->env->msg_cache = slabhash_create(cfg->msg_cache_slabs,
			HASH_DEFAULT_STARTARRAY, cfg->msg_cache_size,
			msgreply_sizefunc, query_info_compare,
			query_entry_delete, reply_info_delete, NULL);
		if(!ctx->env->msg_cache)
			return UB_NOMEM;
	}
	ctx->env->rrset_cache = rrset_cache_adjust(ctx->env->rrset_cache,
		ctx->env->cfg, ctx->env->alloc);
	if(!ctx->env->rrset_cache)
		return UB_NOMEM;
	ctx->env->infra_cache = infra_adjust(ctx->env->infra_cache, cfg);
	if(!ctx->env->infra_cache)
		return UB_NOMEM;
	ctx->finalized = 1;
	return UB_NOERROR;
}
Exemplo n.º 4
0
int main(int argc, char **argv) {
    // For connect/authenticate failures
    int reconnect_delay = 1;

    // RingBuffer buffer for the writer
    char *writer_buffer = 0;

    LINFO("%s starting", APP_NAME);

    config_init(argc > 1 ? argv[1] : 0);
    pthread_create(&config.timer_thread.thread, 0, timer_thread_entry, (void *)&config.timer_thread);
    if (!config_read()) {
        return 1;
    }

    load_data();

    sighelper_sigaction(SIGHUP, reload_config);
    sighelper_sigaction(SIGUSR1, save_data);
    sighelper_sigaction(SIGTERM, terminate);
    sighelper_sigaction(SIGQUIT, terminate);
    sighelper_sigaction(SIGINT, terminate);

    LDEBUG("allocating writer buffer, size %d", config.writer.buffer);
    writer_buffer = malloc(config.writer.buffer);
    ringbuffer_init(&config.writer_thread.ringbuffer,
                    writer_buffer, config.writer.buffer);

    LDEBUG("creating reader queue, size %d", config.reader.queue);
    queue_init(&config.reader_thread.queue, config.reader.queue);

    while (running) {
        LINFO("connecting to %s:%d", config.network.host, config.network.port);

        if (net_connect(&config.socket, config.network.host, config.network.port)) {
            LINFO("opening XMPP stream to %s", config.component.hostname);
            if (!net_stream(&config.socket,
                            "xmcomp",
                            config.component.hostname,
                            config.component.password)) {
                net_disconnect(&config.socket);
            }
        }

        if (!config.socket.connected) {
            LERROR("retrying in %d second(s)", reconnect_delay);
            sleep(reconnect_delay);
            if (reconnect_delay < 60) {
                reconnect_delay <<= 1;
            }
            continue;
        }
        reconnect_delay = 1;

        LINFO("creating writer thread");
        config.writer_thread.socket = &config.socket;
        config.writer_thread.enabled = TRUE;
        pthread_create(&config.writer_thread.thread, 0, writer_thread_entry, (void *)&config.writer_thread);

        LINFO("creating reader thread");
        config.reader_thread.socket = &config.socket;
        config.reader_thread.enabled = TRUE;
        pthread_create(&config.reader_thread.thread, 0, reader_thread_entry, (void *)&config.reader_thread);

        LINFO("creating worker threads");
        config_apply();

        LINFO("started");
        LDEBUG("joining reader thread");
        pthread_join(config.reader_thread.thread, 0);
        // Switch ringbuffer to offline, indicating no more data is expected.
        // As soon as the writer finishes the job, it will terminate
        ringbuffer_offline(&config.writer_thread.ringbuffer);
        LDEBUG("joining writer thread");
        pthread_join(config.writer_thread.thread, 0);

        LINFO("clearing output buffer and disconnecting");
        ringbuffer_clear(&config.writer_thread.ringbuffer);

        net_unstream(&config.socket);
        net_disconnect(&config.socket);
    }

    LINFO("cleaning up");
    ringbuffer_destroy(&config.writer_thread.ringbuffer);
    queue_destroy(&config.reader_thread.queue);
    free(writer_buffer);
    config_destroy();

    return 0;
}
Exemplo n.º 5
0
static void reload_config(int signal) {
    config_read();
    config_apply();
}