2
0
mirror of https://github.com/lm-sensors/lm-sensors synced 2025-08-31 06:15:15 +00:00

sensors: Make error messages more helpful and consistent.

git-svn-id: http://lm-sensors.org/svn/lm-sensors/branches/lm-sensors-3.0.0@4898 7894878c-1315-0410-8ee3-d5d059ff63e0
This commit is contained in:
Jean Delvare
2007-09-29 18:11:38 +00:00
parent a269604853
commit fa1f1aef32
2 changed files with 54 additions and 45 deletions

View File

@@ -3,6 +3,7 @@
Copyright (c) 1998-2003 Frodo Looijaard <frodol@dds.nl>
and Mark D. Studebaker <mdsxyz123@yahoo.com>
Copyright (c) 2003-2006 The lm_sensors team
Copytight (C) 2007 Jean Delvare <khali@linux-fr.org>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -30,7 +31,7 @@
void print_chip_raw(const sensors_chip_name *name)
{
int a, b;
int a, b, err;
const sensors_feature *feature;
const sensors_subfeature *sub;
char *label;
@@ -39,7 +40,8 @@ void print_chip_raw(const sensors_chip_name *name)
a = 0;
while ((feature = sensors_get_features(name, &a))) {
if (!(label = sensors_get_label(name, feature))) {
fprintf(stderr, "ERROR: Can't get feature label!\n");
fprintf(stderr, "ERROR: Can't get label of feature "
"%s!\n", feature->name);
continue;
}
printf("%s:\n", label);
@@ -48,10 +50,12 @@ void print_chip_raw(const sensors_chip_name *name)
b = 0;
while ((sub = sensors_get_all_subfeatures(name, feature, &b))) {
if (sub->flags & SENSORS_MODE_R) {
if (sensors_get_value(name, sub->number, &val))
if ((err = sensors_get_value(name, sub->number,
&val)))
fprintf(stderr, "ERROR: Can't get "
"feature `%s' data!\n",
sub->name);
"value of subfeature %s: %s\n",
sub->name,
sensors_strerror(err));
else
printf(" %s: %.2f\n", sub->name, val);
} else
@@ -71,15 +75,16 @@ static void print_label(const char *label, int space)
printf("%s:%*s", label, space - len, "");
}
static double get_value(const sensors_chip_name *name, int subfeat_nr)
static double get_value(const sensors_chip_name *name,
const sensors_subfeature *sub)
{
double val;
int err;
err = sensors_get_value(name, subfeat_nr, &val);
err = sensors_get_value(name, sub->number, &val);
if (err) {
fprintf(stderr, "ERROR: Can't get value of subfeature %d: %s\n",
subfeat_nr, sensors_strerror(err));
fprintf(stderr, "ERROR: Can't get value of subfeature %s: %s\n",
sub->name, sensors_strerror(err));
val = 0;
}
return val;
@@ -136,7 +141,8 @@ static void print_chip_temp(const sensors_chip_name *name,
char *label;
if (!(label = sensors_get_label(name, feature))) {
fprintf(stderr, "ERROR: Can't get temperature label!\n");
fprintf(stderr, "ERROR: Can't get label of feature %s!\n",
feature->name);
return;
}
print_label(label, label_size);
@@ -144,11 +150,11 @@ static void print_chip_temp(const sensors_chip_name *name,
sf = sensors_get_subfeature(name, feature,
SENSORS_SUBFEATURE_TEMP_INPUT);
val = sf ? get_value(name, sf->number) : 0;
val = sf ? get_value(name, sf) : 0;
sf = sensors_get_subfeature(name, feature,
SENSORS_SUBFEATURE_TEMP_ALARM);
alarm = sf && get_value(name, sf->number);
alarm = sf && get_value(name, sf);
sfmin = sensors_get_subfeature(name, feature,
SENSORS_SUBFEATURE_TEMP_MIN);
@@ -159,35 +165,35 @@ static void print_chip_temp(const sensors_chip_name *name,
if (sfmax) {
sf = sensors_get_subfeature(name, feature,
SENSORS_SUBFEATURE_TEMP_MAX_ALARM);
if (sf && get_value(name, sf->number))
if (sf && get_value(name, sf))
alarm |= 1;
if (sfmin) {
limit1 = get_value(name, sfmin->number);
limit1 = get_value(name, sfmin);
s1 = "low";
limit2 = get_value(name, sfmax->number);
limit2 = get_value(name, sfmax);
s2 = "high";
sf = sensors_get_subfeature(name, feature,
SENSORS_SUBFEATURE_TEMP_MIN_ALARM);
if (sf && get_value(name, sf->number))
if (sf && get_value(name, sf))
alarm |= 1;
} else {
limit1 = get_value(name, sfmax->number);
limit1 = get_value(name, sfmax);
s1 = "high";
sfhyst = sensors_get_subfeature(name, feature,
SENSORS_SUBFEATURE_TEMP_MAX_HYST);
if (sfhyst) {
limit2 = get_value(name, sfhyst->number);
limit2 = get_value(name, sfhyst);
s2 = "hyst";
} else if (sfcrit) {
limit2 = get_value(name, sfcrit->number);
limit2 = get_value(name, sfcrit);
s2 = "crit";
sf = sensors_get_subfeature(name, feature,
SENSORS_SUBFEATURE_TEMP_CRIT_ALARM);
if (sf && get_value(name, sf->number))
if (sf && get_value(name, sf))
alarm |= 1;
crit_displayed = 1;
} else {
@@ -196,13 +202,13 @@ static void print_chip_temp(const sensors_chip_name *name,
}
}
} else if (sfcrit) {
limit1 = get_value(name, sfcrit->number);
limit1 = get_value(name, sfcrit);
s1 = "crit";
sfhyst = sensors_get_subfeature(name, feature,
SENSORS_SUBFEATURE_TEMP_CRIT_HYST);
if (sfhyst) {
limit2 = get_value(name, sfhyst->number);
limit2 = get_value(name, sfhyst);
s2 = "hyst";
} else {
limit2 = 0;
@@ -211,7 +217,7 @@ static void print_chip_temp(const sensors_chip_name *name,
sf = sensors_get_subfeature(name, feature,
SENSORS_SUBFEATURE_TEMP_CRIT_ALARM);
if (sf && get_value(name, sf->number))
if (sf && get_value(name, sf))
alarm |= 1;
crit_displayed = 1;
} else {
@@ -222,7 +228,7 @@ static void print_chip_temp(const sensors_chip_name *name,
sf = sensors_get_subfeature(name, feature,
SENSORS_SUBFEATURE_TEMP_FAULT);
if (sf && get_value(name, sf->number)) {
if (sf && get_value(name, sf)) {
printf(" FAULT ");
} else {
if (fahrenheit)
@@ -232,13 +238,13 @@ static void print_chip_temp(const sensors_chip_name *name,
print_temp_limits(limit1, limit2, s1, s2, alarm);
if (!crit_displayed && sfcrit) {
limit1 = get_value(name, sfcrit->number);
limit1 = get_value(name, sfcrit);
s1 = "crit";
sfhyst = sensors_get_subfeature(name, feature,
SENSORS_SUBFEATURE_TEMP_CRIT_HYST);
if (sfhyst) {
limit2 = get_value(name, sfhyst->number);
limit2 = get_value(name, sfhyst);
s2 = "hyst";
} else {
limit2 = 0;
@@ -247,7 +253,7 @@ static void print_chip_temp(const sensors_chip_name *name,
sf = sensors_get_subfeature(name, feature,
SENSORS_SUBFEATURE_TEMP_CRIT_ALARM);
alarm = sf && get_value(name, sf->number);
alarm = sf && get_value(name, sf);
printf("\n%*s", label_size + 10, "");
print_temp_limits(limit1, limit2, s1, s2, alarm);
@@ -257,7 +263,7 @@ static void print_chip_temp(const sensors_chip_name *name,
sf = sensors_get_subfeature(name, feature,
SENSORS_SUBFEATURE_TEMP_TYPE);
if (sf) {
int sens = (int)get_value(name, sf->number);
int sens = (int)get_value(name, sf);
/* older kernels / drivers sometimes report a beta value for
thermistors */
@@ -284,7 +290,8 @@ static void print_chip_in(const sensors_chip_name *name,
char *label;
if (!(label = sensors_get_label(name, feature))) {
fprintf(stderr, "ERROR: Can't get in label!\n");
fprintf(stderr, "ERROR: Can't get label of feature %s!\n",
feature->name);
return;
}
print_label(label, label_size);
@@ -292,7 +299,7 @@ static void print_chip_in(const sensors_chip_name *name,
sf = sensors_get_subfeature(name, feature,
SENSORS_SUBFEATURE_IN_INPUT);
val = sf ? get_value(name, sf->number) : 0;
val = sf ? get_value(name, sf) : 0;
printf("%+6.2f V", val);
sfmin = sensors_get_subfeature(name, feature,
@@ -301,14 +308,14 @@ static void print_chip_in(const sensors_chip_name *name,
SENSORS_SUBFEATURE_IN_MAX);
if (sfmin && sfmax)
printf(" (min = %+6.2f V, max = %+6.2f V)",
get_value(name, sfmin->number),
get_value(name, sfmax->number));
get_value(name, sfmin),
get_value(name, sfmax));
else if (sfmin)
printf(" (min = %+6.2f V)",
get_value(name, sfmin->number));
get_value(name, sfmin));
else if (sfmax)
printf(" (max = %+6.2f V)",
get_value(name, sfmax->number));
get_value(name, sfmax));
sf = sensors_get_subfeature(name, feature,
SENSORS_SUBFEATURE_IN_ALARM);
@@ -317,8 +324,8 @@ static void print_chip_in(const sensors_chip_name *name,
sfmax = sensors_get_subfeature(name, feature,
SENSORS_SUBFEATURE_IN_MAX_ALARM);
if (sfmin || sfmax) {
alarm_max = sfmax ? get_value(name, sfmax->number) : 0;
alarm_min = sfmin ? get_value(name, sfmin->number) : 0;
alarm_max = sfmax ? get_value(name, sfmax) : 0;
alarm_min = sfmin ? get_value(name, sfmin) : 0;
if (alarm_min || alarm_max) {
printf(" ALARM (");
@@ -332,7 +339,7 @@ static void print_chip_in(const sensors_chip_name *name,
}
} else if (sf) {
printf(" %s",
get_value(name, sf->number) ? "ALARM" : "");
get_value(name, sf) ? "ALARM" : "");
}
printf("\n");
@@ -347,7 +354,8 @@ static void print_chip_fan(const sensors_chip_name *name,
double val;
if (!(label = sensors_get_label(name, feature))) {
fprintf(stderr, "ERROR: Can't get fan label!\n");
fprintf(stderr, "ERROR: Can't get label of feature %s!\n",
feature->name);
return;
}
print_label(label, label_size);
@@ -355,10 +363,10 @@ static void print_chip_fan(const sensors_chip_name *name,
sf = sensors_get_subfeature(name, feature,
SENSORS_SUBFEATURE_FAN_INPUT);
val = sf ? get_value(name, sf->number) : 0;
val = sf ? get_value(name, sf) : 0;
sf = sensors_get_subfeature(name, feature,
SENSORS_SUBFEATURE_FAN_FAULT);
if (sf && get_value(name, sf->number))
if (sf && get_value(name, sf))
printf(" FAULT");
else
printf("%4.0f RPM", val);
@@ -369,18 +377,18 @@ static void print_chip_fan(const sensors_chip_name *name,
SENSORS_SUBFEATURE_FAN_DIV);
if (sfmin && sfdiv)
printf(" (min = %4.0f RPM, div = %1.0f)",
get_value(name, sfmin->number),
get_value(name, sfdiv->number));
get_value(name, sfmin),
get_value(name, sfdiv));
else if (sfmin)
printf(" (min = %4.0f RPM)",
get_value(name, sfmin->number));
get_value(name, sfmin));
else if (sfdiv)
printf(" (div = %1.0f)",
get_value(name, sfdiv->number));
get_value(name, sfdiv));
sf = sensors_get_subfeature(name, feature,
SENSORS_SUBFEATURE_FAN_ALARM);
if (sf && get_value(name, sf->number)) {
if (sf && get_value(name, sf)) {
printf(" ALARM");
}