From ca0450ee28e72c19526fbbfb2f17fc7e086b3258 Mon Sep 17 00:00:00 2001 From: DanielGavin Date: Wed, 12 Mar 2025 22:29:34 +0100 Subject: Add timeout for `odin check`. There are issues with macos and hanging odin processes. --- src/common/util.odin | 14 +++++++++++++- src/common/util_windows.odin | 14 ++++++++++++++ 2 files changed, 27 insertions(+), 1 deletion(-) (limited to 'src/common') diff --git a/src/common/util.odin b/src/common/util.odin index 08a846f..10845c4 100644 --- a/src/common/util.odin +++ b/src/common/util.odin @@ -8,6 +8,7 @@ import "core:os" import "core:path/filepath" import "core:path/slashpath" import "core:strings" +import "core:time" foreign import libc "system:c" @@ -84,6 +85,8 @@ when ODIN_OS == .Darwin || ODIN_OS == .Linux || ODIN_OS == .NetBSD { read_buffer: [50]byte index: int + current_time := time.now() + for fgets(&read_buffer[0], size_of(read_buffer), fp) != nil { read := bytes.index_byte(read_buffer[:], 0) defer index += cast(int)read @@ -91,6 +94,16 @@ when ODIN_OS == .Darwin || ODIN_OS == .Linux || ODIN_OS == .NetBSD { if read > 0 && index + cast(int)read <= len(stdout) { mem.copy(&stdout[index], &read_buffer[0], cast(int)read) } + + elapsed_time := time.now() + duration := time.diff(current_time, elapsed_time) + + if time.duration_seconds(duration) > 20 { + log.error("odin check timed out") + return 0, false, stdout[0:] + } + + current_time = elapsed_time } @@ -102,7 +115,6 @@ when ODIN_OS == .Darwin || ODIN_OS == .Linux || ODIN_OS == .NetBSD { popen :: proc(command: cstring, type: cstring) -> ^FILE --- pclose :: proc(stream: ^FILE) -> i32 --- fgets :: proc "cdecl" (s: [^]byte, n: i32, stream: ^FILE) -> [^]u8 --- - fgetc :: proc "cdecl" (stream: ^FILE) -> i32 --- } } diff --git a/src/common/util_windows.odin b/src/common/util_windows.odin index db280ad..6f4e0c1 100644 --- a/src/common/util_windows.odin +++ b/src/common/util_windows.odin @@ -4,6 +4,7 @@ import "core:fmt" import "core:log" import "core:mem" import "core:strings" +import "core:time" import win32 "core:sys/windows" @@ -126,6 +127,8 @@ run_executable :: proc(command: string, stdout: ^[]byte) -> (u32, bool, []byte) success: win32.BOOL = true + current_time := time.now() + for success { success = win32.ReadFile(stdout_read, &read_buffer[0], len(read_buffer), &read, nil) @@ -134,6 +137,17 @@ run_executable :: proc(command: string, stdout: ^[]byte) -> (u32, bool, []byte) } index += cast(int)read + + elapsed_time := time.now() + duration := time.diff(current_time, elapsed_time) + + if time.duration_seconds(duration) > 20 { + log.error("odin check timed out") + win32.TerminateProcess(process_info.hProcess, 1) + return 0, false, stdout[0:] + } + + current_time = elapsed_time } stdout[index + 1] = 0 -- cgit v1.2.3