From: Theodore Ts'o Date: Mon, 8 Jul 2013 16:08:44 +0000 (-0400) Subject: libext2fs, tests: allow /etc/mtab file to be missing X-Git-Tag: v1.42.9~156 X-Git-Url: https://git.whamcloud.com/gitweb?a=commitdiff_plain;h=42b61c50e5af99a10fc56975ecd08ab71e4f00e8;p=tools%2Fe2fsprogs.git libext2fs, tests: allow /etc/mtab file to be missing The environment variable EXT2FS_NO_MTAB_OK will suppress the error code EXT2_NO_MTAB_FILE when the /etc/mtab file can not be found. This allows the e2fsprogs regression test suite to be run in chroots which might not have an /etc/mtab file. By default will still want to complain if the /etc/mtab file is missing, since we really don't want to discourage distributions and purveyors of embedded systems from running without an /etc/mtab file. But if it's missing it only results in a missing sanity check that might cause file system corruption if the file system is mounted when programs such as e2fsck, tune2fs, or resize2fs is running, so there is no potential security problems that might result if this environment variable is set inappropriately. Signed-off-by: "Theodore Ts'o" --- diff --git a/lib/ext2fs/ismounted.c b/lib/ext2fs/ismounted.c index 6a223df..9bccc74 100644 --- a/lib/ext2fs/ismounted.c +++ b/lib/ext2fs/ismounted.c @@ -53,8 +53,15 @@ static errcode_t check_mntent_file(const char *mtab_file, const char *file, int fd; *mount_flags = 0; - if ((f = setmntent (mtab_file, "r")) == NULL) - return (errno == ENOENT ? EXT2_NO_MTAB_FILE : errno); + if ((f = setmntent (mtab_file, "r")) == NULL) { + if (errno == ENOENT) { + if (getenv("EXT2FS_NO_MTAB_OK")) + return 0; + else + return EXT2_NO_MTAB_FILE; + } + return errno; + } if (stat(file, &st_buf) == 0) { if (S_ISBLK(st_buf.st_mode)) { #ifndef __GNU__ /* The GNU hurd is broken with respect to stat devices */ diff --git a/tests/test_config b/tests/test_config index 36b53b7..6789656 100644 --- a/tests/test_config +++ b/tests/test_config @@ -34,3 +34,5 @@ MKE2FS_CONFIG=./mke2fs.conf export MKE2FS_CONFIG E2FSPROGS_SKIP_PROGRESS=yes export E2FSPROGS_SKIP_PROGRESS +EXT2FS_NO_MTAB_OK=yes +export EXT2FS_NO_MTAB_OK