support isula exec --workdir

Signed-off-by: WangFengTu <wangfengtu@huawei.com>
This commit is contained in:
WangFengTu 2021-03-31 11:06:57 +08:00
parent 46e6dbf54b
commit caf56e2dec
2 changed files with 98 additions and 1 deletions

View File

@ -0,0 +1,90 @@
From ccdbeeb8b502e06355c2e55c9f980e5142891b7c Mon Sep 17 00:00:00 2001
From: WangFengTu <wangfengtu@huawei.com>
Date: Thu, 11 Mar 2021 09:18:51 +0800
Subject: [PATCH] support isula exec --workdir
Signed-off-by: WangFengTu <wangfengtu@huawei.com>
---
src/lxc/attach.c | 4 ++--
src/lxc/tools/arguments.h | 1 +
src/lxc/tools/lxc_attach.c | 15 +++++++++++++--
3 files changed, 16 insertions(+), 4 deletions(-)
diff --git a/src/lxc/attach.c b/src/lxc/attach.c
index c5fc561..2ed2329 100644
--- a/src/lxc/attach.c
+++ b/src/lxc/attach.c
@@ -791,9 +791,9 @@ static int attach_child_main(struct attach_clone_payload *payload)
#ifdef HAVE_ISULAD
/* isulad: set workdir */
- if (init_ctx->container->lxc_conf->init_cwd) {
+ if (options->initial_cwd || init_ctx->container->lxc_conf->init_cwd) {
char *init_cwd;
- init_cwd = init_ctx->container->lxc_conf->init_cwd;
+ init_cwd = options->initial_cwd ? options->initial_cwd : init_ctx->container->lxc_conf->init_cwd;
/* try to create workdir if not exist */
struct stat st;
if (stat(init_cwd, &st) < 0 && mkdir_p(init_cwd, 0750) < 0) {
diff --git a/src/lxc/tools/arguments.h b/src/lxc/tools/arguments.h
index 41ea109..c16d99f 100644
--- a/src/lxc/tools/arguments.h
+++ b/src/lxc/tools/arguments.h
@@ -41,6 +41,7 @@ struct lxc_arguments {
/* for lxc-start */
const char *share_ns[32]; /* size must be greater than LXC_NS_MAX */
#ifdef HAVE_ISULAD
+ char *workdir;
const char *container_info; /* isulad: file used to store pid and ppid info of container */
char *terminal_fifos[3]; /* isulad add, fifos used to redirct stdin/out/err */
const char *exit_monitor_fifo; /* isulad: fifo used to monitor state of monitor process */
diff --git a/src/lxc/tools/lxc_attach.c b/src/lxc/tools/lxc_attach.c
index dbddc2a..3bfbe6a 100644
--- a/src/lxc/tools/lxc_attach.c
+++ b/src/lxc/tools/lxc_attach.c
@@ -76,6 +76,7 @@ static const struct option my_longopts[] = {
{"uid", required_argument, 0, 'u'},
{"gid", required_argument, 0, 'g'},
#else
+ {"workdir", required_argument, 0, 'w'},
{"user", required_argument, 0, 'u'},
{"in-fifo", required_argument, 0, OPT_INPUT_FIFO}, /* isulad add terminal fifos*/
{"out-fifo", required_argument, 0, OPT_OUTPUT_FIFO},
@@ -143,8 +144,9 @@ Options :\n\
"
#else
"\
- --user User ID (format: UID[:GID])\n\
- --timeout Timeout in seconds (default: 0)\n\
+ --user User ID (format: UID[:GID])\n\
+ -w, --workdir Working directory inside the container.\n\
+ --timeout Timeout in seconds (default: 0)\n\
"
#endif
,
@@ -295,6 +297,9 @@ static int my_parser(struct lxc_arguments *args, int c, char *arg)
return -1;
}
break;
+ case 'w':
+ args->workdir=arg;
+ break;
case OPT_INPUT_FIFO:
args->terminal_fifos[0] = arg;
break;
@@ -639,6 +644,12 @@ int main(int argc, char *argv[])
attach_options.open_stdin = true;
}
+#ifdef HAVE_ISULAD
+ if (my_args.workdir) {
+ attach_options.initial_cwd = my_args.workdir;
+ }
+#endif
+
/* isulad: add do attach background */
if (attach_options.attach_flags & LXC_ATTACH_TERMINAL)
wexit = do_attach_foreground(c, &command, &attach_options, &errmsg);
--
2.20.1

View File

@ -1,4 +1,4 @@
%global _release 2021033101 %global _release 2021033102
Name: lxc Name: lxc
Version: 4.0.3 Version: 4.0.3
@ -28,6 +28,7 @@ Patch0017: 0017-fix-compilation-errors-without-libcap.patch
Patch0018: 0018-IO-fix-io-data-miss-when-exec-with-pipes.patch Patch0018: 0018-IO-fix-io-data-miss-when-exec-with-pipes.patch
Patch0019: 0019-metrics-add-total_inactive_file-metric-for-memory.patch Patch0019: 0019-metrics-add-total_inactive_file-metric-for-memory.patch
Patch0020: 0020-support-cgroup-v2.patch Patch0020: 0020-support-cgroup-v2.patch
Patch0021: 0021-support-isula-exec-workdir.patch
BuildRequires: systemd-units git libtool graphviz docbook2X doxygen chrpath BuildRequires: systemd-units git libtool graphviz docbook2X doxygen chrpath
BuildRequires: pkgconfig(libseccomp) BuildRequires: pkgconfig(libseccomp)
@ -199,6 +200,12 @@ make check
%{_mandir}/*/man7/%{name}* %{_mandir}/*/man7/%{name}*
%changelog %changelog
* Thu Mar 11 2021 wangfengtu <wangfengtu@huawei.com> - 4.0.3-2021031102
- Type:enhancement
- ID:NA
- SUG:NA
- DESC: support isula exec --workdir
* Wed Mar 31 2021 wangfengtu <wangfengtu@huawei.com> - 4.0.3-2021033101 * Wed Mar 31 2021 wangfengtu <wangfengtu@huawei.com> - 4.0.3-2021033101
- Type:enhancement - Type:enhancement
- ID:NA - ID:NA