From: Yedaya <yedaya.ka@gmail.com>
To: netdev@vger.kernel.org
Cc: Stephen Hemminger <stephen@networkplumber.org>
Subject: Re: [PATCH] ip: Exit exec in child process if setup fails
Date: Thu, 18 Apr 2024 23:16:46 +0300 [thread overview]
Message-ID: <ZiF/rppvSxED2W8m@abode> (raw)
In-Reply-To: <20240324163436.23276-1-yedaya.ka@gmail.com>
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
>
next prev parent reply other threads:[~2024-04-18 20:16 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-03-24 16:34 [PATCH] ip: Exit exec in child process if setup fails Yedaya Katsman
2024-04-18 20:16 ` Yedaya [this message]
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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=ZiF/rppvSxED2W8m@abode \
--to=yedaya.ka@gmail.com \
--cc=netdev@vger.kernel.org \
--cc=stephen@networkplumber.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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 NNTP newsgroup(s).