[Initscripts-ng-commits] r973 - in /trunk/src/insserv/debian: changelog update-rc.d-insserv
kelmo-guest at users.alioth.debian.org
kelmo-guest at users.alioth.debian.org
Mon Aug 31 14:14:44 UTC 2009
Author: kelmo-guest
Date: Mon Aug 31 14:14:44 2009
New Revision: 973
URL: http://svn.debian.org/wsvn/initscripts-ng/?sc=1&rev=973
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:
trunk/src/insserv/debian/changelog
trunk/src/insserv/debian/update-rc.d-insserv
Modified: trunk/src/insserv/debian/changelog
URL: http://svn.debian.org/wsvn/initscripts-ng/trunk/src/insserv/debian/changelog?rev=973&op=diff
==============================================================================
--- trunk/src/insserv/debian/changelog (original)
+++ trunk/src/insserv/debian/changelog Mon Aug 31 14:14:44 2009
@@ -37,8 +37,11 @@
conffile with correct permissions.
* Add new patch 21_tests_suite_new_functions.patch to add a couple
of new test suite functions to upstream test suite.
-
- -- Petter Reinholdtsen <pere at debian.org> Tue, 28 Jul 2009 19:16:21 +0200
+ * 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.
+
+ -- Kel Modderman <kel at otaku42.de> Tue, 01 Sep 2009 00:13:28 +1000
insserv (1.12.0-10) unstable; urgency=low
Modified: trunk/src/insserv/debian/update-rc.d-insserv
URL: http://svn.debian.org/wsvn/initscripts-ng/trunk/src/insserv/debian/update-rc.d-insserv?rev=973&op=diff
==============================================================================
--- trunk/src/insserv/debian/update-rc.d-insserv (original)
+++ trunk/src/insserv/debian/update-rc.d-insserv Mon Aug 31 14:14:44 2009
@@ -31,7 +31,7 @@
# systems might keep the legacy ordering until the sysadm choose to
# migrate to the new ordering method. sysv-rc version 2.87dsf-2 will
# remove /var/lib/insserv/using-insserv and this divert, thus transfering
-the responsibility for dependency based update-rc.d to sysv-rc.
+# the responsibility for dependency based update-rc.d to sysv-rc.
if ( -f "/var/lib/insserv/using-insserv" && ! -f "/etc/init.d/.legacy-bootordering" ) {
info("using dependency based boot sequencing");
exit insserv_updatercd(@ARGV);
@@ -53,6 +53,9 @@
sub save_last_action {
my ($script, @arguments) = @_;
my $archive = "/var/lib/update-rc.d";
+
+ return if $notreally;
+
open(FILE, ">", "$archive/${script}.new") || die;
print FILE join(" ","update-rc.d", at arguments), "\n";
close(FILE);
@@ -75,6 +78,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";
@@ -392,13 +396,10 @@
} elsif ("defaults" eq $action || "start" eq $action ||
"stop" eq $action) {
# All start/stop/defaults arguments are discarded so emit a
- # message if arguments have been given. When update-rc.d is
- # used in package maintainer scripts output is almost always
- # 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");
- }
+ # message if arguments have been given and are in conflict
+ # with Default-Start/Default-Stop values of LSB comment.
+ cmp_args_with_defaults($scriptname, $action, @args);
+
if ( -f "/etc/init.d/$scriptname" ) {
my $rc = system "insserv", @opts, $scriptname;
if (0 == $rc && !$notreally) {
@@ -409,7 +410,7 @@
error("initscript does not exist: /etc/init.d/$scriptname");
}
} elsif ("disable" eq $action || "enable" eq $action) {
- insserv_toggle($action, $scriptname, @args);
+ insserv_toggle($notreally, $action, $scriptname, @args);
# Call insserv to resequence modified links
my $rc = system "insserv", @opts, $scriptname;
if (0 == $rc && !$notreally) {
@@ -421,9 +422,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>) {
@@ -439,44 +440,100 @@
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, $differ);
+ 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)) {
+ $differ++;
+ $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)) {
+ $differ++;
+ $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)";
+ }
+
+ info "\`$act @_' overridden by LSB info of $lsb_header" if $differ;
}
sub insserv_toggle {
- my ($act, $name) = (shift, shift);
- my ($lsb_header, @runlevels, @symlinks);
-
- # 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");
- }
+ my ($dryrun, $act, $name) = (shift, shift, shift);
+ my (@toggle_lvls, $start_lvls, $stop_lvls, @symlinks);
+ my $lsb_header = lsb_header_for_script($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;
@@ -503,7 +560,7 @@
$new_lnk[$sk] = 'S';
}
- if ($notreally) {
+ if ($dryrun) {
printf("rename(%s, %s)\n", $cur_lnk, join('', @new_lnk));
next;
}
More information about the Initscripts-ng-commits
mailing list