zfsonlinux / pkg-zfs

Native ZFS packaging for Debian and Ubuntu
https://launchpad.net/~zfs-native/+archive/daily
308 stars 55 forks source link

Undeclared dependency on GNU awk asort() in vdev_id #239

Open OsmiumBalloon opened 2 weeks ago

OsmiumBalloon commented 2 weeks ago

Summary

The /lib/udev/vdev_id script included with the zfsutils package on Debian makes use of feature(s) specific to GNU awk (gawk), but the script only specifies awk generically, and the package control file does not specify awk at all. Debian defaults to nawk, which does not provide the feature(s) in question, leading to script aborts.

Environment

Description

In file/lib/udev/vdev_id, in function sas_handler(), on line 321, the code invokes the asort function to sort the array a. The asort() function is a GNU extension; it is not part of the standard awk. See Gawk: Effective AWK Programming, Section 12.3.2. When this code is encountered, the awk interpreter aborts with an error, "function asort never defined".

For example, an extract from syslog, with udev_log set to debug in /etc/udev/udev.conf:

Jun 12 10:37:19 penguin (udev-worker)[3212]: dm-0: '/lib/udev/vdev_id -d dm-0'(err) 'awk: line 7: function asort never defined'

This was with the default Debian awk, mawk, installed. Installing gawk (which automatically makes it the preferred alternative) resolved this error.

The vdev_id code in question is only invoked for multipath SAS storage. Many other packages (or people) want gawk installed anyway. So one needs the particular combination of SAS + multipath + minimalist-install to encounter the bug.

Resolution

In researching this error, I found that another "assuming gawk" bug has been encountered previously. See "vdev_id.conf slot mapping fails on Debian 7", Issue https://github.com/zfsonlinux/pkg-zfs/issues/136, from 2014.

Perhaps the best thing to do here is to simply declare a dependency on gawk and move on with your lives. In 2024 it is not that heavy a requirement, especially in the land of Linux where the userland is usually heavily GNU-based.

Alternatively, if there is a strong desire to avoid GNU-isms for whatever reason, it is possible to find sort routines implemented in pure standard POSIX awk code. See https://unix.stackexchange.com/questions/609866/ for example.