| | 140 | static int _applyToFeatures(FeatureFN fn, void *data, |
| | 141 | const sensors_chip_name *chip, |
| | 142 | const ChipDescriptor *desc) |
| | 143 | { |
| | 144 | int i, ret; |
| | 145 | const FeatureDescriptor *features = desc->features; |
| | 146 | const FeatureDescriptor *feature; |
| | 147 | const char *rawLabel; |
| | 148 | char *label; |
| | 149 | |
| | 150 | for (i = 0; i < MAX_RRD_SENSORS && features[i].format; ++i) { |
| | 151 | feature = features + i; |
| | 152 | rawLabel = feature->feature->name; |
| | 153 | |
| | 154 | label = sensors_get_label(chip, feature->feature); |
| | 155 | if (!label) { |
| | 156 | sensorLog(LOG_ERR, "Error getting sensor label: %s/%s", |
| | 157 | chip->prefix, rawLabel); |
| | 158 | return -1; |
| | 159 | } |
| | 160 | |
| | 161 | rrdCheckLabel(rawLabel, i); |
| | 162 | ret = fn(data, rrdLabels[i], label, feature); |
| | 163 | free(label); |
| | 164 | } |
| | 165 | return 0; |
| | 166 | } |
| | 167 | |
| | 168 | static ChipDescriptor *lookup_known_chips(const sensors_chip_name *chip) |
| | 169 | { |
| | 170 | int i; |
| | 171 | |
| | 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. |
| | 176 | */ |
| | 177 | for (i = 0; knownChips[i].features; i++) { |
| | 178 | if (knownChips[i].name == chip) { |
| | 179 | return &knownChips[i]; |
| | 180 | } |
| | 181 | } |
| | 182 | return NULL; |
| | 183 | } |
| | 184 | |
| 142 | | const sensors_chip_name *chip; |
| 143 | | int i, j, ret = 0, num = 0; |
| 144 | | |
| 145 | | for (j = 0; (ret == 0) && (j < sensord_args.numChipNames); ++ j) { |
| 146 | | i = 0; |
| 147 | | while ((ret == 0) && ((chip = sensors_get_detected_chips(&sensord_args.chipNames[j], &i)) != NULL)) { |
| 148 | | int index0, chipindex = -1; |
| 149 | | |
| 150 | | /* Trick: we compare addresses here. We know it works |
| 151 | | * because both pointers were returned by |
| 152 | | * sensors_get_detected_chips(), so they refer to |
| 153 | | * libsensors internal structures, which do not move. |
| 154 | | */ |
| 155 | | for (index0 = 0; knownChips[index0].features; ++index0) |
| 156 | | if (knownChips[index0].name == chip) { |
| 157 | | chipindex = index0; |
| 158 | | break; |
| 159 | | } |
| 160 | | if (chipindex >= 0) { |
| 161 | | const ChipDescriptor *descriptor = &knownChips[chipindex]; |
| 162 | | const FeatureDescriptor *features = descriptor->features; |
| 163 | | |
| 164 | | for (index0 = 0; (ret == 0) && (num < MAX_RRD_SENSORS) && features[index0].format; ++index0) { |
| 165 | | const FeatureDescriptor *feature = features + index0; |
| 166 | | const char *rawLabel = feature->feature->name; |
| 167 | | char *label = NULL; |
| 168 | | |
| 169 | | if (!(label = sensors_get_label(chip, feature->feature))) { |
| 170 | | sensorLog(LOG_ERR, "Error getting sensor label: %s/%s", chip->prefix, rawLabel); |
| 171 | | ret = -1; |
| 172 | | } else { |
| 173 | | rrdCheckLabel(rawLabel, num); |
| 174 | | ret = fn(data, |
| 175 | | rrdLabels[num], |
| 176 | | label, feature); |
| 177 | | ++ num; |
| 178 | | } |
| 179 | | if (label) |
| 180 | | free(label); |
| 181 | | } |
| 182 | | } |
| 183 | | } |
| 184 | | } |
| 185 | | return ret; |
| | 187 | int i, i_detected, ret; |
| | 188 | const sensors_chip_name *chip, *chip_arg; |
| | 189 | ChipDescriptor *desc; |
| | 190 | |
| | 191 | for (i = 0; i < sensord_args.numChipNames; i++) { |
| | 192 | chip_arg = &sensord_args.chipNames[i]; |
| | 193 | i_detected = 0; |
| | 194 | while ((chip = sensors_get_detected_chips(chip_arg, |
| | 195 | &i_detected))) { |
| | 196 | desc = lookup_known_chips(chip); |
| | 197 | if (!desc) |
| | 198 | continue; |
| | 199 | |
| | 200 | ret = _applyToFeatures(fn, data, chip, desc); |
| | 201 | if (ret) |
| | 202 | return ret; |
| | 203 | } |
| | 204 | } |
| | 205 | return 0; |