/*****************************************************************************
Initializes, gets the root, then walks the picl tree looking for information

Currently, the "core" class is only needed for OPL systems
*****************************************************************************/
char* hwloc_solaris_get_chip_type(void) {
  picl_nodehdl_t root;
  int            val;
  static char chip_type[PICL_PROPNAMELEN_MAX];

  val = picl_initialize();
  if (val != PICL_SUCCESS) { /* Can't initialize session with PICL daemon */
      return(NULL);
  }
  val = picl_get_root(&root);
  if (val != PICL_SUCCESS) {  /* Failed to get root node of the PICL tree */
      return(NULL);
  }
  val = picl_walk_tree_by_class(root, "cpu", (void *)NULL, probe_cpu);
  val = picl_walk_tree_by_class(root, "core", (void *)NULL, probe_cpu);
  picl_shutdown();

  if (called_cpu_probe) {
      strncpy(chip_type, dss_chip_type, PICL_PROPNAMELEN_MAX);
  } else {
      /* no picl information on machine available */
      sysinfo(SI_HW_PROVIDER, chip_type, PICL_PROPNAMELEN_MAX);
  }
  return(chip_type);
}
Пример #2
0
static void
disp_envc_status()
{
	int err;
	char *system = "SYSTEM";
	picl_nodehdl_t system_node, root;

	log_printf(dgettext(TEXT_DOMAIN,
	    "\n"
	    "=========================  Environmental Status "
	    "=========================\n\n"));

	err = picl_initialize();
	if (err != PICL_SUCCESS) {
		exit_code = PD_INTERNAL_FAILURE;
		goto err_out;
	}
	err = picl_get_root(&root);
	if (err != PICL_SUCCESS) {
		exit_code = PD_INTERNAL_FAILURE;
		goto err_out;
	}
	err = find_child_device(root, system, &system_node);
	if (err != PICL_SUCCESS) {
		exit_code = PD_INTERNAL_FAILURE;
		goto err_out;
	}

	err = print_temps(system_node);
	err |= print_keyswitch(system_node);
	err |= print_FSP_LEDS(system_node);
	err |= print_disk(system_node);
	err |= print_fans(system_node);
	err |= print_ps(system_node);

	if (err != PICL_SUCCESS)
		goto err_out;

	return;

err_out:
	log_printf(dgettext(TEXT_DOMAIN,
	    "\nEnvironmental reporting error: %s\n"),
	    picl_strerror(err));
}
Пример #3
0
int
netsnmp_sensor_arch_load(netsnmp_cache *cache, void *vp) {
    int               error_code;
    picl_nodehdl_t    rooth;

    DEBUGMSGTL(("sensors:arch", "Reload PICLd Sensors module\n"));

    error_code = picl_get_root(&rooth);
    if ( error_code != PICL_SUCCESS) {
        DEBUGMSGTL(("sensors:arch", "Couldn't get root node (error %d)\n", error_code));
        return 1;
    }

    error_code = process_sensors(0, rooth);
    if ( error_code != 255 )
        if ( error_code != 7 )  /* ignore PICL_PROPNOTFOUND error */
            DEBUGMSGTL(("sensors:arch", "Internal PICLd problem (error %d)\n", error_code));

    return 0;
}
Пример #4
0
int
main(int argc, char **argv)
{
	locator_info_t	locator_info = {0, 0, 0, 0, 0};
	picl_nodehdl_t	rooth;
	int		err;
	int		c;
	int		on_flag = 0;
	int		off_flag = 0;
	char		*progname;
	char		*locator_name = DEFAULT_NAME;

	(void) setlocale(LC_ALL, "");
	(void) textdomain(TEXT_DOMAIN);

	if ((progname = strrchr(argv[0], '/')) == NULL)
		progname = argv[0];
	else
		progname++;

	while ((c = getopt(argc, argv, "nf")) != EOF) {
		switch (c) {
		case 'n':
			on_flag++;
			break;
		case 'f':
			off_flag++;
			break;
		case '?':
			/*FALLTHROUGH*/
		default:
			usage(progname);
		}
	}
	if (argc != optind)
		usage(progname);

	/* We only take one option */
	if (on_flag && off_flag)
		usage(progname);

	err = picl_initialize();
	if (err != PICL_SUCCESS) {
		(void) fprintf(stderr, gettext("picl_initialize failed: %s\n"),
			picl_strerror(err));
		exit(2);
	}

	err = picl_get_root(&rooth);
	if (err != PICL_SUCCESS) {
		(void) fprintf(stderr, gettext("picl_get_root failed: %s\n"),
			picl_strerror(err));
		err = 2;
		goto OUT;
	}

	if (on_flag) {
		locator_info.locator_func = change_locator_state;
		locator_info.new_state = 1;
	} else if (off_flag) {
		locator_info.locator_func = change_locator_state;
		locator_info.new_state = 0;
	} else {
		locator_info.locator_func = display_locator_state;
	}

	locator_info.name = locator_name;

	err = picl_walk_tree_by_class(rooth, "led", &locator_info,
		locator_walker_func);
	if (err != PICL_SUCCESS) {
		(void) fprintf(stderr,
			gettext("picl_walk_tree_by_class failed: %s\n"),
			picl_strerror(err));
		err = 2;
		goto OUT;
	}

	if (locator_info.found == 0) {
		(void) fprintf(stderr, gettext("'%s' locator not found\n"),
			locator_name);
		err = 2;
	}
	if (locator_info.err != PICL_SUCCESS)
		err = 2;
OUT:
	(void) picl_shutdown();
	return (err);
}
Пример #5
0
/* ******** end of picld sensor procedures * */

