Skip to content

Commit

Permalink
[fix #92] support for CentOS w/ Linux 3.10.0 but new sensors path
Browse files Browse the repository at this point in the history
  • Loading branch information
dgraziotin committed Apr 2, 2017
1 parent 592895d commit 1ee0e1f
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 48 deletions.
46 changes: 23 additions & 23 deletions src/mbpfan.c
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ t_sensors* sensors = NULL;
t_fans* fans = NULL;


bool is_legacy_kernel()
bool is_legacy_sensors_path()
{
struct utsname kernel;
uname(&kernel);
Expand All @@ -75,31 +75,31 @@ bool is_legacy_kernel()
exit(EXIT_FAILURE);
}

// possible fix for https://github.com/dgraziotin/mbpfan/issues/92
// to be soon investigated.

// thanks http://stackoverflow.com/questions/18192998/plain-c-opening-a-directory-with-fopen
// fopen("/sys/devices/platform/coretemp.0/hwmon", "wb");
fopen("/sys/devices/platform/coretemp.0/hwmon", "wb");

// if (errno == EISDIR) {
// return 0;
// } else {
// return 1;
// }
if (errno == EISDIR) {
return 0;
} else {
return 1;
}

str_kernel_version = strtok(NULL, ".");
int kernel_version = atoi(str_kernel_version);
//
// str_kernel_version = strtok(NULL, ".");
// int kernel_version = atoi(str_kernel_version);

if(verbose) {
printf("Detected kernel version: %s\n", kernel.release);
printf("Detected kernel minor revision: %s\n", str_kernel_version);
// if(verbose) {
// printf("Detected kernel version: %s\n", kernel.release);
// printf("Detected kernel minor revision: %s\n", str_kernel_version);

if(daemonize) {
syslog(LOG_INFO, "Kernel version: %s", kernel.release);
syslog(LOG_INFO, "Detected kernel minor revision: %s", str_kernel_version);
}
}
// if(daemonize) {
// syslog(LOG_INFO, "Kernel version: %s", kernel.release);
// syslog(LOG_INFO, "Detected kernel minor revision: %s", str_kernel_version);
// }
// }

return (atoi(kernel.release) == 3 && kernel_version < 15);
// return (atoi(kernel.release) == 3 && kernel_version < 15);
}


Expand All @@ -112,7 +112,7 @@ t_sensors *retrieve_sensors()
char *path = NULL;
char *path_begin = NULL;

if (is_legacy_kernel()) {
if (is_legacy_sensors_path()) {
if(verbose) {
printf("Using legacy sensor path for kernel < 3.15.0\n");

Expand All @@ -126,10 +126,10 @@ t_sensors *retrieve_sensors()
} else {

if(verbose) {
printf("Using new sensor path for kernel >= 3.0.15\n");
printf("Using new sensor path for kernel >= 3.0.15 or some CentOS versions with kernel 3.10.0\n");

if(daemonize) {
syslog(LOG_INFO, "Using new sensor path for kernel >= 3.0.15");
syslog(LOG_INFO, "Using new sensor path for kernel >= 3.0.15 or some CentOS versions with kernel 3.10.0 ");
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/mbpfan.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ typedef struct s_fans t_fans;
/**
* Return true if the kernel is < 3.15.0
*/
bool is_legacy_kernel();
bool is_legacy_sensors_path();

/**
* Tries to use the settings located in
Expand Down
23 changes: 0 additions & 23 deletions src/minunit.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,28 +13,6 @@

int tests_run = 0;

static const char *test_is_legacy_kernel()
{

struct utsname kernel;
uname(&kernel);

int kern_major_release = (int)(kernel.release[0] - '0');

mu_assert("Kernel major version is minor than 3.", kern_major_release > 2);
char *pch;
pch = strtok(kernel.release, ".");
pch = strtok(NULL, ".");

int minor = atoi(pch);

if ((kern_major_release <= 3) && minor < 15)
mu_assert("Legacy kernel not detected by mbpfan.", is_legacy_kernel() == 1);
else
mu_assert("Non-legacy kernel not detected by mbpfan", is_legacy_kernel() == 0);

return 0;
}

static const char *test_sensor_paths()
{
Expand Down Expand Up @@ -203,7 +181,6 @@ static const char *test_settings_reload()

static const char *all_tests()
{
mu_run_test(test_is_legacy_kernel);
mu_run_test(test_sensor_paths);
mu_run_test(test_fan_paths);
mu_run_test(test_get_temp);
Expand Down
1 change: 0 additions & 1 deletion src/minunit.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
extern int tests_run;


static const char *test_is_legacy_kernel();
static const char *test_sensor_paths();
static const char *test_fan_paths();
static const char *test_get_temp();
Expand Down

0 comments on commit 1ee0e1f

Please sign in to comment.