summaryrefslogtreecommitdiffstats
path: root/libmount/src
diff options
context:
space:
mode:
authorKarel Zak2018-10-05 11:04:04 +0200
committerKarel Zak2018-10-05 11:35:45 +0200
commit4f7acf32b536cc3cba8ccde6d685d931540a75f1 (patch)
treecb13cf59cd10c0656e2f75f0187624b029e7f839 /libmount/src
parentbuild-sys: add USE_LIBMOUNT_SUPPORT_NAMESPACES (diff)
downloadkernel-qcow2-util-linux-4f7acf32b536cc3cba8ccde6d685d931540a75f1.tar.gz
kernel-qcow2-util-linux-4f7acf32b536cc3cba8ccde6d685d931540a75f1.tar.xz
kernel-qcow2-util-linux-4f7acf32b536cc3cba8ccde6d685d931540a75f1.zip
libmount: keep namespaces support optional
Reported-by: Ruediger Meier <sweet_f_a@gmx.de> Signed-off-by: Karel Zak <kzak@redhat.com>
Diffstat (limited to 'libmount/src')
-rw-r--r--libmount/src/context.c22
-rw-r--r--libmount/src/version.c3
2 files changed, 21 insertions, 4 deletions
diff --git a/libmount/src/context.c b/libmount/src/context.c
index 26ee1e437..b9c18d94f 100644
--- a/libmount/src/context.c
+++ b/libmount/src/context.c
@@ -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;
}
diff --git a/libmount/src/version.c b/libmount/src/version.c
index a7f3a9b60..5dde17bfe 100644
--- a/libmount/src/version.c
+++ b/libmount/src/version.c
@@ -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