@@ -87,43 +87,25 @@ static char *smprintf(const char *fmt, ...)
8787
8888bool is_legacy_sensors_path ()
8989{
90- struct utsname kernel ;
91- uname ( & kernel ) ;
90+ const char * path_begin = "/sys/devices/platform/coretemp.0/hwmon/hwmon" ;
91+ int counter ;
9292
93- char * str_kernel_version ;
94- str_kernel_version = strtok (kernel .release , "." );
93+ for (counter = 0 ; counter < 10 ; counter ++ ) {
94+ char hwmon_path [strlen (path_begin )+ 2 ];
95+ sprintf (hwmon_path , "%s%d" , path_begin , counter );
9596
96- if (atoi (str_kernel_version ) < 3 ){
97- syslog (LOG_INFO , "mbpfan detected a pre-3.x.x linux kernel. Detected version: %s. Exiting.\n" , kernel .release );
98- printf ("mbpfan detected a pre-3.x.x linux kernel. Detected version: %s. Exiting.\n" , kernel .release );
99- exit (EXIT_FAILURE );
100- }
101-
102-
103- // thanks http://stackoverflow.com/questions/18192998/plain-c-opening-a-directory-with-fopen
104- fopen ("/sys/devices/platform/coretemp.0/hwmon" , "wb" );
97+ FILE * file = fopen (hwmon_path , "rb" );
98+ int isdir = file == NULL && errno == EISDIR ;
99+ if (file != NULL ) {
100+ fclose (file );
101+ }
105102
106- if (errno == EISDIR ) {
107- return 0 ;
108- } else {
109- return 1 ;
103+ if (isdir ) {
104+ return 0 ;
105+ }
110106 }
111107
112- //
113- // str_kernel_version = strtok(NULL, ".");
114- // int kernel_version = atoi(str_kernel_version);
115-
116- // if(verbose) {
117- // printf("Detected kernel version: %s\n", kernel.release);
118- // printf("Detected kernel minor revision: %s\n", str_kernel_version);
119-
120- // if(daemonize) {
121- // syslog(LOG_INFO, "Kernel version: %s", kernel.release);
122- // syslog(LOG_INFO, "Detected kernel minor revision: %s", str_kernel_version);
123- // }
124- // }
125-
126- // return (atoi(kernel.release) == 3 && kernel_version < 15);
108+ return 1 ;
127109}
128110
129111
@@ -167,9 +149,13 @@ t_sensors *retrieve_sensors()
167149 sprintf (hwmon_path , "%s%d" , path_begin , counter );
168150
169151 // thanks http://stackoverflow.com/questions/18192998/plain-c-opening-a-directory-with-fopen
170- fopen (hwmon_path , "wb" );
152+ FILE * file = fopen (hwmon_path , "rb" );
153+ int isdir = file == NULL && errno == EISDIR ;
154+ if (file != NULL ) {
155+ fclose (file );
156+ }
171157
172- if (errno == EISDIR ) {
158+ if (isdir ) {
173159
174160 path_begin = smprintf ("%s/temp" , hwmon_path );
175161
0 commit comments