diff options
author | crupest <crupest@outlook.com> | 2024-06-24 00:06:25 +0800 |
---|---|---|
committer | crupest <crupest@outlook.com> | 2024-08-18 16:50:20 +0800 |
commit | 1b30150ab79ff1338f209a8ddb54b3dc60cfb599 (patch) | |
tree | 97e183587b293ecf768476da0edf3fdcf86e4543 /src/common/platform/unix/UnixPipe.cpp | |
parent | b756bf519cda0684ec46d0d9404cbc59741ec0cb (diff) | |
download | cru-1b30150ab79ff1338f209a8ddb54b3dc60cfb599.tar.gz cru-1b30150ab79ff1338f209a8ddb54b3dc60cfb599.tar.bz2 cru-1b30150ab79ff1338f209a8ddb54b3dc60cfb599.zip |
fix(SubProcess): fix pipe fs close, add tests.
NEED TEST: BufferStream, AutoReadStream, SubProcess.
Diffstat (limited to 'src/common/platform/unix/UnixPipe.cpp')
-rw-r--r-- | src/common/platform/unix/UnixPipe.cpp | 12 |
1 files changed, 8 insertions, 4 deletions
diff --git a/src/common/platform/unix/UnixPipe.cpp b/src/common/platform/unix/UnixPipe.cpp index 4d081d5e..f30c599e 100644 --- a/src/common/platform/unix/UnixPipe.cpp +++ b/src/common/platform/unix/UnixPipe.cpp @@ -7,8 +7,8 @@ #include <unistd.h> namespace cru::platform::unix { -UnixPipe::UnixPipe(Usage usage, UnixPipeFlag flags) - : usage_(usage), flags_(flags) { +UnixPipe::UnixPipe(Usage usage, bool auto_close, UnixPipeFlag flags) + : usage_(usage), auto_close_(auto_close), flags_(flags) { int fds[2]; if (pipe(fds) != 0) { throw ErrnoException(u"Failed to create unix pipe."); @@ -40,8 +40,12 @@ int UnixPipe::GetOtherFileDescriptor() { } UnixPipe::~UnixPipe() { - if (close(GetSelfFileDescriptor()) != 0) { - CRU_LOG_ERROR(u"Failed to close unix pipe file descriptor."); + if (auto_close_) { + auto self_fd = GetSelfFileDescriptor(); + if (::close(self_fd) != 0) { + CRU_LOG_ERROR(u"Failed to close unix pipe file descriptor {}, errno {}.", + self_fd, errno); + } } } } // namespace cru::platform::unix |