Whamcloud - gitweb
libext2fs, tests: allow /etc/mtab file to be missing
authorTheodore Ts'o <tytso@mit.edu>
Mon, 8 Jul 2013 16:08:44 +0000 (12:08 -0400)
committerTheodore Ts'o <tytso@mit.edu>
Mon, 8 Jul 2013 16:08:44 +0000 (12:08 -0400)
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" <tytso@mit.edu>
lib/ext2fs/ismounted.c
tests/test_config

index 6a223df..9bccc74 100644 (file)
@@ -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 */
index 36b53b7..6789656 100644 (file)
@@ -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