diff options
author | Kim Hagen <khagen@multi-development.com> | 2014-04-30 22:39:14 +0200 |
---|---|---|
committer | Kim Hagen <khagen@multi-development.com> | 2014-04-30 22:39:14 +0200 |
commit | 84c14e0983b3c2b9659af2e701b606e43306ccb2 (patch) | |
tree | 74e8762091bab82922e258a47ffb7b12571a5024 /src/cstore/unionfs/cstore-unionfs.cpp | |
parent | 9701d11117f532bd960672b52bc5e96dcc3e33cf (diff) | |
download | vyatta-cfg-84c14e0983b3c2b9659af2e701b606e43306ccb2.tar.gz vyatta-cfg-84c14e0983b3c2b9659af2e701b606e43306ccb2.zip |
Removed dirty workaround for fuse completely.
Use Build-iso to create /etc/fuse.conf file.
Use pipe(),fork(),execl() functions instead of system() function to
call unionfs-fuse.
Diffstat (limited to 'src/cstore/unionfs/cstore-unionfs.cpp')
-rw-r--r-- | src/cstore/unionfs/cstore-unionfs.cpp | 86 |
1 files changed, 69 insertions, 17 deletions
diff --git a/src/cstore/unionfs/cstore-unionfs.cpp b/src/cstore/unionfs/cstore-unionfs.cpp index 39d7634..2e6f4ad 100644 --- a/src/cstore/unionfs/cstore-unionfs.cpp +++ b/src/cstore/unionfs/cstore-unionfs.cpp @@ -24,6 +24,7 @@ #include <errno.h> #include <fcntl.h> #include <sys/mount.h> +#include <wait.h> #include <cli_cstore.h> #include <cstore/unionfs/cstore-unionfs.hpp> @@ -68,6 +69,9 @@ const string UnionfsCstore::C_VAL_NAME = "node.val"; const string UnionfsCstore::C_DEF_NAME = "node.def"; const string UnionfsCstore::C_COMMIT_LOCK_FILE = "/opt/vyatta/config/.lock"; +pid_t pid; +int status; +int commpipe[2]; ////// static static MapT<char, string> _fs_escape_chars; @@ -1478,21 +1482,46 @@ UnionfsCstore::do_mount(const FsPath& rwdir, const FsPath& rdir, const FsPath& mdir) { #ifdef USE_UNIONFSFUSE - string mopts = "/usr/bin/unionfs-fuse "; - mopts += "-o cow -o allow_other "; - mopts += rwdir.path_cstr(); + const char *fusepath, *fuseprog; + const char *fuseoptinit; + const char *fuseopt1, *fuseopt2; + string mopts; + + fusepath = "/usr/bin/unionfs-fuse"; + fuseprog = "unionfs-fuse"; + fuseoptinit = "-o"; + fuseopt1 = "cow"; + fuseopt2 = "allow_other"; + mopts = rwdir.path_cstr(); mopts += "=RW:"; mopts += rdir.path_cstr(); mopts += "=RO"; - mopts += " "; - mopts += mdir.path_cstr(); - if (system(mopts.c_str()) != 0) - { - output_internal("union mount failed [%s][%s][%s]\n", - strerror(errno), mdir.path_cstr(), mopts.c_str()); + if(pipe(commpipe)){ + output_internal("Pipe error!\n"); return false; } + + if((pid = fork()) == -1) { + output_internal("*** ERROR: forking child process failed\n"); + return false; + } + + if(pid) { + dup2(commpipe[1],1); + close(commpipe[0]); + setvbuf(stdout,(char*)NULL,_IONBF,0); + wait(&status); + } + else { + dup2(commpipe[0],0); + close(commpipe[1]); + if (execl(fusepath, fuseprog, fuseoptinit, fuseopt1, fuseoptinit, fuseopt2, mopts.c_str(), mdir.path_cstr(), NULL) != 0) { + output_internal("union mount failed [%s][%s][%s]\n", + strerror(errno), mdir.path_cstr(), mopts.c_str()); + return false; + } + } #else string mopts = "dirs="; mopts += rwdir.path_cstr(); @@ -1512,15 +1541,38 @@ bool UnionfsCstore::do_umount(const FsPath& mdir) { #ifdef USE_UNIONFSFUSE - string umount_cmd = "/usr/bin/fusermount -u "; - umount_cmd += mdir.path_cstr(); - - if (system(umount_cmd.c_str()) != 0) - { - output_internal("union umount failed [%s][%s]\n", - strerror(errno), mdir.path_cstr()); - return(false); + const char *fusermount_path, *fusermount_prog; + const char *fusermount_umount; + + fusermount_path = "/usr/bin/fusermount"; + fusermount_prog = "fusermount"; + fusermount_umount = "-u"; + + if(pipe(commpipe)){ + output_internal("Pipe error!\n"); + return false; + } + + if((pid = fork()) == -1) { + output_internal("*** ERROR: forking child process failed\n"); + return false; + } + + if(pid) { + dup2(commpipe[1],1); + close(commpipe[0]); + setvbuf(stdout,(char*)NULL,_IONBF,0); + wait(&status); + } + else { + dup2(commpipe[0],0); + close(commpipe[1]); + if (execl(fusermount_path, fusermount_prog, fusermount_umount, mdir.path_cstr(), NULL) != 0) { + output_internal("union mount failed [%s][%s]\n", + strerror(errno), mdir.path_cstr()); + return false; } + } #else if (umount(mdir.path_cstr()) != 0) { output_internal("union umount failed [%s][%s]\n", |