ginseng has asked for the wisdom of the Perl Monks concerning the following question:

Along the same line as my just-posted request, Console programming framework, I'd like to hook a ANSI-compliant serial terminal (with limited keys) up to the serial port, and have a perl script running in place of getty.

Let me restate that. I'd like the terminal plugged into a serial port on my UNIX-like (OpenBSD) box to avoid the login procedure (which is difficult with the limited key set) and go directly to a perl script program, running as a given (fixed) user.

I'm hoping someone here may have some experience doing this sort of thing. What functions that getty provides will I need to replace? Can I merely mention the program in /etc/ttys and expect it to work? (My test program caused some difficulty with massive respawning, but that was probably due to the lack of effort put into the test that night...)

I realize this is a little out-of-the-ordinary, but I'm hoping some of the awesome people around here will have some advice to offer...

Replies are listed 'Best First'.
Re: Replacing getty with a perl script?
by Anonymous Monk on Jun 28, 2001 at 11:22 UTC
    My linux distro comes with a program called agetty. It allows you to bypass login and specify which program to run (as a replacement for /bin/login). So /sbin/agetty -l /path/to/program -n 9600 ttyname causes /path/to/program to run on ttyname (it runs as root since no login was prompted for). I don't know if agetty is available for OpenBSD, but if not there may be something with similar functionality.

      My first response is Ahah! Exactly what I want...alas, agetty does not currently run on OpenBSD. It seems to use termio.h, rather than the POSIX termios.h. OpenBSD only has support for the latter.

      I understand that it's not too bad to redefine constants based on the changes between the two files, but that may be a bit much for what i'm expected to do here. I really don't want to go through a 1232 line program and port it to a different operating system.

      So naturally, my second response was "Bummer."

      But you did clue me in on something - I need to find an alternative getty program suppported under OpenBSD, that allows the configuration to dictate whether or not a username is required. I've checked the OpenBSD ports tree, and find only mgetty as an alternative. In order to get the man page with little effort, I did start to install mgetty, and this is what I got:

      bash-2.04# cd /usr/ports/comms/mgetty+sendfax/
      bash-2.04# make install
      ===>  mgetty-1.1.21 is marked as broken: insecure tempfile handling: can overwrite any file on the system.
      

      Probably not what I'm after :(

      So I guess I'll check out FreeBSD and see what alternative getty's are available there...I can probably install some of them without major difficulty.

      All the same, thank you for the assistance!

Re: Replacing getty with a perl script?
by Zaxo (Archbishop) on Jun 28, 2001 at 10:05 UTC

    Non-Perl answer: I do a similar thing for a hardwired Linux serial console. I associate minicom to /dev/ttyS0 in my /etc/inittab file. I don't know OpenBSD boot well enough to advise on details, but it should be fairly easy to set up. The main problem I had was getting termcaps to agree.

    After Compline,
    Zaxo

      I'm not sure what /etc/inittab has in it, but it's probably the same as /etc/ttys on my OpenBSD boxes.

      Here's the kluge I've been able to make work so far. In essence, I wrote a shell script, run as root (as that portion of the login must), and listed it in my gettytab as the program to run after getting a login name for a particular terminal type. Then I played with the /etc/shells file and the user's password file entry to get the perl program run as that user's shell.

      In more detail, my gettytab file uses the 'lo' prefix to identify the program to be run after receiving a username:

      from /etc/gettytab
      yrdterm:\
              :np:sp#9600:lo=/root/login:lm=Login? :
      

      That program (/root/login) does a forced login for a given user. (login -f user can only be run as root.)

      from /root/login
      #!/bin/sh
      /usr/bin/login -f yrd
      

      When the terminal gets set up (under init), it refers to /etc/ttys. This is probably the same as (or similar to) Linux's inittab.

      from /etc/ttys
      ttyC5   "/usr/libexec/getty yrdterm"        vt220   on
      

      (BTW, that's on console 5, not on the serial port, for simplicity in testing. I want to deal configuration of the server and configuration of the serial link separately ;)

      When /root/login drops the terminal to the user yrd's login, I want it to run the perl script as the shell. So i set the user's shell to the perl script, and added it to /etc/shells.

      from /etc/passwd
      yrd:*:1001:1001:yrd:/home/yrd:/home/yrd/weld
      

      Ultimately, I think this is an inelegant, convoluted, almost unacceptable solution :) I really should be able to run one program from /etc/ttys that changes UID to the appropriate user and runs the program. I just don't know how yet ;)