From 24fc5032b5bcc7c3bc25acdcd0cd822afed3f9c5 Mon Sep 17 00:00:00 2001 From: Theodore Ts'o Date: Wed, 26 Aug 1998 15:23:31 +0000 Subject: [PATCH] ChangeLog, unix.c: unix.c (check_if_skip): Move the "not cleanly mounted" check ahead of the maximal mount and too long since checked tests. (reserve_stdio_fds): Make sure 0,1,2 file descriptors are open, so that we don't open the filesystem using the same file descriptor as stdout or stderr. --- e2fsck/ChangeLog | 8 ++++++++ e2fsck/unix.c | 19 ++++++++++++++++--- 2 files changed, 24 insertions(+), 3 deletions(-) diff --git a/e2fsck/ChangeLog b/e2fsck/ChangeLog index 17f883b..59db2cc 100644 --- a/e2fsck/ChangeLog +++ b/e2fsck/ChangeLog @@ -1,3 +1,11 @@ +1998-08-17 Theodore Ts'o + + * unix.c (check_if_skip): Move the "not cleanly mounted" check + ahead of the maximal mount and too long since checked tests. + (reserve_stdio_fds): Make sure 0,1,2 file descriptors are + open, so that we don't open the filesystem using the same + file descriptor as stdout or stderr. + 1998-08-01 Theodore Ts'o * pass2.c (e2fsck_pass2): Fix the progress accounting so that we diff --git a/e2fsck/unix.c b/e2fsck/unix.c index b4710a2..d9d86dc 100644 --- a/e2fsck/unix.c +++ b/e2fsck/unix.c @@ -198,6 +198,8 @@ static void check_if_skip(e2fsck_t ctx) if (fs->super->s_state & EXT2_ERROR_FS) reason = "contains a file system with errors"; + else if ((fs->super->s_state & EXT2_VALID_FS) == 0) + reason = "was not cleanly unmounted"; else if (fs->super->s_mnt_count >= (unsigned) fs->super->s_max_mnt_count) reason = "has reached maximal mount count"; @@ -205,8 +207,6 @@ static void check_if_skip(e2fsck_t ctx) time(0) >= (fs->super->s_lastcheck + fs->super->s_checkinterval)) reason = "has gone too long without being checked"; - else if ((fs->super->s_state & EXT2_VALID_FS) == 0) - reason = "was not cleanly unmounted"; if (reason) { printf("%s %s, check forced.\n", ctx->device_name, reason); return; @@ -246,6 +246,18 @@ static int e2fsck_update_progress(e2fsck_t ctx, int pass, #define PATH_SET "PATH=/sbin" +static void reserve_stdio_fds(NOARGS) +{ + int fd; + + while (1) { + fd = open("/dev/null", O_RDWR); + if (fd > 2) + break; + } + close(fd); +} + static errcode_t PRS(int argc, char *argv[], e2fsck_t *ret_ctx) { int flush = 0; @@ -456,7 +468,8 @@ int main (int argc, char *argv[]) "while trying to initialize program"); exit(1); } - + reserve_stdio_fds(); + #ifdef RESOURCE_TRACK init_resource_track(&ctx->global_rtrack); #endif -- 1.8.3.1