From: Nikolas Garofil Date: Mon, 12 Apr 2010 10:45:10 +0000 (+0200) Subject: Bugfix: ac-adapter is sometimes called ADP1 in sysfs instead of AC X-Git-Url: https://vcs.maemo.org/git/?p=monky;a=commitdiff_plain;h=99eeeae6d03e374579563ae730751298fedac088 Bugfix: ac-adapter is sometimes called ADP1 in sysfs instead of AC --- diff --git a/doc/variables.xml b/doc/variables.xml index 2c6dc6e..1bcbcc5 100644 --- a/doc/variables.xml +++ b/doc/variables.xml @@ -7,8 +7,8 @@ ACPI ac adapter state. On linux, the adapter option specifies the - subfolder of /sys/class/power_supply containing the state information (defaults - to "AC"). Other systems ignore it. + subfolder of /sys/class/power_supply containing the state information (tries "AC" + and "ADP1" if there is no argument given). Non-linux systems ignore it. diff --git a/src/core.c b/src/core.c index a7132c6..ac1a7f3 100644 --- a/src/core.c +++ b/src/core.c @@ -171,8 +171,6 @@ struct text_object *construct_text_object(const char *s, const char *arg, long NORM_ERR("acpiacadapter: arg is only used on linux"); #endif } - if(! obj->data.opaque) - obj->data.opaque = strdup("AC"); #endif /* !__OpenBSD__ */ END OBJ(freq, 0) get_cpu_count(); diff --git a/src/linux.c b/src/linux.c index a41220e..3185217 100644 --- a/src/linux.c +++ b/src/linux.c @@ -1336,6 +1336,8 @@ void get_acpi_fan(char *p_client_buffer, size_t client_buffer_size) Update: it seems the folder name is hardware-dependent. We add an aditional adapter argument, specifying the folder name. + + Update: on some systems it's /sys/class/power_supply/ADP1 instead of /sys/class/power_supply/AC */ void get_acpi_ac_adapter(char *p_client_buffer, size_t client_buffer_size, const char *adapter) @@ -1344,14 +1346,20 @@ void get_acpi_ac_adapter(char *p_client_buffer, size_t client_buffer_size, const char buf[256]; char buf2[256]; + struct stat sb; FILE *fp; if (!p_client_buffer || client_buffer_size <= 0) { return; } - snprintf(buf2, sizeof(buf2), "%s/%s/uevent", SYSFS_AC_ADAPTER_DIR, adapter); - fp = open_file(buf2, &rep); + if(adapter) + snprintf(buf2, sizeof(buf2), "%s/%s/uevent", SYSFS_AC_ADAPTER_DIR, adapter); + else{ + snprintf(buf2, sizeof(buf2), "%s/AC/uevent", SYSFS_AC_ADAPTER_DIR); + if(stat(buf2, &sb) == -1) snprintf(buf2, sizeof(buf2), "%s/ADP1/uevent", SYSFS_AC_ADAPTER_DIR); + } + if(stat(buf2, &sb) == 0) fp = open_file(buf2, &rep); else fp = 0; if (fp) { /* sysfs processing */ while (!feof(fp)) {