Subject: [PATCH 2/5] Check for init scripts with a /usr shebang

From: Raphael Geissert <[email-masked]>
Date: Sun, 14 Jun 2009 21:12:19 -0500

---
 checks/init.d                                      |    3 +++
 checks/init.d.desc                                 |   14 ++++++++++++++
 t/tests/init.d-general/debian/debian/control.in    |   10 ++++++++++
 .../init.d-general-interpreter-in-usr-dir.init     |   13 +++++++++++++
 t/tests/init.d-general/desc                        |    3 ++-
 t/tests/init.d-general/tags                        |    1 +
 6 files changed, 43 insertions(+), 1 deletions(-)
 create mode 100644 t/tests/init.d-general/debian/debian/init.d-general-interpreter-in-usr-dir.init

diff --git a/checks/init.d b/checks/init.d
index 84b5993..97bb780 100644
--- a/checks/init.d
+++ b/checks/init.d
@@ -156,6 +156,9 @@ for (keys %initd_postinst) {
 	    or fail("cannot open init.d file $initd_file: $!");
 	my (%tag, %lsb);
 	while (defined(my $l = <IN>)) {
+	    if ($. eq 1 && $l =~ m,^#!\s*(/usr/[^\s]+),) {
+		tag "init.d-script-uses-usr-interpreter", "/etc/init.d/$_ $1";
+	    }
 	    if ($l =~ m/^\#\#\# BEGIN INIT INFO/) {
 		if ($lsb{BEGIN}) {
 		    tag "init.d-script-has-duplicate-lsb-section", "/etc/init.d/$_";
diff --git a/checks/init.d.desc b/checks/init.d.desc
index 8a3c6cd..a960da9 100644
--- a/checks/init.d.desc
+++ b/checks/init.d.desc
@@ -199,3 +199,17 @@ Info: This <tt>/etc/init.d</tt> script specifies the S runlevel in
  runlevel and is only used during boot.  There is no way to switch to it
  and hence no use for stop scripts for it, so S should be removed from
  Default-Stop.
+
+Tag: init.d-script-uses-usr-interpreter
+Severity: serious
+Certainty: certain
+Info: The given <tt>/etc/init.d</tt> script specifies an interpreter in
+ its shebang located under <tt>/usr</tt>.
+ .
+ Since init scripts can be left on the system when the package is
+ removed but not purged, its dependencies might no longer be installed
+ causing the init script to fail if the interpreter is one of its dependencies.
+ .
+ Another case where the script might fail to execute is early during the boot
+ process, when the <tt>/usr</tt> partition might not yet be mounted by the time
+ the script needs its interpreter.
diff --git a/t/tests/init.d-general/debian/debian/control.in b/t/tests/init.d-general/debian/debian/control.in
index dffb079..7d2d840 100644
--- a/t/tests/init.d-general/debian/debian/control.in
+++ b/t/tests/init.d-general/debian/debian/control.in
@@ -22,3 +22,13 @@ Description: {$description} -- bugs
  This is a test package designed to exercise some feature or tag of
  Lintian.  It is part of the Lintian test suite and may do very odd
  things.  It should not be installed like a regular package.
+
+Package: {$srcpkg}-interpreter-in-usr-dir
+Architecture: {$architecture}
+Depends: $\{shlibs:Depends\}, $\{misc:Depends\}
+Description: {$description} -- bad script interpreter
+ Test a check for a /usr dir interpreter used in an init script
+ .
+ This is a test package designed to exercise some feature or tag of
+ Lintian.  It is part of the Lintian test suite and may do very odd
+ things.  It should not be installed like a regular package.
diff --git a/t/tests/init.d-general/debian/debian/init.d-general-interpreter-in-usr-dir.init b/t/tests/init.d-general/debian/debian/init.d-general-interpreter-in-usr-dir.init
new file mode 100644
index 0000000..d371717
--- /dev/null
+++ b/t/tests/init.d-general/debian/debian/init.d-general-interpreter-in-usr-dir.init
@@ -0,0 +1,13 @@
+#!/usr/bin/perl -w
+
+### BEGIN INIT INFO
+# Provides:          some-useless-thing
+# Required-Start:    $remote_fs $syslog
+# Required-Stop:     $remote_fs $syslog
+# Default-Start:     2 3 4 5
+# Default-Stop:      0 1 6
+# Short-Description: Start daemon at boot time
+# Description:       Enable service provided by daemon.
+### END INIT INFO
+
+printf "start stop reload restart force-reload\n";
diff --git a/t/tests/init.d-general/desc b/t/tests/init.d-general/desc
index 71518ab..91a4a90 100644
--- a/t/tests/init.d-general/desc
+++ b/t/tests/init.d-general/desc
@@ -3,4 +3,5 @@ Sequence: 6000
 Version: 1.0
 Description: Test tags related to the init.d checks
 Test-For:
-  init.d-script-does-not-implement-required-option
\ No newline at end of file
+  init.d-script-does-not-implement-required-option
+  init.d-script-uses-usr-interpreter
diff --git a/t/tests/init.d-general/tags b/t/tests/init.d-general/tags
index 0f20825..d52d0c7 100644
--- a/t/tests/init.d-general/tags
+++ b/t/tests/init.d-general/tags
@@ -2,3 +2,4 @@ E: init.d-general-bugs: init.d-script-does-not-implement-required-option /etc/in
 E: init.d-general-bugs: init.d-script-does-not-implement-required-option /etc/init.d/init.d-general-bugs restart
 E: init.d-general-bugs: init.d-script-does-not-implement-required-option /etc/init.d/init.d-general-bugs start
 E: init.d-general-bugs: init.d-script-does-not-implement-required-option /etc/init.d/init.d-general-bugs stop
+E: init.d-general-interpreter-in-usr-dir: init.d-script-uses-usr-interpreter /etc/init.d/init.d-general-interpreter-in-usr-dir /usr/bin/perl
-- 
1.6.3.1