diff options
Diffstat (limited to 'scripts/system/vyatta_update_console.pl')
-rwxr-xr-x | scripts/system/vyatta_update_console.pl | 90 |
1 files changed, 50 insertions, 40 deletions
diff --git a/scripts/system/vyatta_update_console.pl b/scripts/system/vyatta_update_console.pl index 0ee6a6e5..7c36ec7f 100755 --- a/scripts/system/vyatta_update_console.pl +++ b/scripts/system/vyatta_update_console.pl @@ -34,13 +34,13 @@ die "$0 expects no arguments\n" if (@ARGV); sub update { my ($old, $new) = @_; - if ( compare($old, $new) != 0) { - move($new, $old) - or die "Can't move $new to $old"; - return 1; + if (compare($old, $new) != 0) { + move($new, $old) + or die "Can't move $new to $old"; + return 1; } else { - unlink($new); - return; + unlink($new); + return; } } @@ -48,14 +48,15 @@ my $INITTAB = "/etc/inittab"; my $TMPTAB = "/tmp/inittab.$$"; sub update_inittab { - open (my $inittab, '<', $INITTAB) - or die "Can't open $INITTAB: $!"; + open(my $inittab, '<', $INITTAB) + or die "Can't open $INITTAB: $!"; - open (my $tmp, '>', $TMPTAB) - or die "Can't open $TMPTAB: $!"; + open(my $tmp, '>', $TMPTAB) + or die "Can't open $TMPTAB: $!"; # Clone original inittab but remove all references to serial lines - print {$tmp} grep { ! /^T|^# Vyatta/ } <$inittab>; + # and Xen consoles + print {$tmp} grep {!/^T|^# Vyatta|^h/} <$inittab>; close $inittab; my $config = new Vyatta::Config; @@ -63,29 +64,38 @@ sub update_inittab { print {$tmp} "# Vyatta console configuration (do not modify)\n"; - my $id = 0; + my $serial_id = 0; + my $xen_id = 0; + foreach my $tty ($config->listNodes()) { - my $speed = $config->returnValue("$tty speed"); - $speed = 9600 unless $speed; - - printf {$tmp} "T%d:23:respawn:", $id; - if ($config->exists("$tty modem")) { - printf {$tmp} "/sbin/mgetty -x0 -s %d %s\n", $speed, $tty; - } else { - printf {$tmp} "/sbin/getty -L %s %d vt100\n", $tty, $speed; - } - - # id field is limited to 4 characters - if (++$id >= 1000) { - warn "Ignoring $tty only 1000 serial devices supported\n"; - last; - } + my $speed = $config->returnValue("$tty speed"); + if ($tty =~ /^hvc\d/) { + $speed = 38400 unless $speed; + printf {$tmp} "h%d:23:respawn:", $xen_id; + printf {$tmp} "/sbin/getty %d %s\n", $speed, $tty; + $xen_id++; + } else { + $speed = 9600 unless $speed; + printf {$tmp} "T%d:23:respawn:", $serial_id; + if ($config->exists("$tty modem")) { + printf {$tmp} "/sbin/mgetty -x0 -s %d %s\n", $speed, $tty; + } else { + printf {$tmp} "/sbin/getty -L %s %d vt100\n", $tty, $speed; + } + + # id field is limited to 4 characters + if (++$serial_id >= 1000) { + warn "Ignoring $tty only 1000 serial devices supported\n"; + last; + } + } } close $tmp; if (update($INITTAB, $TMPTAB)) { - # This is same as telinit q - it tells init to re-examine inittab - kill 1, 1; + + # This is same as telinit q - it tells init to re-examine inittab + kill 1, 1; } } @@ -104,20 +114,20 @@ sub update_grub { my $speed = $config->returnValue("ttyS0 speed"); $speed = "9600" unless defined($speed); - open (my $grub, '<', $GRUBCFG) - or die "Can't open $GRUBCFG: $!"; + open(my $grub, '<', $GRUBCFG) + or die "Can't open $GRUBCFG: $!"; - open (my $tmp, '>', $GRUBTMP) - or die "Can't open $GRUBTMP: $!"; + open(my $tmp, '>', $GRUBTMP) + or die "Can't open $GRUBTMP: $!"; while (<$grub>) { - if (/^serial / ) { - print {$tmp} "serial --unit=0 --speed=$speed\n"; - } elsif (/^(.* console=ttyS0),[0-9]+(.*)$/) { - print {$tmp} "$1,$speed$2\n"; - } else { - print {$tmp} $_; - } + if (/^serial /) { + print {$tmp} "serial --unit=0 --speed=$speed\n"; + } elsif (/^(.* console=ttyS0),[0-9]+(.*)$/) { + print {$tmp} "$1,$speed$2\n"; + } else { + print {$tmp} $_; + } } close $grub; close $tmp; |