2011/8/2 Tanaka Akira <akr / fsij.org>:
> 2011/8/2 Eric Wong <normalperson / yhbt.net>:
>
>> That use of select + readpartial is unsafe. =A0Spurious wakeup is a
>> documented behavior of the select() system call, data can be received
>> but checksums can be incorrect and data is discarded (after process is
>> woken up from select()).
>
> If you mean about Linux, it is already fixed (or have workaround) 6 years=
 ago.
> http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-talk/151776
>
> I don't know other example of spurious wakeup.

If you are talking Linux, It's not exactly correct.
udp_poll() take a workaround as a commnets.

/**
 *      udp_poll - wait for a UDP event.
 *      @file - file struct
 *      @sock - socket
 *      @wait - poll table
 *
 *      This is same as datagram poll, except for the special case of
 *      blocking sockets. If application is using a blocking fd
 *      and a packet with checksum error is in the queue;
 *      then it could get return from select indicating data available
 *      but then block when reading it. Add special case code
 *      to work around these arguably broken applications.
 */
unsigned int udp_poll(struct file *file, struct socket *sock, poll_table *w=
ait)
{
        unsigned int mask =3D datagram_poll(file, sock, wait);
        struct sock *sk =3D sock->sk;

        /* Check for false positives due to checksum errors */
        if ((mask & POLLRDNORM) && !(file->f_flags & O_NONBLOCK) &&
            !(sk->sk_shutdown & RCV_SHUTDOWN) && !first_packet_length(sk))
                mask &=3D ~(POLLIN | POLLRDNORM);

        return mask;

}

but look, datagram_poll() has another 30~ caller. (e.g. raw socket)

% git grep datagram_poll
drivers/isdn/mISDN/socket.c:    .poll           =3D datagram_poll,
drivers/net/pppoe.c:    .poll           =3D datagram_poll,
include/linux/skbuff.h:extern unsigned int    datagram_poll(struct
file *file, struct
net/appletalk/ddp.c:    .poll           =3D datagram_poll,
net/ax25/af_ax25.c:     .poll           =3D datagram_poll,
net/bluetooth/hci_sock.c:       .poll           =3D datagram_poll,
net/can/bcm.c:  .poll          =3D datagram_poll,
net/can/raw.c:  .poll          =3D datagram_poll,
net/core/datagram.c: *  Authors:        Alan Cox
<alan / lxorguk.ukuu.org.uk>. (datagram
net/core/datagram.c: *  datagram_poll - generic datagram poll
net/core/datagram.c:unsigned int datagram_poll(struct file *file,
struct socket *sock,
net/core/datagram.c:EXPORT_SYMBOL(datagram_poll);
net/decnet/af_decnet.c: int mask =3D datagram_poll(file, sock, wait);
net/econet/af_econet.c: .poll =3D         datagram_poll,
net/ieee802154/af_ieee802154.c: .poll              =3D datagram_poll,
net/ieee802154/af_ieee802154.c: .poll              =3D datagram_poll,
net/ipv4/af_inet.c:     .poll              =3D datagram_poll,
net/ipv4/udp.c: unsigned int mask =3D datagram_poll(file, sock, wait);
net/ipv6/raw.c: .poll              =3D datagram_poll,             /* ok
         */
net/ipx/af_ipx.c:       .poll           =3D datagram_poll,
net/irda/af_irda.c:     .poll =3D         datagram_poll,
net/irda/af_irda.c:     .poll =3D         datagram_poll,
net/irda/af_irda.c:     .poll =3D         datagram_poll,
net/key/af_key.c:       .poll           =3D       datagram_poll,
net/l2tp/l2tp_ip.c:     .poll              =3D datagram_poll,
net/l2tp/l2tp_ppp.c:    .poll           =3D datagram_poll,
net/llc/af_llc.c:       .poll        =3D datagram_poll,
net/netlink/af_netlink.c:       .poll =3D         datagram_poll,
net/netrom/af_netrom.c: .poll           =3D       datagram_poll,
net/packet/af_packet.c: unsigned int mask =3D datagram_poll(file, sock, wai=
t);
net/packet/af_packet.c: .poll =3D         datagram_poll,
net/phonet/socket.c:    .poll           =3D datagram_poll,
net/rose/af_rose.c:     .poll           =3D       datagram_poll,
net/sctp/socket.c: * This function is done by modeling the current
datagram_poll() and
net/x25/af_x25.c:       .poll =3D         datagram_poll,

IOW, it's only a workaround for udp based broken application. not a
fix. If I understand correctly,
Linux kernel people don't have a plan to fix this issue by in-kernel
change because it makes
performance hurt.

But, of course, if you are only talking about udp applications, you are cor=
rect.

Thanks.