X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=fuse%2Freroutemount.c;h=c1c140b7a1f5cecf201b2404751bca63ced59840;hb=2b07978b1e21113105b6ea76dca1900da83c2dc3;hp=3fa229e2bf85df647521511dc391faa3ce4df940;hpb=59ad54209a4973b76b3abf44f22d61aa75621d89;p=vsys-wrappers.git diff --git a/fuse/reroutemount.c b/fuse/reroutemount.c index 3fa229e..c1c140b 100644 --- a/fuse/reroutemount.c +++ b/fuse/reroutemount.c @@ -4,127 +4,88 @@ #include #include #include -#include "stolen_from_fuse.h" +#include "fdpass.h" char *socket_name = "/vsys/fd_fusemount.control"; +unsigned int arg_length = 128; + +void send_argument(int control_channel_fd, const char *source) { + int sent; + sent=send(control_channel_fd, source, arg_length, 0); + if (sent 0 ) { - // get the fd - fuse_fd = receive_fd(fd); - - // what was the old fd? - int old_fd; - char extra[1024]; - int s = sscanf( data, "fd=%d,%s", &old_fd, extra ); - assert( dup2( fuse_fd, old_fd ) == old_fd ); - } + send_argument(fd, source); + send_argument(fd, target ); + send_argument(fd, filesystemtype ); + send_argument(fd, data ); - close(fd); - return 0; + old_fuse_fd = get_magic_fd (data); -} - -int execv( const char *path, char *const argv[] ) { - if( strstr( path, "fusermount" ) == NULL ) { - return execv( path, argv ); + if (old_fuse_fd == -1) { + printf ("Reroutemount: Could not identify FUSE fd: %d\n", old_fuse_fd); + exit(1); } - // also make sure this is an unmount . . . - int n = 0; - char *arg = argv[n]; - int found_u = 0; - while( arg != NULL ) { - if( strcmp( arg, "-u" ) == 0 ) { - found_u = 1; - break; - } - arg = argv[++n]; - } + send_fd(fd, old_fuse_fd); + new_fuse_fd=receive_fd(fd); - if( !found_u ) { - return execv( path, argv ); + if (new_fuse_fd == -1) { + printf ("Reroutemount: Fusemount returned bad fd: %d\n", new_fuse_fd); + exit(1); } - // Have root do any fusermounts we need done - int fd = connect_socket(); - - do_umount( argv, n, fd ); + if( (dupfd=dup2(new_fuse_fd, old_fuse_fd )) != old_fuse_fd ) { + printf ("Could not duplicate returned file descriptor: %d\n",dupfd); + exit(1); + } - exit(0); + close(fd); + return 0; } -