Example #1
0
void wz_prefork_init(int argc, char **argv)
{
	if (argc < 2) throw std::logic_error("Usage: wz-httpd [--no-daemon] config.xml");

	c_fname = argv[argc - 1];
	log_info("going to read config: %s", c_fname.c_str());
	cfg->load_from_file(c_fname.c_str());

	if (strcmp("--no-daemon", argv[1]))
	{
		if (cfg->r.log_file_name.empty())
		{
			throw std::logic_error("<log_file_name> is not set in config");
		}
		log_info("now logging to '%s'", cfg->r.log_file_name.c_str());
		log_create(cfg->r.log_file_name.c_str(), log_levels(cfg->r.log_level.c_str()));
		doFork = 1;
	}

	cfg->r.finalize();
}
Example #2
0
int ugh_daemon_exec(const char *cfg_filename, unsigned daemon)
{
	int rc;
	ugh_daemon_t d;

	aux_clrptr(&d);

	loop = ev_default_loop(0);

	/* TODO make it possible to set default values for each module config and
	 * global config via ugh_make_command macro (by setting all this at
	 * module_handle_add stage)
	 */
	rc = ugh_config_init(&d.cfg);
	if (0 > rc) return -1;

	rc = ugh_config_load(&d.cfg, cfg_filename);
	if (0 > rc) return -1;

	if (daemon)
	{
		rc = log_create(d.cfg.log_error, log_levels(d.cfg.log_level));
		if (0 > rc) return -1;
	}
	else
	{
		log_level = log_levels(d.cfg.log_level);
	}

	rc = ugh_resolver_init(&d.resolver, &d.cfg);
	if (0 > rc) return -1;

	size_t i;

	for (i = 0; i < ugh_module_handles_size; ++i)
	{
		if (ugh_module_handles[i].module->init)
		{
			rc = ugh_module_handles[i].module->init(&d.cfg, ugh_module_handles[i].config);
			if (0 > rc) return -1;
		}
	}

	rc = ugh_server_listen(&d.srv, &d.cfg, &d.resolver);
	if (0 > rc) return -1;

	ev_timer_init(&d.wev_silent, ugh_wcb_silent, 0, UGH_CONFIG_SILENT_TIMEOUT);
	ev_timer_again(loop, &d.wev_silent);

	ev_run(loop, 0);

	ugh_server_enough(&d.srv);

	for (i = 0; i < ugh_module_handles_size; ++i)
	{
		if (ugh_module_handles[i].module->free)
		{
			rc = ugh_module_handles[i].module->free(&d.cfg, ugh_module_handles[i].config);
			if (0 > rc) return -1;
		}
	}

	ugh_resolver_free(&d.resolver);

	ugh_config_free(&d.cfg);

	return 0;
}
Example #3
0
File: log.c Project: dnstap/knot
int log_levels_add(int facility, logsrc_t src, uint8_t levels)
{
	uint8_t new_levels = log_levels(facility, src) | levels;
	return log_levels_set(facility, src, new_levels);
}