diff options
| author | Paul Buetow <paul@buetow.org> | 2026-06-13 10:15:20 +0300 |
|---|---|---|
| committer | Paul Buetow <paul@buetow.org> | 2026-06-13 10:15:20 +0300 |
| commit | d4971998edae804c39797486be7a342d43e61e5c (patch) | |
| tree | 830c008847704b40b7f45d4c7c620beed03958d6 /src/lib/process.source.sh | |
| parent | e9437367b8fc7a4cb0ffed6c0a8ba89356a3b9ad (diff) | |
Refactor helper modules for im0
Diffstat (limited to 'src/lib/process.source.sh')
| -rw-r--r-- | src/lib/process.source.sh | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/src/lib/process.source.sh b/src/lib/process.source.sh new file mode 100644 index 0000000..5596e03 --- /dev/null +++ b/src/lib/process.source.sh @@ -0,0 +1,24 @@ +run_with_timeout() { + local -r description="$1"; shift + local -r seconds="$1"; shift + local -i status=0 + + if ! command -v timeout >/dev/null 2>&1; then + printf 'ERROR: timeout command is required to run %s\n' \ + "$description" >&2 + return 127 + fi + + if timeout "$seconds" "$@"; then + return + else + status=$? + fi + + if (( status == 124 )); then + printf 'ERROR: %s timed out after %s seconds\n' \ + "$description" "$seconds" >&2 + fi + + return "$status" +} |
