linux-hotplug.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* udev: Why non-blocking poll() with blocking recvmsg()?
@ 2013-08-19 11:39 Tetsuo Handa
  2013-08-19 12:15 ` Martin Pitt
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: Tetsuo Handa @ 2013-08-19 11:39 UTC (permalink / raw)
  To: linux-hotplug

Hello.

I'm experiencing a boot failure problem with wait-for-root utility in Ubuntu 12.04.
Although wait-for-root uses blocking socket, udev_monitor_receive_device() sometimes
immediately returns NULL.

I haven't identified which NULL in udev_monitor_receive_device() is returned.
But I came to wonder why poll() in udev_monitor_receive_device() uses timeout = 0.

---------- Quoting from http://git.kernel.org/cgit/linux/hotplug/udev.git/tree/src/libudev-monitor.c start ----------
UDEV_EXPORT struct udev_device *udev_monitor_receive_device(struct udev_monitor *udev_monitor)
{
(...snipped...)
retry:
(...snipped...)
        buflen = recvmsg(udev_monitor->sock, &smsg, 0);
        if (buflen < 0) {
                if (errno != EINTR)
                        info(udev_monitor->udev, "unable to receive message\n");
                return NULL;
        }
(...snipped...)
        /* skip device, if it does not pass the current filter */
        if (!passes_filter(udev_monitor, udev_device)) {
                struct pollfd pfd[1];
                int rc;

                udev_device_unref(udev_device);

                /* if something is queued, get next device */
                pfd[0].fd = udev_monitor->sock;
                pfd[0].events = POLLIN;
                rc = poll(pfd, 1, 0);
                if (rc > 0)
                        goto retry;
                return NULL;
        }
(...snipped...)
}
---------- Quoting from http://git.kernel.org/cgit/linux/hotplug/udev.git/tree/src/libudev-monitor.c end ----------

recvmsg() waits until something is queued if udev_monitor->sock is blocking,
but poll() does not wait until something is queued even if udev_monitor->sock
is blocking. I think that this inconsistency makes udev_monitor_receive_device()
to immediately return NULL when an event where passes_filter() returns 0 was
already queued but another event where passes_filter() returns 1 is not yet
queued, making wait-for-root utility which is waiting for only "block" subsystem
events fail.

Why don't we unconditionally go to retry rather than poll(pfd, 1, 0) so that
"blocking socket can wait for next event" and "non-blocking socket can return
immediately"?

Regards.

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2013-08-23 12:48 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-08-19 11:39 udev: Why non-blocking poll() with blocking recvmsg()? Tetsuo Handa
2013-08-19 12:15 ` Martin Pitt
2013-08-19 12:37 ` Tetsuo Handa
2013-08-19 12:45 ` Kay Sievers
2013-08-19 13:24 ` Tetsuo Handa
2013-08-23 12:48 ` Tetsuo Handa

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).