mirror of
https://codeberg.org/ziglang/zig.git
synced 2025-12-06 13:54:21 +00:00
Merge pull request #25820 from GiuseppeCesarano/process
Child.start_suspended ported to posix
This commit is contained in:
commit
bf15c791fa
3 changed files with 29 additions and 2 deletions
|
|
@ -1699,6 +1699,14 @@ pub fn dup2(old_fd: fd_t, new_fd: fd_t) !void {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn getpid() pid_t {
|
||||||
|
return system.getpid();
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn getppid() pid_t {
|
||||||
|
return system.getppid();
|
||||||
|
}
|
||||||
|
|
||||||
pub const ExecveError = error{
|
pub const ExecveError = error{
|
||||||
SystemResources,
|
SystemResources,
|
||||||
AccessDenied,
|
AccessDenied,
|
||||||
|
|
|
||||||
|
|
@ -621,6 +621,21 @@ test "dup & dup2" {
|
||||||
try testing.expectEqualStrings("dupdup2", try tmp.dir.readFile("os_dup_test", &buffer));
|
try testing.expectEqualStrings("dupdup2", try tmp.dir.readFile("os_dup_test", &buffer));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
test "getpid" {
|
||||||
|
if (native_os == .wasi) return error.SkipZigTest;
|
||||||
|
if (native_os == .windows) return error.SkipZigTest;
|
||||||
|
|
||||||
|
try expect(posix.getpid() != 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
test "getppid" {
|
||||||
|
if (native_os == .wasi) return error.SkipZigTest;
|
||||||
|
if (native_os == .windows) return error.SkipZigTest;
|
||||||
|
if (native_os == .plan9 and !builtin.link_libc) return error.SkipZigTest;
|
||||||
|
|
||||||
|
try expect(posix.getppid() >= 0);
|
||||||
|
}
|
||||||
|
|
||||||
test "writev longer than IOV_MAX" {
|
test "writev longer than IOV_MAX" {
|
||||||
if (native_os == .windows or native_os == .wasi) return error.SkipZigTest;
|
if (native_os == .windows or native_os == .wasi) return error.SkipZigTest;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -85,8 +85,8 @@ expand_arg0: Arg0Expand,
|
||||||
/// Darwin-only. Disable ASLR for the child process.
|
/// Darwin-only. Disable ASLR for the child process.
|
||||||
disable_aslr: bool = false,
|
disable_aslr: bool = false,
|
||||||
|
|
||||||
/// Darwin and Windows only. Start child process in suspended state. For Darwin it's started
|
/// Start child process in suspended state.
|
||||||
/// as if SIGSTOP was sent.
|
/// For Posix systems it's started as if SIGSTOP was sent.
|
||||||
start_suspended: bool = false,
|
start_suspended: bool = false,
|
||||||
|
|
||||||
/// Windows-only. Sets the CREATE_NO_WINDOW flag in CreateProcess.
|
/// Windows-only. Sets the CREATE_NO_WINDOW flag in CreateProcess.
|
||||||
|
|
@ -669,6 +669,10 @@ fn spawnPosix(self: *ChildProcess) SpawnError!void {
|
||||||
posix.setpgid(0, pid) catch |err| forkChildErrReport(err_pipe[1], err);
|
posix.setpgid(0, pid) catch |err| forkChildErrReport(err_pipe[1], err);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (self.start_suspended) {
|
||||||
|
posix.kill(posix.getpid(), .STOP) catch |err| forkChildErrReport(err_pipe[1], err);
|
||||||
|
}
|
||||||
|
|
||||||
const err = switch (self.expand_arg0) {
|
const err = switch (self.expand_arg0) {
|
||||||
.expand => posix.execvpeZ_expandArg0(.expand, argv_buf.ptr[0].?, argv_buf.ptr, envp),
|
.expand => posix.execvpeZ_expandArg0(.expand, argv_buf.ptr[0].?, argv_buf.ptr, envp),
|
||||||
.no_expand => posix.execvpeZ_expandArg0(.no_expand, argv_buf.ptr[0].?, argv_buf.ptr, envp),
|
.no_expand => posix.execvpeZ_expandArg0(.no_expand, argv_buf.ptr[0].?, argv_buf.ptr, envp),
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue