[Pkg-sysvinit-devel] [PATCH 2/4] update-rc.d: modify internal functions to accept local arguments
Kel Modderman
kel at otaku42.de
Thu Sep 18 08:50:41 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
@@ -75,8 +75,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);
@@ -171,11 +171,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?$/);
@@ -191,23 +192,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(
@@ -221,7 +222,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