#!/bin/sh

# busybox' getty does this itself, util-linux' agetty needs extra help
getty="/sbin/getty"
case $(readlink -f "${getty}") in
    */busybox*)
        ;;
    *)
        if [ -x "/usr/bin/setsid" ] ; then
            setsid="/usr/bin/setsid"
        fi
        options=""
        ;;
esac

if [ -e /sys/class/tty/$2 -a -c /dev/$2 ]; then
	${setsid:-} ${getty} ${options:-} -L $1 $2 $3
else
    # Prevent respawning to fast error if /dev entry does not exist
    sleep 1000
fi
