From 9126d5410889a9798d7ce97cc7a789a374955090 Mon Sep 17 00:00:00 2001 From: Shuanglei Tao Date: Sat, 28 Sep 2019 23:28:14 +0800 Subject: [PATCH] protocol: set pty fd close-on-exec --- src/protocol.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/protocol.c b/src/protocol.c index ce496c7..559da60 100644 --- a/src/protocol.c +++ b/src/protocol.c @@ -176,14 +176,22 @@ spawn_process(struct tty_client *client) { return 1; } else if (pid == 0) { /* child */ setenv("TERM", server->terminal_type, true); - // Don't pass the web socket onto child processes +#if LWS_LIBRARY_VERSION_NUMBER < 3001000 + // libwebsockets set FD_CLOEXEC since v3.1.0 close(lws_get_socket_fd(client->wsi)); +#endif if (execvp(argv[0], argv) < 0) { perror("execvp failed\n"); _exit(-errno); } } + // set the file descriptor close-on-exec + int status_flags = fcntl(pty, F_GETFL); + if (status_flags != -1) { + fcntl(pty, F_SETFD, status_flags | FD_CLOEXEC); + } + lwsl_notice("started process, pid: %d\n", pid); client->pid = pid; client->pty = pty; -- 2.43.4