| author | |
| committer | |
| log | bf15c791faa7bf5a029ec58432b3e8e16c691dff |
| tree | b9e60b460f80a9223dc43fe72d622b4d7c6f79d4 |
| parent | 852a1f718a306aa0a540c527a0c23d50b9f0db08 |
| parent | f4159eff9253bb701bacfa14e37bdb80e8dff7da |
| signature |
Child.start_suspended ported to posix3 files changed, 29 insertions(+), 2 deletions(-)
lib/std/posix.zig+8| ... | @@ -1699,6 +1699,14 @@ pub fn dup2(old_fd: fd_t, new_fd: fd_t) !void { | ... | @@ -1699,6 +1699,14 @@ pub fn dup2(old_fd: fd_t, new_fd: fd_t) !void { |
| 1699 | } | 1699 | } |
| 1700 | } | 1700 | } |
| 1701 | 1701 | ||
| 1702 | pub fn getpid() pid_t { | ||
| 1703 | return system.getpid(); | ||
| 1704 | } | ||
| 1705 | |||
| 1706 | pub fn getppid() pid_t { | ||
| 1707 | return system.getppid(); | ||
| 1708 | } | ||
| 1709 | |||
| 1702 | pub const ExecveError = error{ | 1710 | pub const ExecveError = error{ |
| 1703 | SystemResources, | 1711 | SystemResources, |
| 1704 | AccessDenied, | 1712 | AccessDenied, |
lib/std/posix/test.zig+15| ... | @@ -621,6 +621,21 @@ test "dup & dup2" { | ... | @@ -621,6 +621,21 @@ test "dup & dup2" { |
| 621 | try testing.expectEqualStrings("dupdup2", try tmp.dir.readFile("os_dup_test", &buffer)); | 621 | try testing.expectEqualStrings("dupdup2", try tmp.dir.readFile("os_dup_test", &buffer)); |
| 622 | } | 622 | } |
| 623 | 623 | ||
| 624 | test "getpid" { | ||
| 625 | if (native_os == .wasi) return error.SkipZigTest; | ||
| 626 | if (native_os == .windows) return error.SkipZigTest; | ||
| 627 | |||
| 628 | try expect(posix.getpid() != 0); | ||
| 629 | } | ||
| 630 | |||
| 631 | test "getppid" { | ||
| 632 | if (native_os == .wasi) return error.SkipZigTest; | ||
| 633 | if (native_os == .windows) return error.SkipZigTest; | ||
| 634 | if (native_os == .plan9 and !builtin.link_libc) return error.SkipZigTest; | ||
| 635 | |||
| 636 | try expect(posix.getppid() >= 0); | ||
| 637 | } | ||
| 638 | |||
| 624 | test "writev longer than IOV_MAX" { | 639 | test "writev longer than IOV_MAX" { |
| 625 | if (native_os == .windows or native_os == .wasi) return error.SkipZigTest; | 640 | if (native_os == .windows or native_os == .wasi) return error.SkipZigTest; |
| 626 | 641 |
lib/std/process/Child.zig+6-2| ... | @@ -85,8 +85,8 @@ expand_arg0: Arg0Expand, | ... | @@ -85,8 +85,8 @@ expand_arg0: Arg0Expand, |
| 85 | /// Darwin-only. Disable ASLR for the child process. | 85 | /// Darwin-only. Disable ASLR for the child process. |
| 86 | disable_aslr: bool = false, | 86 | disable_aslr: bool = false, |
| 87 | 87 | ||
| 88 | /// Darwin and Windows only. Start child process in suspended state. For Darwin it's started | 88 | /// Start child process in suspended state. |
| 89 | /// as if SIGSTOP was sent. | 89 | /// For Posix systems it's started as if SIGSTOP was sent. |
| 90 | start_suspended: bool = false, | 90 | start_suspended: bool = false, |
| 91 | 91 | ||
| 92 | /// Windows-only. Sets the CREATE_NO_WINDOW flag in CreateProcess. | 92 | /// Windows-only. Sets the CREATE_NO_WINDOW flag in CreateProcess. |
| ... | @@ -669,6 +669,10 @@ fn spawnPosix(self: *ChildProcess) SpawnError!void { | ... | @@ -669,6 +669,10 @@ fn spawnPosix(self: *ChildProcess) SpawnError!void { |
| 669 | posix.setpgid(0, pid) catch |err| forkChildErrReport(err_pipe[1], err); | 669 | posix.setpgid(0, pid) catch |err| forkChildErrReport(err_pipe[1], err); |
| 670 | } | 670 | } |
| 671 | 671 | ||
| 672 | if (self.start_suspended) { | ||
| 673 | posix.kill(posix.getpid(), .STOP) catch |err| forkChildErrReport(err_pipe[1], err); | ||
| 674 | } | ||
| 675 | |||
| 672 | const err = switch (self.expand_arg0) { | 676 | const err = switch (self.expand_arg0) { |
| 673 | .expand => posix.execvpeZ_expandArg0(.expand, argv_buf.ptr[0].?, argv_buf.ptr, envp), | 677 | .expand => posix.execvpeZ_expandArg0(.expand, argv_buf.ptr[0].?, argv_buf.ptr, envp), |
| 674 | .no_expand => posix.execvpeZ_expandArg0(.no_expand, argv_buf.ptr[0].?, argv_buf.ptr, envp), | 678 | .no_expand => posix.execvpeZ_expandArg0(.no_expand, argv_buf.ptr[0].?, argv_buf.ptr, envp), |