7 #include <sys/socket.h>
11 void remove_string( char *data, char *string ) {
12 char *pos = strstr( data, string );
14 char *comma = strchr( pos, ',' );
16 char *endpos = pos - 1;
23 strcpy( tmp, comma+1 );
29 int do_mount( int control_channel ) {
31 int n = read( control_channel, buf, 1024 );
37 unsigned long mountflags;
40 int r = sscanf( buf, "%s\n%s\n%s\n%ld\n%s\n", source, target, fstype,
43 assert( r == 5 ); // shouldn't be an assert
45 int s = mount( source, target, fstype, mountflags, data );
47 // TODO: should probably make sure this is for a fuse filesystem type . . .
49 if( s != 0 && errno == EINVAL ) {
50 // replace fd with a new one
51 remove_string( data, "fd" );
54 fd = open_fuse_device(&dev);
55 char *end = data+strlen(data);
56 if( strlen(data) != 0 ) {
60 sprintf( end, "fd=%d", fd );
62 s = mount( source, target, fstype, mountflags, data );
68 sprintf( outbuf, "%08x\n", errno );
70 sprintf( outbuf, "%08x\n", fd );
72 write( control_channel, outbuf, strlen(outbuf) );
76 // now we have to sendmsg it back
78 int r = send_fd(control_channel, fd);
82 int x = read(control_channel, outbuf, 1 );
92 int do_umount( int control_channel, int num ) {
98 char *argbuf = (char *) malloc(sizeof(char)*(1024*num+1));
99 const char *args[num+1];
102 // read all of the arguments
106 int n = read( control_channel, argbuf, 1024*num+1 );
107 assert( n < 1024*num+1 ); // no assert here
109 while( num_left > 0 ) {
111 if( sscanf( argbuf, "%s\n", arg ) != 1 ) {
114 int len = strlen(arg);
115 char *a = malloc( sizeof(char)*(strlen(arg)+1) );
117 if( strcmp( a, "-o" ) == 0 ) {
120 args[args_index] = a;
126 } while( args_index < num );
130 // The last argument is the mountpoint, that's really all we care about
131 printf( "umounting %s\n", args[num-1] );
132 int r = fuse_mnt_umount("reroutemount_server", args[num-1], 0 );
134 // write the status (probably not necessary)
137 sprintf( outbuf, "%d\n", errno );
139 sprintf( outbuf, "%d\n", 0 );
141 write( control_channel, outbuf, strlen(outbuf) );
145 int main( int argc, char **argv ) {
148 printf("This script is invoked by vsys\n");
152 sscanf(argv[2],"%d",&control_channel);
156 int n = read( control_channel, buf, 9 );
159 close(control_channel);
164 if( sscanf( buf, "%08x\n", &num ) != 1 ) {
165 close(control_channel);
170 do_mount( control_channel );
172 do_umount( control_channel, num );
174 close(control_channel);