[SCM] Debian package checker branch, master, updated. 2.5.14-26-g1662c3e
The following commit has been merged in the master branch:
commit 197d84af338e1d2dceba25bb3d4f0dbfc08bdd68
Author: Michael Stapelberg <michael@stapelberg.de>
Date: Sat Apr 13 23:14:31 2013 +0200
add systemd checks
Signed-off-by: Niels Thykier <niels@thykier.net>
diff --git a/checks/systemd b/checks/systemd
new file mode 100644
index 0000000..deb8a09
--- /dev/null
+++ b/checks/systemd
@@ -0,0 +1,252 @@
+# systemd -- lintian check script -*- perl -*-
+#
+# Copyright © 2013 Michael Stapelberg
+#
+# based on the apache2 checks file by:
+# Copyright © 2012 Arno Töll
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, you can find it on the World Wide
+# Web at http://www.gnu.org/copyleft/gpl.html, or write to the Free
+# Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,
+# MA 02110-1301, USA.
+
+package Lintian::systemd;
+
+use strict;
+use warnings;
+
+use File::Basename;
+use Text::ParseWords qw(shellwords);
+
+use Lintian::Tags qw(tag);
+use Lintian::Util qw(fail is_ancestor_of);
+
+sub run {
+ my ($pkg, $type, $info) = @_;
+
+ # Figure out whether the maintainer of this package did any effort to
+ # make the package work with systemd. If not, we will not warn in case
+ # of an init script that has no systemd equivalent, for example.
+ my $ships_systemd_file = (scalar ( grep { m,/systemd/, } $info->sorted_index ) > 0);
+
+ # An array of names which are provided by the service files.
+ # This includes Alias= directives, so after parsing
+ # NetworkManager.service, it will contain NetworkManager and
+ # network-manager.
+ my @systemd_targets;
+
+ for my $file ($info->sorted_index) {
+ if ($file =~ m,^etc/tmpfiles\.d/.*\.conf$,) {
+ tag 'systemd-tmpfiles.d-outside-usr-lib', $file;
+ }
+ if ($file =~ m,^etc/systemd/system/.*\.service$,) {
+ tag 'systemd-service-file-outside-lib', $file;
+ }
+ if ($file =~ m,/systemd/system/.*\.service$,) {
+ check_systemd_service_file ($pkg, $info, $file);
+ for my $name (extract_service_file_names ($pkg, $info, $file)) {
+ push @systemd_targets, $name;
+ }
+ }
+ }
+
+ my @init_scripts = grep { m,^etc/init\.d/.+, } $info->sorted_index;
+
+ # Verify that each init script includes /lib/lsb/init-functions,
+ # because that is where the systemd diversion happens.
+ for my $init_script (@init_scripts) {
+ check_init_script ($pkg, $info, $init_script);
+ }
+
+ @init_scripts = map { basename($_) } @init_scripts;
+
+ if ($ships_systemd_file) {
+ for my $init_script (@init_scripts) {
+ tag 'systemd-no-service-for-init-script', $init_script
+ unless grep /\Q$init_script\E\.service/, @systemd_targets;
+ }
+ }
+
+ check_maintainer_scripts ($info);
+}
+
+sub check_init_script {
+ my ($pkg, $info, $file) = @_;
+
+ my $lsb_source_seen;
+ my $unpacked_file = $info->unpacked ($file);
+ unless (-f $unpacked_file &&
+ is_ancestor_of ($info->unpacked, $unpacked_file)) {
+ tag 'init-script-is-not-a-file', $file;
+ return;
+ }
+ open(my $fh, '<', $info->unpacked ($file))
+ or fail "cannot open $file: $!";
+ while (<$fh>) {
+ s/^\s+//;
+ next if /^#/;
+ if (m,^(?:\.|source)\s+/lib/lsb/init-functions,) {
+ $lsb_source_seen = 1;
+ last;
+ }
+ }
+ close($fh);
+
+ if (!$lsb_source_seen) {
+ tag 'init.d-script-does-not-source-init-functions', $file;
+ }
+}
+
+sub check_systemd_service_file {
+ my ($pkg, $info, $file) = @_;
+
+ my @values = extract_service_file_values ($pkg, $info, $file, 'Unit', 'After');
+ my @obsolete = grep { /^(?:syslog|dbus)\.target$/ } @values;
+ tag 'systemd-service-file-refers-to-obsolete-target', $file, $_ for @obsolete;
+}
+
+sub service_file_lines {
+ my ($file, $path) = @_;
+ open(my $fh, '<', $path)
+ or fail "cannot open $file: $!";
+ my @lines;
+ my $continuation;
+ while (<$fh>) {
+ chomp;
+
+ if (defined($continuation)) {
+ $_ = $continuation . $_;
+ $continuation = undef;
+ }
+
+ if (/\\$/) {
+ $continuation = $_;
+ $continuation =~ s/\\$/ /;
+ next;
+ }
+
+ # equivalent of strstrip(l)
+ $_ =~ s,[ \t\n\r]+$,,g;
+
+ next if $_ eq '';
+
+ next if /^[#;\n]/;
+
+ push @lines, $_;
+ }
+ close($fh);
+
+ return @lines;
+}
+
+# Extracts the values of a specific Key from a .service file
+sub extract_service_file_values {
+ my ($pkg, $info, $file, $extract_section, $extract_key) = @_;
+
+ my @values;
+ my $section;
+
+ my $unpacked_file = $info->unpacked ($file);
+ unless (-f $unpacked_file &&
+ is_ancestor_of ($info->unpacked, $unpacked_file)) {
+ tag 'service-file-is-not-a-file', $file;
+ return;
+ }
+ my @lines = service_file_lines($file, $info->unpacked ($file));
+ while (grep { /^\.include / } @lines) {
+ @lines = map {
+ if (/^\.include (.+)$/) {
+# XXX: edge case: what should we do when a service file .includes a file in another package? lintian will not have access and therefore cannot properly check the file.
+ my $path = $1;
+ $path =~ s,^/,,;
+ service_file_lines(basename($path), $info->unpacked ($path));
+ } else {
+ $_;
+ }
+ } @lines;
+ }
+ for (@lines) {
+ # section header
+ if (/^\[([^\]]+)\]$/) {
+ $section = $1;
+ next;
+ }
+
+ if (!defined($section)) {
+ # Assignment outside of section. Ignoring.
+ next;
+ }
+
+ my ($key, $value) = ($_ =~ m,^(.*)=(.*)$,);
+ if ($section eq $extract_section &&
+ $key eq $extract_key) {
+ if ($value eq '') {
+ # Empty assignment resets the list
+ @values = ();
+ }
+
+ @values = (@values, shellwords ($value));
+ }
+ }
+
+ return @values;
+}
+
+sub extract_service_file_names {
+ my ($pkg, $info, $file) = @_;
+
+ my @aliases = extract_service_file_values ($pkg, $info, $file, 'Install', 'Alias');
+ return (basename ($file), @aliases);
+}
+
+sub check_maintainer_scripts {
+ my ($info) = @_;
+
+ open my $fd, '<', $info->lab_data_path('/control-scripts')
+ or fail "cannot open lintian control-scripts file: $!";
+
+ while (<$fd>) {
+ m/^(\S*) (.*)$/ or fail("bad line in control-scripts file: $_");
+ my $interpreter = $1;
+ my $file = $2;
+ my $filename = $info->control ($file);
+
+ # Don't follow links
+ next if -l $filename;
+ # Don't try to parse the file if it does not appear to be a shell script
+ next if $interpreter !~ m/sh\b/;
+
+ open my $sfd, '<', $filename or fail "cannot open maintainer script $filename: $!";
+ while (<$sfd>) {
+ # skip comments
+ next if substr ($_, 0, $-[0]) =~ /#/;
+
+ ## systemctl should not be called in maintainer scripts at all.
+ if (m/\bsystemctl\b/) {
+ tag 'maintainer-script-calls-systemctl', $file;
+ }
+ }
+ close $sfd;
+ }
+
+ close $fd;
+}
+
+1;
+
+# Local Variables:
+# indent-tabs-mode: nil
+# cperl-indent-level: 4
+# End:
+# vim: syntax=perl sw=4 sts=4 sr et
diff --git a/checks/systemd.desc b/checks/systemd.desc
new file mode 100644
index 0000000..a59dc0f
--- /dev/null
+++ b/checks/systemd.desc
@@ -0,0 +1,81 @@
+Check-Script: systemd
+Author: Michael Stapelberg <stapelberg@debian.org>
+Type: binary
+Info: Checks various systemd policy things
+Needs-Info: scripts, index, unpacked, file-info
+
+Tag: systemd-service-file-outside-lib
+Severity: serious
+Certainty: certain
+Info: The package ships a systemd service file outside
+ <tt>/lib/systemd/system/</tt>
+ .
+ System administrators should have the possibility to overwrite a service file
+ (or parts of it, in newer systemd versions) by placing a file in
+ <tt>/etc/systemd/system</tt>, so the canonical location we use for service
+ files is <tt>/lib/systemd/system/</tt>.
+
+Tag: systemd-tmpfiles.d-outside-usr-lib
+Severity: serious
+Certainty: certain
+Info: The package ships a systemd tmpfiles.d(5) conf file outside
+ <tt>/usr/lib/tmpfiles.d/</tt>
+
+Tag: systemd-service-file-refers-to-obsolete-target
+Severity: normal
+Certainty: certain
+Info: The systemd service file refers to an obsolete target.
+ .
+ Some targets are obsolete by now, e.g. syslog.target or dbus.target. For
+ example, declaring <tt>After=syslog.target</tt> is unnecessary by now because
+ syslog is socket-activated and will therefore be started when needed.
+
+Tag: systemd-no-service-for-init-script
+Severity: serious
+Certainty: certain
+Info: The listed init.d script has no systemd equivalent.
+ .
+ Systemd has a SysV init.d script compatibility mode. It provides access to
+ each SysV init.d script as long as there is no native service file with the
+ same name (e.g. <tt>/lib/systemd/system/rsyslog.service</tt> corresponds to
+ <tt>/etc/init.d/rsyslog</tt>).
+ .
+ Your package ships a service file, but for the listed init.d script, there is
+ no corresponding systemd service file.
+
+Tag: init.d-script-does-not-source-init-functions
+Severity: normal
+Certainty: certain
+Info: The <tt>/etc/init.d</tt> script does not source
+ <tt>/lib/lsb/init-functions</tt>. The <tt>systemd</tt> package provides
+ <tt>/lib/lsb/init-functions.d/40-systemd</tt> to redirect
+ <tt>/etc/init.d/$script</tt> calls to systemctl.
+ .
+ Please add a line like this to your <tt>/etc/init.d</tt> script:
+ .
+ . /lib/lsb/init-functions
+
+Tag: maintainer-script-calls-systemctl
+Severity: normal
+Certainty: certain
+Ref: https://wiki.debian.org/Systemd/Packaging
+Info: The maintainer script calls systemctl directly. Actions such as enabling
+ a unit file should be done using <tt>deb-systemd-helper</tt> so that they work
+ on machines with or without systemd. Starting a service should be done via
+ <tt>invoke-rc.d</tt>, if the service has a corresponding sysvinit script, or
+ <tt>deb-systemd-invoke</tt> if it doesn’t.
+ .
+ If you are using debhelper, please use the <tt>dh-systemd</tt> debhelper
+ addon.
+
+Tag: init-script-is-not-a-file
+Severity: serious
+Certainty: certain
+Info: The package contains an init script that is not a regular file or
+ resolvable symlink.
+
+Tag: service-file-is-not-a-file
+Severity: serious
+Certainty: certain
+Info: The package contains a service file that is not a regular file or
+ resolvable symlink.
diff --git a/t/tests/systemd-complex-service-file/debian/debian/install b/t/tests/systemd-complex-service-file/debian/debian/install
new file mode 100644
index 0000000..5d4e053
--- /dev/null
+++ b/t/tests/systemd-complex-service-file/debian/debian/install
@@ -0,0 +1,2 @@
+debian/test.service lib/systemd/system/
+debian/test2.service lib/systemd/system/
diff --git a/t/tests/systemd-complex-service-file/debian/debian/test.service b/t/tests/systemd-complex-service-file/debian/debian/test.service
new file mode 100644
index 0000000..820b731
--- /dev/null
+++ b/t/tests/systemd-complex-service-file/debian/debian/test.service
@@ -0,0 +1,8 @@
+[Unit]
+After=dbus.target
+
+[Service]
+ExecStart=/usr/bin/test
+
+[Install]
+WantedBy=multi-user.target
diff --git a/t/tests/systemd-complex-service-file/debian/debian/test2.service b/t/tests/systemd-complex-service-file/debian/debian/test2.service
new file mode 100644
index 0000000..71c1297
--- /dev/null
+++ b/t/tests/systemd-complex-service-file/debian/debian/test2.service
@@ -0,0 +1,5 @@
+.include /lib/systemd/system/test.service
+
+[Unit]
+After=
+After=syslog.target
diff --git a/t/tests/systemd-complex-service-file/desc b/t/tests/systemd-complex-service-file/desc
new file mode 100644
index 0000000..b42f559
--- /dev/null
+++ b/t/tests/systemd-complex-service-file/desc
@@ -0,0 +1,7 @@
+Testname: systemd-complex-service-file
+Sequence: 6000
+Version: 1.0
+Description: Verifies the .service file parser properly handles .include within
+ service files.
+Test-For:
+ systemd-service-file-refers-to-obsolete-target
diff --git a/t/tests/systemd-complex-service-file/tags b/t/tests/systemd-complex-service-file/tags
new file mode 100644
index 0000000..c4715b9
--- /dev/null
+++ b/t/tests/systemd-complex-service-file/tags
@@ -0,0 +1,2 @@
+W: systemd-complex-service-file: systemd-service-file-refers-to-obsolete-target lib/systemd/system/test.service dbus.target
+W: systemd-complex-service-file: systemd-service-file-refers-to-obsolete-target lib/systemd/system/test2.service syslog.target
diff --git a/testset/scripts/init-skeleton b/t/tests/systemd-general/debian/debian/init
similarity index 89%
copy from testset/scripts/init-skeleton
copy to t/tests/systemd-general/debian/debian/init
index 55f05c0..afffa18 100644
--- a/testset/scripts/init-skeleton
+++ b/t/tests/systemd-general/debian/debian/init
@@ -1,10 +1,10 @@
#! /bin/sh
### BEGIN INIT INFO
-# Provides: skeleton
-# Required-Start: $local_fs $remote_fs
-# Required-Stop: $local_fs $remote_fs
+# Provides: systemd-general
+# Required-Start: $remote_fs $syslog
+# Required-Stop: $remote_fs $syslog
# Default-Start: 2 3 4 5
-# Default-Stop: S 0 1 6
+# Default-Stop: 0 1 6
# Short-Description: Example initscript
# Description: This file should be used to construct scripts to be
# placed in /etc/init.d.
@@ -18,7 +18,7 @@
# Do NOT "set -e"
# PATH should only include /usr/* if it runs after the mountnfs.sh script
-PATH=/usr/sbin:/usr/bin:/sbin:/bin
+PATH=/sbin:/usr/sbin:/bin:/usr/bin
DESC="Description of the service"
NAME=daemonexecutablename
DAEMON=/usr/sbin/$NAME
@@ -33,11 +33,11 @@ SCRIPTNAME=/etc/init.d/$NAME
[ -r /etc/default/$NAME ] && . /etc/default/$NAME
# Load the VERBOSE setting and other rcS variables
-[ -f /etc/default/rcS ] && . /etc/default/rcS
+. /lib/init/vars.sh
# Define LSB log_* functions.
-# Depend on lsb-base (>= 3.0-6) to ensure that this file is present.
-. /lib/lsb/init-functions
+# Depend on lsb-base (>= 3.2-14) to ensure that this file is present
+# and status_of_proc is working.
#
# Function that starts the daemon/service
@@ -114,6 +114,9 @@ case "$1" in
2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
esac
;;
+ status)
+ status_of_proc "$DAEMON" "$NAME" && exit 0 || exit $?
+ ;;
#reload|force-reload)
#
# If do_reload() is not implemented then leave this commented out
@@ -140,14 +143,14 @@ case "$1" in
esac
;;
*)
- # Failed to stop
+ # Failed to stop
log_end_msg 1
;;
esac
;;
*)
#echo "Usage: $SCRIPTNAME {start|stop|restart|reload|force-reload}" >&2
- echo "Usage: $SCRIPTNAME {start|stop|restart|force-reload}" >&2
+ echo "Usage: $SCRIPTNAME {start|stop|status|restart|force-reload}" >&2
exit 3
;;
esac
diff --git a/t/tests/systemd-general/debian/debian/install b/t/tests/systemd-general/debian/debian/install
new file mode 100644
index 0000000..363d12a
--- /dev/null
+++ b/t/tests/systemd-general/debian/debian/install
@@ -0,0 +1,2 @@
+debian/test.service etc/systemd/system/
+debian/test.conf etc/tmpfiles.d/
diff --git a/t/tests/systemd-general/debian/debian/test.conf b/t/tests/systemd-general/debian/debian/test.conf
new file mode 100644
index 0000000..b0c4604
--- /dev/null
+++ b/t/tests/systemd-general/debian/debian/test.conf
@@ -0,0 +1,2 @@
+# See tmpfiles.d(5) for details
+d /var/run/bacula 2775 bacula bacula -
diff --git a/t/tests/systemd-general/debian/debian/test.service b/t/tests/systemd-general/debian/debian/test.service
new file mode 100644
index 0000000..9d73aca
--- /dev/null
+++ b/t/tests/systemd-general/debian/debian/test.service
@@ -0,0 +1,9 @@
+[Unit]
+After=network.target \
+syslog.target
+
+[Service]
+ExecStart=/usr/bin/test
+
+[Install]
+WantedBy=multi-user.target
diff --git a/t/tests/systemd-general/desc b/t/tests/systemd-general/desc
new file mode 100644
index 0000000..dc83420
--- /dev/null
+++ b/t/tests/systemd-general/desc
@@ -0,0 +1,11 @@
+Testname: systemd-general
+Sequence: 6000
+Version: 1.0
+Description: General systemd tests
+Test-For:
+ init.d-script-does-not-source-init-functions
+ maintainer-script-calls-systemctl
+ systemd-service-file-outside-lib
+ systemd-tmpfiles.d-outside-usr-lib
+ systemd-service-file-refers-to-obsolete-target
+ systemd-no-service-for-init-script
diff --git a/t/tests/systemd-general/tags b/t/tests/systemd-general/tags
new file mode 100644
index 0000000..b24bc63
--- /dev/null
+++ b/t/tests/systemd-general/tags
@@ -0,0 +1,6 @@
+E: systemd-general: systemd-no-service-for-init-script systemd-general
+E: systemd-general: systemd-service-file-outside-lib etc/systemd/system/test.service
+E: systemd-general: systemd-tmpfiles.d-outside-usr-lib etc/tmpfiles.d/test.conf
+W: systemd-general: init.d-script-does-not-source-init-functions etc/init.d/systemd-general
+W: systemd-general: maintainer-script-calls-systemctl postrm
+W: systemd-general: systemd-service-file-refers-to-obsolete-target etc/systemd/system/test.service syslog.target
--
Debian package checker
Reply to: