diff options
author | Renato Botelho <renato@netgate.com> | 2016-10-14 07:27:00 -0300 |
---|---|---|
committer | Renato Botelho <renato@netgate.com> | 2016-10-14 09:05:44 -0300 |
commit | 72ca7e40d314a39a227404a15d14c91aa740a2c7 (patch) | |
tree | fd56db3c320fe78a66bb04cf279bd59e7318839f | |
parent | 9a3261c1c40c3ebf51d95b9a2497b0a1b1cf62fc (diff) | |
download | pfsense-72ca7e40d314a39a227404a15d14c91aa740a2c7.zip pfsense-72ca7e40d314a39a227404a15d14c91aa740a2c7.tar.gz |
Prevent /etc/ttys to miss essential lines
We do not create /etc/ttys from scratch but we change it on every boot.
If original file is corrupted for some reason we can end up with a file
missing essential lines. Added a check to verify if these lines are
missing and add them back in this case
-rw-r--r-- | src/etc/inc/pfsense-utils.inc | 43 |
1 files changed, 40 insertions, 3 deletions
diff --git a/src/etc/inc/pfsense-utils.inc b/src/etc/inc/pfsense-utils.inc index fbdd290..d4e7bbf 100644 --- a/src/etc/inc/pfsense-utils.inc +++ b/src/etc/inc/pfsense-utils.inc @@ -1215,17 +1215,54 @@ function setup_serial_port($when = "save", $path = "") { $console_type = 'al.Pc'; $serial_type = 'al.' . $serialspeed; } + + $console_line = "console none unknown off secure\n"; + $ttyv0_line = "ttyv0 \"/usr/libexec/getty {$console_type}\" cons25 on secure\n"; + $ttyu_line = "\"/usr/libexec/getty {$serial_type}\" cons25 {$on_off} secure\n"; + + $found = array(); + foreach ($ttys_split as $tty) { if (stristr($tty, "ttyv0")) { - fwrite($fd, "ttyv0 \"/usr/libexec/getty {$console_type}\" cons25 on secure\n"); - } else if (stristr($tty, "ttyu")) { + $found['ttyv0'] = 1; + fwrite($fd, $ttyv0_line); + } elseif (stristr($tty, "ttyu")) { $ttyn = substr($tty, 0, 5); - fwrite($fd, "{$ttyn} \"/usr/libexec/getty {$serial_type}\" cons25 {$on_off} secure\n"); + $found[$ttyn] = 1; + fwrite($fd, "{$ttyn} {$ttyu_line}"); + } elseif (substr($tty, 0, 7) == 'console') { + $found['console'] = 1; + fwrite($fd, $tty . "\n"); } else { fwrite($fd, $tty . "\n"); } } unset($on_off, $console_type, $serial_type); + + /* Detect missing main lines on original file and try to rebuild it */ + $items = array( + 'console', + 'ttyv0', + 'ttyu0', + 'ttyu1', + 'ttyu2', + 'ttyu3' + ); + + foreach ($items as $item) { + if (isset($found[$item])) { + continue; + } + + if ($item == 'console') { + fwrite($fd, $console_line); + } elseif ($item == 'ttyv0') { + fwrite($fd, $ttyv0_line); + } else { + fwrite($fd, "{$item} {$ttyu_line}"); + } + } + fclose($fd); if ($when != "upgrade") { reload_ttys(); |