diff mbox series

[net-next,v2,1/7] selftests: drv-net: add a warning for bkg + shell + terminate

Message ID 20250219234956.520599-2-kuba@kernel.org (mailing list archive)
State Accepted
Commit 846742f7e32f632166e3b2a106304b2bec7541a9
Delegated to: Netdev Maintainers
Headers show
Series selftests: drv-net: improve the queue test for XSK | expand

Checks

Context Check Description
netdev/series_format success Posting correctly formatted
netdev/tree_selection success Clearly marked for net-next
netdev/ynl success Generated files up to date; no warnings/errors; no diff in generated;
netdev/fixes_present success Fixes tag not required for -next series
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 0 this patch: 0
netdev/build_tools success Errors and warnings before: 26 (+1) this patch: 26 (+1)
netdev/cc_maintainers warning 3 maintainers not CCed: willemb@google.com shuah@kernel.org linux-kselftest@vger.kernel.org
netdev/build_clang success Errors and warnings before: 0 this patch: 0
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/deprecated_api success None detected
netdev/check_selftest success No net selftest shell script
netdev/verify_fixes success No Fixes tag
netdev/build_allmodconfig_warn success Errors and warnings before: 0 this patch: 0
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 10 lines checked
netdev/build_clang_rust success No Rust files in patch. Skipping build
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/source_inline success Was 0 now: 0
netdev/contest success net-next-2025-02-20--12-00 (tests: 893)

Commit Message

Jakub Kicinski Feb. 19, 2025, 11:49 p.m. UTC
Joe Damato reports that some shells will fork before running
the command when python does "sh -c $cmd", while bash does
an exec of $cmd directly. This will have implications for our
ability to terminate the child process on bash vs other shells.
Warn about using

	bkg(... shell=True, termininate=True)

most background commands can hopefully exit cleanly (exit_wait).

Link: https://lore.kernel.org/Z7Yld21sv_Ip3gQx@LQ3V64L9R2
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
---
v2: new
---
 tools/testing/selftests/net/lib/py/utils.py | 4 ++++
 1 file changed, 4 insertions(+)

Comments

Stanislav Fomichev Feb. 20, 2025, 5:27 p.m. UTC | #1
On 02/19, Jakub Kicinski wrote:
> Joe Damato reports that some shells will fork before running
> the command when python does "sh -c $cmd", while bash does
> an exec of $cmd directly. This will have implications for our
> ability to terminate the child process on bash vs other shells.
> Warn about using
> 
> 	bkg(... shell=True, termininate=True)
> 
> most background commands can hopefully exit cleanly (exit_wait).
> 
> Link: https://lore.kernel.org/Z7Yld21sv_Ip3gQx@LQ3V64L9R2
> Signed-off-by: Jakub Kicinski <kuba@kernel.org>

Acked-by: Stanislav Fomichev <sdf@fomichev.me>
Joe Damato Feb. 20, 2025, 5:48 p.m. UTC | #2
On Wed, Feb 19, 2025 at 03:49:50PM -0800, Jakub Kicinski wrote:
> Joe Damato reports that some shells will fork before running
> the command when python does "sh -c $cmd", while bash does
> an exec of $cmd directly.

I'm not sure what's going on, but as I mentioned in the other thread
and below, I am using bash as well.

> This will have implications for our
> ability to terminate the child process on bash vs other shells.
> Warn about using
> 
> 	bkg(... shell=True, termininate=True)
> 
> most background commands can hopefully exit cleanly (exit_wait).
> 
> Link: https://lore.kernel.org/Z7Yld21sv_Ip3gQx@LQ3V64L9R2
> Signed-off-by: Jakub Kicinski <kuba@kernel.org>
> ---
> v2: new
> ---
>  tools/testing/selftests/net/lib/py/utils.py | 4 ++++
>  1 file changed, 4 insertions(+)
> 
> diff --git a/tools/testing/selftests/net/lib/py/utils.py b/tools/testing/selftests/net/lib/py/utils.py
> index 9e3bcddcf3e8..33b153767d89 100644
> --- a/tools/testing/selftests/net/lib/py/utils.py
> +++ b/tools/testing/selftests/net/lib/py/utils.py
> @@ -61,6 +61,10 @@ import time
>          self.terminate = not exit_wait
>          self.check_fail = fail
>  
> +        if shell and self.terminate:
> +            print("# Warning: combining shell and terminate is risky!")
> +            print("#          SIGTERM may not reach the child on zsh/ksh!")

I'm not opposed to putting a warning here, but just as a disclaimer
and for anyone else following along -- I am using bash:

$ echo $SHELL
/bin/bash

