#1004333 please consider more debugging in state file handling

#1004333#5
Date:
2022-01-24 22:12:54 UTC
From:
To:
Hi,

given the following code in a maintainer script:

postinst
if [ -x "/usr/bin/deb-systemd-helper" ]; then
        deb-systemd-helper mask 'sudo.service' || true
fi

postrm
case "$1" in
  purge)
        if [ -x "/usr/bin/deb-systemd-helper" ]; then
                deb-systemd-helper unmask 'sudo.service' || true
        fi

the masking symlink stays around after purge. When the package is
installed, ther is no sudo.service marker file in /var/lib/systemd/deb-systemd-helper-masked/

dpkg/deb-systemd-helper output from package installation:

root@salida:~# dpkg --list sudo
Desired=Unknown/Install/Remove/Purge/Hold
| Status=Not/Inst/Conf-files/Unpacked/halF-conf/Half-inst/trig-aWait/Trig-pend
|/ Err?=(none)/Reinst-required (Status,Err: uppercase=bad)
||/ Name           Version      Architecture Description
+++-==============-============-============-=================================
un  sudo           <none>       <none>       (no description available)
root@salida:~# dpkg --install /home/mh/packages/sudo/build-area/sudo_1.9.8p2-2~1_amd64.deb
Selecting previously unselected package sudo.
(Reading database ... 42180 files and directories currently installed.)
Preparing to unpack .../sudo_1.9.8p2-2~1_amd64.deb ...
Unpacking sudo (1.9.8p2-2~1) ...
Setting up sudo (1.9.8p2-2~1) ...
(deb-systemd-helper DEBUG) is purge = no
(deb-systemd-helper DEBUG) action = mask, scriptname = sudo.service, service_path = sudo.service
Processing triggers for libc-bin (2.33-3) ...
Processing triggers for man-db (2.9.4-4) ...
root@salida:~# ls -la /var/lib/systemd/deb-systemd-helper-masked/
total 8
drwxr-xr-x  2 root root 4096 Jan  5 21:55 .
drwxr-xr-x 11 root root 4096 Jan  5 21:55 ..
-rw-r--r--  1 root root    0 Jan  5 21:55 systemd-timesyncd.service
root@salida:~#

dpkg/deb-systemd-helper output from package purge:

root@salida:~# dpkg --purge sudo
(Reading database ... 42313 files and directories currently installed.)
Removing sudo (1.9.8p2-2~1) ...
Purging configuration files for sudo (1.9.8p2-2~1) ...
(deb-systemd-helper DEBUG) is purge = no
(deb-systemd-helper DEBUG) action = unmask, scriptname = sudo.service, service_path = sudo.service
(deb-systemd-helper DEBUG) Not unmasking /etc/systemd/system/sudo.service because the state file /var/lib/systemd/deb-systemd-helper-masked/sudo.service does not exist
(deb-systemd-helper DEBUG) rmdir_if_empty /var/lib/systemd/deb-systemd-helper-masked
(deb-systemd-helper DEBUG) rmdir(/var/lib/systemd/deb-systemd-helper-masked) failed (Directory not empty)
(deb-systemd-helper DEBUG) rmdir_if_empty /var/lib/systemd/deb-systemd-user-helper-masked
(deb-systemd-helper DEBUG) rmdir(/var/lib/systemd/deb-systemd-user-helper-masked) failed (No such file or directory)
dpkg: warning: while removing sudo, directory '/etc/sudoers.d' not empty so not removed
Processing triggers for libc-bin (2.33-3) ...
Processing triggers for man-db (2.9.4-4) ...
root@salida:~# ls -al /etc/systemd/system/sudo.service
lrwxrwxrwx 1 root root 9 Jan 23 23:25 /etc/systemd/system/sudo.service -> /dev/null
root@salida:~#

What is going wrong here?

Greetings
Marc

#1004333#10
Date:
2022-01-25 08:52:36 UTC
From:
To:
retitle -1 please consider more debugging in state file handling
severity -1 minor
thanks

Turns out that it was an issue in the test system.

Please, however, consider adding a bit more debugging and error
processing. Here is the patch that I used to debug this. This is clearly
not suitable for the release code, but I think you get the idea
--- /usr/bin/deb-systemd-helper 2021-11-01 15:05:55.000000000 +0100 +++ /home/mh/deb-systemd-helper 2022-01-25 00:14:53.235498204 +0100 @@ -464,12 +464,17 @@ my $statefile = $mask_link; $statefile =~ s,^/etc/systemd/$instance/,$masked_state_dir/,; + debug "statefile $statefile."; # Store the fact that we masked this service, so that we can unmask it on # installation time. We cannot unconditionally unmask because that would # interfere with the user’s decision to mask a service. - make_path(dirname($statefile)); - open(my $fh, '>>', $statefile); + debug "dirname statefile ". dirname($statefile); + system("ls -l ". dirname($statefile)); + if (! -e dirname($statefile)) { + make_path(dirname($statefile)) or die "cannot make_path: $!"; + } + open(my $fh, '>>', $statefile) or die "cannot open: $!"; close($fh); } Retitling and resetting severity. Greetings Marc
#1004333#19
Date:
2026-01-10 10:08:08 UTC
From:
To:
Es gibt eine Familienspende in Höhe von 1.850.000,00 USD von Cheng Charlie
Saephan. Bitte antworten Sie für weitere Informationen. Denken Sie daran,
Ihrer Familie und den Bedürftigen in Ihrer Umgebung Gutes zu tun.

Dies ist bereits der zweite Versuch, Sie zu erreichen. Bitte antworten Sie
für weitere Details.