mirror of
https://github.com/Ed94/Odin.git
synced 2026-08-03 22:28:46 +00:00
point stdin, stdout, stderr to /dev/null if unused in os2.process_start
This commit is contained in:
@@ -412,23 +412,51 @@ _process_start :: proc(desc: Process_Desc) -> (process: Process, err: Error) {
|
|||||||
|
|
||||||
if pid == 0 {
|
if pid == 0 {
|
||||||
// in child process now
|
// in child process now
|
||||||
|
stdin_fd: linux.Fd
|
||||||
|
stdout_fd: linux.Fd
|
||||||
|
stderr_fd: linux.Fd
|
||||||
|
|
||||||
if desc.stdin != nil {
|
if desc.stdin != nil {
|
||||||
fd := linux.Fd(fd(desc.stdin))
|
stdin_fd = linux.Fd(fd(desc.stdin))
|
||||||
if _, errno = linux.dup2(fd, STDIN); errno != .NONE {
|
} else {
|
||||||
intrinsics.trap()
|
stdin_fd, errno = linux.open("/dev/null", {})
|
||||||
|
if errno != nil {
|
||||||
|
intrinsics.trap() // TODO: our own special pipe
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
write_devnull: linux.Fd = -1
|
||||||
|
|
||||||
if desc.stdout != nil {
|
if desc.stdout != nil {
|
||||||
fd := linux.Fd(fd(desc.stdout))
|
stdout_fd = linux.Fd(fd(desc.stdout))
|
||||||
if _, errno = linux.dup2(fd, STDOUT); errno != .NONE {
|
} else {
|
||||||
intrinsics.trap()
|
write_devnull, errno = linux.open("/dev/null", {.WRONLY})
|
||||||
|
if errno != nil {
|
||||||
|
intrinsics.trap() // TODO
|
||||||
}
|
}
|
||||||
|
stdout_fd = write_devnull
|
||||||
}
|
}
|
||||||
|
|
||||||
if desc.stderr != nil {
|
if desc.stderr != nil {
|
||||||
fd := linux.Fd(fd(desc.stderr))
|
stderr_fd = linux.Fd(fd(desc.stderr))
|
||||||
if _, errno = linux.dup2(fd, STDERR); errno != .NONE {
|
} else {
|
||||||
intrinsics.trap()
|
if write_devnull == -1 {
|
||||||
|
write_devnull, errno = linux.open("/dev/null", {.WRONLY})
|
||||||
|
if errno != nil {
|
||||||
|
intrinsics.trap() // TODO
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
stderr_fd = write_devnull
|
||||||
|
}
|
||||||
|
|
||||||
|
if _, errno = linux.dup2(stdin_fd, STDIN); errno != .NONE {
|
||||||
|
intrinsics.trap()
|
||||||
|
}
|
||||||
|
if _, errno = linux.dup2(stdout_fd, STDOUT); errno != .NONE {
|
||||||
|
intrinsics.trap()
|
||||||
|
}
|
||||||
|
if _, errno = linux.dup2(stderr_fd, STDERR); errno != .NONE {
|
||||||
|
intrinsics.trap()
|
||||||
}
|
}
|
||||||
|
|
||||||
if errno = linux.execveat(exe_fd, "", &cargs[0], env, {.AT_EMPTY_PATH}); errno != .NONE {
|
if errno = linux.execveat(exe_fd, "", &cargs[0], env, {.AT_EMPTY_PATH}); errno != .NONE {
|
||||||
@@ -437,8 +465,6 @@ _process_start :: proc(desc: Process_Desc) -> (process: Process, err: Error) {
|
|||||||
unreachable()
|
unreachable()
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: We need to come up with a way to detect the execve failure from here.
|
|
||||||
|
|
||||||
process, err = process_open(int(pid))
|
process, err = process_open(int(pid))
|
||||||
if err == .Unsupported {
|
if err == .Unsupported {
|
||||||
return process, nil
|
return process, nil
|
||||||
|
|||||||
Reference in New Issue
Block a user