From: Yedaya Katsman Date: Tue, 23 Apr 2024 18:38:20 +0000 (+0300) Subject: ip: Exit exec in child process if setup fails X-Git-Tag: v6.9.0~5 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=70ba338cd8314410380b8bdae9e5f302e8e98039;p=thirdparty%2Fiproute2.git 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 Signed-off-by: Stephen Hemminger --- diff --git a/lib/exec.c b/lib/exec.c index 9b1c8f4a..89393755 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",