delay in spawning new getty after logging out on console

Bug #7228 reported by Matt Zimmerman
14
Affects Status Importance Assigned to Milestone
util-linux (Ubuntu)
Fix Released
High
LaMont Jones

Bug Description

Here's what is logged to syslog during this time:

Jul 30 00:25:36 localhost hal.hotplug[23486]: waiting for vc info at /class/vc/vcs2
Jul 30 00:25:36 localhost hal.hotplug[23486]: Dont know how to wait for vc at
/class/vc/vcs2; sleeping 1000 ms
Jul 30 00:25:36 localhost hal.hotplug[23492]: waiting for vc info at /class/vc/vcsa2
Jul 30 00:25:36 localhost hal.hotplug[23492]: Dont know how to wait for vc at
/class/vc/vcsa2; sleeping 1000 ms
Jul 30 00:25:39 localhost udev[23495]: removing device node '/dev/vcs2'
Jul 30 00:25:39 localhost udev[23497]: removing device node '/dev/vcsa2'
Jul 30 00:25:40 localhost udev[23503]: creating device node '/dev/vcs2'
Jul 30 00:25:40 localhost udev[23504]: creating device node '/dev/vcsa2'
Jul 30 00:25:46 localhost hal.hotplug[23527]: waiting for vc info at /class/vc/vcs2
Jul 30 00:25:46 localhost hal.hotplug[23527]: Dont know how to wait for vc at
/class/vc/vcs2; sleeping 1000 ms
Jul 30 00:25:46 localhost hal.hotplug[23533]: waiting for vc info at /class/vc/vcsa2
Jul 30 00:25:46 localhost hal.hotplug[23533]: Dont know how to wait for vc at
/class/vc/vcsa2; sleeping 1000 ms
Jul 30 00:25:49 localhost udev[23537]: removing device node '/dev/vcsa2'
Jul 30 00:25:49 localhost udev[23536]: removing device node '/dev/vcs2'
Jul 30 00:25:50 localhost udev[23544]: creating device node '/dev/vcsa2'
Jul 30 00:25:50 localhost udev[23545]: creating device node '/dev/vcs2'

Revision history for this message
Jeff Waugh (jdub) wrote :

See the thread, but this is the mail you want, with PATCH LOVING!

http://freedesktop.org/pipermail/hal/2004-July/000623.html

Revision history for this message
Matt Zimmerman (mdz) wrote :

It turns out that the cause is actually this:

Aug 13 18:00:31 localhost getty[23272]: /dev/tty2: already in use

Which causes getty to sleep for a full 10 seconds. Reassigning to lamont as
util-linux maintainer

Revision history for this message
Matt Zimmerman (mdz) wrote :

This is actually starting to look like a race condition in udev. Here's my
hypothesis for the sequence of events:

- getty starts up
- kernel vc device is created
- hotplug add event is emitted, which invokes udev
- udev sleeps because the sysfs devices haven't been created yet
- sysfs devices are created
- getty errors out, closing the console device
- kernel vc device is destroyed
- sysfs devices disappear
- udev wakes up, and continues to wait for the sysfs entries

Revision history for this message
LaMont Jones (lamont) wrote :

*** Bug 8230 has been marked as a duplicate of this bug. ***

Revision history for this message
LaMont Jones (lamont) wrote :

This from debian bug #226443 has the following. This looks like a low-risk fix
to a rather annoying issue, and is in debian 2.12-8. (2.12-7ubuntu2 differs
from 2.12-7 only in the init script prettification. Hence we'll need to patch
whichever way we go, and simply uploading 2.12-7ubuntu3 seems simplest for the
preview freeze period.)

thoughts?
lamont

Resent-From: Samuel Thibault <email address hidden>

Today, I took my printk() and debuggued that thing right from the
kernel. The problem relies in userspace, as expected: some programs
hold an fd on /dev/tty3. Actually, there are two of them (and actually
only one: getty itself !):

- init will open /dev/tty0 and dup() it as standard output and standard
  error for getty. *If* the current vt is 3, /dev/tty0 will actually get
  to /dev/tty3 (that can be seen in the kernel in tty->name), so that
  getty actually already gets an fd on the tty he wants to open. *But*
  close(0) is done *after* VT_OPENQRY is done ! Hence someone (getty,
  actually) indeed already holds the tty and VT_OPENQRY doesn't give it.
- getty itself opens /dev/tty0 ! Just to be able to call VT_OPENQRY,
  actually. If the current vt is 3, it gets /dev/tty3, and of course,
  VT_OPENQRY doesn't give it !

So the patch I'm submitting just moves the close(0) *before* calling
VT_OPENQRY, and opens /dev/tty1 instead of /dev/tty0 to avoid using
/dev/tty3. This doesn't hurt since no check is done for /dev/tty1.
I now have no "getty fails to initialize /dev/tty[2-6]" anymore...

Please apply and ask for a urgent sarge build asap.

Regards,
Samuel Thibault

--- login-utils/agetty.c.buggy 2004-09-20 15:48:01.000000000 +0200
+++ login-utils/agetty.c 2004-09-20 15:48:38.000000000 +0200
@@ -634,6 +634,9 @@
        if ((st.st_mode & S_IFMT) != S_IFCHR)
            error(_("/dev/%s: not a character device"), tty);

+ (void) close(0);
+ errno = 0; /* ignore close(2) errors */
+
        /*
         * Try to avoid opening a vt that is already open, as this will
         * mean that the keyboard will be unusable.
@@ -663,7 +666,7 @@
                for ( i = 0 ; i < MAX_NR_CONSOLES ; i++ )
                    fds[i] = -1;

- if ((fd = open("/dev/tty0", O_WRONLY, 0) ) < 0
+ if ((fd = open("/dev/tty1", O_WRONLY, 0) ) < 0
                    && errno != ENOENT)
                    error(_("/dev/tty0: cannot open: %m"));

@@ -704,9 +707,6 @@

        /* Open the tty as standard input. */

- (void) close(0);
- errno = 0; /* ignore close(2) errors */
-
        debug(_("open(2)\n"));
        if (open(tty, O_RDWR|O_NONBLOCK, 0) != 0)
            error(_("/dev/%s: cannot open as standard input: %m"), tty);

Revision history for this message
Jeff Waugh (jdub) wrote :

upload approved

Revision history for this message
LaMont Jones (lamont) wrote :

Fixed in 2.12-7ubuntu5

To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Duplicates of this bug

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.