From 791ec95fb9af8c82a8c6e63c84146a6d7d71919c Mon Sep 17 00:00:00 2001 From: Hugo Villeneuve Date: Wed, 29 May 2024 11:53:30 -0400 Subject: [PATCH] Add support for AC in sysfs online status path --- src/batmon.c | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) 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); -- 2.20.1