feature. See also
. The project being documented here (as the example) is the Zig library itself.
Uring.setUpChild
fn setUpChild(sync: *CancelRegion.Sync, options: struct
File
Code
fn setUpChild(sync: *CancelRegion.Sync, options: struct {
stdin_pipe: fd_t,
stdout_pipe: fd_t,
stderr_pipe: fd_t,
dev_null_fd: fd_t,
prog_pipe: fd_t,
argv_buf: [:null]?[*:0]const u8,
env_block: process.Environ.Block,
PATH: []const u8,
spawn: process.SpawnOptions,
}) ForkBailError {
try setUpChildIo(
sync,
options.spawn.stdin,
options.stdin_pipe,
linux.STDIN_FILENO,
options.dev_null_fd,
);
try setUpChildIo(
sync,
options.spawn.stdout,
options.stdout_pipe,
linux.STDOUT_FILENO,
options.dev_null_fd,
);
try setUpChildIo(
sync,
options.spawn.stderr,
options.stderr_pipe,
linux.STDERR_FILENO,
options.dev_null_fd,
);
switch (options.spawn.cwd) {
.inherit => {},
.dir => |cwd_dir| try fchdir(sync, cwd_dir.handle),
.path => |cwd_path| {
var cwd_path_buffer: [PATH_MAX]u8 = undefined;
const cwd_path_posix = try pathToPosix(cwd_path, &cwd_path_buffer);
try chdir(sync, cwd_path_posix);
},
}
// equal to prog_fileno and be clobbered by this dup2 call.
if (options.prog_pipe != -1) try dup2(sync, options.prog_pipe, prog_fileno);
if (options.spawn.gid) |gid| {
switch (linux.errno(linux.setregid(gid, gid))) {
.SUCCESS => {},
.AGAIN => return error.ResourceLimitReached,
.INVAL => return error.InvalidUserId,
.PERM => return error.PermissionDenied,
else => return error.Unexpected,
}
}
if (options.spawn.uid) |uid| {
switch (linux.errno(linux.setreuid(uid, uid))) {
.SUCCESS => {},
.AGAIN => return error.ResourceLimitReached,
.INVAL => return error.InvalidUserId,
.PERM => return error.PermissionDenied,
else => return error.Unexpected,
}
}
if (options.spawn.pgid) |pid| {
switch (linux.errno(linux.setpgid(0, pid))) {
.SUCCESS => {},
.ACCES => return error.ProcessAlreadyExec,
.INVAL => return error.InvalidProcessGroupId,
.PERM => return error.PermissionDenied,
else => return error.Unexpected,
}
}
if (options.spawn.start_suspended) {
switch (linux.errno(linux.kill(0, .STOP))) {
.SUCCESS => {},
.PERM => return error.PermissionDenied,
else => return error.Unexpected,
}
}
return execv(
sync,
options.spawn.expand_arg0,
options.argv_buf.ptr[0].?,
options.argv_buf.ptr,
options.env_block,
options.PATH,
);
}