pasta: Improve error handling on failure to join network namespace
In pasta_wait_for_ns(), open() failing with ENOENT is expected: we're busy-looping until the network namespace appears. But any other failure is not something we're going to recover from: return right away if we don't get either success or ENOENT. Now that pasta_wait_for_ns() can actually fail, handle that in pasta_start_ns() by reporting the issue and exiting. Looping on EPERM, when pasta doesn't actually have the permissions to join a given namespace, isn't exactly a productive thing to do. Signed-off-by: Stefano Brivio <sbrivio@redhat.com>
This commit is contained in:
parent
1c3c68970e
commit
f099afb1f2
1 changed files with 9 additions and 4 deletions
13
pasta.c
13
pasta.c
|
@ -95,10 +95,13 @@ static int pasta_wait_for_ns(void *arg)
|
||||||
char ns[PATH_MAX];
|
char ns[PATH_MAX];
|
||||||
|
|
||||||
snprintf(ns, PATH_MAX, "/proc/%i/ns/net", pasta_child_pid);
|
snprintf(ns, PATH_MAX, "/proc/%i/ns/net", pasta_child_pid);
|
||||||
do
|
do {
|
||||||
while ((c->pasta_netns_fd = open(ns, flags)) < 0);
|
while ((c->pasta_netns_fd = open(ns, flags)) < 0) {
|
||||||
while (setns(c->pasta_netns_fd, CLONE_NEWNET) &&
|
if (errno != ENOENT)
|
||||||
!close(c->pasta_netns_fd));
|
return 0;
|
||||||
|
}
|
||||||
|
} while (setns(c->pasta_netns_fd, CLONE_NEWNET) &&
|
||||||
|
!close(c->pasta_netns_fd));
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -257,6 +260,8 @@ void pasta_start_ns(struct ctx *c, uid_t uid, gid_t gid,
|
||||||
}
|
}
|
||||||
|
|
||||||
NS_CALL(pasta_wait_for_ns, c);
|
NS_CALL(pasta_wait_for_ns, c);
|
||||||
|
if (c->pasta_netns_fd < 0)
|
||||||
|
die("Failed to join network namespace");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in a new issue