mirror of
https://github.com/Ed94/Odin.git
synced 2026-08-06 07:38:48 +00:00
fix error handling; close read end of the child pipe instead of the write end twice
This commit is contained in:
@@ -61,6 +61,9 @@ _process_list :: proc(allocator: runtime.Allocator) -> (list: []int, err: Error)
|
|||||||
return {}, .Invalid_Dir
|
return {}, .Invalid_Dir
|
||||||
case .ENOENT:
|
case .ENOENT:
|
||||||
return {}, .Not_Exist
|
return {}, .Not_Exist
|
||||||
|
case .NONE:
|
||||||
|
case:
|
||||||
|
return {}, _get_platform_error(errno)
|
||||||
}
|
}
|
||||||
defer linux.close(dir_fd)
|
defer linux.close(dir_fd)
|
||||||
|
|
||||||
@@ -482,16 +485,31 @@ _process_start :: proc(desc: Process_Desc) -> (process: Process, err: Error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
linux.close(child_pipe_fds[WRITE])
|
linux.close(child_pipe_fds[WRITE])
|
||||||
defer linux.close(child_pipe_fds[WRITE])
|
defer linux.close(child_pipe_fds[READ])
|
||||||
|
|
||||||
|
process.pid = int(pid)
|
||||||
|
|
||||||
n: int
|
n: int
|
||||||
child_byte: [1]u8
|
child_byte: [1]u8
|
||||||
n, errno = linux.read(child_pipe_fds[READ], child_byte[:])
|
errno = .EINTR
|
||||||
if errno != .NONE {
|
for errno == .EINTR {
|
||||||
return process, _get_platform_error(errno)
|
n, errno = linux.read(child_pipe_fds[READ], child_byte[:])
|
||||||
}
|
}
|
||||||
|
if errno != .NONE {
|
||||||
|
child_state, _ := process_wait(process, 0)
|
||||||
|
if child_state.exited {
|
||||||
|
process.pid = 0 // If the child exited, we reaped it.
|
||||||
|
return process, _get_platform_error(errno)
|
||||||
|
}
|
||||||
|
// else.. something weird happened, but there IS a running process.
|
||||||
|
// Do not return the read error so the user knows to wait on it.
|
||||||
|
}
|
||||||
|
|
||||||
child_errno := linux.Errno(child_byte[0])
|
child_errno := linux.Errno(child_byte[0])
|
||||||
if child_errno != .NONE {
|
if child_errno != .NONE {
|
||||||
|
// We can assume it trapped here.
|
||||||
|
_reap_terminated(process)
|
||||||
|
process.pid = 0
|
||||||
return process, _get_platform_error(child_errno)
|
return process, _get_platform_error(child_errno)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -559,6 +577,7 @@ _reap_terminated :: proc(process: Process) -> (state: Process_State, err: Error)
|
|||||||
|
|
||||||
switch linux.Sig_Child_Code(info.code) {
|
switch linux.Sig_Child_Code(info.code) {
|
||||||
case .NONE, .CONTINUED, .STOPPED:
|
case .NONE, .CONTINUED, .STOPPED:
|
||||||
|
unreachable()
|
||||||
case .EXITED:
|
case .EXITED:
|
||||||
state.exited = true
|
state.exited = true
|
||||||
state.exit_code = int(info.status)
|
state.exit_code = int(info.status)
|
||||||
|
|||||||
Reference in New Issue
Block a user