[Pkg-sysvinit-devel] [PATCH 3/4] update-rc.d: Modify functions to operate on local args rather than global script args
Kel Modderman
kel at otaku42.de
Sun Jul 13 14:48:39 UTC 2008
This allows functions to be reused by another function with specific arguments.
---
--- a/debian/sysv-rc/sbin/update-rc.d
+++ b/debian/sysv-rc/sbin/update-rc.d
@@ -76,8 +76,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);
@@ -172,11 +172,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?$/);
@@ -192,23 +193,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(
@@ -222,7 +223,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