lxc/0039-add-locatability-log-info-for-lxc-attach.patch
zhongtao 904817eaf4 add locatability log info for lxc attach
Signed-off-by: zhongtao <zhongtao17@huawei.com>
(cherry picked from commit 2a1f5ed007432b823306a38e3b86b5bac0e9ff5c)
2024-12-15 10:17:38 +08:00

128 lines
3.7 KiB
Diff

From 987bf5f745aa432412334b54dcd913671527bdf3 Mon Sep 17 00:00:00 2001
From: zhongtao <zhongtao17@huawei.com>
Date: Sat, 14 Dec 2024 00:25:23 +1400
Subject: [PATCH] add locatability log info for lxc attach
Signed-off-by: zhongtao <zhongtao17@huawei.com>
---
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