lxc/0044-support-space-in-volume-mount-and-env.patch
LiFeng c1c967d9bc lxc: make lxc-libs package
Signed-off-by: LiFeng <lifeng68@huawei.com>
2020-02-14 06:13:22 -05:00

119 lines
3.6 KiB
Diff

From 37e6f7c4ffb31290322791d972f4ab8e0fa34dcc Mon Sep 17 00:00:00 2001
From: tanyifeng <tanyifeng1@huawei.com>
Date: Thu, 17 Jan 2019 10:18:23 +0800
Subject: [PATCH 044/139] support space in --volume, --mount and --env
Signed-off-by: tanyifeng <tanyifeng1@huawei.com>
Signed-off-by: LiFeng <lifeng68@huawei.com>
---
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 <time.h>
#include <unistd.h>
#include <pthread.h>
+#include <linux/fs.h>
#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 <sched.h>
#include <unistd.h>
#include <sys/syscall.h>
+#include <sys/types.h>
#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