]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
libmount: make mnt_context_is_fs_mounted work for /proc
authorIvan Delalande <colona@arista.com>
Fri, 7 Jul 2017 01:27:11 +0000 (18:27 -0700)
committerKarel Zak <kzak@redhat.com>
Tue, 18 Jul 2017 07:46:10 +0000 (09:46 +0200)
Assume that /proc is not mounted instead of returning an error when we
are unable to open the mounts and mountinfo files in /proc. Also set
cxt->mtab back to NULL so that it gets properly parsed when we check if
the next filesystem is mounted.

The goal is to have mount -a work when /proc is not mounted, typically
with /proc on the first line of fstab.

Signed-off-by: Ivan Delalande <colona@arista.com>
libmount/src/context.c

index 3620f652542a0666ff3b3ee8ff01360e50ba730a..dbbe35be1cbca6cf33842a28189f721cca0d7545 100644 (file)
@@ -33,6 +33,7 @@
 
 #include "mountP.h"
 #include "fileutils.h"
+#include "strutils.h"
 
 #include <sys/wait.h>
 
@@ -2449,14 +2450,23 @@ int mnt_context_helper_setopt(struct libmnt_context *cxt, int c, char *arg)
 int mnt_context_is_fs_mounted(struct libmnt_context *cxt,
                              struct libmnt_fs *fs, int *mounted)
 {
-       struct libmnt_table *mtab;
+       struct libmnt_table *mtab, *orig;
        int rc;
 
        if (!cxt || !fs || !mounted)
                return -EINVAL;
 
+       orig = cxt->mtab;
        rc = mnt_context_get_mtab(cxt, &mtab);
-       if (rc)
+       if (rc == -ENOENT && mnt_fs_streq_target(fs, "/proc") &&
+           (!cxt->mtab_path || startswith(cxt->mtab_path, "/proc/"))) {
+               if (!orig) {
+                       mnt_unref_table(cxt->mtab);
+                       cxt->mtab = NULL;
+               }
+               *mounted = 0;
+               return 0;       /* /proc not mounted */
+       } else if (rc)
                return rc;
 
        *mounted = mnt_table_is_fs_mounted(mtab, fs);