authorgravatar for david@vortan.devDavid Rubin <david@vortan.dev> 2026-10-09 15:08:52-05:00
committergravatar for david@vortan.devDavid Rubin <david@vortan.dev> 2026-10-09 17:52:13-05:00
log5f4173bb1f9fd8fd05875bb43473a14cb62a3e01
tree7de56cc2d8b297fff98a61f76513d817f9e7f7b5
parent5bec90b3bca72d4dbd8e41858224575ba0611ef5
signature Commit is signed but in an unrecognized format.

Io.Uring: clean up child process setup


1 files changed, 22 insertions(+), 16 deletions(-)

lib/std/Io/Uring.zig+22-16
...@@ -4510,6 +4510,20 @@ fn setUpChild(sync: *CancelRegion.Sync, options: struct {...@@ -4510,6 +4510,20 @@ fn setUpChild(sync: *CancelRegion.Sync, options: struct {
4510 PATH: []const u8,4510 PATH: []const u8,
4511 spawn: process.SpawnOptions,4511 spawn: process.SpawnOptions,
4512}) ForkBailError {4512}) ForkBailError {
4513 // Must happen before clobbering file descriptors below.
4514 switch (options.spawn.cwd) {
4515 .inherit => {},
4516 .dir => |cwd_dir| try fchdir(sync, cwd_dir.handle),
4517 .path => |cwd_path| {
4518 var cwd_path_buffer: [PATH_MAX]u8 = undefined;
4519 const cwd_path_posix = try pathToPosix(cwd_path, &cwd_path_buffer);
4520 try chdir(sync, cwd_path_posix);
4521 },
4522 }
4523
4524 for (options.spawn.inherit_dirs) |dir| try setFdFlags(sync, dir.handle, 0);
4525 for (options.spawn.inherit_files) |file| try setFdFlags(sync, file.handle, 0);
4526
4513 try setUpChildIo(4527 try setUpChildIo(
4514 sync,4528 sync,
4515 options.spawn.stdin,4529 options.spawn.stdin,
...@@ -4532,23 +4546,15 @@ fn setUpChild(sync: *CancelRegion.Sync, options: struct {...@@ -4532,23 +4546,15 @@ fn setUpChild(sync: *CancelRegion.Sync, options: struct {
4532 options.dev_null_fd,4546 options.dev_null_fd,
4533 );4547 );
45344548
4535 switch (options.spawn.cwd) {4549 // Must happen after fchdir above because the cwd file descriptor might be
4536 .inherit => {},4550 // equal to prog_fileno and be clobbered by this operation.
4537 .dir => |cwd_dir| try fchdir(sync, cwd_dir.handle),4551 if (options.prog_pipe != -1) {
4538 .path => |cwd_path| {4552 if (options.prog_pipe == prog_fileno)
4539 var cwd_path_buffer: [PATH_MAX]u8 = undefined;4553 try setFdFlags(sync, options.prog_pipe, 0)
4540 const cwd_path_posix = try pathToPosix(cwd_path, &cwd_path_buffer);4554 else
4541 try chdir(sync, cwd_path_posix);4555 try dup2(sync, options.prog_pipe, prog_fileno);
4542 },
4543 }4556 }
45444557
4545 for (options.spawn.inherit_dirs) |dir| try setFdFlags(sync, dir.handle, 0);
4546 for (options.spawn.inherit_files) |file| try setFdFlags(sync, file.handle, 0);
4547
4548 // Must happen after fchdir above, the cwd file descriptor might be
4549 // equal to prog_fileno and be clobbered by this dup2 call.
4550 if (options.prog_pipe != -1) try dup2(sync, options.prog_pipe, prog_fileno);
4551
4552 if (options.spawn.gid) |gid| {4558 if (options.spawn.gid) |gid| {
4553 switch (linux.errno(linux.setregid(gid, gid))) {4559 switch (linux.errno(linux.setregid(gid, gid))) {
4554 .SUCCESS => {},4560 .SUCCESS => {},
...@@ -4580,7 +4586,7 @@ fn setUpChild(sync: *CancelRegion.Sync, options: struct {...@@ -4580,7 +4586,7 @@ fn setUpChild(sync: *CancelRegion.Sync, options: struct {
4580 }4586 }
45814587
4582 if (options.spawn.start_suspended) {4588 if (options.spawn.start_suspended) {
4583 switch (linux.errno(linux.kill(0, .STOP))) {4589 switch (linux.errno(linux.kill(linux.getpid(), .STOP))) {
4584 .SUCCESS => {},4590 .SUCCESS => {},
4585 .PERM => return error.PermissionDenied,4591 .PERM => return error.PermissionDenied,
4586 else => return error.Unexpected,4592 else => return error.Unexpected,