39
(const sensors_chip_name *chip) {
40
static char buffer[256];
41
if (sensors_snprintf_chip_name(buffer, 256, chip) < 0)
48
(const sensors_chip_name *chip) {
51
sensorLog (LOG_INFO, "Chip: %s", chipName (chip));
52
adapter = sensors_get_adapter_name (&chip->bus);
54
sensorLog (LOG_INFO, "Adapter: %s", adapter);
61
(const sensors_chip_name *chip, const ChipDescriptor *descriptor, int action) {
62
const FeatureDescriptor *features = descriptor->features;
67
if (action == DO_READ)
69
for (index0 = 0; (ret == 0) && features[index0].format; ++ index0) {
70
const FeatureDescriptor *feature = features + index0;
74
if (!(label = sensors_get_label (chip, feature->feature))) {
75
sensorLog (LOG_ERR, "Error getting sensor label: %s/%s", chip->prefix, feature->feature->name);
78
double values[MAX_DATA];
81
if (!ret && feature->alarmNumber != -1) {
82
if ((ret = sensors_get_value (chip, feature->alarmNumber, &tmp))) {
83
sensorLog (LOG_ERR, "Error getting sensor data: %s/#%d: %s", chip->prefix, feature->alarmNumber, sensors_strerror (ret));
86
alarm = (int) (tmp + 0.5);
89
if ((action == DO_SCAN) && !alarm)
93
if (!ret && feature->beepNumber != -1) {
94
if ((ret = sensors_get_value (chip, feature->beepNumber, &tmp))) {
95
sensorLog (LOG_ERR, "Error getting sensor data: %s/#%d: %s", chip->prefix, feature->beepNumber, sensors_strerror (ret));
98
beep = (int) (tmp + 0.5);
102
for (subindex = 0; !ret && (feature->dataNumbers[subindex] >= 0); ++ subindex) {
103
if ((ret = sensors_get_value (chip, feature->dataNumbers[subindex], values + subindex))) {
104
sensorLog (LOG_ERR, "Error getting sensor data: %s/#%d: %s", chip->prefix, feature->dataNumbers[subindex], sensors_strerror (ret));
109
if (action == DO_RRD) { // arse = "N:"
111
const char *rrded = feature->rrd (values);
112
strcat (strcat (rrdBuff, ":"), rrded ? rrded : "U");
115
const char *formatted = feature->format (values, alarm, beep);
117
if (action == DO_READ) {
118
sensorLog (LOG_INFO, " %s: %s", label, formatted);
120
sensorLog (LOG_ALERT, "Sensor alarm: Chip %s: %s: %s", chipName (chip), label, formatted);
134
(const sensors_chip_name *chip) {
136
if ((ret = idChip (chip))) {
137
sensorLog (LOG_ERR, "Error identifying chip: %s", chip->prefix);
138
} else if ((ret = sensors_do_chip_sets (chip))) {
139
sensorLog (LOG_ERR, "Error performing chip sets: %s: %s", chip->prefix, sensors_strerror (ret));
142
sensorLog (LOG_INFO, "Set.");
149
(const sensors_chip_name *chip, int action) {
151
if (action == DO_SET) {
152
ret = setChip (chip);
154
int index0, chipindex = -1;
155
for (index0 = 0; knownChips[index0].features; ++ index0)
156
/* Trick: we compare addresses here. We know it works because both
157
pointers were returned by sensors_get_detected_chips(), so they
158
refer to libsensors internal structures, which do not move. */
159
if (knownChips[index0].name == chip) {
164
ret = doKnownChip (chip, &knownChips[chipindex], action);
172
const sensors_chip_name *chip;
175
for (j = 0; (ret == 0) && (j < numChipNames); ++ j) {
177
while ((ret == 0) && ((chip = sensors_get_detected_chips (&chipNames[j], &i)) != NULL)) {
178
ret = doChip (chip, action);
190
sensorLog (LOG_DEBUG, "sensor read started");
191
ret = doChips (DO_READ);
192
sensorLog (LOG_DEBUG, "sensor read finished");
202
sensorLog (LOG_DEBUG, "sensor sweep started"); /* only logged in debug mode */
203
ret = doChips (DO_SCAN);
204
sensorLog (LOG_DEBUG, "sensor sweep finished");
214
sensorLog (LOG_DEBUG, "sensor set started");
215
ret = doChips (DO_SET);
216
sensorLog (LOG_DEBUG, "sensor set finished");
38
static const char *chipName(const sensors_chip_name *chip)
40
static char buffer[256];
41
if (sensors_snprintf_chip_name(buffer, 256, chip) < 0)
46
static int idChip(const sensors_chip_name *chip)
50
sensorLog(LOG_INFO, "Chip: %s", chipName (chip));
51
adapter = sensors_get_adapter_name(&chip->bus);
53
sensorLog(LOG_INFO, "Adapter: %s", adapter);
58
static int doKnownChip(const sensors_chip_name *chip,
59
const ChipDescriptor *descriptor, int action)
61
const FeatureDescriptor *features = descriptor->features;
66
if (action == DO_READ)
68
for (index0 = 0; (ret == 0) && features[index0].format; ++ index0) {
69
const FeatureDescriptor *feature = features + index0;
73
if (!(label = sensors_get_label(chip, feature->feature))) {
75
"Error getting sensor label: %s/%s",
76
chip->prefix, feature->feature->name);
79
double values[MAX_DATA];
82
if (!ret && feature->alarmNumber != -1) {
83
if ((ret = sensors_get_value(chip,
87
"Error getting sensor data: %s/#%d: %s",
90
sensors_strerror(ret));
93
alarm = (int) (tmp + 0.5);
96
if ((action == DO_SCAN) && !alarm)
100
if (!ret && feature->beepNumber != -1) {
101
if ((ret = sensors_get_value(chip,
105
"Error getting sensor data: %s/#%d: %s",
108
sensors_strerror(ret));
111
beep = (int) (tmp + 0.5);
115
for (subindex = 0; !ret &&
116
(feature->dataNumbers[subindex] >= 0); ++ subindex) {
117
if ((ret = sensors_get_value(chip, feature->dataNumbers[subindex], values + subindex))) {
118
sensorLog(LOG_ERR, "Error getting sensor data: %s/#%d: %s", chip->prefix, feature->dataNumbers[subindex], sensors_strerror(ret));
123
if (action == DO_RRD) { // arse = "N:"
125
const char *rrded = feature->rrd (values);
126
strcat(strcat (rrdBuff, ":"),
127
rrded ? rrded : "U");
130
const char *formatted = feature->format (values, alarm, beep);
132
if (action == DO_READ) {
133
sensorLog(LOG_INFO, " %s: %s", label, formatted);
135
sensorLog(LOG_ALERT, "Sensor alarm: Chip %s: %s: %s", chipName(chip), label, formatted);
147
static int setChip(const sensors_chip_name *chip)
150
if ((ret = idChip(chip))) {
151
sensorLog(LOG_ERR, "Error identifying chip: %s",
153
} else if ((ret = sensors_do_chip_sets(chip))) {
154
sensorLog(LOG_ERR, "Error performing chip sets: %s: %s",
155
chip->prefix, sensors_strerror(ret));
158
sensorLog(LOG_INFO, "Set.");
163
static int doChip(const sensors_chip_name *chip, int action)
166
if (action == DO_SET) {
169
int index0, chipindex = -1;
170
for (index0 = 0; knownChips[index0].features; ++ index0)
172
* Trick: we compare addresses here. We know it works
173
* because both pointers were returned by
174
* sensors_get_detected_chips(), so they refer to
175
* libsensors internal structures, which do not move.
177
if (knownChips[index0].name == chip) {
182
ret = doKnownChip(chip, &knownChips[chipindex],
188
static int doChips(int action)
190
const sensors_chip_name *chip;
193
for (j = 0; (ret == 0) && (j < sensord_args.numChipNames); ++ j) {
196
((chip = sensors_get_detected_chips(&sensord_args.chipNames[j], &i)) != NULL)) {
197
ret = doChip(chip, action);
208
sensorLog(LOG_DEBUG, "sensor read started");
209
ret = doChips(DO_READ);
210
sensorLog(LOG_DEBUG, "sensor read finished");
219
sensorLog(LOG_DEBUG, "sensor sweep started");
220
ret = doChips(DO_SCAN);
221
sensorLog(LOG_DEBUG, "sensor sweep finished");
230
sensorLog(LOG_DEBUG, "sensor set started");
231
ret = doChips(DO_SET);
232
sensorLog(LOG_DEBUG, "sensor set finished");
221
237
/* TODO: loadavg entry */
228
strcpy (rrdBuff, "N");
230
sensorLog (LOG_DEBUG, "sensor rrd started");
231
ret = doChips (DO_RRD);
232
sensorLog (LOG_DEBUG, "sensor rrd finished");
243
strcpy(rrdBuff, "N");
245
sensorLog(LOG_DEBUG, "sensor rrd started");
246
ret = doChips(DO_RRD);
247
sensorLog(LOG_DEBUG, "sensor rrd finished");