Пример #1
0
int event_notify(conf_t *conf, zone_t *zone)
{
	assert(zone);

	/* Check zone contents. */
	if (zone_contents_is_empty(zone->contents)) {
		return KNOT_EOK;
	}

	/* Walk through configured remotes and send messages. */
	conf_val_t notify = conf_zone_get(conf, C_NOTIFY, zone->name);
	while (notify.code == KNOT_EOK) {
		conf_val_t addr = conf_id_get(conf, C_RMT, C_ADDR, &notify);
		size_t addr_count = conf_val_count(&addr);

		for (int i = 0; i < addr_count; i++) {
			conf_remote_t slave = conf_remote(conf, &notify, i);
			int ret = zone_query_execute(conf, zone, KNOT_QUERY_NOTIFY, &slave);
			if (ret == KNOT_EOK) {
				ZONE_QUERY_LOG(LOG_INFO, zone, &slave,
				               "NOTIFY, outgoing", "serial %u",
				               zone_contents_serial(zone->contents));
				break;
			} else {
				ZONE_QUERY_LOG(LOG_WARNING, zone, &slave,
				               "NOTIFY, outgoing", "failed (%s)",
				               knot_strerror(ret));
			}
		}

		conf_val_next(&notify);
	}

	return KNOT_EOK;
}
Пример #2
0
Файл: log.c Проект: jkadlec/knot
int log_reconfigure(conf_t *conf, void *data)
{
	// Data not used
	UNUSED(data);

	// Use defaults if no 'log' section is configured.
	if (conf_id_count(conf, C_LOG) == 0) {
		log_close();
		log_init();
		return KNOT_EOK;
	}

	// Find maximum log facility id
	unsigned files = 0;
	conf_iter_t iter = conf_iter(conf, C_LOG);
	while (iter.code == KNOT_EOK) {
		conf_val_t id = conf_iter_id(conf, &iter);
		if (get_logtype(conf_str(&id)) == LOGT_FILE) {
			++files;
		}

		conf_iter_next(conf, &iter);
	}
	conf_iter_finish(conf, &iter);

	// Initialize logsystem
	struct log_sink *log = sink_setup(files);
	if (log == NULL) {
		return KNOT_ENOMEM;
	}

	// Setup logs
	iter = conf_iter(conf, C_LOG);
	while (iter.code == KNOT_EOK) {
		conf_val_t id = conf_iter_id(conf, &iter);
		const char *logname = conf_str(&id);

		// Get facility.
		int facility = get_logtype(logname);
		if (facility == LOGT_FILE) {
			facility = log_open_file(log, logname);
			if (facility < 0) {
				log_error("failed to open log, file '%s'",
				          logname);
				conf_iter_next(conf, &iter);
				continue;
			}
		}

		conf_val_t level_val;
		unsigned level;

		// Set SERVER logging.
		level_val = conf_id_get(conf, C_LOG, C_SERVER, &id);
		level = conf_opt(&level_val);
		sink_levels_add(log, facility, LOG_SERVER, level);

		// Set ZONE logging.
		level_val = conf_id_get(conf, C_LOG, C_ZONE, &id);
		level = conf_opt(&level_val);
		sink_levels_add(log, facility, LOG_ZONE, level);

		// Set ANY logging.
		level_val = conf_id_get(conf, C_LOG, C_ANY, &id);
		level = conf_opt(&level_val);
		sink_levels_add(log, facility, LOG_ANY, level);

		conf_iter_next(conf, &iter);
	}
	conf_iter_finish(conf, &iter);

	sink_publish(log);

	return KNOT_EOK;
}