]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
BUG/MEDIUM: namespaces: don't fail if no namespace is used
authorWilly Tarreau <w@1wt.eu>
Tue, 20 Oct 2015 13:14:07 +0000 (15:14 +0200)
committerWilly Tarreau <w@1wt.eu>
Tue, 20 Oct 2015 13:29:00 +0000 (15:29 +0200)
Susheel Jalali reported a confusing bug in namespaces implementation.
If namespaces are enabled at build time (USE_NS=1) and *no* namespace
is used at all in the whole config file, my_socketat() returns -1 and
all socket bindings fail. This is because of a wrong condition in this
function. A possible workaround consists in creating some namespaces.

src/namespace.c

index a22f1a5c456106f01a07a42b889fccc7356e41ba..f1e81df7c4bc3155be9c05ab395e526cee7ff816 100644 (file)
@@ -97,14 +97,13 @@ 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))
+       if (default_namespace >= 0 && ns && setns(ns->fd, CLONE_NEWNET) == -1)
                return -1;
 #endif
        sock = socket(domain, type, protocol);
 
 #ifdef CONFIG_HAP_NS
-       if (ns && setns(default_namespace, CLONE_NEWNET) == -1) {
+       if (default_namespace >= 0 && ns && setns(default_namespace, CLONE_NEWNET) == -1) {
                close(sock);
                return -1;
        }