Пример #1
0
static int corosync_main_config_log_destination_set (
	const char *path,
	const char *key,
	const char *subsys,
	const char **error_string,
	unsigned int mode_mask,
	char deprecated,
	const char *replacement)
{
	static char formatted_error_reason[128];
	char *value = NULL;
	unsigned int mode;
	char key_name[MAP_KEYNAME_MAXLEN];

	snprintf(key_name, MAP_KEYNAME_MAXLEN, "%s.%s", path, key);
	if (map_get_string(key_name, &value) == CS_OK) {
		if (deprecated) {
			log_printf(LOGSYS_LEVEL_WARNING,
			 "Warning: the %s config paramater has been obsoleted."
			 " See corosync.conf man page %s directive.",
			 key, replacement);
		}

		mode = logsys_config_mode_get (subsys);

		if (strcmp (value, "yes") == 0 || strcmp (value, "on") == 0) {
			mode |= mode_mask;
			if (logsys_config_mode_set(subsys, mode) < 0) {
				sprintf (formatted_error_reason, "unable to set mode %s", key);
				goto parse_error;
			}
		} else
		if (strcmp (value, "no") == 0 || strcmp (value, "off") == 0) {
			mode &= ~mode_mask;
			if (logsys_config_mode_set(subsys, mode) < 0) {
				sprintf (formatted_error_reason, "unable to unset mode %s", key);
				goto parse_error;
			}
		} else {
			sprintf (formatted_error_reason, "unknown value for %s", key);
			goto parse_error;
		}
	}

	free(value);
	return (0);

parse_error:
	*error_string = formatted_error_reason;
	free(value);
	return (-1);
}
Пример #2
0
static int corosync_main_config_set (
	const char *path,
	const char *subsys,
	const char **error_string)
{
	const char *error_reason = error_string_response;
	char *value = NULL;
	int mode;
	char key_name[MAP_KEYNAME_MAXLEN];

	/*
	 * this bit abuses the internal logsys exported API
	 * to guarantee that all configured subsystems are
	 * initialized too.
	 *
	 * using this approach avoids some headaches caused
	 * by IPC and TOTEM that have a special logging
	 * handling requirements
	 */
	if (subsys != NULL) {
		if (_logsys_subsys_create(subsys, NULL) < 0) {
			error_reason = "unable to create new logging subsystem";
			goto parse_error;
		}
	}

	mode = logsys_config_mode_get(subsys);
	if (mode < 0) {
		error_reason = "unable to get mode";
		goto parse_error;
	}

	if (corosync_main_config_log_destination_set (path, "to_stderr", subsys, &error_reason,
	    LOGSYS_MODE_OUTPUT_STDERR, 0, 1, NULL) != 0)
		goto parse_error;

	if (corosync_main_config_log_destination_set (path, "to_syslog", subsys, &error_reason,
	    LOGSYS_MODE_OUTPUT_SYSLOG, 0, 1, NULL) != 0)
		goto parse_error;

	snprintf(key_name, MAP_KEYNAME_MAXLEN, "%s.%s", path, "syslog_facility");
	if (map_get_string(key_name, &value) == CS_OK) {
		int syslog_facility;

		syslog_facility = qb_log_facility2int(value);
		if (syslog_facility < 0) {
			error_reason = "unknown syslog facility specified";
			goto parse_error;
		}
		if (logsys_config_syslog_facility_set(subsys,
						syslog_facility) < 0) {
			error_reason = "unable to set syslog facility";
			goto parse_error;
		}

		free(value);
	}
	else {
		/* Set default here in case of a reload */
		if (logsys_config_syslog_facility_set(subsys,
						      qb_log_facility2int("daemon")) < 0) {
			error_reason = "unable to set syslog facility";
			goto parse_error;
		}
	}

	snprintf(key_name, MAP_KEYNAME_MAXLEN, "%s.%s", path, "syslog_level");
	if (map_get_string(key_name, &value) == CS_OK) {
		int syslog_priority;

		log_printf(LOGSYS_LEVEL_WARNING,
		 "Warning: the syslog_level config parameter has been obsoleted."
		 " See corosync.conf man page syslog_priority directive.");

		syslog_priority = logsys_priority_id_get(value);
		free(value);

		if (syslog_priority < 0) {
			error_reason = "unknown syslog level specified";
			goto parse_error;
		}
		if (logsys_config_syslog_priority_set(subsys,
						syslog_priority) < 0) {
			error_reason = "unable to set syslog level";
			goto parse_error;
		}
	}

	snprintf(key_name, MAP_KEYNAME_MAXLEN, "%s.%s", path, "syslog_priority");
	if (map_get_string(key_name, &value) == CS_OK) {
		int syslog_priority;

		syslog_priority = logsys_priority_id_get(value);
		free(value);
		if (syslog_priority < 0) {
			error_reason = "unknown syslog priority specified";
			goto parse_error;
		}
		if (logsys_config_syslog_priority_set(subsys,
						syslog_priority) < 0) {
			error_reason = "unable to set syslog priority";
			goto parse_error;
		}
	}
	else {
		if (logsys_config_syslog_priority_set(subsys,
						      logsys_priority_id_get("info")) < 0) {
			error_reason = "unable to set syslog level";
			goto parse_error;
		}
	}

#ifdef LOGCONFIG_USE_ICMAP
	snprintf(key_name, MAP_KEYNAME_MAXLEN, "%s.%s", path, "logfile");
	if (map_get_string(key_name, &value) == CS_OK) {
		if (logsys_config_file_set (subsys, &error_reason, value) < 0) {
			goto parse_error;
		}
		free(value);
	}
#else
	if (!subsys) {
		if (logsys_config_file_set (subsys, &error_reason, main_logfile) < 0) {
			goto parse_error;
		}
	}
#endif

	if (corosync_main_config_log_destination_set (path, "to_file", subsys, &error_reason,
	   LOGSYS_MODE_OUTPUT_FILE, 1, 0, "to_logfile") != 0)
		goto parse_error;

	if (corosync_main_config_log_destination_set (path, "to_logfile", subsys, &error_reason,
	   LOGSYS_MODE_OUTPUT_FILE, 0, 0, NULL) != 0)
		goto parse_error;

	snprintf(key_name, MAP_KEYNAME_MAXLEN, "%s.%s", path, "logfile_priority");
	if (map_get_string(key_name, &value) == CS_OK) {
		int logfile_priority;

		logfile_priority = logsys_priority_id_get(value);
		free(value);
		if (logfile_priority < 0) {
			error_reason = "unknown logfile priority specified";
			goto parse_error;
		}
		if (logsys_config_logfile_priority_set(subsys,
						logfile_priority) < 0) {
			error_reason = "unable to set logfile priority";
			goto parse_error;
		}
	}
	else {
		if (logsys_config_logfile_priority_set(subsys,
						      logsys_priority_id_get("info")) < 0) {
			error_reason = "unable to set syslog level";
			goto parse_error;
		}
	}

	snprintf(key_name, MAP_KEYNAME_MAXLEN, "%s.%s", path, "debug");
	if (map_get_string(key_name, &value) == CS_OK) {
		if (strcmp (value, "trace") == 0) {
			if (logsys_config_debug_set (subsys, LOGSYS_DEBUG_TRACE) < 0) {
				error_reason = "unable to set debug trace";
				free(value);
				goto parse_error;
			}
		} else
		if (strcmp (value, "on") == 0) {
			if (logsys_config_debug_set (subsys, LOGSYS_DEBUG_ON) < 0) {
				error_reason = "unable to set debug on";
				free(value);
				goto parse_error;
			}
		} else
		if (strcmp (value, "off") == 0) {
			if (logsys_config_debug_set (subsys, LOGSYS_DEBUG_OFF) < 0) {
				error_reason = "unable to set debug off";
				free(value);
				goto parse_error;
			}
		} else {
			error_reason = "unknown value for debug";
			free(value);
			goto parse_error;
		}
		free(value);
	}
	else {
		if (logsys_config_debug_set (subsys, LOGSYS_DEBUG_OFF) < 0) {
			error_reason = "unable to set debug off";
			free(value);
			goto parse_error;
		}
	}

	return (0);

parse_error:
	*error_string = error_reason;

	return (-1);
}