Subject: [PATCH 1/5] Fix a bug when looking for required init.d options in comments

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

The regular expression in use was not correctly dealing with comments,
which could result in many false negatives wheen finding the required
option keyword in a comment.
---
 checks/init.d                                      |    2 +-
 t/tests/init.d-general/debian/debian/control.in    |   24 ++++++++++++++++++++
 .../debian/debian/init.d-general-bugs.init         |   14 +++++++++++
 .../debian/debian/init.d-general.init              |   18 +++++++++++++++
 t/tests/init.d-general/desc                        |    6 +++++
 t/tests/init.d-general/tags                        |    4 +++
 6 files changed, 67 insertions(+), 1 deletions(-)
 create mode 100644 t/tests/init.d-general/debian/debian/control.in
 create mode 100644 t/tests/init.d-general/debian/debian/init.d-general-bugs.init
 create mode 100644 t/tests/init.d-general/debian/debian/init.d-general.init
 create mode 100644 t/tests/init.d-general/desc
 create mode 100644 t/tests/init.d-general/tags

diff --git a/checks/init.d b/checks/init.d
index c1e9798..84b5993 100644
--- a/checks/init.d
+++ b/checks/init.d
@@ -192,7 +192,7 @@ for (keys %initd_postinst) {
 		}
 	    }
 
-	    while ($l =~ s/(start|stop|restart|force-reload)//o) {
+	    while ($l =~ s/^[^#]*?(start|stop|restart|force-reload)//o) {
 		$tag{$1} = 1;
 	    }
         }
diff --git a/t/tests/init.d-general/debian/debian/control.in b/t/tests/init.d-general/debian/debian/control.in
new file mode 100644
index 0000000..dffb079
--- /dev/null
+++ b/t/tests/init.d-general/debian/debian/control.in
@@ -0,0 +1,24 @@
+Source: {$srcpkg}
+Priority: extra
+Section: {$section}
+Maintainer: {$author}
+Standards-Version: {$standards_version}
+Build-Depends: debhelper (>= 7)
+
+Package: {$srcpkg}
+Architecture: {$architecture}
+Depends: $\{shlibs:Depends\}, $\{misc:Depends\}
+Description: {$description}
+ 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}-bugs
+Architecture: {$architecture}
+Depends: $\{shlibs:Depends\}, $\{misc:Depends\}
+Description: {$description} -- bugs
+ Test some simple bugs in the check
+ .
+ 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-bugs.init b/t/tests/init.d-general/debian/debian/init.d-general-bugs.init
new file mode 100644
index 0000000..5547e49
--- /dev/null
+++ b/t/tests/init.d-general/debian/debian/init.d-general-bugs.init
@@ -0,0 +1,14 @@
+#!/bin/sh
+
+set -e
+
+### BEGIN INIT INFO
+# Provides:          nothing
+# Required-Start:
+# Required-Stop:
+# Default-Start:
+# Default-Stop:
+# Short-Description: Do nothing at all
+### END INIT INFO
+
+# start stop force-reload restart status
diff --git a/t/tests/init.d-general/debian/debian/init.d-general.init b/t/tests/init.d-general/debian/debian/init.d-general.init
new file mode 100644
index 0000000..c277e99
--- /dev/null
+++ b/t/tests/init.d-general/debian/debian/init.d-general.init
@@ -0,0 +1,18 @@
+#!/bin/sh
+
+set -e
+
+### BEGIN INIT INFO
+# Provides:          nothing
+# Required-Start:
+# Required-Stop:
+# Default-Start:
+# Default-Stop:
+# Short-Description: Do nothing at all
+### END INIT INFO
+
+case "$1" in
+    start|stop|force-reload|restart|status|*)
+	echo hello world!
+    ;;
+esac
diff --git a/t/tests/init.d-general/desc b/t/tests/init.d-general/desc
new file mode 100644
index 0000000..71518ab
--- /dev/null
+++ b/t/tests/init.d-general/desc
@@ -0,0 +1,6 @@
+Testname: init.d-general
+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
diff --git a/t/tests/init.d-general/tags b/t/tests/init.d-general/tags
new file mode 100644
index 0000000..0f20825
--- /dev/null
+++ b/t/tests/init.d-general/tags
@@ -0,0 +1,4 @@
+E: init.d-general-bugs: init.d-script-does-not-implement-required-option /etc/init.d/init.d-general-bugs force-reload
+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
-- 
1.6.3.1