[debhelper-devel] [debhelper] 17/21: dh_installsystemd: Properly quote unit names in autoscripts

Niels Thykier nthykier at moszumanska.debian.org
Fri Oct 13 18:27:21 UTC 2017


This is an automated email from the git hooks/post-receive script.

nthykier pushed a commit to branch master
in repository debhelper.

commit 912b7b9a629e21890fa4488d314d73f3e5dde25c
Author: Niels Thykier <niels at thykier.net>
Date:   Tue Oct 10 18:11:29 2017 +0000

    dh_installsystemd: Properly quote unit names in autoscripts
    
    Signed-off-by: Niels Thykier <niels at thykier.net>
---
 dh_installsystemd                       |  6 +++---
 t/dh_installsystemd/dh_installsystemd.t | 15 +++++++++++----
 2 files changed, 14 insertions(+), 7 deletions(-)

diff --git a/dh_installsystemd b/dh_installsystemd
index 383a7bb..efa5e02 100755
--- a/dh_installsystemd
+++ b/dh_installsystemd
@@ -335,19 +335,19 @@ foreach my $package (@{$dh{DOPACKAGES}}) {
 	next if @start_units == 0 && @enable_units == 0;
 
 	for my $unit (sort @enable_units) {
-		my $base = basename($unit);
+		my $base = q{'} . basename($unit) . q{'};
 		if ($dh{NO_ENABLE}) {
 			autoscript($package, 'postinst', 'postinst-systemd-dont-enable', { 'UNITFILE' => $base });
 		} else {
 			autoscript($package, 'postinst', 'postinst-systemd-enable', { 'UNITFILE' => $base });
 		}
 	}
-	my $enableunitargs = join(" ", sort map { basename($_) } @enable_units);
+	my $enableunitargs = join(' ', sort map { q{'} . basename($_) . q{'} } @enable_units);
 	autoscript($package, 'postrm', 'postrm-systemd', {'UNITFILES' => $enableunitargs });
 	
 	# The $package and $sed parameters are always the same.
 	# This wrapper function makes the following logic easier to read.
-	my $startunitargs = join(" ", sort map { basename($_) } @start_units);
+	my $startunitargs = join(' ', sort map { q{'} . basename($_) . q{'} } @start_units);
 	my $start_autoscript = sub {
 		my ($script, $filename) = @_;
 		autoscript($package, $script, $filename, { 'UNITFILES' => $startunitargs });
diff --git a/t/dh_installsystemd/dh_installsystemd.t b/t/dh_installsystemd/dh_installsystemd.t
index 4dcb293..d3cce0f 100755
--- a/t/dh_installsystemd/dh_installsystemd.t
+++ b/t/dh_installsystemd/dh_installsystemd.t
@@ -27,10 +27,10 @@ sub unit_is_enabled {
 	my $matches;
 	$num_masks = $num_masks // $num_enables;
 	@output=`cat debian/$package.postinst.debhelper`;
-	$matches = grep { m{^if deb-systemd-helper .* was-enabled .*$unit\.service} } @output;
+	$matches = grep { m{^if deb-systemd-helper .* was-enabled .*'\Q$unit\E\.service'} } @output;
 	ok($matches == $num_enables) or diag("$unit appears to have been enabled $matches times (expected $num_enables)");
 	@output=`cat debian/$package.postrm.debhelper`;
-	$matches = grep { m{deb-systemd-helper mask.*$unit\.service} } @output;
+	$matches = grep { m{deb-systemd-helper mask.*'\Q$unit\E\.service'} } @output;
 	ok($matches == $num_masks) or diag("$unit appears to have been masked $matches times (expected $num_masks)");
 }
 sub unit_is_started {
@@ -39,10 +39,10 @@ sub unit_is_started {
 	my $matches;
 	$num_stops = $num_stops // $num_starts;
 	@output=`cat debian/$package.postinst.debhelper`;
-	$matches = grep { m{deb-systemd-invoke \$_dh_action .*$unit.service} } @output;
+	$matches = grep { m{deb-systemd-invoke \$_dh_action .*'\Q$unit\E.service'} } @output;
 	ok($matches == $num_starts) or diag("$unit appears to have been started $matches times (expected $num_starts)");
 	@output=`cat debian/$package.prerm.debhelper`;
-	$matches = grep { m{deb-systemd-invoke stop .*$unit.service} } @output;
+	$matches = grep { m{deb-systemd-invoke stop .*'\Q$unit\E.service'} } @output;
 	ok($matches == $num_stops) or diag("$unit appears to have been stopped $matches times (expected $num_stops)");
 }
 
@@ -109,6 +109,13 @@ each_compat_from_and_above_subtest(11, sub {
 	ok($matches == 1);
 	ok(run_dh_tool('dh_clean'));
 
+	# Quoting #764730
+	make_path('debian/foo/lib/systemd/system/');
+	install_file('debian/foo.service', 'debian/foo/lib/systemd/system/foo\x2dfuse.service');
+	ok(run_dh_tool({ 'needs_root' => 1 }, 'dh_installsystemd'));
+	unit_is_enabled('foo', 'foo\x2dfuse', 1);
+	unit_is_started('foo', 'foo\x2dfuse', 1);
+	ok(run_dh_tool('dh_clean'));
 });
 
 each_compat_up_to_and_incl_subtest(10, sub {

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/debhelper/debhelper.git




More information about the debhelper-devel mailing list