[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Bug#817170: lintian: warn when (systemd) service units install themselves into an unusual target



Package: lintian
Version: 2.5.42
Severity: wishlist
Tags: patch

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA256

I noticed that haveged.service installs itself with
WantedBy=default.target, rather than multi-user.target.

This lintian check warns when a service unit is WantedBy= something other
than {sysinit,multi-user,graphical}.target.

Would pkg-systemd-maintainers care to comment on whether this is a good
idea and/or whether there are likely to be too many false positives? I
ran the following on my system:

    systemctl --no-legend list-unit-files -t service | while read unit rest; do w=$(systemctl cat "$unit" | grep ^WantedBy=); for x in $w; do printf '%s %s\n' $x "$unit"; done; done

and the false positives were from systemd itself, bluez and anacron.

- -- System Information:
Debian Release: 8.3
  APT prefers stable-updates
  APT policy: (550, 'stable-updates'), (550, 'stable'), (530, 'testing'), (520, 'unstable'), (510, 'experimental'), (500, 'unstable-debug'), (500, 'testing-updates')
Architecture: amd64 (x86_64)

Kernel: Linux 4.4.0-1-amd64 (SMP w/2 CPU cores)
Locale: LANG=en_GB.utf8, LC_CTYPE=en_GB.utf8 (charmap=UTF-8)
Shell: /bin/sh linked to /bin/dash
Init: systemd (via /run/systemd/system)

Versions of packages lintian depends on:
ii  binutils                          2.26-5
ii  bzip2                             1.0.6-7+b3
ii  diffstat                          1.58-1
ii  file                              1:5.22+15-2+deb8u1
ii  gettext                           0.19.3-2
ii  hardening-includes                2.6
ii  intltool-debian                   0.35.0+20060710.1
ii  libapt-pkg-perl                   0.1.29+b5
ii  libarchive-zip-perl               1.39-1
ii  libclass-accessor-perl            0.34-1
ii  libclone-perl                     0.38-1+b1
ii  libdata-alias-perl                1.20-1+b1
ii  libdpkg-perl                      1.18.4
ii  libemail-valid-perl               1.195-1
ii  libfile-basedir-perl              0.03-1
ii  libipc-run-perl                   0.92-1
ii  liblist-moreutils-perl            0.413-1+b1
ii  libparse-debianchangelog-perl     1.2.0-1.1
ii  libperl5.22 [libdigest-sha-perl]  5.22.1-8
ii  libtext-levenshtein-perl          0.11-1
ii  libtimedate-perl                  2.3000-2
ii  liburi-perl                       1.64-1
ii  libyaml-libyaml-perl              0.41-6+b1
ii  man-db                            2.7.0.2-5
ii  patchutils                        0.3.3-1
ii  perl                              5.22.1-8
ii  t1utils                           1.38-4
ii  xz-utils                          5.1.1alpha+20120614-2+b3

Versions of packages lintian recommends:
ii  dpkg                                 1.18.4
ii  libautodie-perl                      2.29-2
ii  libperlio-gzip-perl                  0.19-1+b1
ii  perl                                 5.22.1-8
ii  perl-modules-5.22 [libautodie-perl]  5.22.1-8

Versions of packages lintian suggests:
pn  binutils-multiarch     <none>
ii  dpkg-dev               1.18.4
ii  libhtml-parser-perl    3.72-1
ii  libtext-template-perl  1.46-1

- -- no debconf information

-----BEGIN PGP SIGNATURE-----

iQIcBAEBCAAGBQJW3wuNAAoJENILQgJc2ie553sP/1uc3IiFkVw0HRj0ZCul000o
v5qPEXj/Z8ahzw5+JDeklzkmATMA8C4Ickdjhc65Qk/b4MdmqSKplkbqbVZhcqeB
1beWkA+jXNfcVjAGP5lqdA5CTvZ1u7xKhaRMiQ2O3O8hlX0zgk7eEUCTML0czwUx
4Oeo4TtkEnwyVmPOorEbixvyz7VENHHR7G2g6xbed2LlGqSZWJ1aTgqRawEssM9O
LPK1yo0XbTEFNFZ1CFgqLPVlpj/OFnkQJQgnSPDyo4fpiB3IJ4qbJLOXPWxWfGHG
iieVaQGA+KSq0c4FnSyfEz3DDDC17cS1uiCYEZrBldKIOzmootpPXXLKDa4aiDi7
c7XpLFCEExW6WM+Jn3iS5OMXINld1NqdWLvQgjfhSKe6em69NlXsdW3PojcaVHIK
xDLoQRujy4PWowVJGDpKjETeJQKhP9RnCHiXpmKEfjOrRnUAzUeBi7SIZcmb3IvS
esMpSCqlwI5yuspH3bsGUouuW2AMM2ANUSmCv6gW1emSuF2nZBzE9bhXDPSfdBC9
+SZiow546wv0qOOpRsIF8PE3TzW2z6mAnfPb3FFLB7QGCbSQ7Ll8fFR++2ghiu9y
QkqQSgGq1VpDr4lSaIopOMPFGmk5KUAkEZXzi6AX7x1i2l3lutjxeZ0I0cLL3hzw
db/vH9LV5UNwBFzIycy9
=ZGO7
-----END PGP SIGNATURE-----
>From 13fe1c75dae2d64d61adf765478990d5c2c84d4a Mon Sep 17 00:00:00 2001
From: Sam Morris <sam@robots.org.uk>
Date: Tue, 8 Mar 2016 16:11:18 +0000
Subject: [PATCH] systemd: warn if services are WantedBy= an unusual target

---
 checks/systemd.desc | 11 +++++++++++
 checks/systemd.pm   |  7 +++++++
 2 files changed, 18 insertions(+)

diff --git a/checks/systemd.desc b/checks/systemd.desc
index 7c8eddb..dc8ec73 100644
--- a/checks/systemd.desc
+++ b/checks/systemd.desc
@@ -126,3 +126,14 @@ Info: The systemd service file does not contain a <tt>Documentation</tt> key.
  Documentation for systemd service files can be automatically viewed using
  <tt>systemctl help servicename</tt> if this field is present.
 Ref: systemd.unit(5)
+
+Tag: systemd-service-wantedby-unusual-target
+Severity: normal
+Certainty: certain
+Info: The systemd service file declares an unusual WantedBy= relationship.
+ .
+ Most services that want to be started automatically at boot should use
+ WantedBy=multi-user.target or WantedBy=graphical.target. Services that want to
+ be started in rescue or single-user mode should instead use
+ WantedBy=sysinit.target.
+Ref: https://wiki.debian.org/Teams/pkg-systemd/rcSMigration
diff --git a/checks/systemd.pm b/checks/systemd.pm
index 69092be..225f153 100644
--- a/checks/systemd.pm
+++ b/checks/systemd.pm
@@ -195,6 +195,13 @@ sub check_systemd_service_file {
           unless extract_service_file_values($file, 'Unit', 'Documentation',1);
     }
 
+    if ($file =~ /\.service$/) {
+        my @wantedby = extract_service_file_values($file, 'Install', 'WantedBy');
+        my @unusual_wantedby = grep { /(?<!^sysinit)(?<!^multi-user)(?<!^graphical)\.target$/ } @wantedby;
+        tag 'systemd-service-wantedby-unusual-target', $file, $_
+            for @unusual_wantedby;
+    }
+
     return 1;
 }
 
-- 
2.7.0


Reply to: