From 904817eaf41eec3d3868d3bfe28cc2e17aff30d5 Mon Sep 17 00:00:00 2001 From: zhongtao Date: Thu, 12 Dec 2024 18:03:41 +0800 Subject: [PATCH] add locatability log info for lxc attach Signed-off-by: zhongtao (cherry picked from commit 2a1f5ed007432b823306a38e3b86b5bac0e9ff5c) --- ...locatability-log-info-for-lxc-attach.patch | 127 ++++++++++++++++++ lxc.spec | 9 +- 2 files changed, 135 insertions(+), 1 deletion(-) create mode 100644 0039-add-locatability-log-info-for-lxc-attach.patch diff --git a/0039-add-locatability-log-info-for-lxc-attach.patch b/0039-add-locatability-log-info-for-lxc-attach.patch new file mode 100644 index 0000000..dffa309 --- /dev/null +++ b/0039-add-locatability-log-info-for-lxc-attach.patch @@ -0,0 +1,127 @@ +From 987bf5f745aa432412334b54dcd913671527bdf3 Mon Sep 17 00:00:00 2001 +From: zhongtao +Date: Sat, 14 Dec 2024 00:25:23 +1400 +Subject: [PATCH] add locatability log info for lxc attach + +Signed-off-by: zhongtao +--- + src/lxc/attach.c | 50 ++++++++++++++++++++++++++++++++++++++++++++++-- + 1 file changed, 48 insertions(+), 2 deletions(-) + +diff --git a/src/lxc/attach.c b/src/lxc/attach.c +index 0ac37cc..9bd347b 100644 +--- a/src/lxc/attach.c ++++ b/src/lxc/attach.c +@@ -1334,6 +1334,9 @@ int lxc_attach(struct lxc_container *container, lxc_attach_exec_t exec_function, + if (!init_ctx->container->lxc_conf) { + init_ctx->container->lxc_conf = lxc_conf_init(); + if (!init_ctx->container->lxc_conf) { ++#ifdef HAVE_ISULAD ++ ERROR("Failed to init lxc conf"); ++#endif + lxc_proc_put_context_info(init_ctx); + return -1; + } +@@ -1594,9 +1597,15 @@ int lxc_attach(struct lxc_container *container, lxc_attach_exec_t exec_function, + cgroup_ops = cgroup_init(conf); + if (!cgroup_ops) + goto on_error; +- ++#ifdef HAVE_ISULAD ++ if (!cgroup_ops->attach(cgroup_ops, conf, name, lxcpath, pid)) { ++ SYSERROR("Failed to call cgroup ops attach"); ++ goto on_error; ++ } ++#else + if (!cgroup_ops->attach(cgroup_ops, conf, name, lxcpath, pid)) + goto on_error; ++#endif + } + TRACE("Moved intermediate process %d into container's cgroups", pid); + } +@@ -1642,22 +1651,38 @@ int lxc_attach(struct lxc_container *container, lxc_attach_exec_t exec_function, + * and the command will be stuck. + */ + isulad_sigfd = isulad_setup_signal_fd(&isulad_oldmask); +- if (isulad_sigfd < 0) ++ if (isulad_sigfd < 0) { ++ SYSERROR("Failed to setup signal fd"); + goto close_mainloop; ++ } + #endif + + /* Let the child process know to go ahead. */ + status = 0; + ret = lxc_write_nointr(ipc_sockets[0], &status, sizeof(status)); ++#ifdef HAVE_ISULAD ++ if (ret != sizeof(status)) { ++ SYSERROR("Failed to write ipc sockets to notify child process"); ++ goto close_mainloop; ++ } ++#else + if (ret != sizeof(status)) + goto close_mainloop; ++#endif + + TRACE("Told intermediate process to start initializing"); + + /* Get pid of attached process from intermediate process. */ + ret = lxc_read_nointr(ipc_sockets[0], &attached_pid, sizeof(attached_pid)); ++#ifdef HAVE_ISULAD ++ if (ret != sizeof(attached_pid)) { ++ SYSERROR("Failed to read ipc sockets to get attach process pid"); ++ goto close_mainloop; ++ } ++#else + if (ret != sizeof(attached_pid)) + goto close_mainloop; ++#endif + + TRACE("Received pid %d of attached process in parent pid namespace", attached_pid); + +@@ -1669,8 +1694,15 @@ int lxc_attach(struct lxc_container *container, lxc_attach_exec_t exec_function, + + /* Reap intermediate process. */ + ret = wait_for_pid(pid); ++#ifdef HAVE_ISULAD ++ if (ret < 0) { ++ SYSERROR("Failed to wait pid for child process"); ++ goto close_mainloop; ++ } ++#else + if (ret < 0) + goto close_mainloop; ++#endif + + TRACE("Intermediate process %d exited", pid); + +@@ -1708,12 +1740,26 @@ int lxc_attach(struct lxc_container *container, lxc_attach_exec_t exec_function, + + if (conf->seccomp.seccomp) { + ret = lxc_seccomp_recv_notifier_fd(&conf->seccomp, ipc_sockets[0]); ++#ifdef HAVE_ISULAD ++ if (ret < 0) { ++ SYSERROR("Failed to do lxc seccomp recv notifier fd"); ++ goto close_mainloop; ++ } ++#else + if (ret < 0) + goto close_mainloop; ++#endif + + ret = lxc_seccomp_add_notifier(name, lxcpath, &conf->seccomp); ++#ifdef HAVE_ISULAD ++ if (ret < 0) { ++ SYSERROR("Failed to do lxc seccomp add notifier"); ++ goto close_mainloop; ++ } ++#else + if (ret < 0) + goto close_mainloop; ++#endif + } + + /* We're done, the child process should now execute whatever it +-- +2.26.3 + diff --git a/lxc.spec b/lxc.spec index c349204..b5866e2 100644 --- a/lxc.spec +++ b/lxc.spec @@ -1,4 +1,4 @@ -%global _release 2022102425 +%global _release 2022102426 Name: lxc Version: 4.0.3 @@ -46,6 +46,7 @@ Patch0035: 0035-codecheck-fix.patch Patch0036: 0036-containers-in-the-FREEZING-state-also-need-to-be-unf.patch Patch0037: 0037-Add-succeed-message-info-for-ocihook.patch Patch0038: 0038-check-cgroup-path-empty-while-setting-freezer.patch +Patch0039: 0039-add-locatability-log-info-for-lxc-attach.patch BuildRequires: systemd-units git libtool graphviz docbook2X doxygen chrpath BuildRequires: pkgconfig(libseccomp) @@ -232,6 +233,12 @@ rm -rf %{buildroot}%{_sysconfdir}/default/%{name} %endif %changelog +* Thu Dec 12 2024 zhongtao - 4.0.3-2022102426 +- Type:bugfix +- ID:NA +- SUG:NA +- DESC: add locatability log info for lxc attach + * Tue Dec 19 2023 jikai - 4.0.3-2022102425 - Type:bugfix - ID:NA -- Gitee