aboutsummaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorMark Glines <mark@glines.org>2002-06-26 13:47:21 +0000
committerMark Glines <mark@glines.org>2002-06-26 13:47:21 +0000
commit23334c6fd5159acf21f2a7c3a96be84951f0d290 (patch)
tree37523ad8994f9023afdf159f54e7c8a0e0de48ab /lib
parente215e7a2859804f1084813d264d3737809d57f99 (diff)
downloadlibfuse-23334c6fd5159acf21f2a7c3a96be84951f0d290.tar.gz
cleaned up semantics of fd-passing and error handling
Diffstat (limited to 'lib')
-rw-r--r--lib/helper.c25
1 files changed, 19 insertions, 6 deletions
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 @@ static int fuse_mount_obsolete(int *argcp, char **argv)
return 0;
}
+/* return value:
+ * >= 0 => fd
+ * -1 => error
+ */
int receive_fd(int fd) {
struct msghdr msg;
struct iovec iov;
@@ -96,12 +100,17 @@ int receive_fd(int fd) {
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 @@ int fuse_mount(const char *mountpoint, const char *mount_args)
/* 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 @@ int fuse_mount(const char *mountpoint, const char *mount_args)
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;
}