Bug#933934: unmount bash completion complains about "awk: line 18: function gensub never defined"

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

Bug#933934: unmount bash completion complains about "awk: line 18: function gensub never defined"

Laurent Bigonville-5
Package: mount
Version: 2.34-0.1
Severity: normal
File: /usr/share/bash-completion/completions/umount

Hi,

The unmount bash completion complains about "awk: line 18: function
gensub never defined" when trying to complete a device

This looks new to me

Kind regards,

Laurent Bigonville

-- System Information:
Debian Release: bullseye/sid
  APT prefers unstable-debug
  APT policy: (500, 'unstable-debug'), (500, 'unstable'), (1, 'experimental-debug'), (1, 'experimental')
Architecture: amd64 (x86_64)

Kernel: Linux 4.19.0-5-amd64 (SMP w/8 CPU cores)
Locale: LANG=fr_BE.UTF-8, LC_CTYPE=fr_BE.UTF-8 (charmap=UTF-8), LANGUAGE=fr_BE:fr (charmap=UTF-8)
Shell: /bin/sh linked to /usr/bin/dash
Init: systemd (via /run/systemd/system)
LSM: AppArmor: enabled

Versions of packages mount depends on:
ii  libblkid1      2.34-0.1
ii  libc6          2.28-10
ii  libmount1      2.34-0.1
ii  libselinux1    2.9-2
ii  libsmartcols1  2.34-0.1
ii  util-linux     2.34-0.1

mount recommends no packages.

Versions of packages mount suggests:
pn  nfs-common  <none>

-- no debconf information

Reply | Threaded
Open this post in threaded view
|

Bug#933934: unmount bash completion complains about "awk: line 18: function gensub never defined"

Chris Hofstaedtler
Hi,

* Laurent Bigonville <[hidden email]> [190805 10:20]:
> The unmount bash completion complains about "awk: line 18: function
> gensub never defined" when trying to complete a device

Can you confirm that your /usr/bin/awk is not gawk? If so, which one
is it?

Chris

Reply | Threaded
Open this post in threaded view
|

Bug#933934: unmount bash completion complains about "awk: line 18: function gensub never defined"

Laurent Bigonville-5
On 5/08/19 12:22, Chris Hofstaedtler wrote:
> Hi,
Hey,
>
> * Laurent Bigonville <[hidden email]> [190805 10:20]:
>> The unmount bash completion complains about "awk: line 18: function
>> gensub never defined" when trying to complete a device
> Can you confirm that your /usr/bin/awk is not gawk? If so, which one
> is it?
bigon@edoras:~$ ls -la /usr/bin/awk /etc/alternatives/awk
lrwxrwxrwx 1 root root 13 fév  1  2019 /etc/alternatives/awk ->
/usr/bin/mawk
lrwxrwxrwx 1 root root 21 fév  1  2019 /usr/bin/awk ->
/etc/alternatives/awk

So I only have "mawk" installed:

ii  mawk 1.3.3-17+b3                          amd64        a pattern
scanning and text processing language

Reply | Threaded
Open this post in threaded view
|

Bug#933934: unmount bash completion complains about "awk: line 18: function gensub never defined"

Chris Hofstaedtler
Control: tags -1 + help confirmed

Hi,

* Laurent Bigonville <[hidden email]> [190805 13:19]:

> On 5/08/19 12:22, Chris Hofstaedtler wrote:
> > * Laurent Bigonville <[hidden email]> [190805 10:20]:
> > > The unmount bash completion complains about "awk: line 18: function
> > > gensub never defined" when trying to complete a device
> > Can you confirm that your /usr/bin/awk is not gawk? If so, which one
> > is it?
> bigon@edoras:~$ ls -la /usr/bin/awk /etc/alternatives/awk
> lrwxrwxrwx 1 root root 13 fév  1  2019 /etc/alternatives/awk ->
> /usr/bin/mawk
> lrwxrwxrwx 1 root root 21 fév  1  2019 /usr/bin/awk -> /etc/alternatives/awk
>
> So I only have "mawk" installed:
>
> ii  mawk 1.3.3-17+b3                          amd64        a pattern
> scanning and text processing language

Okay, kinda like I thought.

I'm not sure if, for bash-completion, a Depends: gawk is warranted
from Package: mount, which has Priority: required. This would pull
in gawk on pretty much every system (...).

