From: Shuanglei Tao Date: Sat, 28 Sep 2019 15:28:14 +0000 (+0800) Subject: protocol: set pty fd close-on-exec X-Git-Url: http://git.prime8.dev/?a=commitdiff_plain;h=9126d5410889a9798d7ce97cc7a789a374955090;p=ttyd.git protocol: set pty fd close-on-exec --- 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;