コード例 #1
0
ファイル: totemconfig.c プロジェクト: longcongduoi/corosync
static int read_keyfile (
	const char *key_location,
	struct totem_config *totem_config,
	const char **error_string)
{
	int fd;
	int res;
	ssize_t expected_key_len = sizeof (totem_config->private_key);
	int saved_errno;
	char error_str[100];
	const char *error_ptr;

	fd = open (key_location, O_RDONLY);
	if (fd == -1) {
		error_ptr = qb_strerror_r(errno, error_str, sizeof(error_str));
		snprintf (error_string_response, sizeof(error_string_response),
			"Could not open %s: %s\n",
			 key_location, error_ptr);
		goto parse_error;
	}

	res = read (fd, totem_config->private_key, expected_key_len);
	saved_errno = errno;
	close (fd);

	if (res == -1) {
		error_ptr = qb_strerror_r (saved_errno, error_str, sizeof(error_str));
		snprintf (error_string_response, sizeof(error_string_response),
			"Could not read %s: %s\n",
			 key_location, error_ptr);
		goto parse_error;
	}

	totem_config->private_key_len = expected_key_len;

	if (res != expected_key_len) {
		snprintf (error_string_response, sizeof(error_string_response),
			"Could only read %d bits of 1024 bits from %s.\n",
			 res * 8, key_location);
		goto parse_error;
	}

	return 0;

parse_error:
	*error_string = error_string_response;
	return (-1);
}
コード例 #2
0
ファイル: coroparse.c プロジェクト: hnkien/corosync
/* Read config file and load into icmap */
static int read_config_file_into_icmap(
    const char **error_string,
    icmap_map_t config_map)
{
    FILE *fp;
    const char *filename;
    char *error_reason = error_string_response;
    int res;
    char key_name[ICMAP_KEYNAME_MAXLEN];
    struct main_cp_cb_data data;

    filename = getenv ("COROSYNC_MAIN_CONFIG_FILE");
    if (!filename)
        filename = COROSYSCONFDIR "/corosync.conf";

    fp = fopen (filename, "r");
    if (fp == NULL) {
        char error_str[100];
        const char *error_ptr = qb_strerror_r(errno, error_str, sizeof(error_str));
        snprintf (error_reason, sizeof(error_string_response),
                  "Can't read file %s reason = (%s)",
                  filename, error_ptr);
        *error_string = error_reason;
        return -1;
    }

    key_name[0] = 0;

    res = parse_section(fp, key_name, error_string, 0, main_config_parser_cb, config_map, &data);

    fclose(fp);

    if (res == 0) {
        res = read_uidgid_files_into_icmap(error_string, config_map);
    }

    if (res == 0) {
        snprintf (error_reason, sizeof(error_string_response),
                  "Successfully read main configuration file '%s'.", filename);
        *error_string = error_reason;
    }

    return res;
}
コード例 #3
0
ファイル: logsys.c プロジェクト: HideoYamauchi/corosync
/*
 * we need a version that can work when somebody else is already
 * holding a config mutex lock or we will never get out of here
 */
static int logsys_config_file_set_unlocked (
		int subsysid,
		const char **error_string,
		const char *file)
{
	static char error_string_response[512];
	int i;
	char file_format[128];

	if (logsys_loggers[subsysid].target_id > 0) {
		int32_t f;
		for (f = 0; f < logsys_loggers[subsysid].file_idx; f++) {
			qb_log_filter_ctl(logsys_loggers[subsysid].target_id,
				QB_LOG_FILTER_REMOVE,
				QB_LOG_FILTER_FILE,
				logsys_loggers[subsysid].files[f],
				LOG_TRACE);
		}
	}

	logsys_loggers[subsysid].dirty = QB_TRUE;
	if (file == NULL) {
		return (0);
	}

	if (logsys_loggers[subsysid].target_id > 0 &&
	    logsys_loggers[subsysid].logfile != NULL &&
	    strcmp(file, logsys_loggers[subsysid].logfile) == 0) {
		return (0);
	}

	if (strlen(file) >= PATH_MAX) {
		snprintf (error_string_response,
			sizeof(error_string_response),
			"%s: logfile name exceed maximum system filename length",
			logsys_loggers[subsysid].subsys);
		*error_string = error_string_response;
		return (-1);
	}

	if (logsys_loggers[subsysid].logfile != NULL) {
		free(logsys_loggers[subsysid].logfile);
		logsys_loggers[subsysid].logfile = NULL;
	}

	logsys_loggers[subsysid].logfile = strdup(file);

	if (logsys_loggers[subsysid].logfile == NULL) {
		snprintf (error_string_response,
			sizeof(error_string_response),
			"Unable to allocate memory for logfile '%s'",
			file);
		*error_string = error_string_response;
		return (-1);
	}

	for (i = 0; i <= LOGSYS_MAX_SUBSYS_COUNT; i++) {
		if ((logsys_loggers[i].logfile != NULL) &&
		    (strcmp (logsys_loggers[i].logfile, file) == 0) &&
		    (i != subsysid)) {
			/* we have found another subsys with this config file
			 * so add a filter
			 */
			logsys_loggers[subsysid].target_id = logsys_loggers[i].target_id;
			return (0);
		}
	}

	if (logsys_loggers[subsysid].target_id > 0) {
		int num_using_current = 0;
		for (i = 0; i <= LOGSYS_MAX_SUBSYS_COUNT; i++) {
			if (logsys_loggers[subsysid].target_id ==
				logsys_loggers[i].target_id) {
				num_using_current++;
			}
		}
		if (num_using_current == 1) {
			/* no one else is using this close it */
			qb_log_file_close(logsys_loggers[subsysid].target_id);
		}
	}

	logsys_loggers[subsysid].target_id = qb_log_file_open(file);
	if (logsys_loggers[subsysid].target_id < 0) {
		int err = -logsys_loggers[subsysid].target_id;
		char error_str[LOGSYS_MAX_PERROR_MSG_LEN];
		const char *error_ptr;
		error_ptr = qb_strerror_r(err, error_str, sizeof(error_str));

		free(logsys_loggers[subsysid].logfile);
		logsys_loggers[subsysid].logfile = NULL;
		snprintf (error_string_response,
			sizeof(error_string_response),
			"Can't open logfile '%s' for reason: %s (%d)",
			 file, error_ptr, err);
		*error_string = error_string_response;
		return (-1);
	}
	logsys_file_format_get(file_format, 128);
	qb_log_format_set(logsys_loggers[subsysid].target_id, file_format);

	qb_log_ctl(logsys_loggers[subsysid].target_id,
		   QB_LOG_CONF_ENABLED,
		   (logsys_loggers[subsysid].mode & LOGSYS_MODE_OUTPUT_FILE));
	if (logsys_thread_started) {
		qb_log_ctl(logsys_loggers[subsysid].target_id, QB_LOG_CONF_THREADED, QB_TRUE);
	}

	return (0);
}