[Pkg-sysvinit-commits] r1666 - in sysvinit/trunk/debian: . sysv-rc/sbin

Kel Modderman kelmo-guest at alioth.debian.org
Mon Aug 31 13:36:33 UTC 2009


Author: kelmo-guest
Date: 2009-08-31 13:36:33 +0000 (Mon, 31 Aug 2009)
New Revision: 1666

Modified:
   sysvinit/trunk/debian/changelog
   sysvinit/trunk/debian/sysv-rc/sbin/update-rc.d
Log:
Make sure update-rc.d compares command line parameters for start/stop
runlevel configuration with the Default-Start and Default-Stop values in
LSB info comment of script and warns if there are differences.

Modified: sysvinit/trunk/debian/changelog
===================================================================
--- sysvinit/trunk/debian/changelog	2009-08-30 09:44:12 UTC (rev 1665)
+++ sysvinit/trunk/debian/changelog	2009-08-31 13:36:33 UTC (rev 1666)
@@ -51,6 +51,9 @@
     former can be replaced with dh_testdir and dh_testroot instead.
   * Fix reject hunk of debian/patches/70_compiler_warnings.dpatch to
     fix another compile warning.
+  * Make sure update-rc.d compares command line parameters for start/stop
+    runlevel configuration with the Default-Start and Default-Stop values in
+    LSB info comment of script and warns if there are differences.
 
   [ Petter Reinholdtsen ]
   * Adjust init.d/bootlogd dependencies to start before hostname,
@@ -82,7 +85,7 @@
     only useful for kernels up to linux 2.2, which is no longer
     supported (Closes: #544249).  Thanks to Marco d'Itri for the tip.
 
- -- Kel Modderman <kel at otaku42.de>  Sun, 02 Aug 2009 05:46:21 +1000
+ -- Kel Modderman <kel at otaku42.de>  Mon, 31 Aug 2009 22:53:55 +1000
 
 sysvinit (2.87dsf-2) unstable; urgency=low
 

Modified: sysvinit/trunk/debian/sysv-rc/sbin/update-rc.d
===================================================================
--- sysvinit/trunk/debian/sysv-rc/sbin/update-rc.d	2009-08-30 09:44:12 UTC (rev 1665)
+++ sysvinit/trunk/debian/sysv-rc/sbin/update-rc.d	2009-08-31 13:36:33 UTC (rev 1666)
@@ -73,6 +73,7 @@
 	exit (1);
     }
     &parse_lsb_header("$initd/$bn");
