#!/bin/sh

t=/dev/$1

# Reset the console tty to standard settings
/bin/stty -F $t sane pass8 -ixon -cstopb clocal

# Kill any processes with the console tty open before starting a new
# login session (login tries to do this, but vhangup() spares processes
# that ignore SIGHUP)
/usr/sbin/lsof -p ^$$ -t $t 0<&- 1>&- 2>&- | /usr/bin/xargs -r /bin/kill -9

# Flush tty input and output queues
/usr/sbin/flushtty <$t

# We use mingetty instead of agetty, as the latter messes up the tty
# settings if it receives junk characters at the wrong speed
exec /sbin/mingetty --noclear $t