$ bash --version
GNU bash, version 5.2.21(1)-release (x86_64-pc-linux-gnu)
Joe Damato Feb. 20, 2025, 7:31 p.m. UTC | #3
On Wed, Feb 19, 2025 at 03:49:50PM -0800, Jakub Kicinski wrote:
> Joe Damato reports that some shells will fork before running
> the command when python does "sh -c $cmd", while bash does
> an exec of $cmd directly. This will have implications for our
> ability to terminate the child process on bash vs other shells.
> Warn about using
> 
> 	bkg(... shell=True, termininate=True)
> 
> most background commands can hopefully exit cleanly (exit_wait).
> 
> Link: https://lore.kernel.org/Z7Yld21sv_Ip3gQx@LQ3V64L9R2
> Signed-off-by: Jakub Kicinski <kuba@kernel.org>
> ---
> v2: new
> ---
>  tools/testing/selftests/net/lib/py/utils.py | 4 ++++
>  1 file changed, 4 insertions(+)
> 
> diff --git a/tools/testing/selftests/net/lib/py/utils.py b/tools/testing/selftests/net/lib/py/utils.py
> index 9e3bcddcf3e8..33b153767d89 100644
> --- a/tools/testing/selftests/net/lib/py/utils.py
> +++ b/tools/testing/selftests/net/lib/py/utils.py
> @@ -61,6 +61,10 @@ import time
>          self.terminate = not exit_wait
>          self.check_fail = fail
>  
> +        if shell and self.terminate:
> +            print("# Warning: combining shell and terminate is risky!")
> +            print("#          SIGTERM may not reach the child on zsh/ksh!")
> +

This warning did not print on my system, FWIW. Up to you if you want
to respin and drop it or just leave it be.

I am fine with this warning being added, although I disagree with
the commit message as mentioned in my previous email.

Since the code seems fine though:

Acked-by: Joe Damato <jdamato@fastly.com>
Jakub Kicinski Feb. 20, 2025, 9:10 p.m. UTC | #4
On Thu, 20 Feb 2025 14:31:35 -0500 Joe Damato wrote:
> > +        if shell and self.terminate:
> > +            print("# Warning: combining shell and terminate is risky!")
> > +            print("#          SIGTERM may not reach the child on zsh/ksh!")
> > +  
> 
> This warning did not print on my system, FWIW. Up to you if you want
> to respin and drop it or just leave it be.

You mean when running this patchset? It shouldn't, the current 
test uses ksft_wait rather than terminate. The warning is for
test developers trying to use the risky config in new tests.

> I am fine with this warning being added, although I disagree with
> the commit message as mentioned in my previous email.

I'll edit the commit message when applying. Unless you want to dig
deeper and find out why your bash/env is different than mine :(

GNU bash, version 5.2.32(1)-release (x86_64-redhat-linux-gnu)

We know that "some shells" fork, that's the important point.
Joe Damato Feb. 20, 2025, 10:53 p.m. UTC | #5
On Thu, Feb 20, 2025 at 01:10:59PM -0800, Jakub Kicinski wrote:
> On Thu, 20 Feb 2025 14:31:35 -0500 Joe Damato wrote:
> > > +        if shell and self.terminate:
> > > +            print("# Warning: combining shell and terminate is risky!")
> > > +            print("#          SIGTERM may not reach the child on zsh/ksh!")
> > > +  
> > 
> > This warning did not print on my system, FWIW. Up to you if you want
> > to respin and drop it or just leave it be.
> 
> You mean when running this patchset? It shouldn't, the current 
> test uses ksft_wait rather than terminate. The warning is for
> test developers trying to use the risky config in new tests.
> 
> > I am fine with this warning being added, although I disagree with
> > the commit message as mentioned in my previous email.
> 
> I'll edit the commit message when applying. Unless you want to dig
> deeper and find out why your bash/env is different than mine :(

No, no - no need for that much extra work. Just wanted to mention
for anyone following along or who stumbles on this in the future
that my shell is bash, is all :)

Thanks again for the work on this.
diff mbox series

Patch

diff --git a/tools/testing/selftests/net/lib/py/utils.py b/tools/testing/selftests/net/lib/py/utils.py
index 9e3bcddcf3e8..33b153767d89 100644
--- a/tools/testing/selftests/net/lib/py/utils.py
+++ b/tools/testing/selftests/net/lib/py/utils.py
@@ -61,6 +61,10 @@  import time
         self.terminate = not exit_wait
         self.check_fail = fail
 
+        if shell and self.terminate:
+            print("# Warning: combining shell and terminate is risky!")
+            print("#          SIGTERM may not reach the child on zsh/ksh!")
+
     def __enter__(self):
         return self