Bug#861204: deb-systemd-invoke: fails to handle units with escaped characters
Bernd Zeimetz
bzed at debian.org
Tue Apr 25 21:09:03 BST 2017
Package: init-system-helpers
Version: 1.47
Severity: serious
Tags: patch
Hi,
to fix #856429 I need to handle a unit with an escaped character
correctly in the maintainer scripts generated by dh_systemd*.
Unfortunately deb-systemd-invoke does not quote the unit name
properly in a systemctl call, so it fails to handle the unit.
A patch is attached, with it deb-systemd-invoke works as expected.
I did not test my changes to t/001-deb-systemd-helper.t as I don't
have the necessary perl module installed and didn't want to mess
with CPAN. But I'd assume its correct.
Thanks for fixing,
Bernd
--
Bernd Zeimetz Debian GNU/Linux Developer
http://bzed.de http://www.debian.org
GPG Fingerprint: ECA1 E3F2 8E11 2432 D485 DD95 EB36 171A 6FF9 435F
-------------- next part --------------
From f506723313b8b85e062b61ccda5e31d7adc3a176 Mon Sep 17 00:00:00 2001
From: Bernd Zeimetz <bzed at debian.org>
Date: Tue, 25 Apr 2017 21:40:00 +0200
Subject: [PATCH] Handle units with escaped characters correctly.
Also see
https://www.freedesktop.org/software/systemd/man/systemd-escape.html
---
script/deb-systemd-invoke | 2 +-
t/001-deb-systemd-helper.t | 10 +++++-----
2 files changed, 6 insertions(+), 6 deletions(-)
diff --git a/script/deb-systemd-invoke b/script/deb-systemd-invoke
index 4255d06..a4b3fbc 100755
--- a/script/deb-systemd-invoke
+++ b/script/deb-systemd-invoke
@@ -85,7 +85,7 @@ if ($action eq "start" || $action eq "restart") {
my $global_exit_code = 0;
for my $unit (@units) {
my $unit_installed = 0;
- my $enabled_output = `/bin/systemctl is-enabled -- $unit`;
+ my $enabled_output = `/bin/systemctl is-enabled -- '$unit'`;
# matching enabled and enabled-runtime as an installed non static unit
if ($enabled_output =~ /enabled/) {
$unit_installed = 1;
diff --git a/t/001-deb-systemd-helper.t b/t/001-deb-systemd-helper.t
index 64332e3..2d5da28 100644
--- a/t/001-deb-systemd-helper.t
+++ b/t/001-deb-systemd-helper.t
@@ -54,7 +54,7 @@ unless ($ENV{'TEST_ON_REAL_SYSTEM'}) {
# ? Verify ?is-enabled? is not true for a random, non-existing unit file. ?
# ?????????????????????????????????????????????????????????????????????????????
-my ($fh, $random_unit) = tempfile('unitXXXXX',
+my ($fh, $random_unit) = tempfile('unit\x2dXXXXX',
SUFFIX => '.service',
TMPDIR => 1,
UNLINK => 1);
@@ -303,13 +303,13 @@ ExecStart=/bin/sleep 1
[Install]
WantedBy=multi-user.target
-Alias=footest.service
+Alias=foo\x2dtest.service
EOT
close($fh);
isnt_enabled($random_unit);
-isnt_enabled('footest.service');
-my $alias_path = "/etc/systemd/system/footest.service";
+isnt_enabled('foo\x2dtest.service');
+my $alias_path = "/etc/systemd/system/foo\x2dtest.service";
ok(! -l $alias_path, 'alias link does not exist yet');
$retval = system("DPKG_MAINTSCRIPT_PACKAGE=test $dsh enable $random_unit");
is($retval, 0, "enable command succeeded");
@@ -376,7 +376,7 @@ EOT
close($fh);
isnt_enabled($random_unit);
-isnt_enabled('footest.service');
+isnt_enabled('foo\x2dtest.service');
# note that in this case $alias_path and $mask_path are identical
$retval = system("DPKG_MAINTSCRIPT_PACKAGE=test $dsh enable $random_unit");
is($retval, 0, "enable command succeeded");
--
2.11.0
More information about the Pkg-systemd-maintainers
mailing list