[Pkg-sysvinit-devel] [PATCH 1/2] update-rc.d: modify functions to accept local arguments

Kel Modderman kel at otaku42.de
Mon Aug 25 12:53:21 UTC 2008


Modify defaults and startstop functions to operate on local args rather than
global script args.

This allows the functions to be reused internally with specific arguments.
---
--- a/debian/sysv-rc/sbin/update-rc.d
+++ b/debian/sysv-rc/sbin/update-rc.d
@@ -63,8 +63,8 @@
 
 $_ = $ARGV[0];
 if    (/^remove$/)       { &checklinks ("remove"); }
-elsif (/^defaults$/)     { &defaults; &makelinks }
-elsif (/^(start|stop)$/) { &startstop; &makelinks; }
+elsif (/^defaults$/)     { &defaults (@ARGV); &makelinks; }
+elsif (/^(start|stop)$/) { &startstop (@ARGV); &makelinks; }
 else                     { &usage; }
 
 exit (0);
@@ -159,11 +159,12 @@
 # Process the arguments after the "defaults" keyword.
 
 sub defaults {
+    my @argv = @_;
     my ($start, $stop) = (20, 20);
 
-    &usage ("defaults takes only one or two codenumbers") if ($#ARGV > 2);
-    $start = $stop = $ARGV[1] if ($#ARGV >= 1);
-    $stop  =         $ARGV[2] if ($#ARGV >= 2);
+    &usage ("defaults takes only one or two codenumbers") if ($#argv > 2);
+    $start = $stop = $argv[1] if ($#argv >= 1);
+    $stop  =         $argv[2] if ($#argv >= 2);
     &usage ("codenumber must be a number between 0 and 99")
 	if ($start !~ /^\d\d?$/ || $stop  !~ /^\d\d?$/);
 
@@ -179,23 +180,23 @@
 # Process the arguments after the start or stop keyword.
 
 sub startstop {
-
+    my @argv = @_;
     my($letter, $NN, $level);
 
-    while ($#ARGV >= 0) {
-	if    ($ARGV[0] eq 'start') { $letter = 'S'; }
-	elsif ($ARGV[0] eq 'stop')  { $letter = 'K' }
+    while ($#argv >= 0) {
+	if    ($argv[0] eq 'start') { $letter = 'S'; }
+	elsif ($argv[0] eq 'stop')  { $letter = 'K'; }
 	else {
 	    &usage("expected start|stop");
 	}
 
-	if ($ARGV[1] !~ /^\d\d?$/) {
-	    &usage("expected NN after $ARGV[0]");
+	if ($argv[1] !~ /^\d\d?$/) {
+	    &usage("expected NN after $argv[0]");
 	}
-	$NN = sprintf("%02d", $ARGV[1]);
+	$NN = sprintf("%02d", $argv[1]);
 
-	shift @ARGV; shift @ARGV;
-	$level = shift @ARGV;
+	shift @argv; shift @argv;
+	$level = shift @argv;
 	do {
 	    if ($level !~ m/^[0-9S]$/) {
 		&usage(
@@ -209,7 +210,7 @@
 	    $level = 99 if ($level eq 'S');
 	    $startlinks[$level] = "$letter$NN" if ($letter eq 'S');
 	    $stoplinks[$level]  = "$letter$NN" if ($letter eq 'K');
-	} while (($level = shift @ARGV) ne '.');
+	} while (($level = shift @argv) ne '.');
 	&usage("action with list of runlevels not terminated by \`.'")
 	    if ($level ne '.');
     }
---



More information about the Pkg-sysvinit-devel mailing list