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

[lintian] 01/01: Warn about unit files that install to usual WantedBy= targets. Thanks to Sam Morris for the initial patch. (Closes: #817170)



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

lamby pushed a commit to branch 817170-warn-when-systemd-service-units-install-themselves-into-an-unusual-target
in repository lintian.

commit 4ee4080591bb108419306d65a6528891f14b2ee5
Author: Chris Lamb <lamby@debian.org>
Date:   Tue Feb 6 08:58:46 2018 +0000

    Warn about unit files that install to usual WantedBy= targets. Thanks to Sam Morris for the initial patch. (Closes: #817170)
---
 checks/systemd.desc                                | 12 ++++++++++++
 checks/systemd.pm                                  | 13 +++++++++++--
 data/systemd/wantedby-whitelist                    |  4 ++++
 debian/changelog                                   |  3 +++
 t/tests/systemd-general/debian/debian/test.service |  2 +-
 t/tests/systemd-general/desc                       |  1 +
 t/tests/systemd-general/tags                       |  2 ++
 7 files changed, 34 insertions(+), 3 deletions(-)

diff --git a/checks/systemd.desc b/checks/systemd.desc
index 2d0b0c8..44b36a4 100644
--- a/checks/systemd.desc
+++ b/checks/systemd.desc
@@ -157,3 +157,15 @@ Info: The listed service file simply uses ths existing SysV init script
  init script. This will also make the init scripts more readable and easier
  to support other alternatives. Note that as /etc/init.d/* files are
  conffiles, such updates are not guaranteed to reach users.
+
+Tag: systemd-service-file-refers-to-unusual-wantedby-target
+Severity: normal
+Certainty: certain
+Info: The specified systemd service file declares an unusual
+ <tt>WantedBy=</tt> relationship.
+ .
+ Most services that want to be started automatically at boot should use
+ <tt>WantedBy=multi-user.target</tt> or <tt>WantedBy=graphical.target</tt>.
+ Services that want to be started in rescue or single-user mode should
+ instead use <tt>WantedBy=sysinit.target</tt>
+Ref: https://wiki.debian.org/Teams/pkg-systemd/rcSMigration
diff --git a/checks/systemd.pm b/checks/systemd.pm
index 877d9ea..a1a2b2c 100644
--- a/checks/systemd.pm
+++ b/checks/systemd.pm
@@ -39,6 +39,9 @@ use Lintian::Data;
 # Init script that do not need a service file
 my $INIT_WHITELIST = Lintian::Data->new('systemd/init-whitelist');
 
+# Usual WantedBy= targets
+my $WANTEDBY_WHITELIST = Lintian::Data->new('systemd/wantedby-whitelist');
+
 sub run {
     my (undef, undef, $info) = @_;
 
@@ -212,14 +215,20 @@ sub check_systemd_service_file {
     }
 
     if (not $file->is_symlink or $file->link ne '/dev/null') {
+        my @wanted_by
+          = extract_service_file_values($file, 'Install', 'WantedBy',1);
+        foreach my $target (@wanted_by) {
+            tag 'systemd-service-file-refers-to-unusual-wantedby-target',
+              $file, $target
+              unless any { $target eq $_ } $WANTEDBY_WHITELIST->all;
+        }
         tag 'systemd-service-file-missing-documentation-key', $file,
           unless extract_service_file_values($file, 'Unit', 'Documentation',1);
         #<<< no perltidy - These are better formatted one per line
         tag 'systemd-service-file-missing-install-key', $file,
-          unless extract_service_file_values($file, 'Install', 'WantedBy',1)
+          unless @wanted_by
           or extract_service_file_values($file, 'Install', 'RequiredBy',1)
           or extract_service_file_values($file, 'Install', 'Also',1)
-
           or any { /^oneshot$/ } extract_service_file_values($file, 'Service', 'Type')
           or $file =~ m,@\.service$,;
         #>>>
diff --git a/data/systemd/wantedby-whitelist b/data/systemd/wantedby-whitelist
new file mode 100644
index 0000000..b113a7d
--- /dev/null
+++ b/data/systemd/wantedby-whitelist
@@ -0,0 +1,4 @@
+# "Usual" targets for WantedBy
+graphical.target
+multi-user.target
+sysinit.target
diff --git a/debian/changelog b/debian/changelog
index 749e90c..5b96d39 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -36,6 +36,9 @@ lintian (2.5.74) UNRELEASED; urgency=medium
       maintainer-script-should-not-use-recursive-chown-or-chmod tag.
       Heavily based on a patch by Daniel Kahn Gillmor - thanks!
       (Closes: #889489)
+  * checks/systemd.{desc,pm}:
+    + [CL] Warn about unit files that install to usual WantedBy= targets.
+      Thanks to Sam Morris for the initial patch.  (Closes: #817170)
   * checks/udev.pm:
     + [CL] Add simple GOTO parsing to avoid false positives when checking
       for udev rules for SUBSYSTEM specifiers.  (Closes: #869547, #889639)
diff --git a/t/tests/systemd-general/debian/debian/test.service b/t/tests/systemd-general/debian/debian/test.service
index e58d61c..a456a3d 100644
--- a/t/tests/systemd-general/debian/debian/test.service
+++ b/t/tests/systemd-general/debian/debian/test.service
@@ -8,6 +8,6 @@ ExecStartPre = /bin/true
 ExecStart=/usr/bin/test
 
 [Install]
-WantedBy=multi-user.target
+WantedBy=multi-user.target unusual.target
 Alias=systemd-aliasd.service
 Alias=anothertest
diff --git a/t/tests/systemd-general/desc b/t/tests/systemd-general/desc
index 6c931f1..f69798e 100644
--- a/t/tests/systemd-general/desc
+++ b/t/tests/systemd-general/desc
@@ -14,4 +14,5 @@ Test-For:
  systemd-service-file-missing-documentation-key
  systemd-service-file-refers-to-obsolete-bindto
  systemd-service-file-refers-to-obsolete-target
+ systemd-service-file-refers-to-unusual-wantedby-target
  systemd-tmpfiles.d-outside-usr-lib
diff --git a/t/tests/systemd-general/tags b/t/tests/systemd-general/tags
index 700d1d1..40032c5 100644
--- a/t/tests/systemd-general/tags
+++ b/t/tests/systemd-general/tags
@@ -23,3 +23,5 @@ W: systemd-general: systemd-service-file-refers-to-obsolete-bindto etc/systemd/s
 W: systemd-general: systemd-service-file-refers-to-obsolete-bindto usr/lib/systemd/system/test.service
 W: systemd-general: systemd-service-file-refers-to-obsolete-target etc/systemd/system/test.service syslog.target
 W: systemd-general: systemd-service-file-refers-to-obsolete-target usr/lib/systemd/system/test.service syslog.target
+W: systemd-general: systemd-service-file-refers-to-unusual-wantedby-target etc/systemd/system/test.service unusual.target
+W: systemd-general: systemd-service-file-refers-to-unusual-wantedby-target usr/lib/systemd/system/test.service unusual.target

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


Reply to: