From 32660cea04f6e7c353435061b876575539ac8cd9 Mon Sep 17 00:00:00 2001 From: Paul Holzinger Date: Fri, 23 Jun 2023 12:23:50 +0200 Subject: pasta: include errno in error message When the open() or setns() calls fails pasta exits early and prints an error. However it did not include the errno so it was impossible to know why the syscall failed. Signed-off-by: Paul Holzinger Reviewed-by: David Gibson [sbrivio: Split print to fit 80 columns in pasta_open_ns()] Signed-off-by: Stefano Brivio --- pasta.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) (limited to 'pasta.c') diff --git a/pasta.c b/pasta.c index 13ab18b..8c85546 100644 --- a/pasta.c +++ b/pasta.c @@ -135,15 +135,17 @@ void pasta_open_ns(struct ctx *c, const char *netns) int nfd = -1; nfd = open(netns, O_RDONLY | O_CLOEXEC); - if (nfd < 0) - die("Couldn't open network namespace %s", netns); + if (nfd < 0) { + die("Couldn't open network namespace %s: %s", + netns, strerror(errno)); + } c->pasta_netns_fd = nfd; NS_CALL(ns_check, c); if (c->pasta_netns_fd < 0) - die("Couldn't switch to pasta namespaces"); + die("Couldn't switch to pasta namespaces: %s", strerror(errno)); if (!c->no_netns_quit) { char buf[PATH_MAX] = { 0 }; @@ -261,7 +263,7 @@ void pasta_start_ns(struct ctx *c, uid_t uid, gid_t gid, NS_CALL(pasta_wait_for_ns, c); if (c->pasta_netns_fd < 0) - die("Failed to join network namespace"); + die("Failed to join network namespace: %s", strerror(errno)); } /** -- cgit v1.2.3