#endif /* solaris2 */
static int
_sensor_load(time_t t)
{
#ifdef solaris2
    int i,j;
#ifdef HAVE_PICL_H 
    int er_code;
    picl_errno_t     error_code;
    int level=0;
    picl_nodehdl_t  rooth;
#else
    int typ;
    int temp=0; /* do not reset this later, more than one typ has temperatures*/
    int other=0;
    const char *fantypes[]={"CPU","PWR","AFB"};
    kstat_ctl_t *kc;
    kstat_t *kp;
    envctrl_fan_t *fan_info;
    envctrl_ps_t *power_info;
    envctrl_encl_t *enc_info;
#endif

/* DEBUGMSG(("ucd-snmp/lmSensors", "Reading the sensors\n")); */

/* initialize the array */
    for (i = 0; i < N_TYPES; i++){
        sensor_array[i].n = 0;
        for (j=0; j < MAX_SENSORS; j++){
            sensor_array[i].sensor[j].name[0] = '\0';
            sensor_array[i].sensor[j].value = 0;
             }
        } /*end for i*/

/* try picld (if supported), if that doesn't work, try kstat */
#ifdef HAVE_PICL_H 

er_code = picl_initialize();

if (er_code == PICL_SUCCESS) {

    error_code = picl_get_root(&rooth);

    if (error_code != PICL_SUCCESS) {
        DEBUGMSG(("ucd-snmp/lmSensors", "picld couldn't get root error code->%d\n",error_code));
        }
    else{
        DEBUGMSGTL(("ucd-snmp/lmSensors", "found root\n"));
        error_code = process_sensors(level,rooth);
        if (error_code != 255) 
            if (error_code != 7)
                DEBUGMSG(("ucd-snmp/lmSensors", "picld had an internal problem error code->%d\n",error_code));
        } /* end else */

    picl_shutdown();

}  /* end if err_code for picl_initialize */

else {  
    DEBUGMSG(("ucd-snmp/lmSensors", "picld couldn't initialize picld because error code->%d\n",er_code));

} /*end else picl_initialize */

#else  /* end of picld section */
/* initialize kstat */

kc = kstat_open();
if (kc == 0) {
    DEBUGMSG(("ucd-snmp/lmSensors", "couldn't open kstat"));
    } /* endif kc */
else{
    temp = 0;
    kp = kstat_lookup(kc, ENVCTRL_MODULE_NAME, 0, ENVCTRL_KSTAT_FANSTAT);
    if (kp == 0) {
        DEBUGMSGTL(("ucd-snmp/lmSensors", "couldn't lookup fan kstat\n"));
        } /* endif lookup fans */
    else{
        if (kstat_read(kc, kp, 0) == -1) {
            DEBUGMSGTL(("ucd-snmp/lmSensors", "couldn't read fan kstat"));
            } /* endif kstatread fan */
        else{
            typ = 1;
            fan_info = (envctrl_fan_t *) kp->ks_data;
            sensor_array[typ].n = kp->ks_ndata;
            for (i=0; i < kp->ks_ndata; i++){
                DEBUGMSG(("ucd-snmp/lmSensors", "found instance %d fan type %d speed %d OK %d bustedfan %d\n",
                    fan_info->instance, fan_info->type,fan_info->fanspeed,fan_info->fans_ok,fan_info->fanflt_num));
                sensor_array[typ].sensor[i].value = fan_info->fanspeed;
                snprintf(sensor_array[typ].sensor[i].name,(MAX_NAME - 1),
                   "fan type %s number %d",fantypes[fan_info->type],fan_info->instance);
                sensor_array[typ].sensor[i].name[MAX_NAME - 1] = '\0';
                fan_info++;
                } /* end for fan_info */
            } /* end else kstatread fan */
        } /* end else lookup fans*/


    kp = kstat_lookup(kc, ENVCTRL_MODULE_NAME, 0, ENVCTRL_KSTAT_PSNAME);
    if (kp == 0) {
        DEBUGMSGTL(("ucd-snmp/lmSensors", "couldn't lookup power supply kstat\n"));
        } /* endif lookup power supply */
    else{
        if (kstat_read(kc, kp, 0) == -1) {
            DEBUGMSGTL(("ucd-snmp/lmSensors", "couldn't read power supply kstat\n"));
            } /* endif kstatread fan */
        else{
            typ = 0; /* this is a power supply temperature, not a voltage*/
            power_info = (envctrl_ps_t *) kp->ks_data;
            sensor_array[typ].n = kp->ks_ndata;
            for (i=0; i < kp->ks_ndata; i++){
                DEBUGMSG(("ucd-snmp/lmSensors", "found instance %d psupply temp mC %d %dW OK %d share %d limit %d\n",
                    power_info->instance, power_info->ps_tempr*1000,power_info->ps_rating,
                    power_info->ps_ok,power_info->curr_share_ok,power_info->limit_ok));
                sensor_array[typ].sensor[temp].value = power_info->ps_tempr*1000;
                snprintf(sensor_array[typ].sensor[temp].name,(MAX_NAME-1),
                         "power supply %d",power_info->instance);
                sensor_array[typ].sensor[temp].name[MAX_NAME - 1] = '\0';
                power_info++; /* increment the data structure */
                temp++; /* increment the temperature sensor array element */
                } /* end for power_info */
            } /* end else kstatread power supply */
        } /* end else lookup power supplies*/

    kp = kstat_lookup(kc, ENVCTRL_MODULE_NAME, 0, ENVCTRL_KSTAT_ENCL);
    if (kp == 0) {
        DEBUGMSGTL(("ucd-snmp/lmSensors", "couldn't lookup enclosure kstat\n"));
        } /* endif lookup enclosure */
    else{
        if (kstat_read(kc, kp, 0) == -1) {
            DEBUGMSGTL(("ucd-snmp/lmSensors", "couldn't read enclosure kstat\n"));
            } /* endif kstatread enclosure */
        else{
            enc_info = (envctrl_encl_t *) kp->ks_data; 
            other = 0;
            for (i=0; i < kp->ks_ndata; i++){
               switch (enc_info->type){
               case ENVCTRL_ENCL_FSP:
                   DEBUGMSG(("ucd-snmp/lmSensors", "front panel value %d\n",enc_info->value));
                   typ = 3; /* misc */
                   sensor_array[typ].sensor[other].value = enc_info->value;
                   strlcpy(sensor_array[typ].sensor[other].name, "FSP",
                           MAX_NAME);
                   other++;
                   break;
               case ENVCTRL_ENCL_AMBTEMPR:
                   DEBUGMSG(("ucd-snmp/lmSensors", "ambient temp mC %d\n",enc_info->value*1000));
                   typ = 0; /* temperature sensor */
                   sensor_array[typ].sensor[temp].value = enc_info->value*1000;
                   strlcpy(sensor_array[typ].sensor[temp].name, "Ambient",
                           MAX_NAME);
                   temp++;
                   break;
               case ENVCTRL_ENCL_BACKPLANE4:
                   DEBUGMSG(("ucd-snmp/lmSensors", "There is a backplane4\n"));
                   typ = 3; /* misc */
                   sensor_array[typ].sensor[other].value = enc_info->value;
                   strlcpy(sensor_array[typ].sensor[other].name, "Backplane4",
                           MAX_NAME);
                   other++;
                   break;
               case ENVCTRL_ENCL_BACKPLANE8:
                   DEBUGMSG(("ucd-snmp/lmSensors", "There is a backplane8\n"));
                   typ = 3; /* misc */
                   sensor_array[typ].sensor[other].value = enc_info->value;
                   strlcpy(sensor_array[typ].sensor[other].name, "Backplane8",
                           MAX_NAME);
                   other++;
                   break;
               case ENVCTRL_ENCL_CPUTEMPR:
                   DEBUGMSG(("ucd-snmp/lmSensors", "CPU%d temperature mC %d\n",enc_info->instance,enc_info->value*1000));
                   typ = 0; /* temperature sensor */
                   sensor_array[typ].sensor[temp].value = enc_info->value*1000;
                   snprintf(sensor_array[typ].sensor[temp].name,MAX_NAME,"CPU%d",enc_info->instance);
                   sensor_array[typ].sensor[temp].name[MAX_NAME-1]='\0'; /* null terminate */
                   temp++;
                   break;
               default:
                   DEBUGMSG(("ucd-snmp/lmSensors", "unknown element instance %d type %d value %d\n",
                       enc_info->instance, enc_info->type, enc_info->value));
                   break;
               } /* end switch */
               enc_info++;
               } /* end for enc_info */
               sensor_array[3].n = other;
               sensor_array[0].n = temp;
            } /* end else kstatread enclosure */
        } /* end else lookup enclosure*/

    kstat_close(kc);

} /* end else kstat */
#endif

#else /* end solaris2 only ie. ifdef everything else */

    const sensors_chip_name *chip;
    const sensors_feature_data *data;
    int             chip_nr = 0;
    unsigned int    i = 0;

    DEBUGMSG(("ucd-snmp/lmSensors", "=> sensor_load\n"));

    for (i = 0; i < N_TYPES; i++)
    {
        sensor_array[i].n = 0;
        sensor_array[i].current_len = 0;

        /* Malloc the default number of sensors. */
        sensor_array[i].sensor = (_sensor*)malloc(sizeof(_sensor) * DEFAULT_SENSORS);
        if (sensor_array[i].sensor == NULL)
        {
           /* Continuing would be unsafe */
           snmp_log(LOG_ERR, "Cannot malloc sensor array!"); 
           return 1;
        } /* end if */
        sensor_array[i].current_len = DEFAULT_SENSORS;
    } /* end for */

    while ((chip = sensors_get_detected_chips(&chip_nr))) {
	int             a = 0;
	int             b = 0;

        while ((data = sensors_get_all_features(*chip, &a, &b))) {
            char           *label = NULL;
            double          val;

            if ((data->mode & SENSORS_MODE_R) &&
                (data->mapping == SENSORS_NO_MAPPING) &&
                !sensors_get_label(*chip, data->number, &label) &&
                !sensors_get_feature(*chip, data->number, &val)) {
                int             type = -1;
                float           mul = 0;
                _sensor_array  *array;

                /* The label, as determined for a given chip in sensors.conf,
                 * is used to place each sensor in the appropriate bucket.
                 * Volt, Fan, Temp, and Misc.  If the text being looked for below
                 * is not in the label of a given sensor (e.g., the temp1 sensor
                 * has been labeled 'CPU' and not 'CPU temp') it will end up being
                 * lumped in the MISC bucket. */

                if (strstr(label, "V")) {
                    type = VOLT_TYPE;
                    mul = 1000.0;
                }
                if (strstr(label, "fan") || strstr(label, "Fan")) {
                    type = FAN_TYPE;
                    mul = 1.0;
                }
                if (strstr(label, "temp") || strstr(label, "Temp")) {
                    type = TEMP_TYPE;
                    mul = 1000.0;
                }
                if (type == -1) {
                    type = MISC_TYPE;
                    mul = 1000.0;
                }

                array = &sensor_array[type];
                if ( array->current_len <= array->n) {
                    _sensor* old_buffer = array->sensor;
                    size_t new_size = (sizeof(_sensor) * array->current_len) + (sizeof(_sensor) * DEFAULT_SENSORS);
                    array->sensor = (_sensor*)realloc(array->sensor, new_size);
                    if (array->sensor == NULL)
                    {
                       /* Continuing would be unsafe */
                       snmp_log(LOG_ERR, "too many sensors to fit, and failed to alloc more, failing on %s\n", label);
                       free(old_buffer);
                       old_buffer = NULL;
                       if (label) {
                           free(label);
                           label = NULL;
                       } /* end if label */
                       return 1;
                    } /* end if array->sensor */
                    array->current_len = new_size / sizeof(_sensor);
                    DEBUGMSG(("ucd-snmp/lmSensors", "type #%d increased to %d elements\n", type, (int)array->current_len));
                } /* end if array->current */
                strlcpy(array->sensor[array->n].name, label, MAX_NAME);
                array->sensor[array->n].value = (int) (val * mul);
                DEBUGMSGTL(("sensors","sensor %s, value %d\n",
                            array->sensor[array->n].name,
                            array->sensor[array->n].value));
                array->n++;
            } /* end if data-mode */
	    if (label) {
		free(label);
		label = NULL;
	    } /* end if label */
        } /* end while data */
    } /* end while chip */
    DEBUGMSG(("ucd-snmp/lmSensors", "<= sensor_load\n"));
#endif  /* end else ie. ifdef everything else */
    /* Update the timestamp after a load. */
    timestamp = t;
    return 0;
}
Пример #6
0
static void
_sensor_load(clock_t t)
{
#ifdef solaris2
    int i,j;
    int typ;
    int temp;
    int other;
    int er_code;
    char *fantypes[]={"CPU","PWR","AFB"};
    kstat_ctl_t *kc;
    kstat_t *kp;
    envctrl_fan_t *fan_info;
    envctrl_ps_t *power_info;
    envctrl_encl_t *enc_info;

#ifdef HAVE_PICL_H
    picl_errno_t     error_code;
    picl_nodehdl_t  rooth,plath;
    char sname[PICL_PROPNAMELEN_MAX] = "SYSTEM";
#endif 

/* DEBUGMSG(("ucd-snmp/lmSensors", "Reading the sensors\n")); */

/* initialize the array */
    for (i = 0; i < N_TYPES; i++){
        sensor_array[i].n = 0;
        for (j=0; j < MAX_SENSORS; j++){
            sensor_array[i].sensor[j].name[0] = '\0';
            sensor_array[i].sensor[j].value = 0;
             }
        } /*end for i*/

/* try picld (if supported), if that doesn't work, try kstat */
#ifdef HAVE_PICL_H 

er_code = picl_initialize();

if (er_code == PICL_SUCCESS) {

    error_code = picl_get_root(&rooth);

    if (error_code != PICL_SUCCESS) {
        DEBUGMSG(("ucd-snmp/lmSensors", "picld couldn't get root error code->%d\n",error_code));
        }
    else{
        error_code = get_child(rooth,sname,&plath);

        if (error_code == PICL_SUCCESS){
            error_code = process_sensors(plath);

            if (error_code != 255) 
                if (error_code != 7)
                    DEBUGMSG(("ucd-snmp/lmSensors", "picld had an internal problem error code->%d\n",error_code));
            } /* endif error_code */
        else{
            DEBUGMSG(("ucd-snmp/lmSensors", "picld couldn't get system tree error code->%d\n",error_code));
            } /* end else error_code */
        } /* end else */

    picl_shutdown();

}  /* end if err_code for picl_initialize */

else{  /* try kstat instead */

    DEBUGMSG(("ucd-snmp/lmSensors", "picld couldn't initialize picld because error code->%d\n",er_code));

#endif  /* end of picld section */
/* initialize kstat */

kc = kstat_open();
if (kc == 0) {
    DEBUGMSG(("ucd-snmp/lmSensors", "couldn't open kstat"));
    } /* endif kc */
else{
    kp = kstat_lookup(kc, ENVCTRL_MODULE_NAME, 0, ENVCTRL_KSTAT_FANSTAT);
    if (kp == 0) {
        DEBUGMSGTL(("ucd-snmp/lmSensors", "couldn't lookup fan kstat"));
        } /* endif lookup fans */
    else{
        if (kstat_read(kc, kp, 0) == -1) {
            DEBUGMSGTL(("ucd-snmp/lmSensors", "couldn't read fan kstat"));
            } /* endif kstatread fan */
        else{
            typ = 1;
            fan_info = (envctrl_fan_t *) kp->ks_data;
            sensor_array[typ].n = kp->ks_ndata;
            for (i=0; i < kp->ks_ndata; i++){
                DEBUGMSG(("ucd-snmp/lmSensors", "found instance %d fan type %d speed %d OK %d bustedfan %d\n",
                    fan_info->instance, fan_info->type,fan_info->fanspeed,fan_info->fans_ok,fan_info->fanflt_num));
                sensor_array[typ].sensor[i].value = fan_info->fanspeed;
                snprintf(sensor_array[typ].sensor[i].name,(MAX_NAME - 1),
                   "fan type %s number %d",fantypes[fan_info->type],fan_info->instance);
                sensor_array[typ].sensor[i].name[MAX_NAME - 1] = '\0';
                fan_info++;
                } /* end for fan_info */
            } /* end else kstatread fan */
        } /* end else lookup fans*/


    kp = kstat_lookup(kc, ENVCTRL_MODULE_NAME, 0, ENVCTRL_KSTAT_PSNAME);
    if (kp == 0) {
        DEBUGMSGTL(("ucd-snmp/lmSensors", "couldn't lookup power supply kstat"));
        } /* endif lookup power supply */
    else{
        if (kstat_read(kc, kp, 0) == -1) {
            DEBUGMSGTL(("ucd-snmp/lmSensors", "couldn't read power supply kstat"));
            } /* endif kstatread fan */
        else{
            typ = 2;
            power_info = (envctrl_ps_t *) kp->ks_data;
            sensor_array[typ].n = kp->ks_ndata;
            for (i=0; i < kp->ks_ndata; i++){
                DEBUGMSG(("ucd-snmp/lmSensors", "found instance %d psupply temp %d %dW OK %d share %d limit %d\n",
                    power_info->instance, power_info->ps_tempr,power_info->ps_rating,
                    power_info->ps_ok,power_info->curr_share_ok,power_info->limit_ok));
                sensor_array[typ].sensor[i].value = power_info->ps_tempr;
                snprintf(sensor_array[typ].sensor[i].name,(MAX_NAME-1),
                         "power supply %d",power_info->instance);
                sensor_array[typ].sensor[i].name[MAX_NAME - 1] = '\0';
                power_info++;
                } /* end for power_info */
            } /* end else kstatread power supply */
        } /* end else lookup power supplies*/

    kp = kstat_lookup(kc, ENVCTRL_MODULE_NAME, 0, ENVCTRL_KSTAT_ENCL);
    if (kp == 0) {
        DEBUGMSGTL(("ucd-snmp/lmSensors", "couldn't lookup enclosure kstat"));
        } /* endif lookup enclosure */
    else{
        if (kstat_read(kc, kp, 0) == -1) {
            DEBUGMSGTL(("ucd-snmp/lmSensors", "couldn't read enclosure kstat"));
            } /* endif kstatread enclosure */
        else{
            enc_info = (envctrl_encl_t *) kp->ks_data; 
            temp = 0;
            other = 0;
            for (i=0; i < kp->ks_ndata; i++){
               switch (enc_info->type){
               case ENVCTRL_ENCL_FSP:
                   DEBUGMSG(("ucd-snmp/lmSensors", "front panel value %d\n",enc_info->value));
                   typ = 3; /* misc */
                   sensor_array[typ].sensor[other].value = enc_info->value;
                   strncpy(sensor_array[typ].sensor[other].name,"FSP",MAX_NAME-1);
                   sensor_array[typ].sensor[other].name[MAX_NAME-1]='\0'; /* null terminate */
                   other++;
                   break;
               case ENVCTRL_ENCL_AMBTEMPR:
                   DEBUGMSG(("ucd-snmp/lmSensors", "ambient temp %d\n",enc_info->value));
                   typ = 0; /* temperature sensor */
                   sensor_array[typ].sensor[temp].value = enc_info->value;
                   strncpy(sensor_array[typ].sensor[temp].name,"Ambient",MAX_NAME-1);
                   sensor_array[typ].sensor[temp].name[MAX_NAME-1]='\0'; /* null terminate */
                   temp++;
                   break;
               case ENVCTRL_ENCL_BACKPLANE4:
                   DEBUGMSG(("ucd-snmp/lmSensors", "There is a backplane4\n"));
                   typ = 3; /* misc */
                   sensor_array[typ].sensor[other].value = enc_info->value;
                   strncpy(sensor_array[typ].sensor[other].name,"Backplane4",MAX_NAME-1);
                   sensor_array[typ].sensor[other].name[MAX_NAME-1]='\0'; /* null terminate */
                   other++;
                   break;
               case ENVCTRL_ENCL_BACKPLANE8:
                   DEBUGMSG(("ucd-snmp/lmSensors", "There is a backplane8\n"));
                   typ = 3; /* misc */
                   sensor_array[typ].sensor[other].value = enc_info->value;
                   strncpy(sensor_array[typ].sensor[other].name,"Backplane8",MAX_NAME-1);
                   sensor_array[typ].sensor[other].name[MAX_NAME-1]='\0'; /* null terminate */
                   other++;
                   break;
               case ENVCTRL_ENCL_CPUTEMPR:
                   DEBUGMSG(("ucd-snmp/lmSensors", "CPU%d temperature %d\n",enc_info->instance,enc_info->value));
                   typ = 0; /* temperature sensor */
                   sensor_array[typ].sensor[temp].value = enc_info->value;
                   snprintf(sensor_array[typ].sensor[temp].name,MAX_NAME,"CPU%d",enc_info->instance);
                   sensor_array[typ].sensor[other].name[MAX_NAME-1]='\0'; /* null terminate */
                   temp++;
                   break;
               default:
                   DEBUGMSG(("ucd-snmp/lmSensors", "unknown element instance &d type &d value %d\n",
                       enc_info->instance, enc_info->type, enc_info->value));
                   break;
               } /* end switch */
               enc_info++;
               } /* end for enc_info */
               sensor_array[3].n = other;
               sensor_array[0].n = temp;
            } /* end else kstatread enclosure */
        } /* end else lookup enclosure*/

    kstat_close(kc);

#ifdef HAVE_PICL_H
    } /* end else kc not needed if no picld*/
#endif

} /* end else kstat */
#else /* end solaris2 */

    const sensors_chip_name *chip;
    const sensors_feature_data *data;
    int             chip_nr = 0;

    int             i;
    for (i = 0; i < N_TYPES; i++)
        sensor_array[i].n = 0;

    while (chip = sensors_get_detected_chips(&chip_nr)) {
	int             a = 0;
	int             b = 0;
        while (data = sensors_get_all_features(*chip, &a, &b)) {
            char           *label = NULL;
            double          val;

            if ((data->mode & SENSORS_MODE_R) &&
                (data->mapping == SENSORS_NO_MAPPING) &&
                !sensors_get_label(*chip, data->number, &label) &&
                !sensors_get_feature(*chip, data->number, &val)) {
                int             type = -1;
                float           mul;
                _sensor_array  *array;


                if (strstr(label, "V")) {
                    type = 2;
                    mul = 1000.0;
                }
                if (strstr(label, "fan") || strstr(label, "Fan")) {
                    type = 1;
                    mul = 1.0;
                }
                if (strstr(label, "temp") || strstr(label, "Temp")) {
                    type = 0;
                    mul = 1000.0;
                }
                if (type == -1) {
                    type = 3;
                    mul = 1000.0;
                }

                array = &sensor_array[type];
                if (MAX_SENSORS <= array->n) {
                    snmp_log(LOG_ERR, "too many sensors. ignoring %s\n", label);
                    break;
                }
                strncpy(array->sensor[array->n].name, label, MAX_NAME);
                array->sensor[array->n].value = (int) (val * mul);
                DEBUGMSGTL(("sensors","sensor %d, value %d\n",
                            array->sensor[array->n].name,
                            array->sensor[array->n].value));
                array->n++;
            }
	    if (label) {
		free(label);
		label = NULL;
	    }
        }
    }
#endif /*else solaris2 */
    timestamp = t;
}
Пример #7
0
/* Get EDID info. from the display-edif-block property of the vgatext device node */
struct vbe_edid1_info *vbe_get_edid_info(char *edid_file, char *xorg_log)
{
	struct vbe_edid1_info *ret = NULL;
        picl_nodehdl_t  hdl;
	u_int16_t man;
	int count = 0;

