Add support for AC in sysfs online status path
authorHugo Villeneuve <hugo@hugovil.com>
Wed, 29 May 2024 15:53:30 +0000 (11:53 -0400)
committerHugo Villeneuve <hugo@hugovil.com>
Wed, 29 May 2024 15:53:43 +0000 (11:53 -0400)
src/batmon.c

index 695c0d4..6ddcf92 100644 (file)
@@ -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);