]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: namespaces: don't build namespace.c if disabled
authorWilly Tarreau <w@1wt.eu>
Sun, 11 Nov 2018 13:38:09 +0000 (14:38 +0100)
committerWilly Tarreau <w@1wt.eu>
Mon, 12 Nov 2018 18:15:15 +0000 (19:15 +0100)
When namespaces are disabled, support is still reported because the file
is built with almost nothing in it but built anyway. Instead of extending
the scope of the numerous ifdefs in this file, better avoid building it
when namespaces are diabled. In this case we define my_socketat() as an
inline function mapping directly to socket(). The struct netns_entry
still needs to be defined because it's used by various other functions
in the code.

Makefile
include/common/namespace.h
src/namespace.c

index 3b089d227c1b09883403936394efcf3ed15efaa8..965d89d66c3518adbe5443af5b27d5b1c304deab 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -871,6 +871,7 @@ endif
 ifneq ($(USE_NS),)
 OPTIONS_CFLAGS += -DCONFIG_HAP_NS
 BUILD_OPTIONS  += $(call ignore_implicit,USE_NS)
+OPTIONS_OBJS  += src/namespace.o
 endif
 
 #### Global link options
@@ -916,7 +917,7 @@ OBJS = src/proto_http.o src/cfgparse.o src/server.o src/stream.o        \
        src/hpack-dec.o src/memory.o src/lb_fwrr.o src/lb_chash.o        \
        src/lb_fas.o src/hathreads.o src/chunk.o src/lb_map.o            \
        src/xxhash.o src/regex.o src/shctx.o src/buffer.o src/action.o   \
-       src/h1.o src/compression.o src/pipe.o src/namespace.o            \
+       src/h1.o src/compression.o src/pipe.o                            \
        src/sha1.o src/hpack-tbl.o src/hpack-enc.o src/uri_auth.o        \
        src/time.o src/proto_udp.o src/arg.o src/signal.o                \
        src/protocol.o src/lru.o src/hdr_idx.o src/hpack-huff.o          \
index fa4185db61dfff84bc66f197f3d1d612ca6d6fda..7aacff968170e38bab1d1e66f818b685a37649e8 100644 (file)
@@ -4,9 +4,6 @@
 #include <stdlib.h>
 #include <ebistree.h>
 
-struct netns_entry;
-int my_socketat(const struct netns_entry *ns, int domain, int type, int protocol);
-
 #ifdef CONFIG_HAP_NS
 
 struct netns_entry
@@ -16,10 +13,21 @@ struct netns_entry
        int fd;
 };
 
+int my_socketat(const struct netns_entry *ns, int domain, int type, int protocol);
 struct netns_entry* netns_store_insert(const char *ns_name);
 const struct netns_entry* netns_store_lookup(const char *ns_name, size_t ns_name_len);
 
 int netns_init(void);
+
+#else /* no namespace support */
+
+struct netns_entry;
+
+static inline int my_socketat(const struct netns_entry *ns, int domain, int type, int protocol)
+{
+       return socket(domain, type, protocol);
+}
+
 #endif /* CONFIG_HAP_NS */
 
 #endif /* _NAMESPACE_H */
index 93d92480ddaa8e3969cc927e1905f915a76ea317..72f5079ebdb8646ddf32f0fa8638462b14869364 100644 (file)
@@ -17,8 +17,6 @@
 #include <proto/log.h>
 #include <types/global.h>
 
-#ifdef CONFIG_HAP_NS
-
 /* Opens the namespace <ns_name> and returns the FD or -1 in case of error
  * (check errno).
  */
@@ -88,7 +86,6 @@ const struct netns_entry* netns_store_lookup(const char *ns_name, size_t ns_name
        else
                return NULL;
 }
-#endif
 
 /* Opens a socket in the namespace described by <ns> with the parameters <domain>,
  * <type> and <protocol> and returns the FD or -1 in case of error (check errno).
@@ -97,19 +94,15 @@ int my_socketat(const struct netns_entry *ns, int domain, int type, int protocol
 {
        int sock;
 
-#ifdef CONFIG_HAP_NS
        if (default_namespace >= 0 && ns && setns(ns->fd, CLONE_NEWNET) == -1)
                return -1;
-#endif
+
        sock = socket(domain, type, protocol);
 
-#ifdef CONFIG_HAP_NS
        if (default_namespace >= 0 && ns && setns(default_namespace, CLONE_NEWNET) == -1) {
                close(sock);
                return -1;
        }
-#endif
-
        return sock;
 }