From f02158439677d0c1d4b2ed2ed1ba9bc43923a05d Mon Sep 17 00:00:00 2001 From: Asain Kujovic Date: Tue, 24 Dec 2024 02:13:36 +0100 Subject: [PATCH] - LXC attach should exit on SIGCHLD Signed-off-by: Asain Kujovic --- src/lxc/attach.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/lxc/attach.c b/src/lxc/attach.c index 8f2f7a37c..27acd401e 100644 --- a/src/lxc/attach.c +++ b/src/lxc/attach.c @@ -1430,6 +1430,15 @@ static inline void lxc_attach_terminal_close_log(struct lxc_terminal *terminal) close_prot_errno_disarm(terminal->log_fd); } +void lxc_attach_sig_handler(int signum) { + // exit on SIGCHLD, but not if sender-pid is 0 (main process) + if (signum == SIGCHLD) { + int sender_pid = waitpid(-1, NULL, WNOHANG); + if (sender_pid > 0) + exit(EXIT_SUCCESS); + } +} + int lxc_attach(struct lxc_container *container, lxc_attach_exec_t exec_function, void *exec_payload, lxc_attach_options_t *options, pid_t *attached_process) @@ -1734,6 +1743,7 @@ int lxc_attach(struct lxc_container *container, lxc_attach_exec_t exec_function, signal(SIGINT, SIG_IGN); signal(SIGQUIT, SIG_IGN); } + signal(SIGCHLD, lxc_attach_sig_handler); /* Reap transient process. */ ret = wait_for_pid(pid); -- 2.47.2