Carrying a local patch to revert the change doesn't sound
sustainable. I'm not an awk expert to come up with a patch that
would implement the same functionality for mawk.

Whats your viewpoint / your thoughts on this?

Thanks,
Chris

Reply | Threaded
Open this post in threaded view
|

Bug#933934: unmount bash completion complains about "awk: line 18: function gensub never defined"

Étienne Mollier
In reply to this post by Laurent Bigonville-5
Good day,

I happened to see this issue in the how-can-i-help, and tracked
gensub() down to /usr/share/bash-completion/completions/umount.
At the end of the script, the COMPREPLY variable is set by the
use of `findmnt` and `awk`:

        COMPREPLY=( $( compgen -W "$(findmnt -lno TARGET | awk \
                '{
                        if ($0 ~ ENVIRON["HOME"]) {
                                homeless = $0
                                homeless = gensub(ENVIRON["HOME"], "\\\\~", "g", homeless)
                                homeless = gensub(/(\s)/, "\\\\\\1", "g", homeless)
                                print homeless
                        }
                        if ($0 ~ ENVIRON["PWD"]) {
                                reldir = $0
                                reldir = gensub(ENVIRON["PWD"]"/", "", "g", reldir)
                                reldir = gensub(/(\s)/, "\\\\\\1", "g", reldir)
                                print "./" reldir
                                print reldir
                        }
                        gsub(/\s/, "\\\\&")
                        print $0
                }'

These code sections enable to take in account, on one side, the
"~" expansion for home directories, and for the other, building
"./" relative paths from the current working directory.  The gsub
at the end is an attempt to escape space characters, so that the
tab completion already gives a properly escaped command.

When trying to port the AWK script, I stumbled upon failures to
escape properly said spaces.  Besides, it is not the only
dangerous character available in the ASCII interpreter,
regarding the Bash shell.  Apparently the problems with escape
sequences are related to the peculiar behavior of the Bash
built-ins related to completion, here `compgen`.  To clear
things up, I ended up having to move the code block in a side
function _umount_points_list(), which adds up to the user
namespace as soon as an attempt to autocomplete a umount command
is done; so if the name is not fine, perhaps another one can be
considered:

        _umount_points_list()
        {
                # List of characters to escape, shamelessly stolen from "scp" comp.
                local escape_chars='[][(){}<>\",:;^&!$=?`|\\'\'' \t\f\n\r\v]'
                # This is most odd, but we are adding artifically a space after the
                # file name because, somehow, it enables proper escaping of dangerous
                # characters, e.g. "|" -> "\|".  Without space, it is possible to get
                # either 0 "|" or 2 "\\|" backslashes, but 1 does not work.  Also,
                # sticking to sub() and gsub(), instead of gensub(), allows to be AWK
                # implementation agnostic.
                findmnt -lno TARGET | awk '{
                        if ($0 ~ "^"ENVIRON["HOME"]) {
                                homeless = $0
                                sub("^"ENVIRON["HOME"], "~", homeless)
                                gsub("'"$escape_chars"'", "\\\\&", homeless)
                                print homeless " "
                        }
                        if ($0 ~ "^"ENVIRON["PWD"]) {
                                reldir = $0
                                sub("^"ENVIRON["PWD"]"/?", "", reldir)
                                gsub("'"$escape_chars"'", "\\\\&", reldir)
                                print "./" reldir " "
                                print reldir " "
                        }
                        gsub("'"$escape_chars"'", "\\\\&")
                        print $0 " "
                }'
        }

And the call to set COMPREPLY is thus cleared up a bit:

        local IFS=$'\n'
        COMPREPLY=( $( compgen -W '$( _umount_points_list )'  -- "$cur" ) )

These changes go a bit beyond the scope of the description of
the bug, but I thought it would be a good idea to let you know
about the issue.

Oh, by the way, when hard coding the AWK interpreter name in the
script, I could ensure compatibility with gawk, mawk, and even
busybox awk.  :)

Should you find this useful, there is a patch in attachment,
against util-linux 2.34-0.1.

I hope this helps instead of bringing confusion,
Kind Regards,
--
Étienne Mollier <[hidden email]>
               5AB1 4EDF 63BB CCFF 8B54 2FA9 59DA 56FE FFF3 882D

umount-completion.patch (2K) Download Attachment
signature.asc (673 bytes) Download Attachment