+2007-06-03 Miklos Szeredi <miklos@szeredi.hu>
+
+ * libulockmgr: Work around a kernel bug in recv(), causing it to
+ sometimes return zero even if data was available on the socket.
+
2007-05-29 Miklos Szeredi <miklos@szeredi.hu>
* lib: optimization: store parent pointer in node instead of
next->prev = owner;
}
+/*
+ * There's a bug in the linux kernel (< 2.6.22) recv() implementation
+ * on AF_UNIX, SOCK_STREAM sockets, that could cause it to return
+ * zero, even if data was available. Retrying the recv will return
+ * the data in this case.
+*/
+static int do_recv(int sock, void *buf, size_t len, int flags)
+{
+ int res = recv(sock, buf, len, flags);
+ if (res == 0)
+ res = recv(sock, buf, len, flags);
+
+ return res;
+}
+
static int ulockmgr_send_message(int sock, void *buf, size_t buflen,
int *fdp, int numfds)
{
if (f)
f->inuse++;
- res = recv(cfd, msg, sizeof(struct message), MSG_WAITALL);
+ res = do_recv(cfd, msg, sizeof(struct message), MSG_WAITALL);
if (res == -1) {
perror("libulockmgr: recv");
msg->error = EIO;
sigemptyset(&unblock);
sigaddset(&unblock, SIGUSR1);
pthread_sigmask(SIG_UNBLOCK, &unblock, &old);
- res = recv(cfd, msg, sizeof(struct message), MSG_WAITALL);
+ res = do_recv(cfd, msg, sizeof(struct message), MSG_WAITALL);
errno_save = errno;
pthread_sigmask(SIG_SETMASK, &old, NULL);
if (res == sizeof(struct message))
msg.msg_controllen = sizeof(ccmsg);
res = recvmsg(sock, &msg, MSG_WAITALL);
- if (!res)
- return 0;
+ if (!res) {
+ /* retry on zero return, see do_recv() in ulockmgr.c */
+ res = recvmsg(sock, &msg, MSG_WAITALL);
+ if (!res)
+ return 0;
+ }
if (res == -1) {
perror("ulockmgr_server: recvmsg");
return -1;