| author | |
| committer | |
| log | 6d47198303847409a900f57bbe84195b32375093 |
| tree | 58cf515c3cea23b281cee0e7d41b61f7fdbbafa2 |
| parent | 7a9500fd80990a3dc47821e627162bf769eecbba |
3 files changed, 12 insertions(+), 5 deletions(-)
lib/std/child_process.zig+8-2| ... | @@ -221,7 +221,10 @@ pub const ChildProcess = struct { | ... | @@ -221,7 +221,10 @@ pub const ChildProcess = struct { |
| 221 | return term; | 221 | return term; |
| 222 | } | 222 | } |
| 223 | 223 | ||
| 224 | try windows.TerminateProcess(self.id, exit_code); | 224 | windows.TerminateProcess(self.id, exit_code) catch |err| switch (err) { |
| 225 | error.PermissionDenied => return error.AlreadyTerminated, | ||
| 226 | else => return err, | ||
| 227 | }; | ||
| 225 | try self.waitUnwrappedWindows(); | 228 | try self.waitUnwrappedWindows(); |
| 226 | return self.term.?; | 229 | return self.term.?; |
| 227 | } | 230 | } |
| ... | @@ -231,7 +234,10 @@ pub const ChildProcess = struct { | ... | @@ -231,7 +234,10 @@ pub const ChildProcess = struct { |
| 231 | self.cleanupStreams(); | 234 | self.cleanupStreams(); |
| 232 | return term; | 235 | return term; |
| 233 | } | 236 | } |
| 234 | try os.kill(self.id, os.SIG.TERM); | 237 | os.kill(self.id, os.SIG.TERM) catch |err| switch (err) { |
| 238 | error.ProcessNotFound => return error.AlreadyTerminated, | ||
| 239 | else => return err, | ||
| 240 | }; | ||
| 235 | try self.waitUnwrapped(); | 241 | try self.waitUnwrapped(); |
| 236 | return self.term.?; | 242 | return self.term.?; |
| 237 | } | 243 | } |
lib/std/os.zig+2-2| ... | @@ -639,14 +639,14 @@ pub fn raise(sig: u8) RaiseError!void { | ... | @@ -639,14 +639,14 @@ pub fn raise(sig: u8) RaiseError!void { |
| 639 | @compileError("std.os.raise unimplemented for this target"); | 639 | @compileError("std.os.raise unimplemented for this target"); |
| 640 | } | 640 | } |
| 641 | 641 | ||
| 642 | pub const KillError = error{PermissionDenied} || UnexpectedError; | 642 | pub const KillError = error{ ProcessNotFound, PermissionDenied } || UnexpectedError; |
| 643 | 643 | ||
| 644 | pub fn kill(pid: pid_t, sig: u8) KillError!void { | 644 | pub fn kill(pid: pid_t, sig: u8) KillError!void { |
| 645 | switch (errno(system.kill(pid, sig))) { | 645 | switch (errno(system.kill(pid, sig))) { |
| 646 | .SUCCESS => return, | 646 | .SUCCESS => return, |
| 647 | .INVAL => unreachable, // invalid signal | 647 | .INVAL => unreachable, // invalid signal |
| 648 | .PERM => return error.PermissionDenied, | 648 | .PERM => return error.PermissionDenied, |
| 649 | .SRCH => unreachable, // always a race condition | 649 | .SRCH => return error.ProcessNotFound, |
| 650 | else => |err| return unexpectedErrno(err), | 650 | else => |err| return unexpectedErrno(err), |
| 651 | } | 651 | } |
| 652 | } | 652 | } |
lib/std/os/windows.zig+2-1| ... | @@ -1593,11 +1593,12 @@ pub fn GetModuleFileNameW(hModule: ?HMODULE, buf_ptr: [*]u16, buf_len: DWORD) Ge | ... | @@ -1593,11 +1593,12 @@ pub fn GetModuleFileNameW(hModule: ?HMODULE, buf_ptr: [*]u16, buf_len: DWORD) Ge |
| 1593 | return buf_ptr[0..rc :0]; | 1593 | return buf_ptr[0..rc :0]; |
| 1594 | } | 1594 | } |
| 1595 | 1595 | ||
| 1596 | pub const TerminateProcessError = error{Unexpected}; | 1596 | pub const TerminateProcessError = error{ PermissionDenied, Unexpected }; |
| 1597 | 1597 | ||
| 1598 | pub fn TerminateProcess(hProcess: HANDLE, uExitCode: UINT) TerminateProcessError!void { | 1598 | pub fn TerminateProcess(hProcess: HANDLE, uExitCode: UINT) TerminateProcessError!void { |
| 1599 | if (kernel32.TerminateProcess(hProcess, uExitCode) == 0) { | 1599 | if (kernel32.TerminateProcess(hProcess, uExitCode) == 0) { |
| 1600 | switch (kernel32.GetLastError()) { | 1600 | switch (kernel32.GetLastError()) { |
| 1601 | Win32Error.ACCESS_DENIED => return error.PermissionDenied, | ||
| 1601 | else => |err| return unexpectedError(err), | 1602 | else => |err| return unexpectedError(err), |
| 1602 | } | 1603 | } |
| 1603 | } | 1604 | } |