summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNicolas Dichtel <nicolas.dichtel@6wind.com>2013-08-29 14:29:07 +0200
committerStephen Hemminger <stephen@networkplumber.org>2013-09-03 08:20:16 -0700
commit3c61c01a666d9f4dbb871305ab6791e19ede7d4a (patch)
tree38bce36e380f80b4e7f07add32774c97e332f00f
parentefa4dde4c7fe7e0fd4a7172b1222816f419e8cd8 (diff)
ipnetns: fix ip batch mode when using 'netns exec'
Since commit a05f6511f543, ip batch mode is broken when using 'netns exec' cmd. When WIFEXITED() returns true, it means that the child exited normally, hence we must not call exit() but just returns the status. If we call exit, the next commands in the file file are not executed. If WIFEXITED() returns false, we can call exit() because it means that the child failed. This patch partially reverts commit a05f6511f543. Signed-off-by: Nicolas Dichtel <nicolas.dichtel@6wind.com>
-rw-r--r--ip/ipnetns.c12
1 files changed, 8 insertions, 4 deletions
diff --git a/ip/ipnetns.c b/ip/ipnetns.c
index c8a47920..89dda3ff 100644
--- a/ip/ipnetns.c
+++ b/ip/ipnetns.c
@@ -205,11 +205,15 @@ static int netns_exec(int argc, char **argv)
exit(1);
}
- /* If child failed, propagate status */
- if (WIFEXITED(status))
- exit(WEXITSTATUS(status));
+ if (WIFEXITED(status)) {
+ /* ip must return the status of the child,
+ * but do_cmd() will add a minus to this,
+ * so let's add another one here to cancel it.
+ */
+ return -WEXITSTATUS(status);
+ }
- return 0;
+ exit(1);
}
}