From 4f7acf32b536cc3cba8ccde6d685d931540a75f1 Mon Sep 17 00:00:00 2001 From: Karel Zak Date: Fri, 5 Oct 2018 11:04:04 +0200 Subject: libmount: keep namespaces support optional Reported-by: Ruediger Meier Signed-off-by: Karel Zak --- libmount/src/context.c | 22 ++++++++++++++++++---- libmount/src/version.c | 3 +++ 2 files changed, 21 insertions(+), 4 deletions(-) (limited to 'libmount/src') 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 -- cgit v1.2.3-55-g7522