From baabb2596394fecf89c610e2473d8b930595f3aa Mon Sep 17 00:00:00 2001 From: tanyifeng Date: Thu, 17 Jan 2019 10:18:23 +0800 Subject: [PATCH 044/122] support space in --volume, --mount and --env Signed-off-by: tanyifeng Signed-off-by: LiFeng --- src/lxc/conf.c | 16 ++++++++++++++++ src/lxc/confile.c | 9 ++++++++- src/lxc/namespace.h | 1 + src/lxc/utils.h | 3 +++ 4 files changed, 28 insertions(+), 1 deletion(-) diff --git a/src/lxc/conf.c b/src/lxc/conf.c index 8fa63f7..48e31af 100644 --- a/src/lxc/conf.c +++ b/src/lxc/conf.c @@ -54,6 +54,7 @@ #include #include #include +#include #include "af_unix.h" #include "caps.h" @@ -2695,6 +2696,19 @@ static int mount_file_entries(const struct lxc_conf *conf, int ret = -1; while (getmntent_r(file, &mntent, buf, sizeof(buf))) { + /* Note: Workaround for volume file path with space*/ + mntent.mnt_fsname = lxc_string_replace(SPACE_MAGIC_STR, " ", mntent.mnt_fsname); + if(!mntent.mnt_fsname) { + SYSERROR("memory allocation error"); + return -1; + } + mntent.mnt_dir = lxc_string_replace(SPACE_MAGIC_STR, " ", mntent.mnt_dir); + if(!mntent.mnt_dir) { + SYSERROR("memory allocation error"); + free(mntent.mnt_fsname); + return -1; + } + ERROR("mntent.mnt_fsname:%s, mntent.mnt_dir:%s", mntent.mnt_fsname, mntent.mnt_dir); if (!rootfs->path) ret = mount_entry_on_systemfs(&mntent); else if (mntent.mnt_dir[0] != '/') @@ -2703,6 +2717,8 @@ static int mount_file_entries(const struct lxc_conf *conf, else ret = mount_entry_on_absolute_rootfs(&mntent, rootfs, lxc_name, lxc_path); + free(mntent.mnt_fsname); + free(mntent.mnt_dir); if (ret < 0) return -1; } diff --git a/src/lxc/confile.c b/src/lxc/confile.c index db63b55..7e9d5c8 100644 --- a/src/lxc/confile.c +++ b/src/lxc/confile.c @@ -1036,6 +1036,7 @@ static int set_config_environment(const char *key, const char *value, struct lxc_conf *lxc_conf, void *data) { struct lxc_list *list_item = NULL; + char *replaced; if (lxc_config_value_empty(value)) return lxc_clear_environment(lxc_conf); @@ -1044,7 +1045,12 @@ static int set_config_environment(const char *key, const char *value, if (!list_item) goto on_error; - list_item->elem = strdup(value); + /* isulad: recover space replaced by SPACE_MAGIC_STR */ + replaced = lxc_string_replace(SPACE_MAGIC_STR, " ", value); + if(!replaced) + goto on_error; + + list_item->elem = replaced; if (!list_item->elem) goto on_error; @@ -3661,6 +3667,7 @@ static int get_config_environment(const char *key, char *retv, int inlen, memset(retv, 0, inlen); lxc_list_for_each(it, &c->environment) { + strprint(retv, inlen, "%s\n", (char *)it->elem); } diff --git a/src/lxc/namespace.h b/src/lxc/namespace.h index ab583da..9caaf89 100644 --- a/src/lxc/namespace.h +++ b/src/lxc/namespace.h @@ -26,6 +26,7 @@ #include #include #include +#include #ifndef CLONE_PARENT_SETTID #define CLONE_PARENT_SETTID 0x00100000 diff --git a/src/lxc/utils.h b/src/lxc/utils.h index 4313942..73ffdd9 100644 --- a/src/lxc/utils.h +++ b/src/lxc/utils.h @@ -43,6 +43,9 @@ #include "raw_syscalls.h" #include "string_utils.h" +/* isulad: replace space with SPACE_MAGIC_STR */ +#define SPACE_MAGIC_STR "[#)" + /* returns 1 on success, 0 if there were any failures */ extern int lxc_rmdir_onedev(const char *path, const char *exclude); extern int get_u16(unsigned short *val, const char *arg, int base); -- 1.8.3.1