kdebase: lm_sensor.patch

File lm_sensor.patch, 3.7 KB (added by Paul Rogers, 15 years ago)

lm-sensors Patch file

  • kdebase-3.5.8/ksysguard/ksysguardd/Linux/lmsensors.c

    diff -up kdebase-3.5.8/ksysguard/ksysguardd/Linux/lmsensors.c.lmsens3x kdebase-3.5.8/ksysguard/ksysguardd/Linux/lmsensors.c
    old new typedef struct  
    3636{
    3737  char* fullName;
    3838  const sensors_chip_name* scn;
     39#if SENSORS_API_VERSION & 0x400
     40  const sensors_feature *sf;
     41  const sensors_subfeature *sfd;
     42#else
    3943  const sensors_feature_data* sfd;
     44#endif
    4045} LMSENSOR;
    4146
    4247static CONTAINER LmSensors;
    static LMSENSOR* findMatchingSensor( con  
    6570  return s;
    6671}
    6772
     73#if SENSORS_API_VERSION & 0x400
     74void initLmSensors( struct SensorModul* sm )
     75{
     76  const sensors_chip_name* scn;
     77  int nr = 0;
     78
     79  if ( sensors_init( NULL ) ) {
     80    LmSensorsOk = -1;
     81    return;
     82  }
     83
     84  LmSensors = new_ctnr();
     85  while ( ( scn = sensors_get_detected_chips( NULL, &nr ) ) != NULL ) {
     86    int nr1 = 0;
     87    const sensors_feature* sf;
     88
     89    while ( ( sf = sensors_get_features( scn, &nr1 ) ) != 0 ) {
     90      const sensors_subfeature *ssubf;
     91      LMSENSOR *p;
     92      char *s, *label;
     93     
     94      switch( sf->type )
     95      {
     96        case SENSORS_FEATURE_IN:
     97          ssubf = sensors_get_subfeature( scn, sf,
     98                                          SENSORS_SUBFEATURE_IN_INPUT );
     99          break;
     100   
     101        case SENSORS_FEATURE_FAN:
     102          ssubf = sensors_get_subfeature( scn, sf,
     103                                          SENSORS_SUBFEATURE_FAN_INPUT );
     104          break;
     105   
     106        case SENSORS_FEATURE_TEMP:
     107          ssubf = sensors_get_subfeature( scn, sf,
     108                                          SENSORS_SUBFEATURE_TEMP_INPUT );
     109          break;
     110      }
     111     
     112      if ( !ssubf )
     113        continue;
     114
     115      label = sensors_get_label( scn, sf );
     116      p = (LMSENSOR*)malloc( sizeof( LMSENSOR ) );
     117      p->fullName = (char*)malloc( strlen( "lmsensors/" ) +
     118                                   strlen( scn->prefix ) + 1 +
     119                                   strlen( label ) + 1 );
     120      sprintf( p->fullName, "lmsensors/%s/%s", scn->prefix, label );
     121
     122      /* Make sure that name contains only proper characters. */
     123      for ( s = p->fullName; *s; s++ )
     124        if ( *s == ' ' )
     125          *s = '_';
     126
     127      p->scn = scn;
     128      p->sf = sf;
     129      p->sfd = ssubf;
     130
     131      /* Note a name collision should never happen with the lm_sensors-3x code,
     132         but it does in the case of k8temp, when there are 2 identical labeled
     133         sensors per CPU. This are really 2 distinct sensors measuring the
     134         same thing, but fullName must be unique so we just drop the second
     135         sensor */
     136      if ( search_ctnr( LmSensors, sensorCmp, p ) < 0 ) {
     137        push_ctnr( LmSensors, p );
     138        registerMonitor( p->fullName, "float", printLmSensor, printLmSensorInfo, sm );
     139      } else {
     140        free( p->fullName );
     141        free( p );
     142      }
     143      free( label );
     144    }
     145  }
     146  bsort_ctnr( LmSensors, sensorCmp );
     147}
     148#else /* SENSORS_API_VERSION & 0x400 */
    68149void initLmSensors( struct SensorModul* sm )
    69150{
    70151  const sensors_chip_name* scn;
    void initLmSensors( struct SensorModul*  
    117198          free( p->fullName );
    118199          free( p );
    119200        }
     201        free( label );
    120202      }
    121203    }
    122204  }
    123205  bsort_ctnr( LmSensors, sensorCmp );
    124206}
     207#endif /* SENSORS_API_VERSION & 0x400 */
    125208
    126209void exitLmSensors( void )
    127210{
    void printLmSensor( const char* cmd )  
    137220    fprintf( CurrentClient, "0\n" );
    138221    return;
    139222  }
    140 
     223#if SENSORS_API_VERSION & 0x400
     224  sensors_get_value( s->scn, s->sfd->number, &value );
     225#else
    141226  sensors_get_feature( *(s->scn), s->sfd->number, &value );
     227#endif
    142228  fprintf( CurrentClient, "%f\n", value );
    143229}