From: Asain Kujovic Date: Tue, 24 Dec 2024 01:13:36 +0000 (+0100) Subject: - LXC attach should exit on SIGCHLD X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=f02158439677d0c1d4b2ed2ed1ba9bc43923a05d;p=thirdparty%2Flxc.git - LXC attach should exit on SIGCHLD Signed-off-by: Asain Kujovic --- 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);