aboutsummaryrefslogtreecommitdiff
path: root/lib/std/child_process.zig
diff options
context:
space:
mode:
authorAndrew Kelley <andrew@ziglang.org>2021-09-15 14:46:31 -0700
committerAndrew Kelley <andrew@ziglang.org>2021-09-15 14:51:08 -0700
commitf3ebfcae3882c03da84821abed40167ea07a8c78 (patch)
treef1b759c94cba5b020a9ffb141fc62cb686fc5f04 /lib/std/child_process.zig
parent111a2dcf3ad53c0c8ad2c9e7c9bd042b81e90c82 (diff)
parent0395b35cee8d4082cc40b0dcd0298f797f42309d (diff)
downloadzig-f3ebfcae3882c03da84821abed40167ea07a8c78.tar.gz
zig-f3ebfcae3882c03da84821abed40167ea07a8c78.zip
Merge remote-tracking branch 'origin/master' into llvm13
Conflicts: * cmake/Findclang.cmake * cmake/Findlld.cmake * cmake/Findllvm.cmake In master branch, more search paths were added to these files with "12" in the path. In this commit I updated them to "13". * src/stage1/codegen.cpp * src/zig_llvm.cpp * src/zig_llvm.h In master branch, ZigLLVMBuildCmpXchg is improved to add `is_single_threaded`. However, the LLVM 13 C API has this already, and in the llvm13 branch, ZigLLVMBuildCmpXchg is deleted in favor of the C API. In this commit I updated stage2 to use the LLVM 13 C API rather than depending on an improved ZigLLVMBuildCmpXchg. Additionally, src/target.zig largestAtomicBits needed to be updated to include the new m68k ISA.
Diffstat (limited to 'lib/std/child_process.zig')
-rw-r--r--lib/std/child_process.zig39
1 files changed, 20 insertions, 19 deletions
diff --git a/lib/std/child_process.zig b/lib/std/child_process.zig
index 7d8881a679..530a9b68a6 100644
--- a/lib/std/child_process.zig
+++ b/lib/std/child_process.zig
@@ -7,6 +7,7 @@ const os = std.os;
const process = std.process;
const File = std.fs.File;
const windows = os.windows;
+const linux = os.linux;
const mem = std.mem;
const math = std.math;
const debug = std.debug;
@@ -160,7 +161,7 @@ pub const ChildProcess = struct {
self.cleanupStreams();
return term;
}
- try os.kill(self.pid, os.SIGTERM);
+ try os.kill(self.pid, os.SIG.TERM);
self.waitUnwrapped();
return self.term.?;
}
@@ -189,8 +190,8 @@ pub const ChildProcess = struct {
max_output_bytes: usize,
) !void {
var poll_fds = [_]os.pollfd{
- .{ .fd = child.stdout.?.handle, .events = os.POLLIN, .revents = undefined },
- .{ .fd = child.stderr.?.handle, .events = os.POLLIN, .revents = undefined },
+ .{ .fd = child.stdout.?.handle, .events = os.POLL.IN, .revents = undefined },
+ .{ .fd = child.stderr.?.handle, .events = os.POLL.IN, .revents = undefined },
};
var dead_fds: usize = 0;
@@ -199,7 +200,7 @@ pub const ChildProcess = struct {
// of space an ArrayList will allocate grows exponentially.
const bump_amt = 512;
- const err_mask = os.POLLERR | os.POLLNVAL | os.POLLHUP;
+ const err_mask = os.POLL.ERR | os.POLL.NVAL | os.POLL.HUP;
while (dead_fds < poll_fds.len) {
const events = try os.poll(&poll_fds, std.math.maxInt(i32));
@@ -209,9 +210,9 @@ pub const ChildProcess = struct {
var remove_stderr = false;
// Try reading whatever is available before checking the error
// conditions.
- // It's still possible to read after a POLLHUP is received, always
+ // It's still possible to read after a POLL.HUP is received, always
// check if there's some data waiting to be read first.
- if (poll_fds[0].revents & os.POLLIN != 0) {
+ if (poll_fds[0].revents & os.POLL.IN != 0) {
// stdout is ready.
const new_capacity = std.math.min(stdout.items.len + bump_amt, max_output_bytes);
try stdout.ensureCapacity(new_capacity);
@@ -226,7 +227,7 @@ pub const ChildProcess = struct {
remove_stdout = poll_fds[0].revents & err_mask != 0;
}
- if (poll_fds[1].revents & os.POLLIN != 0) {
+ if (poll_fds[1].revents & os.POLL.IN != 0) {
// stderr is ready.
const new_capacity = std.math.min(stderr.items.len + bump_amt, max_output_bytes);
try stderr.ensureCapacity(new_capacity);
@@ -461,7 +462,7 @@ pub const ChildProcess = struct {
if (builtin.os.tag == .linux) {
var fd = [1]std.os.pollfd{std.os.pollfd{
.fd = self.err_pipe[0],
- .events = std.os.POLLIN,
+ .events = std.os.POLL.IN,
.revents = undefined,
}};
@@ -471,7 +472,7 @@ pub const ChildProcess = struct {
// According to eventfd(2) the descriptro is readable if the counter
// has a value greater than 0
- if ((fd[0].revents & std.os.POLLIN) != 0) {
+ if ((fd[0].revents & std.os.POLL.IN) != 0) {
const err_int = try readIntFd(self.err_pipe[0]);
return @errSetCast(SpawnError, @intToError(err_int));
}
@@ -494,18 +495,18 @@ pub const ChildProcess = struct {
}
fn statusToTerm(status: u32) Term {
- return if (os.WIFEXITED(status))
- Term{ .Exited = os.WEXITSTATUS(status) }
- else if (os.WIFSIGNALED(status))
- Term{ .Signal = os.WTERMSIG(status) }
- else if (os.WIFSTOPPED(status))
- Term{ .Stopped = os.WSTOPSIG(status) }
+ return if (os.W.IFEXITED(status))
+ Term{ .Exited = os.W.EXITSTATUS(status) }
+ else if (os.W.IFSIGNALED(status))
+ Term{ .Signal = os.W.TERMSIG(status) }
+ else if (os.W.IFSTOPPED(status))
+ Term{ .Stopped = os.W.STOPSIG(status) }
else
Term{ .Unknown = status };
}
fn spawnPosix(self: *ChildProcess) SpawnError!void {
- const pipe_flags = if (io.is_async) os.O_NONBLOCK else 0;
+ const pipe_flags = if (io.is_async) os.O.NONBLOCK else 0;
const stdin_pipe = if (self.stdin_behavior == StdIo.Pipe) try os.pipe2(pipe_flags) else undefined;
errdefer if (self.stdin_behavior == StdIo.Pipe) {
destroyPipe(stdin_pipe);
@@ -523,7 +524,7 @@ pub const ChildProcess = struct {
const any_ignore = (self.stdin_behavior == StdIo.Ignore or self.stdout_behavior == StdIo.Ignore or self.stderr_behavior == StdIo.Ignore);
const dev_null_fd = if (any_ignore)
- os.openZ("/dev/null", os.O_RDWR, 0) catch |err| switch (err) {
+ os.openZ("/dev/null", os.O.RDWR, 0) catch |err| switch (err) {
error.PathAlreadyExists => unreachable,
error.NoSpaceLeft => unreachable,
error.FileTooBig => unreachable,
@@ -575,12 +576,12 @@ pub const ChildProcess = struct {
// and execve from the child process to the parent process.
const err_pipe = blk: {
if (builtin.os.tag == .linux) {
- const fd = try os.eventfd(0, os.EFD_CLOEXEC);
+ const fd = try os.eventfd(0, linux.EFD.CLOEXEC);
// There's no distinction between the readable and the writeable
// end with eventfd
break :blk [2]os.fd_t{ fd, fd };
} else {
- break :blk try os.pipe2(os.O_CLOEXEC);
+ break :blk try os.pipe2(os.O.CLOEXEC);
}
};
errdefer destroyPipe(err_pipe);