diff options
author | Mark Glines <mark@glines.org> | 2002-04-18 14:41:48 +0000 |
---|---|---|
committer | Mark Glines <mark@glines.org> | 2002-04-18 14:41:48 +0000 |
commit | 65ba219885aefa096437c2bd92ad8394a5ecda75 (patch) | |
tree | a035d3b16cf2d89a7d6da8dd2a02f47e439f75c3 /util | |
parent | f0cd8e4c394b16c496ed08a3448be0b5fdbfa5e5 (diff) |
fuse_mount_ioslave() and helper util
Diffstat (limited to 'util')
-rw-r--r-- | util/.cvsignore | 1 | ||||
-rw-r--r-- | util/Makefile.am | 3 | ||||
-rw-r--r-- | util/fuse_ioslave.c | 57 |
3 files changed, 60 insertions, 1 deletions
diff --git a/util/.cvsignore b/util/.cvsignore index 5f7d28d..ab2dc89 100644 --- a/util/.cvsignore +++ b/util/.cvsignore @@ -2,3 +2,4 @@ Makefile.in Makefile .deps fusermount +fuse_ioslave diff --git a/util/Makefile.am b/util/Makefile.am index 48f9957..0e4434f 100644 --- a/util/Makefile.am +++ b/util/Makefile.am @@ -1,8 +1,9 @@ ## Process this file with automake to produce Makefile.in -bin_PROGRAMS = fusermount +bin_PROGRAMS = fusermount fuse_ioslave fusermount_SOURCES = fusermount.c +fuse_ioslave_SOURCES = fuse_ioslave.c install-exec-hook: -chown root $(DESTDIR)$(bindir)/fusermount diff --git a/util/fuse_ioslave.c b/util/fuse_ioslave.c new file mode 100644 index 0000000..1fa3bbf --- /dev/null +++ b/util/fuse_ioslave.c @@ -0,0 +1,57 @@ +#include <stdio.h> /* fprintf */ +#include <errno.h> /* errno */ +#include <string.h> /* strerror */ +#include <unistd.h> /* read,write,close */ +#include <stdlib.h> /* getenv,strtol */ +#include <sys/select.h> /* select */ +#include <sys/socket.h> /* send, recv */ +#include <sys/un.h> /* struct sockaddr_un */ +#define BUFSIZE (2<<16) +#undef IOSLAVE_DEBUG +char *scratch; + +int send_fd(int sock_fd, int send_fd) { + int retval; + struct msghdr msg; + struct cmsghdr *p_cmsg; + struct iovec vec; + char cmsgbuf[CMSG_SPACE(sizeof(send_fd))]; + int *p_fds; + char sendchar = 0; + msg.msg_control = cmsgbuf; + msg.msg_controllen = sizeof(cmsgbuf); + p_cmsg = CMSG_FIRSTHDR(&msg); + p_cmsg->cmsg_level = SOL_SOCKET; + p_cmsg->cmsg_type = SCM_RIGHTS; + p_cmsg->cmsg_len = CMSG_LEN(sizeof(send_fd)); + p_fds = (int *) CMSG_DATA(p_cmsg); + *p_fds = send_fd; + msg.msg_controllen = p_cmsg->cmsg_len; + msg.msg_name = NULL; + msg.msg_namelen = 0; + msg.msg_iov = &vec; + msg.msg_iovlen = 1; + msg.msg_flags = 0; + /* "To pass file descriptors or credentials you need to send/read at + * least one byte" (man 7 unix) + */ + vec.iov_base = &sendchar; + vec.iov_len = sizeof(sendchar); + retval = sendmsg(sock_fd, &msg, 0); + if (retval != 1) { + perror("sendmsg"); + } + return retval; +} + +int main() { + char *env = getenv("_FUSE_IOSLAVE_FD"); + int fd; + 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); + } + return 0; +} |