- char inbuf[10];
- int n = read( fd, inbuf, 9 );
- inbuf[n] = '\0';
-
- int r;
- assert( sscanf( inbuf, "%08x\n", &r ) == 1);
-
- int fuse_fd = 0;
- if( r < 0 ) {
- errno = r;
- return -1;
- } else if( r > 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 );
+ old_fuse_fd = get_magic_fd (data);
+
+ send_fd(fd, old_fuse_fd);
+
+ if (fuse_fd == -1) {
+ printf ("Reroutemount: Could not identify FUSE fd: %d\n", fuse_fd);
+ exit(1);
+ }
+
+ new_fuse_fd=receive_fd(fd);
+
+ if (new_fuse_fd == -1) {
+ printf ("Reroutemount: Fusemount returned bad fd: %d\n", fuse_fd);
+ exit(1);
+ }