mirror of
https://github.com/lm-sensors/lm-sensors.git
synced 2026-11-12 16:50:15 +00:00
Add support for foo#_label sysfs files
git-svn-id: http://lm-sensors.org/svn/lm-sensors/branches/lm-sensors-3.0.0@4550 7894878c-1315-0410-8ee3-d5d059ff63e0
This commit is contained in:
1 parent
3e37149f04
commit
eeee6f9bb7
1 file changed
+23
-7
+23
-7
@@ -151,6 +151,8 @@ int sensors_get_label(sensors_chip_name name, int feature, char **result)
|
||||
{
|
||||
const sensors_chip *chip;
|
||||
const sensors_chip_feature *featureptr;
|
||||
char buf[128], path[PATH_MAX];
|
||||
FILE *f;
|
||||
int i;
|
||||
|
||||
*result = NULL;
|
||||
@@ -162,16 +164,30 @@ int sensors_get_label(sensors_chip_name name, int feature, char **result)
|
||||
for (chip = NULL; (chip = sensors_for_all_config_chips(name, chip));)
|
||||
for (i = 0; i < chip->labels_count; i++)
|
||||
if (!strcasecmp(featureptr->data.name,chip->labels[i].name)){
|
||||
if (*result)
|
||||
free(*result);
|
||||
if (!(*result = strdup(chip->labels[i].value)))
|
||||
sensors_fatal_error("sensors_get_label",
|
||||
"Allocating label text");
|
||||
return 0;
|
||||
*result = strdup(chip->labels[i].value);
|
||||
goto sensors_get_label_exit;
|
||||
}
|
||||
|
||||
/* No user specified label, check for a _label sysfs file */
|
||||
snprintf(path, PATH_MAX, "%s/%s_label", name.busname,
|
||||
featureptr->data.name);
|
||||
|
||||
if ((f = fopen(path, "r"))) {
|
||||
i = fread(buf, 1, sizeof(buf) - 1, f);
|
||||
fclose(f);
|
||||
if (i > 0) {
|
||||
/* i - 1 to strip the '\n' at the end */
|
||||
buf[i - 1] = 0;
|
||||
*result = strdup(buf);
|
||||
goto sensors_get_label_exit;
|
||||
}
|
||||
}
|
||||
|
||||
/* No label, return the feature name instead */
|
||||
if (!(*result = strdup(featureptr->data.name)))
|
||||
*result = strdup(featureptr->data.name);
|
||||
|
||||
sensors_get_label_exit:
|
||||
if (*result == NULL)
|
||||
sensors_fatal_error("sensors_get_label",
|
||||
"Allocating label text");
|
||||
return 0;
|
||||
|
||||
Reference in new issue
Block a user