Skip to content

Commit 1941f45

Browse files
robabramgaul
authored andcommitted
Add support for alternate applesmc module device path.
1 parent d4473d4 commit 1941f45

File tree

1 file changed

+35
-4
lines changed

1 file changed

+35
-4
lines changed

src/mbpfan.c

Lines changed: 35 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
#include <stdarg.h>
3232
#include <stdio.h>
3333
#include <stdlib.h>
34+
#include <limits.h>
3435
#include <unistd.h>
3536
#include <string.h>
3637
#include <time.h>
@@ -52,6 +53,7 @@
5253

5354
#define CORETEMP_PATH "/sys/devices/platform/coretemp.0"
5455
#define APPLESMC_PATH "/sys/devices/platform/applesmc.768"
56+
#define ALT_APPLESMC_PATH "/sys/bus/acpi/drivers/applesmc"
5557

5658
/* temperature thresholds
5759
* low_temp - temperature below which fan speed will be at minimum
@@ -74,6 +76,9 @@ int polling_interval = 1;
7476

7577
t_sensors *sensors = NULL;
7678
t_fans *fans = NULL;
79+
char applesmc_path[PATH_MAX];
80+
char applesmc_fan_path[PATH_MAX];
81+
7782

7883
char *smprintf(const char *fmt, ...)
7984
{
@@ -273,7 +278,7 @@ t_fans *retrieve_fans()
273278
char *path_fan_max = NULL;
274279
char *path_fan_min = NULL;
275280

276-
const char *path_begin = "/sys/devices/platform/applesmc.768/fan";
281+
const char *path_begin = (const char *) &applesmc_fan_path;
277282
const char *path_output_end = "_output";
278283
const char *path_label_end = "_label";
279284
const char *path_man_end = "_manual";
@@ -553,15 +558,41 @@ void check_requirements(const char *program_path)
553558
}
554559

555560
closedir(dir);
561+
memset(&applesmc_path, 0, PATH_MAX);
562+
memset(&applesmc_fan_path, 0, PATH_MAX);
556563

557564
dir = opendir(APPLESMC_PATH);
558565

559-
if (ENOENT == errno) {
560-
mbp_log(LOG_ERR, "%s needs applesmc support. Please either load it or build it into the kernel. Exiting.", program_path);
561-
exit(EXIT_FAILURE);
566+
if (ENOENT != errno) {
567+
strncpy((char *) &applesmc_path, APPLESMC_PATH, PATH_MAX);
568+
} else {
569+
/**
570+
* Check for alternate ACPI device path for newer macbooks
571+
*/
572+
closedir(dir);
573+
dir = opendir(ALT_APPLESMC_PATH);
574+
if (ENOENT != errno) {
575+
struct dirent *ent;
576+
while ((ent = readdir(dir)) != NULL) {
577+
if (strncmp("APP", (const char *) &ent->d_name, 3) == 0) {
578+
snprintf((char *) &applesmc_path, PATH_MAX, "%s/%s", ALT_APPLESMC_PATH, (char *) &ent->d_name);
579+
break;
580+
}
581+
}
582+
}
562583
}
563584

564585
closedir(dir);
586+
587+
if (strlen(applesmc_path) != 0) {
588+
strncpy((char *) &applesmc_fan_path, (char *) &applesmc_path, PATH_MAX);
589+
strcat((char *) &applesmc_fan_path, "/fan");
590+
if (verbose) mbp_log(LOG_INFO, "applesmc device path: %s", (char *) &applesmc_path);
591+
592+
} else {
593+
mbp_log(LOG_ERR, "%s needs applesmc support. Please either load it or build it into the kernel. Exiting.", program_path);
594+
exit(EXIT_FAILURE);
595+
}
565596
}
566597

567598
int get_max_mhz(void)

0 commit comments

Comments
 (0)