From 51e2d6d356ed91f10ecaf5b116761e14baa8f417 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Marczykowski-G=C3=B3recki?= Date: Fri, 7 Aug 2015 21:45:22 +0200 Subject: [PATCH] qrexec: make sure that all the pipes/sockets are closed on cleanup This will ensure that the child process will receive info that the connection is closed. Otherwise it could hang on write() or in some cases read() - on its stdin/stdout. Thanks @adrelanos for help with debugging. --- qrexec/qrexec-agent-data.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/qrexec/qrexec-agent-data.c b/qrexec/qrexec-agent-data.c index e44024d..61b55f4 100644 --- a/qrexec/qrexec-agent-data.c +++ b/qrexec/qrexec-agent-data.c @@ -403,6 +403,26 @@ int process_child_io(libvchan_t *data_vchan, } } } + /* make sure that all the pipes/sockets are closed, so the child process + * (if any) will know that the connection is terminated */ + if (stdout_fd != -1) { + if (shutdown(stdout_fd, SHUT_RD) < 0) { + if (errno == ENOTSOCK) + close(stdout_fd); + } + stdout_fd = -1; + } + if (stdin_fd != -1) { + if (shutdown(stdin_fd, SHUT_WR) < 0) { + if (errno == ENOTSOCK) + close(stdin_fd); + } + stdin_fd = -1; + } + if (stderr_fd != -1) { + close(stderr_fd); + stderr_fd = -1; + } return child_process_status; }