0

I have a DEC VT101 serial terminal hooked up to a Raspberry Pi 3 running Debian using a USB RS-232 null modem cable. When I turn the terminal off, I would like for the shell session to end, and when I turn the terminal back on, I'd like that to start a new login session. How can I do this? Right now, when the terminal is turned off then back on, the screen remains blank until I do something e.g. press Return which will make Bash draw a new prompt.

At the very least, if I could figure out how to query whether there was a system receiving the data from the USB null modem cable, I could script the automatic logging in/out myself. One approach I have in mind would be to send answerback queries to the terminal when there has been no recent user input then assume the terminal is off if I don't get a response after a certain amount of time.

2 Answers 2

0

The usual way of doing this was by detecting when the DTR ("data terminal ready") signal drops. This does require more than just ground, receive data and transmit data to be wired up.

The stty settings have to be adjusted to not ignore the DTR signal. Try running stty -clocal. If your connection is immediately dropped, then your cable does not have the appropriate pins connected. If you still have a shell connection after running the stty command, then try turning the terminal off and on. I would expect the session to be killed then. If not, then it's possible that your serial cable loops the DSR ("data set ready") signal coming out of the RS232 adapter back into its DTR input; you can test this by removing the cable from the adapter and see if that logs you out. If so, then you need to rewire the serial cable.

3
  • Running stty -clocal didn't kill the connection. Rewiring the cable isn't a practical solution for me right now, so I can't personally test this answer out. I'll request this question be converted to a community wiki if I don't get any other responses. Commented Feb 9, 2019 at 7:11
  • This post helped me refine my Googling, and I came across stackoverflow.com/questions/25232237/… which has additional details. I was able to find the type of cable I need searching for "full handshake." I'll follow-up once I receive cable and have time to test it out. Commented Feb 10, 2019 at 1:30
  • That didn't work, so I created a program using the approach outlined in the second paragraph of my post: unix.stackexchange.com/a/504838/204879 Commented Mar 7, 2019 at 2:39
0

Since I was unable to figure out how to get hangup detection using my existing hardware, I created a software-based solution called HUPMon written in C. In determines if a terminal is online by sending a Cursor Position Report (CPR) sequence to the terminal and awaiting a response. If no response is received, the terminal is presumed to be offline. The repository includes a script and systemd unit file that can be used in lieu of agetty(8) that does something similar to this script:

stty 19200 sane -brkint ixoff -imaxbel

while :; do
    if [ "$(hupmon -1)" = "DEVICE_ONLINE" ]; then
        stty 19200 sane -brkint ixoff -imaxbel
        printf "\033[r\033[H\033[J" # Clear the screen.
        TERM="vt100" hupmon /bin/login
    fi

    sleep 1
done

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .