From c07f9f26392ac006a986d4c7488719000614ca64 Mon Sep 17 00:00:00 2001 From: Theodore Ts'o Date: Mon, 12 Apr 2004 00:16:44 -0400 Subject: [PATCH] In e2fsck, when trying to determine if the system is running on battery, be more flexible about the name of the ACPI device that corresponds to the AC adapter. (Addresses Debian bug #242136) --- e2fsck/ChangeLog | 6 ++++++ e2fsck/unix.c | 26 ++++++++++++++++++++++---- 2 files changed, 28 insertions(+), 4 deletions(-) diff --git a/e2fsck/ChangeLog b/e2fsck/ChangeLog index 280860e..dd49064 100644 --- a/e2fsck/ChangeLog +++ b/e2fsck/ChangeLog @@ -1,3 +1,9 @@ +2004-04-12 Theodore Ts'o + + * 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 * Makefile.in: Update the modtime even if subst doesn't need to diff --git a/e2fsck/unix.c b/e2fsck/unix.c index 89c2fa6..0f9f696 100644 --- a/e2fsck/unix.c +++ b/e2fsck/unix.c @@ -39,6 +39,12 @@ extern int optind; #ifdef HAVE_MALLOC_H #include #endif +#ifdef HAVE_SYS_TYPES_H +#include +#endif +#ifdef HAVE_DIRENT_H +#include +#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; } -- 1.8.3.1