diff options
author | Stephen Hemminger <stephen.hemminger@vyatta.com> | 2010-12-02 14:08:52 -0800 |
---|---|---|
committer | Stephen Hemminger <stephen.hemminger@vyatta.com> | 2010-12-02 15:02:46 -0800 |
commit | 4c5e7207dd7a12990e9b10e0bb8ca9e61e312e79 (patch) | |
tree | f322a661699b7555cb5c9d75d04f29b453c0bd96 | |
parent | 2ecdc54c99554b128941ae831535c2fe133d920d (diff) | |
download | vyatta-cfg-system-4c5e7207dd7a12990e9b10e0bb8ca9e61e312e79.tar.gz vyatta-cfg-system-4c5e7207dd7a12990e9b10e0bb8ca9e61e312e79.zip |
Allow configuring console speed etc
Bug 3849, 2289, 4126
Adds configuration of serial console:
set system console {
device ttyS0 {
speed 19200
}
device ttyACM0 {
speed 57600
type modem
}
}
This covers the cases of deleting serial console, changing speed,
and allowing modem console devices
-rwxr-xr-x | scripts/rl-system.init | 11 | ||||
-rwxr-xr-x | scripts/system/vyatta_update_console.pl | 92 | ||||
-rw-r--r-- | templates/system/console/device/node.tag/modem/node.def | 2 | ||||
-rw-r--r-- | templates/system/console/device/type/node.def | 5 | ||||
-rw-r--r-- | templates/system/console/node.def | 3 |
5 files changed, 54 insertions, 59 deletions
diff --git a/scripts/rl-system.init b/scripts/rl-system.init index 5c8ba7a6..fddea32a 100755 --- a/scripts/rl-system.init +++ b/scripts/rl-system.init @@ -10,10 +10,9 @@ # General Public License for more details. # # This code was originally developed by Vyatta, Inc. -# Portions created by Vyatta are Copyright (C) 2007 Vyatta, Inc. +# Copyright (C) 2007-2010 Vyatta, Inc. # All Rights Reserved. # -# Author: Tom Grennan <tgrennan@vyatta.com> # Description: Vyatta Router system setup # Indirect init sub-script of vyatta-router.init # @@ -222,9 +221,6 @@ start () { # Remove links from the commit hook directory rm -f /etc/commit/* - # Remove serial console settings -# sed -i -e '/^T/d' /etc/inittab - ## Clear out apt config file--it will be filled in by config load empty /etc/apt/sources.list } @@ -237,8 +233,3 @@ case "$ACTION" in esac exit $? - -# Local Variables: -# mode: shell-script -# sh-indentation: 4 -# End: diff --git a/scripts/system/vyatta_update_console.pl b/scripts/system/vyatta_update_console.pl index 8fbb82a4..5045a0dd 100755 --- a/scripts/system/vyatta_update_console.pl +++ b/scripts/system/vyatta_update_console.pl @@ -20,6 +20,8 @@ # based on Vyatta configuration use strict; +use warnings; + use lib "/opt/vyatta/share/perl5"; use Vyatta::Config; use File::Compare; @@ -27,24 +29,30 @@ use File::Copy; die "$0 expects no arguments\n" if (@ARGV); +# if file is unchanged, do nothing and return false +# otherwise update to new version sub update { - my ($inpath, $outpath) = @_; - - if ( compare($inpath, $outpath) != 0) { - copy($outpath, $inpath) - or die "Can't copy $outpath to $inpath"; + my ($old, $new) = @_; + + if ( compare($old, $new) != 0) { + move($new, $old) + or die "Can't move $new to $old"; + return 1; + } else { + unlink($new); + return; } - unlink($inpath); } -sub update_inittab { - my ($inpath, $outpath) = @_; +my $INITTAB = "/etc/inittab"; +my $TMPTAB = "/tmp/inittab.$$"; - open (my $inittab, '<', $inpath) - or return; +sub update_inittab { + open (my $inittab, '<', $INITTAB) + or die "Can't open $INITTAB: $!"; - open (my $tmp, '>', $outpath) - or die "Can't open $outpath: $!"; + open (my $tmp, '>', $TMPTAB) + or die "Can't open $TMPTAB: $!"; # Clone original inittab but remove all references to serial lines print {$tmp} grep { ! /^T/ } <$inittab>; @@ -57,28 +65,35 @@ sub update_inittab { foreach my $tty ($config->listNodes()) { my $speed = $config->returnValue("$tty speed"); $speed = 9600 unless $speed; - my $type = $config->returnValue("$tty type"); - - print {$tmp} "T$id:23:respawn:"; - # Three cases modem, direct, and normal - if ($type eq "modem") { - print {$tmp} "/sbin/mgetty -x0 -s"; + print {$tmp} "T$id:23:respawn:"; + if ($config->exists("$tty modem")) { + printf {$tmp} "/sbin/mgetty -x0 -s %d %s\n", $speed, $tty; } else { - print {$tmp} "/sbin/getty"; - print {$tmp} " -L" if ($type eq "direct"); + printf {$tmp} "/sbin/getty -L %s %d vt100\n", $tty, $speed; + } + + # Limit to 0-9 because of limitation of last char in id field + if (++$id >= 10) { + warn "Ignoring $tty only 10 serial devices supported\n"; + last; } - print {$tmp} "$speed $tty\n"; - ++$id; } close $tmp; - update($inpath, $outpath); + if (update($INITTAB, $TMPTAB)) { + # This is same as telinit q - it tells init to re-examine inittab + kill 1, 1; + } } +my $GRUBCFG = "/boot/grub/grub.cfg"; +my $GRUBTMP = "/tmp/grub.cfg.$$"; + # For existing serial line change speed (if necessary) +# Only applys to ttyS0 sub update_grub { - my ($inpath, $outpath) = @_; + return unless (-f $GRUBCFG); my $config = new Vyatta::Config; $config->setLevel("system console device"); @@ -87,35 +102,28 @@ sub update_grub { my $speed = $config->returnValue("ttyS0 speed"); $speed = "9600" unless defined($speed); - open (my $grub, '<', $inpath) - or die "Can't open $inpath: $!"; - open (my $tmp, '>', $outpath) - or die "Can't open $outpath: $!"; + open (my $grub, '<', $GRUBCFG) + or die "Can't open $GRUBCFG: $!"; + + open (my $tmp, '>', $GRUBTMP) + or die "Can't open $GRUBTMP: $!"; - select $tmp; while (<$grub>) { if (/^serial / ) { - print "serial --unit=0 --speed=$speed\n"; + print {$tmp} "serial --unit=0 --speed=$speed\n"; } elsif (/^(.* console=ttyS0),[0-9]+ (.*)$/) { - print "$1,$speed $2\n"; + print {$tmp} "$1,$speed $2\n"; } else { - print $_; + print {$tmp} $_; } } close $grub; close $tmp; - select STDOUT; - update($inpath, $outpath); + update($GRUBCFG, $GRUBTMP); } -my $INITTAB = "/etc/inittab"; -my $TMPTAB = "/tmp/inittab.$$"; -my $GRUBCFG = "/boot/grub/grub.cfg"; -my $GRUBTMP = "/tmp/grub.cfg.$$"; - -update_inittab($INITTAB, $TMPTAB); - -update_grub($GRUBCFG, $GRUBTMP); +update_inittab; +update_grub; exit 0; diff --git a/templates/system/console/device/node.tag/modem/node.def b/templates/system/console/device/node.tag/modem/node.def new file mode 100644 index 00000000..30e24cf7 --- /dev/null +++ b/templates/system/console/device/node.tag/modem/node.def @@ -0,0 +1,2 @@ +help: Device is Hayes compatiable modem + diff --git a/templates/system/console/device/type/node.def b/templates/system/console/device/type/node.def deleted file mode 100644 index 9bce3b38..00000000 --- a/templates/system/console/device/type/node.def +++ /dev/null @@ -1,5 +0,0 @@ -type: txt -allowed: echo modem direct -help: Configure serial line paremeters -val_help: direct ; Ignore carrier detect (local line) -val_help: modem ; Use HAYES modem answering sequence diff --git a/templates/system/console/node.def b/templates/system/console/node.def index 92d2f79b..d42f8cf6 100644 --- a/templates/system/console/node.def +++ b/templates/system/console/node.def @@ -1,4 +1,3 @@ priority: 100 help: Serial console configuration -# don't do configuration yet -- still broken -#end: sudo /opt/vyatta/sbin/vyatta_update_console.pl +end: sudo /opt/vyatta/sbin/vyatta_update_console.pl |