BUG/MINOR: namespace: avoid closing fd when socket failed in my_socketat
authorWilliam Dauchy <w.dauchy@criteo.com>
Wed, 12 Feb 2020 20:23:20 +0000 (21:23 +0100)
committerChristopher Faulet <cfaulet@haproxy.com>
Fri, 21 Feb 2020 10:19:38 +0000 (11:19 +0100)
we cannot return right after socket opening as we need to move back to
the default namespace first

this should fix github issue #500

this might be backported to all version >= 1.6

Fixes: b3e54fe387c7c1 ("MAJOR: namespace: add Linux network namespace
support")
Signed-off-by: William Dauchy <w.dauchy@criteo.com>
(cherry picked from commit f7dcdc8a6f63b172360019beb6e1e22e7c98f17d)
Signed-off-by: Christopher Faulet <cfaulet@haproxy.com>

src/namespace.c

index f23da48..89a968e 100644 (file)
@@ -121,7 +121,8 @@ int my_socketat(const struct netns_entry *ns, int domain, int type, int protocol
        sock = socket(domain, type, protocol);
 
        if (default_namespace >= 0 && ns && setns(default_namespace, CLONE_NEWNET) == -1) {
-               close(sock);
+               if (sock >= 0)
+                       close(sock);
                return -1;
        }
        return sock;