From 6920adda0dce8cc9fb585da658dd983833c2a928 Mon Sep 17 00:00:00 2001 From: David Gibson Date: Wed, 2 Aug 2023 13:15:40 +1000 Subject: util: Make ns_enter() a void function and report setns() errors ns_enter() returns an integer... but it's always zero. If we actually fail the function doesn't return. Therefore it makes more sense for this to be a function returning void, and we can remove the cases where we pointlessly checked its return value. In addition ns_enter() is usually called from an ephemeral thread created by NS_CALL(). That means that the exit(EXIT_FAILURE) there usually won't be reported (since NS_CALL() doesn't wait() for the thread). So, use die() instead to print out some information in the unlikely event that our setns() here does fail. Signed-off-by: David Gibson Signed-off-by: Stefano Brivio --- tap.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'tap.c') diff --git a/tap.c b/tap.c index a6a73d3..0f90cab 100644 --- a/tap.c +++ b/tap.c @@ -1182,9 +1182,9 @@ static int tap_ns_tun(void *arg) struct ctx *c = (struct ctx *)arg; memcpy(ifr.ifr_name, c->pasta_ifn, IFNAMSIZ); + ns_enter(c); - if (ns_enter(c) || - (tun_ns_fd = open("/dev/net/tun", flags)) < 0 || + if ((tun_ns_fd = open("/dev/net/tun", flags)) < 0 || ioctl(tun_ns_fd, TUNSETIFF, &ifr) || !(c->pasta_ifi = if_nametoindex(c->pasta_ifn))) { if (tun_ns_fd != -1) -- cgit v1.2.3