aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorYedaya Katsman <yedaya.ka@gmail.com>2024-04-23 21:38:20 +0300
committerStephen Hemminger <stephen@networkplumber.org>2024-04-25 12:00:25 -0700
commit70ba338cd8314410380b8bdae9e5f302e8e98039 (patch)
tree2dddad3fcf1657d832f750d611cf1127d96ff336
parent911c62bf9de61da7aa03e1cd5e5db26322d12aa9 (diff)
downloadiproute2-70ba338cd8314410380b8bdae9e5f302e8e98039.tar.gz
ip: Exit exec in child process if setup fails
If we forked, returning from the function will make the calling code to continue in both the child and parent process. Make cmd_exec exit if setup failed and it forked already. An example of issues this causes, where a failure in setup causes multiple unnecessary tries: ``` $ ip netns ef ab $ ip -all netns exec ls netns: ef setting the network namespace "ef" failed: Operation not permitted netns: ab setting the network namespace "ab" failed: Operation not permitted netns: ab setting the network namespace "ab" failed: Operation not permitted ``` Signed-off-by: Yedaya Katsman <yedaya.ka@gmail.com> Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
-rw-r--r--lib/exec.c7
1 files changed, 6 insertions, 1 deletions
diff --git a/lib/exec.c b/lib/exec.c
index 9b1c8f4a1..893937550 100644
--- a/lib/exec.c
+++ b/lib/exec.c
@@ -36,8 +36,13 @@ int cmd_exec(const char *cmd, char **argv, bool do_fork,
}
}
- if (setup && setup(arg))
+ if (setup && setup(arg)) {
+ if (do_fork) {
+ /* In child, nothing to do */
+ _exit(1);
+ }
return -1;
+ }
if (execvp(cmd, argv) < 0)
fprintf(stderr, "exec of \"%s\" failed: %s\n",