Changeset 4828
- Timestamp:
- 09/21/07 14:15:18 (1 year ago)
- Files:
-
- lm-sensors/branches/lm-sensors-3.0.0/prog/sensord/chips.c (modified) (3 diffs)
- lm-sensors/branches/lm-sensors-3.0.0/prog/sensord/lib.c (modified) (3 diffs)
- lm-sensors/branches/lm-sensors-3.0.0/prog/sensord/rrd.c (modified) (2 diffs)
- lm-sensors/branches/lm-sensors-3.0.0/prog/sensord/sense.c (modified) (1 diff)
- lm-sensors/branches/lm-sensors-3.0.0/prog/sensord/sensord.h (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
lm-sensors/branches/lm-sensors-3.0.0/prog/sensord/chips.c
r4827 r4828 333 333 } 334 334 335 /* Note that alarms and beeps are no longer (or not yet) supported */ 336 ChipDescriptor * generateChipDescriptor(const sensors_chip_name *chip)335 static 336 FeatureDescriptor * generateChipFeatures (const sensors_chip_name *chip) 337 337 { 338 338 int nr, count = 1; 339 339 const sensors_feature_data *sensor; 340 ChipDescriptor *descriptor;341 340 FeatureDescriptor *features; 342 341 … … 349 348 350 349 /* Allocate the memory we need */ 351 descriptor = calloc(1, sizeof(ChipDescriptor));352 350 features = calloc(count, sizeof(FeatureDescriptor)); 353 if (!descriptor || !features) { 354 free(descriptor); 355 free(features); 351 if (!features) 356 352 return NULL; 357 }358 descriptor->features = features;359 353 360 354 /* Fill in the data structures */ … … 388 382 } 389 383 390 return descriptor; 391 } 384 return features; 385 } 386 387 ChipDescriptor * knownChips; 388 389 int initKnownChips (void) 390 { 391 int nr, count = 1; 392 const sensors_chip_name *name; 393 394 /* How many chips do we have? */ 395 nr = 0; 396 while ((name = sensors_get_detected_chips(NULL, &nr))) 397 count++; 398 399 /* Allocate the memory we need */ 400 knownChips = calloc(count, sizeof(ChipDescriptor)); 401 if (!knownChips) 402 return 1; 403 404 /* Fill in the data structures */ 405 count = 0; 406 nr = 0; 407 while ((name = sensors_get_detected_chips(NULL, &nr))) { 408 knownChips[count].name = name; 409 if ((knownChips[count].features = generateChipFeatures(name))) 410 count++; 411 } 412 413 return 0; 414 } 415 416 void freeKnownChips (void) 417 { 418 int index0; 419 420 for (index0 = 0; knownChips[index0].features; index0++) 421 free (knownChips[index0].features); 422 free (knownChips); 423 } lm-sensors/branches/lm-sensors-3.0.0/prog/sensord/lib.c
r4693 r4828 117 117 loadLib 118 118 (void) { 119 return loadConfig (0); 119 int ret; 120 ret = loadConfig (0); 121 if (!ret) 122 ret = initKnownChips (); 123 return ret; 120 124 } 121 125 … … 123 127 reloadLib 124 128 (void) { 125 return loadConfig (1); 129 int ret; 130 freeKnownChips (); 131 ret = loadConfig (1); 132 if (!ret) 133 ret = initKnownChips (); 134 return ret; 126 135 } 127 136 … … 129 138 unloadLib 130 139 (void) { 140 freeKnownChips (); 131 141 sensors_cleanup (); 132 142 return 0; lm-sensors/branches/lm-sensors-3.0.0/prog/sensord/rrd.c
r4817 r4828 142 142 for (j = 0; (ret == 0) && (j < numChipNames); ++ j) { 143 143 while ((ret == 0) && ((chip = sensors_get_detected_chips (&chipNames[j], &i)) != NULL)) { 144 ChipDescriptor *descriptor; 145 descriptor = generateChipDescriptor (chip); 146 if (descriptor) { 144 int index0, chipindex = -1; 145 for (index0 = 0; knownChips[index0].features; ++ index0) 146 /* Trick: we compare addresses here. We know it works because both 147 pointers were returned by sensors_get_detected_chips(), so they 148 refer to libsensors internal structures, which do not move. */ 149 if (knownChips[index0].name == chip) { 150 chipindex = index0; 151 break; 152 } 153 if (chipindex >= 0) { 154 const ChipDescriptor *descriptor = &knownChips[chipindex]; 147 155 const FeatureDescriptor *features = descriptor->features; 148 int index0;149 156 150 157 for (index0 = 0; (ret == 0) && (num < MAX_RRD_SENSORS) && features[index0].format; ++ index0) { … … 168 175 free (label); 169 176 } 170 free (descriptor->features);171 free (descriptor);172 177 } 173 178 } lm-sensors/branches/lm-sensors-3.0.0/prog/sensord/sense.c
r4825 r4828 169 169 ret = setChip (chip); 170 170 } else { 171 ChipDescriptor *descriptor; 172 descriptor = generateChipDescriptor (chip); 173 if (descriptor) { 174 ret = doKnownChip (chip, descriptor, action); 175 free (descriptor->features); 176 free (descriptor); 177 } 171 int index0, chipindex = -1; 172 for (index0 = 0; knownChips[index0].features; ++ index0) 173 /* Trick: we compare addresses here. We know it works because both 174 pointers were returned by sensors_get_detected_chips(), so they 175 refer to libsensors internal structures, which do not move. */ 176 if (knownChips[index0].name == chip) { 177 chipindex = index0; 178 break; 179 } 180 if (chipindex >= 0) 181 ret = doKnownChip (chip, &knownChips[chipindex], action); 178 182 } 179 183 return ret; lm-sensors/branches/lm-sensors-3.0.0/prog/sensord/sensord.h
r4825 r4828 96 96 97 97 typedef struct { 98 const sensors_chip_name *name; 98 99 FeatureDescriptor *features; 99 100 } ChipDescriptor; 100 101 101 extern ChipDescriptor * generateChipDescriptor (const sensors_chip_name *chip); 102 extern ChipDescriptor * knownChips; 103 extern int initKnownChips (void); 104 extern void freeKnownChips (void);
