diff options
author | An-Cheng Huang <ancheng@vyatta.com> | 2010-08-26 19:04:24 -0700 |
---|---|---|
committer | An-Cheng Huang <ancheng@vyatta.com> | 2010-08-26 19:04:24 -0700 |
commit | efe1f2b5aea0065f94394b916f1fa8b447229d5a (patch) | |
tree | 9e12a5a7cd095ce073a58a53ebd3af5f377fae1c /src | |
parent | dd0e8e1abf74b79a0fd259007d803db7359dffc2 (diff) | |
download | vyatta-cfg-efe1f2b5aea0065f94394b916f1fa8b447229d5a.tar.gz vyatta-cfg-efe1f2b5aea0065f94394b916f1fa8b447229d5a.zip |
fix for bug 5960
* change "commit" to use syscalls (instead of system("...") calls) for mount/umount.
* this is a temporary fix, and such low-level details need to be moved into the backend library.
Diffstat (limited to 'src')
-rw-r--r-- | src/common/unionfs.c | 65 |
1 files changed, 29 insertions, 36 deletions
diff --git a/src/common/unionfs.c b/src/common/unionfs.c index da4cd7e..9fe2497 100644 --- a/src/common/unionfs.c +++ b/src/common/unionfs.c @@ -3,6 +3,7 @@ #include <dirent.h> #include <sys/types.h> #include <sys/stat.h> +#include <sys/mount.h> #include <syslog.h> #include <unistd.h> #include <glib-2.0/glib.h> @@ -23,6 +24,10 @@ extern vtw_path t_path; * behavior so no status is returned (since system() return code was not * checked). this should probably be changed so each invocation is checked * for error. + * + * XXX these (and many other things here) will need to be moved into the + * library to consolidate the usage of all low-level implementation + * details. */ static inline void sys_mkdir_p(const char *path) @@ -54,6 +59,25 @@ sys_cp(const char *src_file, const char *dst_file) } } +static inline void +sys_umount_session() +{ + if (umount(get_mdirp()) != 0) { + perror("umount"); + } +} + +static inline void +sys_mount_session() +{ + char mopts[MAX_LENGTH_DIR_PATH * 2]; + snprintf(mopts, MAX_LENGTH_DIR_PATH * 2, "dirs=%s=rw:%s=ro", + get_cdirp(), get_adirp()); + if (mount("unionfs", get_mdirp(), "unionfs", 0, mopts) != 0) { + perror("mount"); + } +} + void set_path(char *path, boolean config); @@ -743,9 +767,6 @@ common_commit_copy_to_live_config(GNode *node, boolean suppress_piecewise_copy, static const char format1point1[]="mv -f %s/* -t %s"; /*mdirp, tmpp*/ static const char format1point5[]="rm -fr '%s'/*"; /*tmpp*/ - static const char format2[]="sudo umount %s"; //mdirp - static const char format8[]="sudo mount -t unionfs -o dirs=%s=rw:%s=ro unionfs %s"; //cdirp, adirp, mdirp - set_echo(TRUE); char mbuf[MAX_LENGTH_DIR_PATH]; @@ -802,15 +823,9 @@ common_commit_copy_to_live_config(GNode *node, boolean suppress_piecewise_copy, system(command); } - //unmount temp (i.e. rm merge) - sprintf(command, format2, mbuf_root); - if (g_debug) { - printf("%s\n",command); - syslog(LOG_DEBUG,"%s\n",command); - fflush(NULL); - } + // unmount the session dir if (test_mode == FALSE) { - system(command); + sys_umount_session(); } if (suppress_piecewise_copy) { @@ -837,14 +852,8 @@ common_commit_copy_to_live_config(GNode *node, boolean suppress_piecewise_copy, piecewise_copy(node, test_mode); } - sprintf(command, format8, cbuf_root,abuf_root,mbuf_root); - if (g_debug) { - printf("%s\n",command); - syslog(LOG_DEBUG,"%s\n",command); - fflush(NULL); - } if (test_mode == FALSE) { - system(command); + sys_mount_session(); } fflush(NULL); @@ -876,10 +885,7 @@ common_commit_clean_temp_config(GNode *root_node, boolean test_mode) char *command; command = malloc(MAX_LENGTH_DIR_PATH); /* XXX must ... remove ... this ... */ - static const char format2[]="sudo umount %s"; //mdirp static const char format5[]="rm -fr '%s'/{.*,*} >&/dev/null ; /bin/true"; /*cdirp*/ - static const char format7[]="sudo mount -t unionfs -o dirs=%s=rw:%s=ro unionfs %s"; //cdirp, adirp, mdirp - char tbuf[MAX_LENGTH_DIR_PATH]; sprintf(tbuf,"%s",get_tmpp()); @@ -892,15 +898,8 @@ common_commit_clean_temp_config(GNode *root_node, boolean test_mode) set_echo(TRUE); - sprintf(command, format2, mbuf); - if (g_debug) { - printf("%s\n",command); - syslog(LOG_DEBUG,"%s\n",command); - fflush(NULL); - } - if (test_mode == FALSE) { - system(command); + sys_umount_session(); } /* @@ -939,14 +938,8 @@ common_commit_clean_temp_config(GNode *root_node, boolean test_mode) system(command); } - sprintf(command, format7, cbuf,abuf,mbuf); - if (g_debug) { - printf("%s\n",command); - syslog(LOG_DEBUG,"%s\n",command); - fflush(NULL); - } if (test_mode == FALSE) { - system(command); + sys_mount_session(); } /* notify other users in config mode */ |