From 5ae994270b1490684b9a03f1b2fa47b15f61f6cb Mon Sep 17 00:00:00 2001 From: Daan De Meyer Date: Wed, 27 Nov 2019 21:24:16 +0100 Subject: [PATCH] Initialize the endpoint for attach before calling fork. This way, when an error occurs in the attach endpoint logic, conmon can exit immediately without having to clean up the child process. --- src/conmon.c | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/src/conmon.c b/src/conmon.c index e3c61361..81b8eb01 100644 --- a/src/conmon.c +++ b/src/conmon.c @@ -1480,6 +1480,20 @@ int main(int argc, char *argv[]) add_argv(runtime_argv, opt_cid, NULL); end_argv(runtime_argv); + /* Setup endpoint for attach */ + _cleanup_free_ char *attach_symlink_dir_path = NULL; + if (opt_bundle_path != NULL) { + attach_symlink_dir_path = setup_attach_socket(); + dummyfd = setup_terminal_control_fifo(); + setup_console_fifo(); + + if (opt_attach) { + ndebug("sending attach message to parent"); + write_sync_fd(attach_pipe_fd, 0, NULL); + ndebug("sent attach message to parent"); + } + } + sigset_t mask, oldmask; if ((sigemptyset(&mask) < 0) || (sigaddset(&mask, SIGTERM) < 0) || (sigaddset(&mask, SIGQUIT) < 0) || (sigaddset(&mask, SIGINT) < 0) || sigprocmask(SIG_BLOCK, &mask, &oldmask) < 0) @@ -1588,20 +1602,6 @@ int main(int argc, char *argv[]) if (slavefd_stderr > -1) close(slavefd_stderr); - /* Setup endpoint for attach */ - _cleanup_free_ char *attach_symlink_dir_path = NULL; - if (opt_bundle_path != NULL) { - attach_symlink_dir_path = setup_attach_socket(); - dummyfd = setup_terminal_control_fifo(); - setup_console_fifo(); - - if (opt_attach) { - ndebug("sending attach message to parent"); - write_sync_fd(attach_pipe_fd, 0, NULL); - ndebug("sent attach message to parent"); - } - } - if (csname != NULL) { g_unix_fd_add(console_socket_fd, G_IO_IN, terminal_accept_cb, csname); /* Process any SIGCHLD we may have missed before the signal handler was in place. */