diff options
author | 2022-11-25 22:55:00 -0800 | |
---|---|---|
committer | 2022-11-25 22:55:35 -0800 | |
commit | 8519ff02e6d5449484a5a4f858626303543c8a55 (patch) | |
tree | ba8d0d98ac580d8c11d33dfa895198bf571804b9 | |
parent | 397cb6600b831a1ab5daeac07a5e2d8f113f7c71 (diff) | |
download | bun-8519ff02e6d5449484a5a4f858626303543c8a55.tar.gz bun-8519ff02e6d5449484a5a4f858626303543c8a55.tar.zst bun-8519ff02e6d5449484a5a4f858626303543c8a55.zip |
Prevent closing stdout / stderr
-rw-r--r-- | src/bun.js/node/syscall.zig | 12 |
1 files changed, 10 insertions, 2 deletions
diff --git a/src/bun.js/node/syscall.zig b/src/bun.js/node/syscall.zig index 4f4b6a4d2..9d5b06540 100644 --- a/src/bun.js/node/syscall.zig +++ b/src/bun.js/node/syscall.zig @@ -212,9 +212,17 @@ pub fn open(file_path: [:0]const u8, flags: JSC.Node.Mode, perm: JSC.Node.Mode) unreachable; } -// The zig standard library marks BADF as unreachable -// That error is not unreachable for us +/// This function will prevent stdout and stderr from being closed. pub fn close(fd: std.os.fd_t) ?Syscall.Error { + if (fd == std.os.STDOUT_FILENO or fd == std.os.STDERR_FILENO) { + log("close({d}) SKIPPED", .{fd}); + return null; + } + + return closeAllowingStdoutAndStderr(fd); +} + +pub fn closeAllowingStdoutAndStderr(fd: std.os.fd_t) ?Syscall.Error { log("close({d})", .{fd}); std.debug.assert(fd != bun.invalid_fd); if (comptime std.meta.trait.isSignedInt(@TypeOf(fd))) |