Bug#1005972: sourced functions when run from set -e shells are suprising
On Sat, 19 Feb 2022 at 00:21, Thomas Stewart wrote: > I think all functions that are > sourced should be audited to handle "set -e" and all initramfs-tools > eventually modified to use "set -e". Dear Maintainer, There is a view among shell-script experts that adding "set -e" anywhere is to be discouraged [1][2][3]. So I suggest that in any situation where remediation is required, "set -e" should be removed, not added. "set -e" is a fantasy to have "automatic" error handling in shell scripts, but it breaks in all kinds of non-naive situations. The best practice for shell scripts is to actually handle errors where they occur: command || exit 1 This is not difficult, if that behaviour is desired. It would be better if Debian policy was modified to be clearer about this. Kind regards David [1] https://lists.gnu.org/archive/html/help-bash/2017-05/msg00020.html [2] http://mywiki.wooledge.org/BashFAQ/105 [3] https://fvue.nl/wiki/Bash:_Error_handling
Bug#1005972: sourced functions when run from set -e shells are suprising
Package: initramfs-tools Version: 0.140 Severity: minor Dear Maintainer, Half of the initramfs-tools hook scripts on my system use "set -e"[0]. However if /usr/share/initramfs-tools/scripts/functions is sourced it does not handle errors correctly when called from a "set -e" shell, for example the function "configure_networking" runs ipconfig and if it times out it will exit non-zero. S the "for ROUNDTTT" loop does not complete, further ipconfig invocations are not attempted and the calling hook script exists before completion. The hook scripts on my system (fsck, resume and xfs) that call scripts/functions don't use "set -e". However some scripts in the archive do call configure_networking from a "set -e" shell, eg aoe[2]. I ran into this when writing a new custom hook script for clevis and was surprised by the current behaviour. I think all functions that are sourced should be audited to handle "set -e" and all initramfs-tools eventually modified to use "set -e". Kind Regards Tom -- mkinitramfs hooks /etc/initramfs-tools/hooks/: /usr/share/initramfs-tools/hooks: amd64_microcode btrfs cryptgnupg cryptgnupg-sc cryptkeyctl cryptopensc cryptpassdev cryptroot cryptroot-unlock dmsetup fsck fuse intel_microcode keymap klibc-utils kmod lvm2 mdadm ntfs_3g plymouth reiserfsprogs resume thermal thin-provisioning-tools udev xfs zz-busybox [0] $ head -10 /usr/share/initramfs-tools/hooks/* | egrep "^=|-e" ==> /usr/share/initramfs-tools/hooks/amd64_microcode <== ==> /usr/share/initramfs-tools/hooks/btrfs <== set -e ==> /usr/share/initramfs-tools/hooks/cryptgnupg <== set -e ==> /usr/share/initramfs-tools/hooks/cryptgnupg-sc <== set -e ==> /usr/share/initramfs-tools/hooks/cryptkeyctl <== set -e ==> /usr/share/initramfs-tools/hooks/cryptopensc <== set -e ==> /usr/share/initramfs-tools/hooks/cryptpassdev <== set -e ==> /usr/share/initramfs-tools/hooks/cryptroot <== ==> /usr/share/initramfs-tools/hooks/cryptroot-unlock <== ==> /usr/share/initramfs-tools/hooks/dmsetup <== ==> /usr/share/initramfs-tools/hooks/fsck <== ==> /usr/share/initramfs-tools/hooks/fuse <== set -e ==> /usr/share/initramfs-tools/hooks/intel_microcode <== ==> /usr/share/initramfs-tools/hooks/keymap <== ==> /usr/share/initramfs-tools/hooks/klibc-utils <== ==> /usr/share/initramfs-tools/hooks/kmod <== #!/bin/sh -e ==> /usr/share/initramfs-tools/hooks/lvm2 <== ==> /usr/share/initramfs-tools/hooks/mdadm <== set -eu ==> /usr/share/initramfs-tools/hooks/ntfs_3g <== set -e ==> /usr/share/initramfs-tools/hooks/plymouth <== set -e ==> /usr/share/initramfs-tools/hooks/reiserfsprogs <== ==> /usr/share/initramfs-tools/hooks/resume <== ==> /usr/share/initramfs-tools/hooks/thermal <== ==> /usr/share/initramfs-tools/hooks/thin-provisioning-tools <== ==> /usr/share/initramfs-tools/hooks/udev <== #!/bin/sh -e ==> /usr/share/initramfs-tools/hooks/xfs <== ==> /usr/share/initramfs-tools/hooks/zz-busybox <== set -e [1] https://sources.debian.org/src/initramfs-tools/0.140/scripts/functions/?hl=236#L315 [2] https://sources.debian.org/src/aoetools/36-5/debian/local-top_aoe/