5

In my /etc/inittab I am using the following line:

ttyS0::respawn:/bin/login

This gives me a login prompt if I want to connect to the serial port. But it keeps echoing this:

[hostname] login: 
Login timed out [hostname] login: 
Login timed out [hostname] login: 

How can I stop that and get it to not timeout?

So to clarify what came up in the comments:

  • The login timeout is the regular expected behaviour
  • I want to change that behaviour on my machine, so that login does not timeout anymore
  • In other Linux distributions you can edit LOGIN_TIMEOUT in /etc/login.defs as explained in this answer: change tty login timeout - ArchLinux
  • This does not work in Busybox
  • That's impossible to guess without details on why it's timing out which we don't have access to. The machine is most likely overloaded. Are you aware of something that could be running and causing it to become excessively slow? You should restart it, login and monitor what causes it. – Julie Pelletier Jan 26 '17 at 15:46
  • The machine is not at all overloaded, it is idle. But after 60 seconds login times out. This behaviour is consistent over different versions of busybox on different architectures and even on Ubuntu. This is just what login does by default. To reproduce this, just enter login on any Linux machine that supports this command and wait for 60 seconds. This answer unix.stackexchange.com/questions/144303/… explains how to change the timeout under Arch Linux, but it does not work under Busybox. – Dakkaron Jan 26 '17 at 15:51
  • 1
    I don't want it to timeout, as stated in the question. It is the correct default behaviour, but I want to change it so that it does not timeout. – Dakkaron Jan 26 '17 at 15:54
  • 1
    Does not work on Busybox. I tried that (see three comments above your comment). – Dakkaron Jan 26 '17 at 16:40
  • 2
    The votes to close this as "too broad" are wrong. This is a very specific, and (to those of us who have used terminals, especially over dial-up links) well known feature of terminal login. And all that the questioner is asking is how to turn it off. – JdeBP Jan 26 '17 at 18:39
3

Apparently impossible without changing the source code.

Searching for login.defs or LOGIN_TIMEOUT yields indeed no relevant results and looking at loginutils/login.c it really seems like the value and the whole timer are hardcoded:

enum {
    TIMEOUT = 60,
    EMPTY_USERNAME_COUNT = 10,
    /* Some users found 32 chars limit to be too low: */
    USERNAME_SIZE = 64,
    TTYNAME_SIZE = 32,
};

[…]

static void alarm_handler(int sig UNUSED_PARAM)
{
    /* This is the escape hatch! Poor serial line users and the like
     * arrive here when their connection is broken.
     * We don't want to block here */
    ndelay_on(STDOUT_FILENO);
    /* Test for correct attr restoring:
     * run "getty 0 -" from a shell, enter bogus username, stop at
     * password prompt, let it time out. Without the tcsetattr below,
     * when you are back at shell prompt, echo will be still off.
     */
    tcsetattr_stdin_TCSANOW(&G.tty_attrs);
    printf("\r\nLogin timed out after %u seconds\r\n", TIMEOUT);
    fflush_all();
    /* unix API is brain damaged regarding O_NONBLOCK,
     * we should undo it, or else we can affect other processes */
    ndelay_off(STDOUT_FILENO);
    _exit(EXIT_SUCCESS);
}

[…]

int login_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
int login_main(int argc UNUSED_PARAM, char **argv)
{

[…]

    /* We install timeout handler only _after_ we saved G.tty_attrs */
    signal(SIGALRM, alarm_handler);
    alarm(TIMEOUT);

Note how there the last part isn't indented, there seems to be no if around it, so it always runs. How you could probably do is to uncomment the last two lines and compile busybox anew if that is possible.

Alternative idea

From busybox' example inittab:

# <action>: Valid actions include: sysinit, respawn, askfirst, wait, once,
#                                  restart, ctrlaltdel, and shutdown.
#
#       Note: askfirst acts just like respawn, but before running the specified
#       process it displays the line "Please press Enter to activate this
#       console." and then waits for the user to press enter before starting
#       the specified process.

So you could simply change respawn to askfirst. This way /bin/login after the timeout expires would simply goes back to the Please press Enter… prompt instead of starting /bin/login right away again.

4

As you have spotted, the login program can be, and usually is, configured to time out if no input is received for a certain number of seconds. There are various motivations for this behaviour, ranging from wanting to keep unused dial-up lines clear to the world wanting you to clean your screen. There are, equally, reasons for not wanting it, as you have here. Hanging up to clear the line is fairly meaningless if there's no modem, for one thing.

Unfortunately, login programs vary in this regard. The login from (say) Debian's login package respects a /etc/login.defs configuration file. I have LOGIN_TIMEOUT set to 0 in mine. But other login programs have this unconfigurable and hardwired. There is more than just the one login program in the world. ☺

The login program in FreeBSD is — alas! — one such. So too, is the login program that is built in to Busybox. The former has a hardwired timeout of 300 seconds; the latter, a mere 60 seconds.

The Busybox code is a compile-time constant. You'll have to actually modify the source to the program and re-build it in order to disable this behaviour. Per commentary in the code of the FreeBSD login program that explains why it is a run-time variable not a compile-time constant, the FreeBSD authors expect you to vary this by patching the /usr/bin/login binary itself.

There are a few mitigating strategies. One is — alas! — to keep getty in the loop. FreeBSD's login is invoked by FreeBSD's getty, which has a to capability in /etc/gettydefs that is normally set to zero. Busybox's getty similarly has a -t option. Both mean that an idle, not logged in, serial terminal sits forever at the login: prompt displayed by getty, and the timeout in login is not begun.

I don't use getty on virtual terminals, myself. So for FreeBSD I have a very simple login-prompt program that simply waits for the user to press return. And on Linux I turn off the timeout with login.defs as mentioned.

For real terminals on serial lines, however, I still use getty.

Further reading

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.