Пример #1
0
/*
 * format set is the only global specific option that
 * doesn't apply at system/subsystem level.
 */
static int corosync_main_config_format_set (
	const char **error_string)
{
	const char *error_reason;
	char new_format_buffer[PATH_MAX];
	char *value = NULL;
	int err = 0;

	if (map_get_string("logging.fileline", &value) == CS_OK) {
		if (strcmp (value, "on") == 0) {
			if (!insert_into_buffer(new_format_buffer,
					sizeof(new_format_buffer),
					" %f:%l", "g]")) {
				err = logsys_format_set(new_format_buffer);
			} else
			if (!insert_into_buffer(new_format_buffer,
					sizeof(new_format_buffer),
					"%f:%l", NULL)) {
				err = logsys_format_set(new_format_buffer);
			}
		} else
		if (strcmp (value, "off") == 0) {
			/* nothing to do here */
		} else {
			error_reason = "unknown value for fileline";
			free(value);
			goto parse_error;
		}

		free(value);
	}

	if (err) {
		error_reason = "not enough memory to set logging format buffer";
		goto parse_error;
	}

	if (map_get_string("logging.function_name", &value) == CS_OK) {
		if (strcmp (value, "on") == 0) {
			if (!insert_into_buffer(new_format_buffer,
					sizeof(new_format_buffer),
					"%n:", "f:")) {
				err = logsys_format_set(new_format_buffer);
			} else
			if (!insert_into_buffer(new_format_buffer,
					sizeof(new_format_buffer),
					" %n", "g]")) {
				err = logsys_format_set(new_format_buffer);
			}
		} else
		if (strcmp (value, "off") == 0) {
			/* nothing to do here */
		} else {
			error_reason = "unknown value for function_name";
			free(value);
			goto parse_error;
		}

		free(value);
	}

	if (err) {
		error_reason = "not enough memory to set logging format buffer";
		goto parse_error;
	}

	if (map_get_string("logging.timestamp", &value) == CS_OK) {
		if (strcmp (value, "on") == 0) {
			if(!insert_into_buffer(new_format_buffer,
					sizeof(new_format_buffer),
					"%t ", NULL)) {
				err = logsys_format_set(new_format_buffer);
			}
		} else
		if (strcmp (value, "off") == 0) {
			/* nothing to do here */
		} else {
			error_reason = "unknown value for timestamp";
			free(value);
			goto parse_error;
		}

		free(value);
	}

	if (err) {
		error_reason = "not enough memory to set logging format buffer";
		goto parse_error;
	}

	return (0);

parse_error:
	*error_string = error_reason;

	return (-1);
}
Пример #2
0
static int corosync_main_config_read_logging (
	const char **error_string)
{
	const char *error_reason;
#ifdef LOGCONFIG_USE_ICMAP
	icmap_iter_t iter;
	const char *key_name;
#else
	cmap_iter_handle_t iter;
	char key_name[CMAP_KEYNAME_MAXLEN];
#endif
	char key_subsys[MAP_KEYNAME_MAXLEN];
	char key_item[MAP_KEYNAME_MAXLEN];
	int res;

	/* format set is supported only for toplevel */
	if (corosync_main_config_format_set(&error_reason) < 0) {
		goto parse_error;
	}

	if (corosync_main_config_set ("logging", NULL, &error_reason) < 0) {
		goto parse_error;
	}

	/*
	 * we will need 2 of these to compensate for new logging
	 * config format
	 */
#ifdef LOGCONFIG_USE_ICMAP
	iter = icmap_iter_init("logging.logger_subsys.");
	while ((key_name = icmap_iter_next(iter, NULL, NULL)) != NULL) {
#else
	cmap_iter_init(cmap_handle, "logging.logger_subsys.", &iter);
	while ((cmap_iter_next(cmap_handle, iter, key_name, NULL, NULL)) == CS_OK) {
#endif
		res = sscanf(key_name, "logging.logger_subsys.%[^.].%s", key_subsys, key_item);

		if (res != 2) {
			continue ;
		}

		if (strcmp(key_item, "subsys") != 0) {
			continue ;
		}

		snprintf(key_item, MAP_KEYNAME_MAXLEN, "logging.logger_subsys.%s", key_subsys);

		if (corosync_main_config_set(key_item, key_subsys, &error_reason) < 0) {
			goto parse_error;
		}
	}
#ifdef LOGCONFIG_USE_ICMAP
	icmap_iter_finalize(iter);
#else
	cmap_iter_finalize(cmap_handle, iter);
#endif

	logsys_config_apply();
	return 0;

parse_error:
	*error_string = error_reason;

	return (-1);
}

#ifdef LOGCONFIG_USE_ICMAP 
static void main_logging_notify(
		int32_t event,
		const char *key_name,
		struct icmap_notify_value new_val,
		struct icmap_notify_value old_val,
		void *user_data)
#else
static void main_logging_notify(
		cmap_handle_t cmap_handle_unused,
		cmap_handle_t cmap_track_handle_unused,
		int32_t event,
		const char *key_name,
		struct cmap_notify_value new_val,
		struct cmap_notify_value old_val,
		void *user_data)
#endif
{
	const char *error_string;
	static int reload_in_progress = 0;

	/* If a full reload happens then suspend updates for individual keys until
	 * it's all completed
	 */
	if (strcmp(key_name, "config.reload_in_progress") == 0) {
		if (*(uint8_t *)new_val.data == 1) {
			reload_in_progress = 1;
		} else {
			reload_in_progress = 0;
		}
	}
	if (reload_in_progress) {
		log_printf(LOGSYS_LEVEL_DEBUG, "Ignoring key change, reload in progress. %s\n", key_name);
		return;
	}

	/*
	 * Reload the logsys configuration
	 */
	if (logsys_format_set(NULL) == -1) {
		fprintf (stderr, "Unable to setup logging format.\n");
	}
	corosync_main_config_read_logging(&error_string);
}

#ifdef LOGCONFIG_USE_ICMAP
static void add_logsys_config_notification(void)
{
	icmap_track_t icmap_track = NULL;

	icmap_track_add("logging.",
			ICMAP_TRACK_ADD | ICMAP_TRACK_DELETE | ICMAP_TRACK_MODIFY | ICMAP_TRACK_PREFIX,
			main_logging_notify,
			NULL,
			&icmap_track);

	icmap_track_add("config.reload_in_progress",
			ICMAP_TRACK_ADD | ICMAP_TRACK_MODIFY,
			main_logging_notify,
			NULL,
			&icmap_track);
}
Пример #3
0
int _logsys_system_setup(
	const char *mainsystem,
	unsigned int mode,
	int syslog_facility,
	int syslog_priority)
{
	int i;
	int32_t fidx;
	char tempsubsys[LOGSYS_MAX_SUBSYS_NAMELEN];

	if ((mainsystem == NULL) ||
	    (strlen(mainsystem) >= LOGSYS_MAX_SUBSYS_NAMELEN)) {
		return -1;
	}

	/*
	 * Setup libqb as a subsys
	 */
	i = _logsys_subsys_create ("QB", "array.c,log.c,log_syslog.c,log_blackbox.c,log_format.c,"
		"log_file.c,log_dcs.c,log_thread.c,ipc_shm.c,ipcs.c,ipc_us.c,loop.c,"
		"loop_poll_epoll.c,loop_job.c,loop_poll_poll.c,loop_poll_kqueue.c,"
		"loop_timerlist.c,loop_poll.c,ringbuffer.c,ringbuffer_helper.c,trie.c,"
		"map.c,skiplist.c,rpl_sem.c,hdb.c,unix.c,hashtable.c,strlcpy.c,ipc_socket.c,"
		"strchrnul.c,ipc_setup.c,strlcat.c");
	if (i < 0) {
		return -1;
	}

	/*
	 * name clash
	 * _logsys_subsys_filename_add (i, "util.c");
	 */

	/*
	 * This file (logsys.c) is not exactly QB. We need tag for logsys.c if flightrecorder init
	 * fails, and QB seems to be closest.
	 */
	_logsys_subsys_filename_add (i, "logsys.c");

	i = LOGSYS_MAX_SUBSYS_COUNT;

	pthread_mutex_lock (&logsys_config_mutex);

	snprintf(logsys_loggers[i].subsys,
		 LOGSYS_MAX_SUBSYS_NAMELEN,
		"%s", mainsystem);

	logsys_loggers[i].mode = mode;
	logsys_loggers[i].debug = LOGSYS_DEBUG_OFF;
	logsys_loggers[i].file_idx = 0;
	logsys_loggers[i].logfile_priority = syslog_priority;
	logsys_loggers[i].syslog_priority = syslog_priority;

	qb_log_init(mainsystem, syslog_facility, syslog_priority);
	if (logsys_loggers[i].mode & LOGSYS_MODE_OUTPUT_STDERR) {
		qb_log_ctl(QB_LOG_STDERR, QB_LOG_CONF_ENABLED, QB_TRUE);
	} else {
		qb_log_ctl(QB_LOG_STDERR, QB_LOG_CONF_ENABLED, QB_FALSE);
	}
	if (logsys_loggers[i].mode & LOGSYS_MODE_OUTPUT_SYSLOG) {
		qb_log_ctl(QB_LOG_SYSLOG, QB_LOG_CONF_ENABLED, QB_TRUE);
	} else {
		qb_log_ctl(QB_LOG_SYSLOG, QB_LOG_CONF_ENABLED, QB_FALSE);
	}
	qb_log_ctl(QB_LOG_SYSLOG, QB_LOG_CONF_PRIORITY_BUMP, LOG_INFO - LOG_DEBUG);

	qb_log_filter_ctl(QB_LOG_BLACKBOX, QB_LOG_FILTER_ADD,
			  QB_LOG_FILTER_FILE, "*", LOG_TRACE);
	qb_log_ctl(QB_LOG_BLACKBOX, QB_LOG_CONF_SIZE, IPC_LOGSYS_SIZE);
	qb_log_ctl(QB_LOG_BLACKBOX, QB_LOG_CONF_THREADED, QB_FALSE);

	/*
	 * Blackbox is disabled at the init and enabled later based
	 * on config (logging.blackbox) value.
	 */
	qb_log_ctl(QB_LOG_BLACKBOX, QB_LOG_CONF_ENABLED, QB_FALSE);

	if (logsys_format_set(NULL) == -1) {
		return -1;
	}

	qb_log_tags_stringify_fn_set(_logsys_tags_stringify);

	logsys_loggers[i].init_status = LOGSYS_LOGGER_INIT_DONE;
	logsys_system_needs_init = LOGSYS_LOGGER_INIT_DONE;

	for (i = 0; i < LOGSYS_MAX_SUBSYS_COUNT; i++) {
		if ((strcmp (logsys_loggers[i].subsys, "") != 0) &&
		    (logsys_loggers[i].init_status ==
		     LOGSYS_LOGGER_NEEDS_INIT)) {
			fidx = logsys_loggers[i].file_idx;
			strncpy (tempsubsys, logsys_loggers[i].subsys,
				 sizeof (tempsubsys));
			tempsubsys[sizeof (tempsubsys) - 1] = '\0';
			logsys_subsys_init(tempsubsys, i);
			logsys_loggers[i].file_idx = fidx;
			_logsys_config_mode_set_unlocked(i, logsys_loggers[i].mode);
			_logsys_config_apply_per_subsys(i);
		}
	}

	pthread_mutex_unlock (&logsys_config_mutex);

	return (0);
}