| 1 |
#!/bin/sh |
| 2 |
|
| 3 |
# In order to give proper access to the tty, we need to locate the device |
| 4 |
# corresponding to the console we are actually using. |
| 5 |
|
| 6 |
console= |
| 7 |
if ! [ -f /var/run/console-device ]; then |
| 8 |
# Get the configure consoles using sysctl |
| 9 |
# 's#^.*: ##' : remove the prompt |
| 10 |
# 's#/.*$##' : remove unconfigured devices |
| 11 |
# 's#dcons,##g' : remove dcons |
| 12 |
# 's#,# #g' : separate consoles with spaces instead of commas |
| 13 |
consoles=$(sysctl "kern.console" | sed -e 's#^.*: ##' \ |
| 14 |
-e 's#/.*$##' \ |
| 15 |
-e 's#dcons,##g' \ |
| 16 |
-e 's#,# #g') |
| 17 |
|
| 18 |
for c in $consoles ; do |
| 19 |
case $c in |
| 20 |
# Serial devices |
| 21 |
ttyu*|cuau*) |
| 22 |
console="$c" |
| 23 |
break |
| 24 |
;; |
| 25 |
# Virtual consoles |
| 26 |
ttyv*) |
| 27 |
console=$c |
| 28 |
break |
| 29 |
;; |
| 30 |
consolectl*) |
| 31 |
console="ttyv0" |
| 32 |
break |
| 33 |
;; |
| 34 |
# Unknown consoles, ignore them |
| 35 |
*) |
| 36 |
;; |
| 37 |
esac |
| 38 |
done |
| 39 |
|
| 40 |
if [ -z "$console" ]; then |
| 41 |
# Still nothing? Default to /dev/console. |
| 42 |
console="console" |
| 43 |
fi |
| 44 |
echo /dev/$console > /var/run/console-device |
| 45 |
fi |
| 46 |
|
| 47 |
# Some other session may have it as ctty. Steal it from them |
| 48 |
exec /sbin/steal-ctty $(cat /var/run/console-device) "$@" |