Skip to content

Commit f021584

Browse files
committed
- LXC attach should exit on SIGCHLD
Signed-off-by: Asain Kujovic <asainnp@gmail.com>
1 parent 192ee85 commit f021584

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

src/lxc/attach.c

+10
Original file line numberDiff line numberDiff line change
@@ -1430,6 +1430,15 @@ static inline void lxc_attach_terminal_close_log(struct lxc_terminal *terminal)
14301430
close_prot_errno_disarm(terminal->log_fd);
14311431
}
14321432

1433+
void lxc_attach_sig_handler(int signum) {
1434+
// exit on SIGCHLD, but not if sender-pid is 0 (main process)
1435+
if (signum == SIGCHLD) {
1436+
int sender_pid = waitpid(-1, NULL, WNOHANG);
1437+
if (sender_pid > 0)
1438+
exit(EXIT_SUCCESS);
1439+
}
1440+
}
1441+
14331442
int lxc_attach(struct lxc_container *container, lxc_attach_exec_t exec_function,
14341443
void *exec_payload, lxc_attach_options_t *options,
14351444
pid_t *attached_process)
@@ -1734,6 +1743,7 @@ int lxc_attach(struct lxc_container *container, lxc_attach_exec_t exec_function,
17341743
signal(SIGINT, SIG_IGN);
17351744
signal(SIGQUIT, SIG_IGN);
17361745
}
1746+
signal(SIGCHLD, lxc_attach_sig_handler);
17371747

17381748
/* Reap transient process. */
17391749
ret = wait_for_pid(pid);

0 commit comments

Comments
 (0)