Avoid masking/unmasking the empty list of mount units (!116)

After the previous commit "Stop masking the root file system mount
unit", GParted now reports this error to the terminal on Debian 10 and
11:
    # gparted
    To few arguments.
    GParted 1.5.0-git
    configuration --enable-online-resize
    libparted 3.2

Debian installations, at least on PC hardware and using BIOS booting so
they don't have a /boot/efi file system, only have a single file system,
/ (root).  That is now excluded from masking so gparted shell wrapper
runs systemctl without any mount units to mask.  Hence the error.
    # systemctl --runtime mask --quiet --
    Too few arguments.
    # echo $?
    1

Fix this by only masking and unmasking units when the list of mounts
is non-empty.

Closes !116 - Systemd mount masking and udev rule location updates
This commit is contained in:
Mike Fleetwood 2023-08-02 12:30:39 +01:00 committed by Curtis Gedak
parent 4dc683b261
commit 852816be70
1 changed files with 5 additions and 2 deletions

View File

@ -148,6 +148,7 @@ done
#
# Use systemctl to prevent automount by masking currently unmasked mount points
#
MOUNTLIST=''
if test "x$HAVE_SYSTEMCTL" = "xyes"; then
MOUNTLIST=`systemctl show --all --property=Where,What,Id,LoadState '*.mount' | \
awk '
@ -172,7 +173,9 @@ if test "x$HAVE_SYSTEMCTL" = "xyes"; then
/^$/ { process_unit() }
END { process_unit() }
'`
systemctl --runtime mask --quiet -- $MOUNTLIST
if test "x$MOUNTLIST" != "x"; then
systemctl --runtime mask --quiet -- $MOUNTLIST
fi
fi
#
@ -234,7 +237,7 @@ done
#
# Use systemctl to unmask those mount points masked above
#
if test "x$HAVE_SYSTEMCTL" = "xyes"; then
if test "x$HAVE_SYSTEMCTL" = "xyes" && test "x$MOUNTLIST" != "x"; then
systemctl --runtime unmask --quiet -- $MOUNTLIST 2> /dev/null || \
{
cd /run/systemd/system &&