Netdev Archive mirror
 help / color / mirror / Atom feed
* [PATCH] ip: Exit exec in child process if setup fails
@ 2024-03-24 16:34 Yedaya Katsman
  2024-04-18 20:16 ` Yedaya
  0 siblings, 1 reply; 5+ messages in thread
From: Yedaya Katsman @ 2024-03-24 16:34 UTC (permalink / raw
  To: netdev; +Cc: Stephen Hemminger, 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_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>
---
 lib/exec.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/lib/exec.c b/lib/exec.c
index 9b1c8f4a1396..893937550079 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",
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH] ip: Exit exec in child process if setup fails
  2024-03-24 16:34 [PATCH] ip: Exit exec in child process if setup fails Yedaya Katsman
@ 2024-04-18 20:16 ` Yedaya
  2024-04-21  1:58   ` David Ahern
  0 siblings, 1 reply; 5+ messages in thread
From: Yedaya @ 2024-04-18 20:16 UTC (permalink / raw
  To: netdev; +Cc: Stephen Hemminger

Ping - in case you missed this

On Sun, Mar 24, 2024 at 06:34:36PM +0200, Yedaya Katsman 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:
> 
> ```
> $ 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>
> ---
>  lib/exec.c | 7 ++++++-
>  1 file changed, 6 insertions(+), 1 deletion(-)
> 
> diff --git a/lib/exec.c b/lib/exec.c
> index 9b1c8f4a1396..893937550079 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",
> -- 
> 2.34.1
> 

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] ip: Exit exec in child process if setup fails
  2024-04-18 20:16 ` Yedaya
@ 2024-04-21  1:58   ` David Ahern
  0 siblings, 0 replies; 5+ messages in thread
From: David Ahern @ 2024-04-21  1:58 UTC (permalink / raw
  To: Yedaya, netdev; +Cc: Stephen Hemminger

On 4/18/24 2:16 PM, Yedaya wrote:
> Ping - in case you missed this
> 

please re-send; I think it fell through the cracks.


^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH] ip: Exit exec in child process if setup fails
@ 2024-04-23 18:38 Yedaya Katsman
  2024-04-25 19:10 ` patchwork-bot+netdevbpf
  0 siblings, 1 reply; 5+ messages in thread
From: Yedaya Katsman @ 2024-04-23 18:38 UTC (permalink / raw
  To: netdev; +Cc: Stephen Hemminger, 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_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>
---
 lib/exec.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/lib/exec.c b/lib/exec.c
index 9b1c8f4a1396..893937550079 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",
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH] ip: Exit exec in child process if setup fails
  2024-04-23 18:38 Yedaya Katsman
@ 2024-04-25 19:10 ` patchwork-bot+netdevbpf
  0 siblings, 0 replies; 5+ messages in thread
From: patchwork-bot+netdevbpf @ 2024-04-25 19:10 UTC (permalink / raw
  To: Yedaya Katsman; +Cc: netdev, stephen

Hello:

This patch was applied to iproute2/iproute2.git (main)
by Stephen Hemminger <stephen@networkplumber.org>:

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!
-- 
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html



^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2024-04-25 19:10 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-03-24 16:34 [PATCH] ip: Exit exec in child process if setup fails Yedaya Katsman
2024-04-18 20:16 ` Yedaya
2024-04-21  1:58   ` David Ahern
  -- strict thread matches above, loose matches on Subject: below --
2024-04-23 18:38 Yedaya Katsman
2024-04-25 19:10 ` patchwork-bot+netdevbpf

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).