summaryrefslogtreecommitdiff
path: root/src/Command.zig
diff options
context:
space:
mode:
authorMitchell Hashimoto <mitchell.hashimoto@gmail.com>2024-07-02 09:47:50 -0700
committerMitchell Hashimoto <mitchell.hashimoto@gmail.com>2024-07-02 09:47:50 -0700
commit9baf4d143d0867a383b8dea414f5bccd8766637f (patch)
tree162dc5aaec56b5fee97cc753f3a3aeac4c83b13f /src/Command.zig
parent57c6f37dcdce05248d6dcecf07143587c75919e0 (diff)
command: if chdir fails for subprocess, ignore the error
Fixes #1911
Diffstat (limited to 'src/Command.zig')
-rw-r--r--src/Command.zig17
1 files changed, 13 insertions, 4 deletions
diff --git a/src/Command.zig b/src/Command.zig
index 60a898309..5bf2f1290 100644
--- a/src/Command.zig
+++ b/src/Command.zig
@@ -159,12 +159,21 @@ fn startPosix(self: *Command, arena: Allocator) !void {
// We are the child.
// Setup our file descriptors for std streams.
- if (self.stdin) |f| try setupFd(f.handle, posix.STDIN_FILENO);
- if (self.stdout) |f| try setupFd(f.handle, posix.STDOUT_FILENO);
- if (self.stderr) |f| try setupFd(f.handle, posix.STDERR_FILENO);
+ if (self.stdin) |f| setupFd(f.handle, posix.STDIN_FILENO) catch
+ return error.ExecFailedInChild;
+ if (self.stdout) |f| setupFd(f.handle, posix.STDOUT_FILENO) catch
+ return error.ExecFailedInChild;
+ if (self.stderr) |f| setupFd(f.handle, posix.STDERR_FILENO) catch
+ return error.ExecFailedInChild;
// Setup our working directory
- if (self.cwd) |cwd| try posix.chdir(cwd);
+ if (self.cwd) |cwd| posix.chdir(cwd) catch {
+ // This can fail if we don't have permission to go to
+ // this directory or if due to race conditions it doesn't
+ // exist or any various other reasons. We don't want to
+ // crash the entire process if this fails so we ignore it.
+ // We don't log because that'll show up in the output.
+ };
// If the user requested a pre exec callback, call it now.
if (self.pre_exec) |f| f(self);