diff options
author | Theodore Ts'o <tytso@mit.edu> | 2005-01-17 13:59:18 -0500 |
---|---|---|
committer | Theodore Ts'o <tytso@mit.edu> | 2005-01-17 13:59:18 -0500 |
commit | ecd0d8fe2a5948d9676e3c4e3a7bd0569322b056 (patch) | |
tree | eab20f59d512883ac5b2f9fc897912186fed70f6 | |
parent | 2000746b2328de8db90cbe735c26453394f31d48 (diff) | |
download | e2fsprogs-ecd0d8fe2a5948d9676e3c4e3a7bd0569322b056.tar.gz |
Clean up Matthais's "fix crash when /proc/acpi/ac_acapter is not present"
patch.
-rw-r--r-- | e2fsck/unix.c | 33 |
1 files changed, 17 insertions, 16 deletions
diff --git a/e2fsck/unix.c b/e2fsck/unix.c index 43a64b5e..1adc1831 100644 --- a/e2fsck/unix.c +++ b/e2fsck/unix.c @@ -222,24 +222,25 @@ static int is_on_batt(void) return (acflag != 1); } 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) { - closedir(d); - return 1; + if (d) { + while (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) { + closedir(d); + return 1; + } } - } - if (d) closedir(d); + } return 0; } |