From 06838478f4dd0ea7c081b2a52366729a6041c7b1 Mon Sep 17 00:00:00 2001 From: WangFengTu Date: Thu, 11 Mar 2021 15:11:32 +0800 Subject: [PATCH] support isula exec --workdir Signed-off-by: WangFengTu --- 0020-support-isula-exec-workdir.patch | 90 +++++++++++++++++++++++++++ lxc.spec | 9 ++- 2 files changed, 98 insertions(+), 1 deletion(-) create mode 100644 0020-support-isula-exec-workdir.patch diff --git a/0020-support-isula-exec-workdir.patch b/0020-support-isula-exec-workdir.patch new file mode 100644 index 0000000..202f2ab --- /dev/null +++ b/0020-support-isula-exec-workdir.patch @@ -0,0 +1,90 @@ +From ccdbeeb8b502e06355c2e55c9f980e5142891b7c Mon Sep 17 00:00:00 2001 +From: WangFengTu +Date: Thu, 11 Mar 2021 09:18:51 +0800 +Subject: [PATCH] support isula exec --workdir + +Signed-off-by: WangFengTu +--- + 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 + diff --git a/lxc.spec b/lxc.spec index 45a55a7..5c365e5 100644 --- a/lxc.spec +++ b/lxc.spec @@ -1,4 +1,4 @@ -%global _release 2021012801 +%global _release 2021031101 Name: lxc Version: 4.0.3 @@ -27,6 +27,7 @@ Patch0016: 0016-avoid-using-void-pointers-in-caclulation.patch Patch0017: 0017-fix-compilation-errors-without-libcap.patch Patch0018: 0018-IO-fix-io-data-miss-when-exec-with-pipes.patch Patch0019: 0019-metrics-add-total_inactive_file-metric-for-memory.patch +Patch0020: 0020-support-isula-exec-workdir.patch BuildRequires: systemd-units git libtool graphviz docbook2X doxygen chrpath BuildRequires: pkgconfig(libseccomp) @@ -198,6 +199,12 @@ make check %{_mandir}/*/man7/%{name}* %changelog +* Thu Mar 11 2021 wangfengtu - 4.0.3-2021031101 +- Type:enhancement +- ID:NA +- SUG:NA +- DESC: support isula exec --workdir + * Thu Jan 28 2021 lifeng - 4.0.3-2021012801 - Type:enhancement - ID:NA -- Gitee