Hwmon::~Hwmon() { while (counters != NULL) { HwmonCounter * counter = counters; counters = counter->getNext(); delete counter; } sensors_cleanup(); }
static void _j4status_sensors_uninit(J4statusPluginContext *context) { g_list_free_full(context->sections, _j4status_sensors_feature_free); g_free(context); sensors_cleanup(); }
static void free_query_data(void *p) { struct sensors_temp_info *sti = (struct sensors_temp_info *) p; list_del(&sti->list); if (sti->chip) sensors_free_chip_name(sti->chip); FREE(sti); sensors_cleanup(); }
static void temperature_cleanup(struct temperature* temp) { if (temp) { if (temp->count) free(temp->numbers); free(temp); } sensors_cleanup(); }
static void sensors_free_features(void) { featurelist_t *nextft; if (first_feature == NULL) return; sensors_cleanup(); for (featurelist_t *thisft = first_feature; thisft != NULL; thisft = nextft) { nextft = thisft->next; sfree(thisft); } first_feature = NULL; }
int sensors_init(FILE *input) { int res; if (!sensors_init_sysfs()) return -SENSORS_ERR_KERNEL; if ((res = sensors_read_sysfs_bus()) || (res = sensors_read_sysfs_chips())) goto exit_cleanup; if (input) { res = parse_config(input, NULL); if (res) goto exit_cleanup; } else { const char* name; /* No configuration provided, use default */ input = fopen(name = DEFAULT_CONFIG_FILE, "r"); if (!input && errno == ENOENT) input = fopen(name = ALT_CONFIG_FILE, "r"); if (input) { res = parse_config(input, name); fclose(input); if (res) goto exit_cleanup; } else if (errno != ENOENT) { sensors_parse_error_wfn(strerror(errno), name, 0); res = -SENSORS_ERR_PARSE; goto exit_cleanup; } /* Also check for files in default directory */ res = add_config_from_dir(DEFAULT_CONFIG_DIR); if (res) goto exit_cleanup; } return 0; exit_cleanup: sensors_cleanup(); return res; }
static int l_readAll(lua_State *L) { sensors_init(NULL); const sensors_chip_name *scn; const sensors_feature *sf; const sensors_subfeature *ss; int n, n1, n2, err; double r; char scns[80]; lua_newtable(L); //Push new table on to stack. Index -1 for(n = 0; (scn = sensors_get_detected_chips(NULL, &n)) != NULL; ) { // Iterate over detected chips for(n1 = 0; (sf = sensors_get_features(scn, &n1)) != NULL; ) // Iterate over features of chip for(n2 = 0; (ss = sensors_get_all_subfeatures(scn, sf, &n2)) != NULL; ) { // Iterate over subfeatures of features from chip sprintf(scns, "%s-%x-%x__%s", scn->prefix, scn->bus.nr, scn->addr, ss->name); // Set scns to (chip.prefix - chip.bus.nr - chip.addr __ subfeature.name ) err = sensors_get_value(scn, ss->number, &r); // Get value from chip using subfeature.number, store result in r. If err != 0 then an error occured. if (err == 0) { // Sensor data. Addres in char* scns, name in ss->name, result in r lua_pushnumber(L, r); //Push table value on stack. Table is now at -2 lua_setfield(L, -2, scns); //Set 3rd argument as key in table at stack index -2 to stack index -1 } else { return(luaL_error(L, "Can't read sensors!")); } } } sensors_cleanup(); return(1); }
HwmonDriver::~HwmonDriver() { sensors_cleanup(); }
LMSensorList::~LMSensorList() { for (LMSensorList::iterator it = m_sensors.begin(); it != m_sensors.end(); ++it) delete *it; sensors_cleanup(); }
void exit_cleanup() { printf("\nCleanup.."); sensors_cleanup(); printf(". done, exiting\n"); exit(0); }
static int sensors_load_conf (void) { static int call_once = 0; FILE *fh = NULL; featurelist_t *last_feature = NULL; const sensors_chip_name *chip; int chip_num; int status; if (call_once) return 0; call_once = 1; if (conffile != NULL) { fh = fopen (conffile, "r"); if (fh == NULL) { char errbuf[1024]; ERROR ("sensors plugin: fopen(%s) failed: %s", conffile, sstrerror (errno, errbuf, sizeof (errbuf))); return (-1); } } status = sensors_init (fh); if (fh) fclose (fh); if (status != 0) { ERROR ("sensors plugin: Cannot initialize sensors. " "Data will not be collected."); return (-1); } #if SENSORS_API_VERSION < 0x400 chip_num = 0; while ((chip = sensors_get_detected_chips (&chip_num)) != NULL) { int feature_num0 = 0; int feature_num1 = 0; while (42) { const sensors_feature_data *feature; int feature_type; featurelist_t *fl; feature = sensors_get_all_features (*chip, &feature_num0, &feature_num1); /* Check if all features have been read. */ if (feature == NULL) break; /* "master features" only */ if (feature->mapping != SENSORS_NO_MAPPING) { DEBUG ("sensors plugin: sensors_load_conf: " "Ignoring subfeature `%s', " "because (feature->mapping " "!= SENSORS_NO_MAPPING).", feature->name); continue; } /* skip ignored in sensors.conf */ if (sensors_get_ignored (*chip, feature->number) == 0) { DEBUG ("sensors plugin: sensors_load_conf: " "Ignoring subfeature `%s', " "because " "`sensors_get_ignored' told " "me so.", feature->name); continue; } feature_type = sensors_feature_name_to_type ( feature->name); if (feature_type == SENSOR_TYPE_UNKNOWN) { DEBUG ("sensors plugin: sensors_load_conf: " "Ignoring subfeature `%s', " "because its type is " "unknown.", feature->name); continue; } fl = calloc (1, sizeof (*fl)); if (fl == NULL) { ERROR ("sensors plugin: calloc failed."); continue; } fl->chip = chip; fl->data = feature; fl->type = feature_type; if (first_feature == NULL) first_feature = fl; else last_feature->next = fl; last_feature = fl; } /* while sensors_get_all_features */ } /* while sensors_get_detected_chips */ /* #endif SENSORS_API_VERSION < 0x400 */ #elif (SENSORS_API_VERSION >= 0x400) && (SENSORS_API_VERSION < 0x500) chip_num = 0; while ((chip = sensors_get_detected_chips (NULL, &chip_num)) != NULL) { const sensors_feature *feature; int feature_num = 0; while ((feature = sensors_get_features (chip, &feature_num)) != NULL) { const sensors_subfeature *subfeature; int subfeature_num = 0; /* Only handle voltage, fanspeeds and temperatures */ if ((feature->type != SENSORS_FEATURE_IN) && (feature->type != SENSORS_FEATURE_FAN) && (feature->type != SENSORS_FEATURE_TEMP) && (feature->type != SENSORS_FEATURE_POWER)) { DEBUG ("sensors plugin: sensors_load_conf: " "Ignoring feature `%s', " "because its type is not " "supported.", feature->name); continue; } while ((subfeature = sensors_get_all_subfeatures (chip, feature, &subfeature_num)) != NULL) { featurelist_t *fl; if ((subfeature->type != SENSORS_SUBFEATURE_IN_INPUT) && (subfeature->type != SENSORS_SUBFEATURE_FAN_INPUT) && (subfeature->type != SENSORS_SUBFEATURE_TEMP_INPUT) && (subfeature->type != SENSORS_SUBFEATURE_POWER_INPUT)) continue; fl = calloc (1, sizeof (*fl)); if (fl == NULL) { ERROR ("sensors plugin: calloc failed."); continue; } fl->chip = chip; fl->feature = feature; fl->subfeature = subfeature; if (first_feature == NULL) first_feature = fl; else last_feature->next = fl; last_feature = fl; } /* while (subfeature) */ } /* while (feature) */ } /* while (chip) */ #endif /* (SENSORS_API_VERSION >= 0x400) && (SENSORS_API_VERSION < 0x500) */ if (first_feature == NULL) { sensors_cleanup (); INFO ("sensors plugin: lm_sensors reports no " "features. Data will not be collected."); return (-1); } return (0); } /* int sensors_load_conf */
int main(int argc, char *argv[]) { int c, i, err, do_bus_list; const char *config_file_name = NULL; struct option long_opts[] = { { "help", no_argument, NULL, 'h' }, { "set", no_argument, NULL, 's' }, { "version", no_argument, NULL, 'v'}, { "fahrenheit", no_argument, NULL, 'f' }, { "no-adapter", no_argument, NULL, 'A' }, { "config-file", required_argument, NULL, 'c' }, { "bus-list", no_argument, NULL, 'B' }, { 0, 0, 0, 0 } }; setlocale(LC_CTYPE, ""); do_raw = 0; do_sets = 0; do_bus_list = 0; hide_adapter = 0; while (1) { c = getopt_long(argc, argv, "hsvfAc:u", long_opts, NULL); if (c == EOF) break; switch(c) { case ':': case '?': print_short_help(); exit(1); case 'h': print_long_help(); exit(0); case 'v': print_version(); exit(0); case 'c': config_file_name = optarg; break; case 's': do_sets = 1; break; case 'f': fahrenheit = 1; break; case 'A': hide_adapter = 1; break; case 'u': do_raw = 1; break; case 'B': do_bus_list = 1; break; default: fprintf(stderr, "Internal error while parsing options!\n"); exit(1); } } err = read_config_file(config_file_name); if (err) exit(err); /* build the degrees string */ set_degstr(); if (do_bus_list) { print_bus_list(); } else if (optind == argc) { /* No chip name on command line */ if (!do_the_real_work(NULL, &err)) { fprintf(stderr, "No sensors found!\n" "Make sure you loaded all the kernel drivers you need.\n" "Try sensors-detect to find out which these are.\n"); err = 1; } } else { int cnt = 0; sensors_chip_name chip; for (i = optind; i < argc; i++) { if (sensors_parse_chip_name(argv[i], &chip)) { fprintf(stderr, "Parse error in chip name `%s'\n", argv[i]); print_short_help(); err = 1; goto exit; } cnt += do_the_real_work(&chip, &err); sensors_free_chip_name(&chip); } if (!cnt) { fprintf(stderr, "Specified sensor(s) not found!\n"); err = 1; } } exit: sensors_cleanup(); exit(err); }