diff options
| author | Robby Zambito <contact@robbyzambito.me> | 2026-01-31 20:29:34 -0500 |
|---|---|---|
| committer | Robby Zambito <contact@robbyzambito.me> | 2026-01-31 21:43:27 -0500 |
| commit | daf18d35526870e39f3009b6bf9a64d0b4859b9f (patch) | |
| tree | 194cc256629ed91749d9b35b4caff2856a0b3ed9 /src/main.zig | |
| parent | 4f721afcfd5db46b7d81b2ab1f9a827fec0b56cf (diff) | |
Exec command directly if subshell fails
If execing the child fails, it might be because the shell doesn't exist.
Try running the command directly before giving up.
Diffstat (limited to 'src/main.zig')
| -rw-r--r-- | src/main.zig | 31 |
1 files changed, 30 insertions, 1 deletions
diff --git a/src/main.zig b/src/main.zig index d7c9a61..734357b 100644 --- a/src/main.zig +++ b/src/main.zig @@ -178,7 +178,36 @@ pub fn main(init: std.process.Init) !void { .stdout = .pipe, .stderr = .ignore, .stdin = .ignore, - }) catch continue; + }) catch |err| switch (err) { + error.AccessDenied, + error.FileBusy, + error.FileNotFound, + error.FileSystem, + error.InvalidExe, + error.IsDir, + error.NotDir, + error.OutOfMemory, + error.PermissionDenied, + error.SymLinkLoop, + error.SystemResources, + => blk: { + var argv_buf: [128][]const u8 = undefined; + var argv: ArrayList([]const u8) = .initBuffer(&argv_buf); + var payload_iter = std.mem.splitAny(u8, connection_payload, " \t\n"); + while (payload_iter.next()) |arg| argv.appendBounded(arg) catch continue; + break :blk std.process.spawn(init.io, .{ + .argv = argv.items, + .stdout = .pipe, + .stderr = .ignore, + .stdin = .ignore, + }) catch continue; + }, + error.Canceled, + error.NoDevice, + error.OperationUnsupported, + => |e| return e, + else => continue, + }; var child_output_buf: [SaprusClient.max_payload_len]u8 = undefined; var child_output_reader = child.stdout.?.reader(init.io, &child_output_buf); |
