summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Stapelberg <michael@stapelberg.de>2013-09-19 02:34:12 +0000
committerMichael Stapelberg <michael@stapelberg.de>2013-09-19 02:34:12 +0000
commit557100573c4c0d68f6d3e82c593c4da751ce7818 (patch)
tree88cd021b55fbe3607f229f849e36365d7263161e
parent2b6898672734111c046208b687c45692a2a6eadd (diff)
downloadinit-system-helpers-557100573c4c0d68f6d3e82c593c4da751ce7818.tar.gz
Store masked state to respect user’s maskingdebian/1.10
We cannot just unconditionally unmask services on installation time, otherwise “systemctl mask” executed by the user will be reversed. To that end, files in /var/lib/systemd/deb-systemd-helper-masked/ signal that d-s-h masked the service and is allowed to unmask it.
-rw-r--r--debian/init-system-helpers.postinst6
-rwxr-xr-xscript/deb-systemd-helper20
-rw-r--r--t/001-deb-systemd-helper.t17
3 files changed, 37 insertions, 6 deletions
diff --git a/debian/init-system-helpers.postinst b/debian/init-system-helpers.postinst
index cbea846..6afcaec 100644
--- a/debian/init-system-helpers.postinst
+++ b/debian/init-system-helpers.postinst
@@ -9,12 +9,6 @@ if dpkg --compare-versions "$2" lt "1.9"; then
fi
fi
-if dpkg --compare-versions "$2" lt "1.10"; then
- if [ -d /var/lib/systemd/deb-systemd-helper-masked ]; then
- rm -rf /var/lib/systemd/deb-systemd-helper-masked
- fi
-fi
-
#DEBHELPER#
exit 0
diff --git a/script/deb-systemd-helper b/script/deb-systemd-helper
index 92290ae..3adcd9d 100755
--- a/script/deb-systemd-helper
+++ b/script/deb-systemd-helper
@@ -93,6 +93,7 @@ use Data::Dumper;
my $quiet = 0;
my $enabled_state_dir = '/var/lib/systemd/deb-systemd-helper-enabled';
+my $masked_state_dir = '/var/lib/systemd/deb-systemd-helper-masked';
# Globals are bad, but in this specific case, it really makes things much
# easier to write and understand.
@@ -386,6 +387,16 @@ sub mask_service {
symlink('/dev/null', $mask_link) or
error("unable to link $mask_link to /dev/null: $!");
$changed_sth = 1;
+
+ my $statefile = $mask_link;
+ $statefile =~ s,^/etc/systemd/system/,$masked_state_dir/,;
+
+ # 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);
+ close($fh);
}
sub unmask_service {
@@ -401,10 +412,19 @@ sub unmask_service {
return;
}
+ my $statefile = $mask_link;
+ $statefile =~ s,^/etc/systemd/system/,$masked_state_dir/,;
+
+ if (! -e $statefile) {
+ debug "Not unmasking $mask_link because the state file $statefile does not exist";
+ return;
+ }
+
print STDERR "rm '$mask_link'\n" unless $quiet;
unlink($mask_link) or
error("unable to remove $mask_link: $!");
$changed_sth = 1;
+ unlink($statefile);
}
my $result = GetOptions(
diff --git a/t/001-deb-systemd-helper.t b/t/001-deb-systemd-helper.t
index 5bb9ecd..4d814ea 100644
--- a/t/001-deb-systemd-helper.t
+++ b/t/001-deb-systemd-helper.t
@@ -191,4 +191,21 @@ is(readlink($mask_path), '/dev/null', 'service masked');
$retval = system("DPKG_MAINTSCRIPT_PACKAGE=test $dsh unmask $random_unit");
ok(! -e $mask_path, 'symlink no longer exists');
+# ┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
+# ┃ Verify “mask”/unmask don’t do anything when the user already masked. ┃
+# ┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛
+
+ok(! -l $mask_path, 'mask link does not exist yet');
+symlink('/dev/null', $mask_path);
+ok(-l $mask_path, 'mask link exists');
+is(readlink($mask_path), '/dev/null', 'service masked');
+
+$retval = system("DPKG_MAINTSCRIPT_PACKAGE=test $dsh mask $random_unit");
+ok(-l $mask_path, 'mask link exists');
+is(readlink($mask_path), '/dev/null', 'service still masked');
+
+$retval = system("DPKG_MAINTSCRIPT_PACKAGE=test $dsh unmask $random_unit");
+ok(-l $mask_path, 'mask link exists');
+is(readlink($mask_path), '/dev/null', 'service still masked');
+
done_testing;