[Initscripts-ng-commits] r878 - 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 Mar 16 21:37:58 UTC 2009


Author: kelmo-guest
Date: Mon Mar 16 21:37:58 2009
New Revision: 878

URL: http://svn.debian.org/wsvn/initscripts-ng/?sc=1&rev=878
Log:
Add interface to disable|enable service symlinks for all Default-
Start runlevels or those specified on the command line. This is
analogous to the interface introduced to update-rc.d of 2.86.ds1-62.

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=878&op=diff
==============================================================================
--- trunk/src/insserv/debian/changelog (original)
+++ trunk/src/insserv/debian/changelog Mon Mar 16 21:37:58 2009
@@ -19,8 +19,11 @@
   * Add debian/patches/90_no_runlevel_spec_for_debian.patch to remove
     reference to known runlevels on Debian systems. These should be
     defined in Debian policy. (Closes: #500542)
-
- -- Kel Modderman <kel at otaku42.de>  Sun, 15 Mar 2009 19:56:45 +1000
+  * Add interface to disable|enable service symlinks for all Default-
+    Start runlevels or those specified on the command line. This is
+    analogous to the interface introduced to update-rc.d of 2.86.ds1-62.
+
+ -- Kel Modderman <kel at otaku42.de>  Tue, 17 Mar 2009 07:36:37 +1000
 
 insserv (1.12.0-4) 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=878&op=diff
==============================================================================
--- trunk/src/insserv/debian/update-rc.d-insserv (original)
+++ trunk/src/insserv/debian/update-rc.d-insserv Mon Mar 16 21:37:58 2009
@@ -4,37 +4,131 @@
 use warnings;
 
 my @opts;
+my $scriptname;
+my $action;
+my $dryrun = 0;
+
 while($#ARGV >= 0 && ($_ = $ARGV[0]) =~ /^-/) {
     shift @ARGV;
-    if (/^-n$/) { push(@opts, $_); next }
+    if (/^-n$/) { push(@opts, $_); $dryrun++; next }
     if (/^-f$/) { push(@opts, $_); next }
     if (/^-h|--help$/) { &usage; }
     &usage("unknown option");
 }
-my $scriptname = $ARGV[0];
-if ("remove" eq $ARGV[1]) {
+
+usage("not enough arguments") if ($#ARGV < 1);
+
+$scriptname = shift @ARGV;
+$action = shift @ARGV;
+if ("remove" eq $action) {
     if ( -f "/etc/init.d/$scriptname" ) {
         exec "insserv", @opts, "-r", $scriptname;
     } else {
-        # insserv remove all dangling symlinks, no need to tell it
+        # insserv removes all dangling symlinks, no need to tell it
         # what to look for.
         exec "insserv", @opts;
     }
-} elsif ("defaults" eq $ARGV[1] || "start" eq $ARGV[1] || "stop" eq $ARGV[1]) {
+} elsif ("defaults" eq $action || "start" eq $action || "stop" eq $action) {
     # Ignore start/stop/defaults arguments, just add it
+    exec "insserv", @opts, $scriptname;
+} elsif ("disable" eq $action || "enable" eq $action) {
+    toggle($action, $scriptname, @ARGV);
+    # Call insserv to resequence modified links
     exec "insserv", @opts, $scriptname;
 } else {
     usage();
 }
 
 sub usage {
-        print STDERR "update-rc.d: error: @_\n" if ($#_ >= 0);
-        print STDERR <<EOF;
+    print STDERR "update-rc.d: error: @_\n" if ($#_ >= 0);
+    print STDERR <<EOF;
 usage: update-rc.d [-n] [-f] <basename> remove
        update-rc.d [-n] <basename> defaults [NN | sNN kNN]
        update-rc.d [-n] <basename> start|stop NN runlvl [runlvl] [...] .
+       update-rc.d [-n] <basename> disable|enable [runlvl1 runlvl2 ...]
                 -n: not really
                 -f: force
 EOF
-        exit (1);
+    exit (1);
 }
+
+sub error {
+    print STDERR "update-rc.d: error: @_\n";
+    exit (1);
+}
+
+sub parse_def_start {
+    my $script = shift;
+    my (%lsb, @def_start_lvls);
+
+    open my $fh, '<', $script or error("unable to read $script");
+    while (<$fh>) {
+        chomp;
+	if (m/^### BEGIN INIT INFO$/) {
+	    $lsb{'begin'}++;
+	}
+	elsif (m/^### END INIT INFO$/) {
+	    $lsb{'end'}++;
+	    last;
+	}
+	elsif ($lsb{'begin'} and not $lsb{'end'}) {
+	    if (m/^# Default-Start:\s*(\S?.*)$/) {
+		@def_start_lvls = split(' ', $1);
+	    }
+        }
+    }
+    close($fh);
+
+    return @def_start_lvls;
+}
+
+sub 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";
+    } 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 = @_;
+    } else {
+	@runlevels = parse_def_start($lsb_header);
+	if ($#runlevels < 0) {
+	    error("$name Default-Start contains no runlevels, aborting.");
+    	}
+    }
+
+    # Find symlinks in rc.d directories. Refuse to modify links
+    # in runlevels 0 or 6, these adjustments are best done manually
+    # (with rm) or provided by the maintainer of script per default.
+    for my $lvl (@runlevels) {
+	if ($lvl !~ /^[S12345]$/) {
+	    error("$act action will have no effect on runlevel $lvl");
+	}
+	push(@symlinks, $_) for glob("/etc/rc$lvl.d/[SK][0-9][0-9]$name");
+    }
+
+    # Toggle S/K bit of script symlink.
+    for my $cur_lnk (@symlinks) {
+	my @new_lnk = split(//, $cur_lnk);
+
+	if ("disable" eq $act) {
+	    next if $new_lnk[11] eq 'K';
+	    $new_lnk[11] = 'K';
+	} else {
+	    next if $new_lnk[11] eq 'S';
+	    $new_lnk[11] = 'S';
+	}
+
+	next if $dryrun;
+	rename($cur_lnk, join('', @new_lnk)) or error($!);
+    }
+}




More information about the Initscripts-ng-commits mailing list