@@ -258,18 +258,38 @@ static int read_value(const char *path)
258
258
return value ;
259
259
}
260
260
261
+ static void read_value_str (const char * path , char * str , size_t len )
262
+ {
263
+ FILE * file = fopen (path , "r" );
264
+ if (file != NULL ) {
265
+ fgets (str , len , file );
266
+ fclose (file );
267
+ }
268
+ }
269
+
270
+ static void trim_trailing_whitespace (char * str )
271
+ {
272
+ for (ssize_t i = strlen (str ) - 1 ; i >= 0 ; -- i ) {
273
+ if (isspace (str [i ]) || str [i ] == '\n' ) {
274
+ str [i ] = '\0' ;
275
+ }
276
+ }
277
+ }
278
+
261
279
t_fans * retrieve_fans ()
262
280
{
263
281
t_fans * fans_head = NULL ;
264
282
t_fans * fan = NULL ;
265
283
266
284
char * path_output = NULL ;
285
+ char * path_label = NULL ;
267
286
char * path_manual = NULL ;
268
287
char * path_fan_max = NULL ;
269
288
char * path_fan_min = NULL ;
270
289
271
290
const char * path_begin = "/sys/devices/platform/applesmc.768/fan" ;
272
291
const char * path_output_end = "_output" ;
292
+ const char * path_label_end = "_label" ;
273
293
const char * path_man_end = "_manual" ;
274
294
const char * path_max_speed = "_max" ;
275
295
const char * path_min_speed = "_min" ;
@@ -280,6 +300,7 @@ t_fans *retrieve_fans()
280
300
for (counter = 0 ; counter < NUM_FANS ; counter ++ ) {
281
301
282
302
path_output = smprintf ("%s%d%s" , path_begin , counter , path_output_end );
303
+ path_label = smprintf ("%s%d%s" , path_begin , counter , path_label_end );
283
304
path_manual = smprintf ("%s%d%s" , path_begin , counter , path_man_end );
284
305
path_fan_min = smprintf ("%s%d%s" ,path_begin , counter , path_min_speed );
285
306
path_fan_max = smprintf ("%s%d%s" ,path_begin , counter , path_max_speed );
@@ -303,7 +324,12 @@ t_fans *retrieve_fans()
303
324
fan -> fan_max_speed = MAX_FAN_SPEED_DEFAULT ;
304
325
else
305
326
fan -> fan_max_speed = fan_speed ;
306
-
327
+
328
+ size_t max_label_len = 64 ;
329
+ fan -> label = malloc (max_label_len );
330
+ read_value_str (path_label , fan -> label , max_label_len );
331
+ trim_trailing_whitespace (fan -> label );
332
+
307
333
fan -> old_speed = 0 ;
308
334
309
335
if (fans_head == NULL ) {
@@ -326,6 +352,8 @@ t_fans *retrieve_fans()
326
352
}
327
353
free (path_fan_min );
328
354
path_fan_min = NULL ;
355
+ free (path_label );
356
+ path_label = NULL ;
329
357
free (path_fan_max );
330
358
path_fan_max = NULL ;
331
359
free (path_output );
@@ -620,10 +648,10 @@ void mbpfan()
620
648
}
621
649
622
650
if (verbose ) {
623
- printf ("Old Temp %d: New Temp: %d, Fan Speed: %d\n" , old_temp , new_temp , fan_speed );
651
+ printf ("Fan: %s Old Temp %d: New Temp: %d Speed: %d\n" , fan -> label , old_temp , new_temp , fan_speed );
624
652
625
653
if (daemonize ) {
626
- syslog (LOG_INFO , "Old Temp %d: New Temp: %d, Fan Speed: %d" , old_temp , new_temp , fan_speed );
654
+ syslog (LOG_INFO , "Fan: %s Old Temp %d: New Temp: %d Speed: %d" , fan -> label , old_temp , new_temp , fan_speed );
627
655
}
628
656
}
629
657
0 commit comments