cleaned up semantics of fd-passing and error handling
diff --git a/lib/helper.c b/lib/helper.c
index ff59f4a..f523f99 100644
--- a/lib/helper.c
+++ b/lib/helper.c
@@ -75,6 +75,10 @@
     return 0;
 }
 
+/* return value:
+ * >= 0  => fd
+ * -1    => error
+ */
 int receive_fd(int fd) {
     struct msghdr msg;
     struct iovec iov;
@@ -96,12 +100,17 @@
     msg.msg_control = ccmsg;
     msg.msg_controllen = sizeof(ccmsg);
 
-    rv = recvmsg(fd, &msg, 0);
+    while(((rv = recvmsg(fd, &msg, 0)) == -1) && errno == EINTR);
     if (rv == -1) {
         perror("recvmsg");
         return -1;
     }
-
+    if(!rv) {
+        /* EOF */
+        fprintf(stderr, "got EOF\n");
+        return -1;
+    }
+    
     cmsg = CMSG_FIRSTHDR(&msg);
     if (!cmsg->cmsg_type == SCM_RIGHTS) {
         fprintf(stderr, "got control message of unknown type %d\n",
@@ -120,8 +129,13 @@
     /* FIXME: parse mount_args (or just pass it to fusermount ???) */
     mount_args = mount_args;
 
-    if(socketpair(PF_UNIX,SOCK_DGRAM,0,fds)) {
+    /* make sure the socket fds are greater than 0 */
+    fd = open("/dev/null",O_RDONLY); 
+    rv = socketpair(PF_UNIX,SOCK_STREAM,0,fds);
+    close(fd);
+    if(rv) {
         fprintf(stderr,"fuse: failed to socketpair()\n");
+        close(fd);
         return -1;
     }
     pid = fork();
@@ -143,10 +157,9 @@
 
     fd = fds[1];
     close(fds[0]);
-    while((rv = receive_fd(fd)) < 0)
-        sleep(1);
+    rv = receive_fd(fd);
     close(fd);
-    while(wait(NULL) != pid); /* bury zombie */
+    waitpid(pid,NULL,0); /* bury zombie */
     return rv;
 }
 
diff --git a/util/fuse_ioslave.c b/util/fuse_ioslave.c
index 1fa3bbf..df7c66d 100644
--- a/util/fuse_ioslave.c
+++ b/util/fuse_ioslave.c
@@ -1,5 +1,5 @@
-#include <stdio.h>                /* fprintf */
-#include <errno.h>                /* errno */
+#include <stdio.h>                 /* fprintf */
+#include <errno.h>                 /* errno */
 #include <string.h>                /* strerror */
 #include <unistd.h>                /* read,write,close */
 #include <stdlib.h>                /* getenv,strtol */
@@ -10,6 +10,10 @@
 #undef IOSLAVE_DEBUG
 char *scratch;
 
+/* return values:
+ * 0  => success
+ * -1 => error condition
+ */
 int send_fd(int sock_fd, int send_fd) {
     int retval;
     struct msghdr msg;
@@ -37,11 +41,12 @@
      */
     vec.iov_base = &sendchar;
     vec.iov_len = sizeof(sendchar);
-    retval = sendmsg(sock_fd, &msg, 0);
+    while((retval = sendmsg(sock_fd, &msg, 0)) == -1 && errno == EINTR);
     if (retval != 1) {
         perror("sendmsg");
+        return -1;
     }
-    return retval;
+    return 0;
 }
 
 int main() {
@@ -50,8 +55,7 @@
     if (!env)
         exit(fprintf(stderr, "fuse_ioslave: do not run me directly\n"));
     fd = strtol(env, NULL, 0);
-    while (send_fd(fd, 0) < 0) {
-        sleep(5);
-    }
+    if(send_fd(fd, 0) == -1)
+    	fprintf(stderr,"failed to send fd\n");
     return 0;
 }