]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
libmount: keep namespaces support optional
authorKarel Zak <kzak@redhat.com>
Fri, 5 Oct 2018 09:04:04 +0000 (11:04 +0200)
committerKarel Zak <kzak@redhat.com>
Fri, 5 Oct 2018 09:35:45 +0000 (11:35 +0200)
Reported-by: Ruediger Meier <sweet_f_a@gmx.de>
Signed-off-by: Karel Zak <kzak@redhat.com>
libmount/src/context.c
libmount/src/version.c

index 26ee1e437cd76a6b6363959c7867c1bf5aba8fde..b9c18d94f7240ee5fad7c42f73e04b49a9d48287 100644 (file)
@@ -2739,15 +2739,15 @@ static void close_ns(struct libmnt_ns *ns)
  * Sets target namespace to namespace represented by @path. If @path is NULL,
  * target namespace is cleared.
  *
+ * This function sets errno to ENOSYS and returns error if libmount is
+ * compiled without namespaces support.
+*
  * Returns: 0 on success, negative number in case of error.
  *
  * Since: 2.33
  */
 int mnt_context_set_target_ns(struct libmnt_context *cxt, const char *path)
 {
-       int errsv = 0;
-       int tmp;
-
        if (!cxt)
                return -EINVAL;
 
@@ -2760,6 +2760,10 @@ int mnt_context_set_target_ns(struct libmnt_context *cxt, const char *path)
                return 0;
        }
 
+#ifdef USE_LIBMOUNT_SUPPORT_NAMESPACES
+       int errsv = 0;
+       int tmp;
+
        errno = 0;
 
        /* open original namespace */
@@ -2793,6 +2797,10 @@ int mnt_context_set_target_ns(struct libmnt_context *cxt, const char *path)
 err:
        close(tmp);
        errno = errsv;
+
+#else /* ! USE_LIBMOUNT_SUPPORT_NAMESPACES */
+       errno = ENOSYS;
+#endif
        return -errno;
 }
 
@@ -2846,15 +2854,20 @@ struct libmnt_ns *mnt_context_get_origin_ns(struct libmnt_context *cxt)
  */
 struct libmnt_ns *mnt_context_switch_ns(struct libmnt_context *cxt, struct libmnt_ns *ns)
 {
-       struct libmnt_ns *old;
+       struct libmnt_ns *old = NULL;
 
        if (!cxt || !ns)
                return NULL;
 
+       /*
+        * If mnt_context_set_target_ns() has never been used than @ns file
+        * descriptor is -1 and this function is noop.
+        */
        old = cxt->ns_cur;
        if (ns == old || ns->fd == -1)
                return old;
 
+#ifdef USE_LIBMOUNT_SUPPORT_NAMESPACES
        /* remember the curremt cache */
        if (old->cache != cxt->cache) {
                mnt_unref_cache(old->cache);
@@ -2882,6 +2895,7 @@ struct libmnt_ns *mnt_context_switch_ns(struct libmnt_context *cxt, struct libmn
        mnt_unref_cache(cxt->cache);
        cxt->cache = ns->cache;
        mnt_ref_cache(cxt->cache);
+#endif /* USE_LIBMOUNT_SUPPORT_NAMESPACES */
 
        return old;
 }
index a7f3a9b608bb30617afb15e319b79441aa88e5b0..5dde17bfe4ada493ebb37983e0d49c88fd901097 100644 (file)
@@ -34,6 +34,9 @@ static const char *lib_features[] = {
 #ifdef USE_LIBMOUNT_SUPPORT_MTAB
        "mtab",
 #endif
+#ifdef USE_LIBMOUNT_SUPPORT_NAMESPACES
+       "namespaces",
+#endif
 #if !defined(NDEBUG)
        "assert",       /* libc assert.h stuff */
 #endif