aboutsummaryrefslogtreecommitdiff
path: root/core
diff options
context:
space:
mode:
authorLaytan Laats <laytanlaats@hotmail.com>2024-10-04 10:38:47 +0200
committerLaytan Laats <laytanlaats@hotmail.com>2024-10-04 10:38:47 +0200
commit77b033cf96af6a2cafcee23e52ea6e220f1beae4 (patch)
tree16f430aafd67ccb28a2ffb638c2573b4bb6e7a27 /core
parent5d556fe277c924b910308383f63785f9c5376cc3 (diff)
kill process if there was an error during reading to not leave a zombie
Diffstat (limited to 'core')
-rw-r--r--core/os/os2/process.odin83
1 files changed, 43 insertions, 40 deletions
diff --git a/core/os/os2/process.odin b/core/os/os2/process.odin
index c034a9fea..4e361f1d9 100644
--- a/core/os/os2/process.odin
+++ b/core/os/os2/process.odin
@@ -395,54 +395,57 @@ process_exec :: proc(
process = process_start(desc) or_return
}
- stdout_builder := strings.builder_make(allocator) or_return
- stderr_builder := strings.builder_make(allocator) or_return
-
- has_stdout, has_stderr: bool
- read_data: for !has_stdout || !has_stderr {
- buf: [1024]u8 = ---
- n: int
- has_data: bool
-
- if !has_stdout {
- has_data, err = pipe_has_data(stdout_r)
- if has_data {
- n, err = read(stdout_r, buf[:])
- if strings.write_bytes(&stdout_builder, buf[:n]) != n {
- err = .Out_Of_Memory
+ {
+ defer if err != nil { _ = process_kill(process) }
+
+ stdout_builder := strings.builder_make(allocator) or_return
+ stderr_builder := strings.builder_make(allocator) or_return
+
+ has_stdout, has_stderr: bool
+ read_data: for !has_stdout || !has_stderr {
+ buf: [1024]u8 = ---
+ n: int
+ has_data: bool
+
+ if !has_stdout {
+ has_data, err = pipe_has_data(stdout_r)
+ if has_data {
+ n, err = read(stdout_r, buf[:])
+ if strings.write_bytes(&stdout_builder, buf[:n]) != n {
+ err = .Out_Of_Memory
+ }
+ }
+ switch err {
+ case nil: // nothing
+ case .EOF, .Broken_Pipe:
+ stdout = stdout_builder.buf[:]
+ has_stdout = true
+ case:
+ return
}
}
- switch err {
- case nil: // nothing
- case .EOF, .Broken_Pipe:
- stdout = stdout_builder.buf[:]
- has_stdout = true
- case:
- return
- }
- }
- if !has_stderr {
- has_data, err = pipe_has_data(stderr_r)
- if has_data {
- n, err = read(stderr_r, buf[:])
- if strings.write_bytes(&stderr_builder, buf[:n]) != n {
- err = .Out_Of_Memory
+ if !has_stderr {
+ has_data, err = pipe_has_data(stderr_r)
+ if has_data {
+ n, err = read(stderr_r, buf[:])
+ if strings.write_bytes(&stderr_builder, buf[:n]) != n {
+ err = .Out_Of_Memory
+ }
+ }
+ switch err {
+ case nil: // nothing
+ case .EOF, .Broken_Pipe:
+ stderr = stderr_builder.buf[:]
+ has_stderr = true
+ case:
+ return
}
- }
- switch err {
- case nil: // nothing
- case .EOF, .Broken_Pipe:
- stderr = stderr_builder.buf[:]
- has_stderr = true
- case:
- return
}
}
}
- err = nil
- state = process_wait(process) or_return
+ state, err = process_wait(process)
return
}