From 807c1dfe8a897f9c61bf3549ff2566917b53023b Mon Sep 17 00:00:00 2001 From: crupest Date: Mon, 24 Jun 2024 00:06:25 +0800 Subject: feat: fix linux build, complete PosixSpawnSubProcess. NEED TEST: BufferStream, AutoReadStream, SubProcess. --- src/common/platform/unix/PosixSpawnSubProcess.cpp | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'src/common/platform/unix/PosixSpawnSubProcess.cpp') diff --git a/src/common/platform/unix/PosixSpawnSubProcess.cpp b/src/common/platform/unix/PosixSpawnSubProcess.cpp index fba536e5..1d69f54a 100644 --- a/src/common/platform/unix/PosixSpawnSubProcess.cpp +++ b/src/common/platform/unix/PosixSpawnSubProcess.cpp @@ -107,6 +107,15 @@ void PosixSpawnSubProcess::PlatformCreateProcess() { error = posix_spawn_file_actions_adddup2( &file_actions, stderr_pipe_.GetOtherFileDescriptor(), STDERR_FILENO); check_error(u"Failed to call posix_spawn_file_actions_adddup2 on stderr."); + error = posix_spawn_file_actions_addclose( + &file_actions, stdin_pipe_.GetSelfFileDescriptor()); + check_error(u"Failed to call posix_spawn_file_actions_addclose on stdin."); + error = posix_spawn_file_actions_addclose( + &file_actions, stdout_pipe_.GetSelfFileDescriptor()); + check_error(u"Failed to call posix_spawn_file_actions_addclose on stdout."); + error = posix_spawn_file_actions_addclose( + &file_actions, stderr_pipe_.GetSelfFileDescriptor()); + check_error(u"Failed to call posix_spawn_file_actions_addclose on stderr."); posix_spawnattr_t attr; error = posix_spawnattr_init(&attr); @@ -131,6 +140,13 @@ void PosixSpawnSubProcess::PlatformCreateProcess() { error = posix_spawnp(&pid_, exe.c_str(), &file_actions, &attr, argv, envp); check_error(u"Failed to call posix_spawnp."); + + error = ::close(stdin_pipe_.GetOtherFileDescriptor()); + check_error(u"Failed to close stdin."); + error = ::close(stdout_pipe_.GetOtherFileDescriptor()); + check_error(u"Failed to close stdout."); + error = ::close(stderr_pipe_.GetOtherFileDescriptor()); + check_error(u"Failed to close stderr."); } SubProcessExitResult PosixSpawnSubProcess::PlatformWaitForProcess() { -- cgit v1.2.3