Hi,
I just found the following bug.
Consider this program listening on a local socket
--8<---------------cut here---------------start------------->8---
#define _GNU_SOURCE
#include <assert.h>
#include <errno.h>
#include <stdio.h>
#include <string.h>
#include <sys/socket.h>
#include <sys/un.h>
#include <unistd.h>
#define SOCKPATH "/tmp/socket"
int
main()
{
int fd;
int err;
struct sockaddr_un sock_addr;
fd = socket(AF_LOCAL, SOCK_STREAM | SOCK_CLOEXEC | SOCK_NONBLOCK, 0);
assert(fd != -1);
unlink(SOCKPATH);
sock_addr.sun_family = AF_UNIX;
strcpy (sock_addr.sun_path, SOCKPATH);
err = bind (fd, (struct sockaddr *) &sock_addr, sizeof (sock_addr));
assert(err == 0);
err = listen(fd, SOMAXCONN);
assert(err == 0);
printf("Listening on %s\n", SOCKPATH);
char buf[1];
ssize_t n;
fd_set readfds;
FD_ZERO(&readfds);
FD_SET(fd, &readfds);
select(fd + 1, &readfds, NULL, NULL, NULL);
int client = accept4(fd, NULL, NULL, SOCK_NONBLOCK);
n = read(client, buf, 0);
perror("read");
printf("Read %zd bytes\n", n);
close(client);
printf("Exiting\n");
close(fd);
unlink(SOCKPATH);
return 0;
}
--8<---------------cut here---------------end--------------->8---
Connecting with any client results in the read call failing with EWOULDBLOCK.
I think what is happening is that the pipe_wait_readable call in pipe_recv sees
that no data is available and fails with EWOULDBLOCK. I guess there would need
to be similar condition as in pipe_send as there is nothing to do but I am not
sure how it should look like.
The context for finding this was "nscd --statistics".
Thanks.
Y.