[libnbd PATCH] nbdsh: Simplify the script
There is no need for any hacks if we just do what execution of the module would have done. Signed-off-by: Martin Kletzander <mkletzan@redhat.com> --- sh/nbdsh.in | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/sh/nbdsh.in b/sh/nbdsh.in index d10f0c1b6b26..f66e2918d304 100644 --- a/sh/nbdsh.in +++ b/sh/nbdsh.in @@ -1,4 +1,4 @@ -#!/bin/sh - +#!/usr/bin/env @PYTHON@ # Copyright (C) 2011-2019 Red Hat Inc. # # @configure_input@ @@ -17,10 +17,6 @@ # License along with this library; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA -# Test if /bin/sh supports exec -a option (only supported in bash 4.2 -# and above, and not part of POSIX). -if /bin/sh -c 'exec -a test true' 2>/dev/null; then - exec -a nbdsh @PYTHON@ -mnbd "$@" -else - exec @PYTHON@ -mnbd "$@" -fi +import nbdsh + +nbdsh.shell() -- 2.32.0
On Tue, Jun 22, 2021 at 01:33:27PM +0200, Martin Kletzander wrote:
There is no need for any hacks if we just do what execution of the module would have done.
Signed-off-by: Martin Kletzander <mkletzan@redhat.com> --- sh/nbdsh.in | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-)
diff --git a/sh/nbdsh.in b/sh/nbdsh.in index d10f0c1b6b26..f66e2918d304 100644 --- a/sh/nbdsh.in +++ b/sh/nbdsh.in @@ -1,4 +1,4 @@ -#!/bin/sh - +#!/usr/bin/env @PYTHON@
What does argv[0] say in this case? How about ps listings?
# Copyright (C) 2011-2019 Red Hat Inc. # # @configure_input@ @@ -17,10 +17,6 @@ # License along with this library; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
-# Test if /bin/sh supports exec -a option (only supported in bash 4.2 -# and above, and not part of POSIX). -if /bin/sh -c 'exec -a test true' 2>/dev/null; then - exec -a nbdsh @PYTHON@ -mnbd "$@"
The result of this hack is a ps listing that shows 'nbdsh' (rather than /usr/bin/env or /path/to/python) as the running process name.
-else - exec @PYTHON@ -mnbd "$@" -fi +import nbdsh + +nbdsh.shell()
I'm afraid that undoing your hack results in a worse experience for chasing down nbdsh processes. -- Eric Blake, Principal Software Engineer Red Hat, Inc. +1-919-301-3266 Virtualization: qemu.org | libvirt.org
On Tue, Jun 22, 2021 at 9:20 PM Martin Kletzander <mkletzan@redhat.com> wrote:
There is no need for any hacks if we just do what execution of the module would have done.
Signed-off-by: Martin Kletzander <mkletzan@redhat.com> --- sh/nbdsh.in | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-)
diff --git a/sh/nbdsh.in b/sh/nbdsh.in index d10f0c1b6b26..f66e2918d304 100644 --- a/sh/nbdsh.in +++ b/sh/nbdsh.in @@ -1,4 +1,4 @@ -#!/bin/sh - +#!/usr/bin/env @PYTHON@
Do we really care about specific @PYTHON@? If not we can use: #!/usr/bin/python3
# Copyright (C) 2011-2019 Red Hat Inc. # # @configure_input@ @@ -17,10 +17,6 @@ # License along with this library; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
-# Test if /bin/sh supports exec -a option (only supported in bash 4.2 -# and above, and not part of POSIX). -if /bin/sh -c 'exec -a test true' 2>/dev/null; then - exec -a nbdsh @PYTHON@ -mnbd "$@" -else - exec @PYTHON@ -mnbd "$@" -fi +import nbdsh + +nbdsh.shell() -- 2.32.0
_______________________________________________ Libguestfs mailing list Libguestfs@redhat.com https://listman.redhat.com/mailman/listinfo/libguestfs
On Tue, Jun 22, 2021 at 10:29:14PM +0300, Nir Soffer wrote:
On Tue, Jun 22, 2021 at 9:20 PM Martin Kletzander <mkletzan@redhat.com> wrote:
There is no need for any hacks if we just do what execution of the module would have done.
Signed-off-by: Martin Kletzander <mkletzan@redhat.com> --- sh/nbdsh.in | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-)
diff --git a/sh/nbdsh.in b/sh/nbdsh.in index d10f0c1b6b26..f66e2918d304 100644 --- a/sh/nbdsh.in +++ b/sh/nbdsh.in @@ -1,4 +1,4 @@ -#!/bin/sh - +#!/usr/bin/env @PYTHON@
Do we really care about specific @PYTHON@?
If not we can use:
#!/usr/bin/python3
That is not reliably portable, especially to non-Linux platforms like *BSD as it isn't always in /usr/bin Regards, Daniel -- |: https://berrange.com -o- https://www.flickr.com/photos/dberrange :| |: https://libvirt.org -o- https://fstop138.berrange.com :| |: https://entangle-photo.org -o- https://www.instagram.com/dberrange :|
On Tue, Jun 22, 2021 at 01:33:27PM +0200, Martin Kletzander wrote:
There is no need for any hacks if we just do what execution of the module would have done.
Signed-off-by: Martin Kletzander <mkletzan@redhat.com> --- sh/nbdsh.in | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-)
diff --git a/sh/nbdsh.in b/sh/nbdsh.in index d10f0c1b6b26..f66e2918d304 100644 --- a/sh/nbdsh.in +++ b/sh/nbdsh.in @@ -1,4 +1,4 @@ -#!/bin/sh - +#!/usr/bin/env @PYTHON@ # Copyright (C) 2011-2019 Red Hat Inc. # # @configure_input@ @@ -17,10 +17,6 @@ # License along with this library; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
-# Test if /bin/sh supports exec -a option (only supported in bash 4.2 -# and above, and not part of POSIX). -if /bin/sh -c 'exec -a test true' 2>/dev/null; then - exec -a nbdsh @PYTHON@ -mnbd "$@" -else - exec @PYTHON@ -mnbd "$@" -fi +import nbdsh + +nbdsh.shell()
Can we set argv[0] from Python? That would solve the problem that Eric has noted. This seems to say that you have to use an external module (which we'd like to avoid from a tool as simple as nbdsh): https://superuser.com/questions/427642/is-it-possible-to-set-the-process-nam... https://bugs.python.org/issue5672 But maybe there's a way to make it work only in Linux, which would be fine. Rich. -- Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones Read my programming and virtualization blog: http://rwmj.wordpress.com Fedora Windows cross-compiler. Compile Windows programs, test, and build Windows installers. Over 100 libraries supported. http://fedoraproject.org/wiki/MinGW
On Wed, Jun 23, 2021 at 12:29:38PM +0100, Richard W.M. Jones wrote:
On Tue, Jun 22, 2021 at 01:33:27PM +0200, Martin Kletzander wrote:
There is no need for any hacks if we just do what execution of the module would have done.
Signed-off-by: Martin Kletzander <mkletzan@redhat.com> --- sh/nbdsh.in | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-)
diff --git a/sh/nbdsh.in b/sh/nbdsh.in index d10f0c1b6b26..f66e2918d304 100644 --- a/sh/nbdsh.in +++ b/sh/nbdsh.in @@ -1,4 +1,4 @@ -#!/bin/sh - +#!/usr/bin/env @PYTHON@ # Copyright (C) 2011-2019 Red Hat Inc. # # @configure_input@ @@ -17,10 +17,6 @@ # License along with this library; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
-# Test if /bin/sh supports exec -a option (only supported in bash 4.2 -# and above, and not part of POSIX). -if /bin/sh -c 'exec -a test true' 2>/dev/null; then - exec -a nbdsh @PYTHON@ -mnbd "$@" -else - exec @PYTHON@ -mnbd "$@" -fi +import nbdsh + +nbdsh.shell()
Can we set argv[0] from Python? That would solve the problem that Eric has noted.
This seems to say that you have to use an external module (which we'd like to avoid from a tool as simple as nbdsh):
https://superuser.com/questions/427642/is-it-possible-to-set-the-process-nam... https://bugs.python.org/issue5672
But maybe there's a way to make it work only in Linux, which would be fine.
Just keep it like it is, I guess. I guess I can kind of see why is it beneficial to have the process named based on the script, but how come it is an issue when python scripts do not do that, but it's fine when shell scripts do not mask the fact that they are running under a shell interpreter. Anyway, I was trying to fix a niche problem that is not really that important. I can just switch /bin/sh to be a symlink to dash and it will be dealt with. Sorry for wasting your time, have a nice day.
-- Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones Read my programming and virtualization blog: http://rwmj.wordpress.com Fedora Windows cross-compiler. Compile Windows programs, test, and build Windows installers. Over 100 libraries supported. http://fedoraproject.org/wiki/MinGW
participants (5)
-
Daniel P. Berrangé -
Eric Blake -
Martin Kletzander -
Nir Soffer -
Richard W.M. Jones