Subject: Re: [PATCH] net: unix: non blocking recvmsg() should not return -EINTR

From: Rainer Weikusat <[email-masked]>
Date: Fri, 28 Mar 2014 20:35:34 +0000

Rainer Weikusat <rw@sable> writes:

[...]

> ---------
> #include <fcntl.h>
> #include <string.h>
> #include <sys/socket.h>
> #include <sys/un.h>
>
> int main(void)
> {
>     struct sockaddr_un sun;
>     int fd;
>
>     fd = socket(AF_UNIX, SOCK_DGRAM, 0);
>     sun.sun_family = AF_UNIX;
>     strncpy(sun.sun_path, "/tmp/bla", sizeof(sun.sun_path));
>     bind(fd, (struct sockaddr *)&sun, sizeof(sun));
>
>     if (fork() == 0) read(fd, &fd, sizeof(fd));
>
>     sleep(1);
>
>     fcntl(fd, F_SETFL, O_NONBLOCK);
>     read(fd, &fd, sizeof(fd));
>
>     return 0;
> }
> --------

In the interest of fairness, here's a more realistic test case (tested
on 3.2.9 and 3.2.54):

--------------
#include <fcntl.h>
#include <string.h>
#include <sys/socket.h>
#include <sys/un.h>

int main(void)
{
    struct sockaddr_un sun;
    int fd;

    fd = socket(AF_UNIX, SOCK_DGRAM, 0);
    sun.sun_family = AF_UNIX;
    strncpy(sun.sun_path, "/tmp/bla", sizeof(sun.sun_path));
    bind(fd, (struct sockaddr *)&sun, sizeof(sun));

    if (fork() == 0) recv(fd, &fd, sizeof(fd), 0);

    sleep(1);

    recv(fd, &fd, sizeof(fd), MSG_DONTWAIT);

    return 0;
}