	mem = NULL;

	if (edid_file == NULL && xorg_log == NULL) {
        	if (picl_initialize() == 0) {
                	if (picl_get_root(&hdl) == 0) {
                        	if (picl_walk_tree_by_class(hdl, NULL,
                                	NULL, walk_callback) != 0) {
                                	picl_shutdown();
					return (NULL);
                        	}
                	} else {
                        	picl_shutdown();
				return (NULL);
                	}
        	} else {
			return (NULL);
        	}
        	picl_shutdown();

	} else if (edid_file != NULL) {
		/* Read raw EDID data from file */
		FILE *ef = fopen(edid_file, "r");

		if (ef != NULL) {
			mem = malloc(EDID1_LEN);
			if (fread(mem, EDID1_LEN, 1, ef) == 1) {
				perror("Unable to read edid file ");
				free(mem);
				mem = NULL;
			} 
			(void) fclose(ef);
		} else {
			perror("Unable to read edid file ");
		}

	} else if (xorg_log != NULL) {
		/* Parse EDID data block from Xorg logfile */
		FILE *fh;
		char line[512], hexbyte[5];
		char *xline, *pos;
		int edid_data = 0;
		int i, j;
		int bytes = 0;

		count = 0;
		mem = malloc(sizeof(struct _EDIFinfo));
		hexbyte[0] = '0';
		hexbyte[1] = 'x';
		hexbyte[4] = '\0';
		fh = fopen(xorg_log, "r");
		if (fh != NULL) {
			while ((xline = fgets(line, 512, fh)) != NULL) {
				if (strstr(xline, "EDID (in hex):")) {
					edid_data = 1;
					continue;
				}
				if (edid_data && count < 8) {
					pos = strstr(xline, " 	");
					if (!pos) {
						free(mem);
						mem = NULL;
						break;
					}

					pos += 2;
					for (i=0; i<16; i++) {
						j = i * 2;
						hexbyte[2] = pos[j];
						hexbyte[3] = pos[j+1];
						mem[bytes++] = strtol(hexbyte, NULL, 0);
					}
					count++;

				} else if (count == 8) {
					break;
				}
			}

			/* Second try to detect Raw EDID dump from NVIDIA binary
			   driver */
			if (count < 8) {
				bytes = 0;
				count = 0;
				if (mem == NULL)
					mem = malloc(sizeof(struct _EDIFinfo));
				rewind(fh);
				while ((xline = fgets(line, 512, fh)) != NULL) {
					if (strstr(xline, "Raw EDID bytes:")) {
						edid_data = 1;
						continue;
					}
					if (edid_data && count < 8) {
						pos = strstr(xline, "--- End of EDID");
						if (pos) {
							free(mem);
							mem = NULL;
							break;
						}
						pos = strstr(xline, ":   ");
						if (!pos)
							continue;
	
						pos += 4;
						for (i=0; i<48;) {
							while (pos[i] == ' ') i++;
							hexbyte[2] = pos[i];
							hexbyte[3] = pos[i+1];
							mem[bytes++] = strtol(hexbyte, NULL, 0);
							i += 2;
						}
						count++;
	
					} else if (count == 8) {
						break;
					}
				}
			}
			(void) fclose(fh);
		}
	}

	/*
 	 * mem == NULL means that either PICL did not find the
	 * display-edif-block or the EDID data file could not be read.
 	 * So either the monitor does not provide EDID data or there is
	 * some other problem. In any case we cannot continue.
 	 */
	if (mem == NULL || count < 8) {
		if (mem != NULL)
			free(mem);
		printf("No EDID data\n");
		return (NULL);
	}

	/* Get memory for return. */
	ret = malloc(sizeof(struct vbe_edid1_info));
	if(ret == NULL) {
		(void) free(mem);
		return (NULL);
	}

	/* Copy the buffer for return. */
	memcpy(ret, mem, sizeof(struct _EDIFinfo));

	memcpy(&man, &ret->manufacturer_name, 2);
	man = ntohs(man);
	memcpy(&ret->manufacturer_name, &man, 2);

	free(mem);
	mem = NULL;
	return ret;
}