Improve logic for detecting runlevel
authorJamie Cameron <jcameron@webmin.com>
Thu, 10 Mar 2011 20:03:30 +0000 (12:03 -0800)
committerJamie Cameron <jcameron@webmin.com>
Thu, 10 Mar 2011 20:03:30 +0000 (12:03 -0800)
init/init-lib.pl

index 675d614..a4642d9 100755 (executable)
@@ -358,24 +358,27 @@ if (open(TAB, $iconfig{'inittab_file'})) {
                }
        close(TAB);
        }
-elsif (&has_command("runlevel")) {
+
+if (&has_command("runlevel")) {
        # Use runlevel command to get current level
        local $out = &backquote_command("runlevel");
        if ($out =~ /^(\S+)\s+(\S+)/) {
                push(@rv, $2);
                }
        }
+elsif (&has_command("who")) {
+       # Use who -r command to get runlevel
+       local $out = &backquote_command("who -r 2>/dev/null");
+       if (!$? && $out =~ /run-level\s+(\d+)/) {
+               push(@rv, $1);
+               }
+       }
+
+# Add statically configured runlevels
 if ($config{"inittab_rl_$rv[0]"}) {
        @rv = split(/,/, $config{"inittab_rl_$rv[0]"});
        }
 push(@rv, $config{'inittab_extra'});
-
-# Add current runlevel. This is needed on EC2, as the boot runlevel can be
-# 4 even if inittab says 3!
-local $out = &backquote_command("who -r 2>/dev/null");
-if (!$? && $out =~ /run-level\s+(\d+)/) {
-       push(@rv, $1);
-       }
 return &unique(@rv);
 }