ip: Exit exec in child process if setup fails
Subsystems (3)
PATCH 1/1 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 <[email protected]>
--- lib/exec.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-)
lib/exec.c +6 -1
@@ -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",
Signature · 1 line
2.34.1
Ping - in case you missed this
Quoted 50 lines · Yedaya Katsman
If we forked, returning from the function will make the calling code to continue in both the child and parent process. Make
cmd_execexit 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 <[email protected]>--- lib/exec.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-)lib/exec.c +6
-1@@ -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",Signature · 1 line
2.34.1
Quoted 2 lines · Yedaya
Ping - in case you missed this
please re-send; I think it fell through the cracks.