Пример #1
0
/* Wrapper around sensors_yyparse(), which clears the locale so that
   the decimal numbers are always parsed properly. */
static int sensors_parse(void)
{
	int res;
	char *locale;

	/* Remember the current locale and clear it */
	locale = setlocale(LC_ALL, NULL);
	if (locale) {
		locale = strdup(locale);
		if (!locale)
			sensors_fatal_error(__func__, "Out of memory");

		setlocale(LC_ALL, "C");
	}

	res = sensors_yyparse();

	/* Restore the old locale */
	if (locale) {
		setlocale(LC_ALL, locale);
		free(locale);
	}

	return res;
}
Пример #2
0
static int parse_config(FILE *input, const char *name)
{
	int err;
	char *name_copy;

	if (name) {
		/* Record configuration file name for error reporting */
		name_copy = strdup(name);
		if (!name_copy)
			sensors_fatal_error(__func__, "Out of memory");
		sensors_add_config_files(&name_copy);
	} else
		name_copy = NULL;

	if (sensors_scanner_init(input, name_copy)) {
		err = -SENSORS_ERR_PARSE;
		goto exit_cleanup;
	}
	err = sensors_parse();
	sensors_scanner_exit();
	if (err) {
		err = -SENSORS_ERR_PARSE;
		goto exit_cleanup;
	}

	err = sensors_substitute_busses();

exit_cleanup:
	free_config_busses();
	return err;
}
Пример #3
0
/* Look up the label for a given feature. Note that chip should not
   contain wildcard values! The returned string is newly allocated (free it
   yourself). On failure, NULL is returned.
   If no label exists for this feature, its name is returned itself. */
char *sensors_get_label(const sensors_chip_name *name,
			const sensors_feature *feature)
{
	char *label;
	const sensors_chip *chip;
	char buf[PATH_MAX];
	FILE *f;
	int i;

	if (sensors_chip_name_has_wildcards(name))
		return NULL;

	for (chip = NULL; (chip = sensors_for_all_config_chips(name, chip));)
		for (i = 0; i < chip->labels_count; i++)
			if (!strcmp(feature->name, chip->labels[i].name)) {
				label = chip->labels[i].value;
				goto sensors_get_label_exit;
			}

	/* No user specified label, check for a _label sysfs file */
	snprintf(buf, PATH_MAX, "%s/%s_label", name->path, feature->name);
	
	if ((f = fopen(buf, "r"))) {
		i = fread(buf, 1, sizeof(buf), f);
		fclose(f);
		if (i > 0) {
			/* i - 1 to strip the '\n' at the end */
			buf[i - 1] = 0;
			label = buf;
			goto sensors_get_label_exit;
		}
	}

	/* No label, return the feature name instead */
	label = feature->name;
	
sensors_get_label_exit:
	label = strdup(label);
	if (!label)
		sensors_fatal_error(__func__, "Allocating label text");
	return label;
}