+    &cmp_args_with_defaults($bn, $ARGV[0], @ARGV);
 } elsif (-f "$initd/$bn") {
     if (!$force) {
 	printf STDERR "update-rc.d: $initd/$bn exists during rc.d purge (use -f to force)\n";
@@ -395,7 +396,7 @@
         # redirected to /dev/null thanks to dh_installinit, so this
         # should not be too noisy.
         if ($#args >= 0) {
-            info("\`$action @args' overridden by LSB info of $scriptname");
+            cmp_args_with_defaults($scriptname, $action, @args);
         }
         if ( -f "/etc/init.d/$scriptname" ) {
             my $rc = system "insserv", @opts, $scriptname;
@@ -419,9 +420,9 @@
     }
 }
 
-sub parse_def_start {
+sub parse_def_start_stop {
     my $script = shift;
-    my (%lsb, @def_start_lvls);
+    my (%lsb, @def_start_lvls, @def_stop_lvls);
 
     open my $fh, '<', $script or error("unable to read $script");
     while (<$fh>) {
@@ -437,44 +438,96 @@
             if (m/^# Default-Start:\s*(\S?.*)$/) {
                 @def_start_lvls = split(' ', $1);
             }
+            if (m/^# Default-Stop:\s*(\S?.*)$/) {
+                @def_stop_lvls = split(' ', $1);
+            }
         }
     }
     close($fh);
 
-    return @def_start_lvls;
+    return (\@def_start_lvls, \@def_stop_lvls);
 }
 
+sub lsb_header_for_script {
+    my $name = shift;
+
+    foreach my $file ("/etc/insserv/overrides/$name", "/etc/init.d/$name",
+                      "/usr/share/insserv/overrides/$name") {
+        return $file if -s $file;
+    }
+
+    error("cannot find a LSB script for $name");
+}
+
+sub cmp_args_with_defaults {
+    my ($name, $act) = (shift, shift);
+    my ($lsb_start_ref, $lsb_stop_ref, $arg_str, $lsb_str);
+    my (@arg_start_lvls, @arg_stop_lvls, @lsb_start_lvls, @lsb_stop_lvls);
+    my $lsb_header = lsb_header_for_script($name);
+
+    ($lsb_start_ref, $lsb_stop_ref) = parse_def_start_stop($lsb_header);
+    @lsb_start_lvls = @$lsb_start_ref;
+    @lsb_stop_lvls  = @$lsb_stop_ref;
+    return if (!@lsb_start_lvls and !@lsb_stop_lvls);
+
+    if ($act eq 'defaults') {
+        @arg_start_lvls = (2, 3, 4, 5);
+        @arg_stop_lvls  = (0, 1, 6);
+    } elsif ($act eq 'start' or $act eq 'stop') {
+        my $start = $act eq 'start' ? 1 : 0;
+        my $stop = $act eq 'stop' ? 1 : 0;
+
+        foreach my $arg (@_) {
+            if ($arg eq 'start') {
+                $start = 1; $stop = 0; next;
+            } elsif ($arg eq 'stop') {
+                $start = 0; $stop = 1; next;
+            } elsif ($arg =~ /^[0-9]{2}$/) {
+                next;
+            } elsif ($arg eq '.') {
+                next;
+            }
+            push(@arg_start_lvls, $arg) if $start;
+            push(@arg_stop_lvls, $arg) if $stop;
+        }
+    }
+
+    if ($#arg_start_lvls != $#lsb_start_lvls or
+        join("\0", sort @arg_start_lvls) ne join("\0", sort @lsb_start_lvls)) {
+        $arg_str = @arg_start_lvls ? "@arg_start_lvls" : "none";
+        $lsb_str = @lsb_start_lvls ? "@lsb_start_lvls" : "none";
+        warning "$name start runlevel arguments ($arg_str) do not match",
+                "LSB Default-Start values ($lsb_str)";
+    }
+    if ($#arg_stop_lvls != $#lsb_stop_lvls or
+        join("\0", sort @arg_stop_lvls) ne join("\0", sort @lsb_stop_lvls)) {
+        $arg_str = @arg_stop_lvls ? "@arg_stop_lvls" : "none";
+        $lsb_str = @lsb_stop_lvls ? "@lsb_stop_lvls" : "none";
+        warning "$name stop runlevel arguments ($arg_str) do not match",
+                "LSB Default-Stop values ($lsb_str)";
+    }
+}
+
 sub insserv_toggle {
     my ($act, $name) = (shift, shift);
-    my ($lsb_header, @runlevels, @symlinks);
+    my (@toggle_lvls, $start_lvls, $stop_lvls, @symlinks);
+    my $lsb_header = lsb_header_for_script($name);
 
-    # Prefer insserv override file if it exists.
-    if (-s "/etc/insserv/overrides/$name") {
-        $lsb_header = "/etc/insserv/overrides/$name";
-    } elsif (-s "/etc/init.d/$name") {
-        $lsb_header = "/etc/init.d/$name";
-    } elsif (-s "/usr/share/insserv/overrides/$name") {
-        # These overrides take effect only when no LSB info is
-        # in /etc/init.d/$name
-        $lsb_header = "/usr/share/insserv/overrides/$name";
-    } else {
-        error("cannot find an initscript for $name");
-    }
-
     # Extra arguments to disable|enable action are runlevels. If none
     # given parse LSB info for Default-Start value.
     if ($#_ >= 0) {
-        @runlevels = @_;
+        @toggle_lvls = @_;
     } else {
-        @runlevels = parse_def_start($lsb_header);
-        if ($#runlevels < 0) {
+        ($start_lvls, $stop_lvls) = parse_def_start_stop($lsb_header);
+        @toggle_lvls = @$start_lvls;
+        if ($#toggle_lvls < 0) {
             error("$name Default-Start contains no runlevels, aborting.");
         }
     }
 
     # Find symlinks in rc.d directories. Refuse to modify links in runlevels
     # not used for normal system start sequence.
-    for my $lvl (@runlevels) {
+    for my $lvl (@toggle_lvls) {
         if ($lvl !~ /^[S2345]$/) {
             warning("$act action will have no effect on runlevel $lvl");
             next;




More information about the Pkg-sysvinit-commits mailing list