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