Skip to contentSkip to conversation

ip: Exit exec in child process if setup fails

PATCH Applied Yedaya Katsman 2 participants 2 messages Apr 23, 2024 – Apr 25, 2024

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

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
```
---
 lib/exec.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)
lib/exec.c +6 -1
index 9b1c8f4a1396..893937550079 100644
@@ -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
#1 lore raw
This patch was applied to iproute2/iproute2.git (main) by Stephen Hemminger <[email protected]>:

Hello:

This patch was applied to iproute2/iproute2.git (main) by Stephen Hemminger <[email protected]>:

Quoted 8 lines · On Tue, 23 Apr 2024 21:38:20 +0300 you wrote:

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:

[...]

Here is the summary with links:
- ip: Exit exec in child process if setup fails

    https://git.kernel.org/pub/scm/network/iproute2/iproute2.git/commit/?id=70ba338cd831

You are awesome, thank you!

Signature · 2 lines
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html