From: Hugo Villeneuve Date: Wed, 29 May 2024 15:53:30 +0000 (-0400) Subject: Add support for AC in sysfs online status path X-Git-Url: http://gitweb.hugovil.com/?a=commitdiff_plain;h=791ec95fb9af8c82a8c6e63c84146a6d7d71919c;p=dockapps%2Fdockbatmon.git Add support for AC in sysfs online status path --- diff --git a/src/batmon.c b/src/batmon.c index 695c0d4..6ddcf92 100644 --- a/src/batmon.c +++ b/src/batmon.c @@ -60,7 +60,6 @@ static int font_size; static int capacity; static int ac_online = false; static const char battery[] = "BAT0"; -static const char ac[] = "AC0"; static const char ac_acpi_dir_base[] = "/sys/class/power_supply"; static const char battery_acpi_dir_base[] = "/sys/class/power_supply"; @@ -103,13 +102,17 @@ static void read_ac_status(void) { char path[256]; - sprintf(path, "%s/%s/online", ac_acpi_dir_base, ac); + sprintf(path, "%s/%s/online", ac_acpi_dir_base, "AC"); if (access(path, F_OK ) < 0) { - perror(path); - fprintf(stderr, - "Unable to find power supply AC online status.\n"); - exit(EXIT_FAILURE); + sprintf(path, "%s/%s/online", ac_acpi_dir_base, "AC0"); + + if (access(path, F_OK ) < 0) { + perror(path); + fprintf(stderr, + "Unable to find power supply AC online status.\n"); + exit(EXIT_FAILURE); + } } ac_online = read_int_from_file(path);