]> git.ipfire.org Git - thirdparty/e2fsprogs.git/commitdiff
In e2fsck, when trying to determine if the system is running on
authorTheodore Ts'o <tytso@mit.edu>
Mon, 12 Apr 2004 04:16:44 +0000 (00:16 -0400)
committerTheodore Ts'o <tytso@mit.edu>
Mon, 12 Apr 2004 04:16:44 +0000 (00:16 -0400)
battery, be more flexible about the name of the ACPI device that
corresponds to the AC adapter.  (Addresses Debian bug #242136)

e2fsck/ChangeLog
e2fsck/unix.c

index 280860e6a02fc5660ca1d8fe26f008880fdeb2eb..dd49064ceba25de3f72504f3d351161a485437f7 100644 (file)
@@ -1,3 +1,9 @@
+2004-04-12  Theodore Ts'o  <tytso@mit.edu>
+
+       * unix.c (is_on_batt): Be more flexible about the name of the ACPI
+               device that corresponds to the AC adapter.  (Addresses
+               Debian bug #242136)
+
 2004-04-03  Theodore Ts'o  <tytso@mit.edu>
 
        * Makefile.in: Update the modtime even if subst doesn't need to
index 89c2fa6a0b285072ecc05ea6dd5e84f217552447..0f9f696396e548387082edbc5eec803bea4841ff 100644 (file)
@@ -39,6 +39,12 @@ extern int optind;
 #ifdef HAVE_MALLOC_H
 #include <malloc.h>
 #endif
+#ifdef HAVE_SYS_TYPES_H
+#include <sys/types.h>
+#endif
+#ifdef HAVE_DIRENT_H
+#include <dirent.h>
+#endif
 
 #include "et/com_err.h"
 #include "e2fsck.h"
@@ -203,8 +209,10 @@ static void check_mount(e2fsck_t ctx)
 static int is_on_batt(void)
 {
        FILE    *f;
-       char    tmp[80], tmp2[80];
+       DIR     *d;
+       char    tmp[80], tmp2[80], fname[80];
        unsigned int    acflag;
+       struct dirent*  de;
 
        f = fopen("/proc/apm", "r");
        if (f) {
@@ -213,14 +221,24 @@ static int is_on_batt(void)
                fclose(f);
                return (acflag != 1);
        }
-       f = fopen("/proc/acpi/ac_adapter/AC/state", "r");
-       if (f) {
+       d = opendir("/proc/acpi/ac_adapter");
+       while (d && (de=readdir(d))) {
+               if (!strncmp(".", de->d_name, 1))
+                       continue;
+               snprintf(fname, 80, "/proc/acpi/ac_adapter/%s/state", 
+                        de->d_name);
+               f = fopen(fname, "r");
+               if (!f)
+                       continue;
                if (fscanf(f, "%s %s", tmp2, tmp) != 2)
                        tmp[0] = 0;
                fclose(f);
-               if (strncmp(tmp, "off-line", 8) == 0)
+               if (strncmp(tmp, "off-line", 8) == 0) {
+                       closedir(d);
                        return 1;
+               }
        }
+       closedir(d);
        return 0;
 }