diff options
Diffstat (limited to '')
| -rw-r--r-- | src/tools/shell.rs | 23 |
1 files changed, 13 insertions, 10 deletions
diff --git a/src/tools/shell.rs b/src/tools/shell.rs index c64bab3..7f909bc 100644 --- a/src/tools/shell.rs +++ b/src/tools/shell.rs | |||
| @@ -1,3 +1,10 @@ | |||
| 1 | /* | ||
| 2 | * This file is part of agent686 | ||
| 3 | * Copyright (C) 2026 Salmonik <salmon@2137697.xyz> | ||
| 4 | * SPDX-License-Identifier: GPL-3.0-or-later | ||
| 5 | * https://git.2137697.xyz/agent686 | ||
| 6 | */ | ||
| 7 | |||
| 1 | use std::fs::File; | 8 | use std::fs::File; |
| 2 | use std::io::{Read, Seek, SeekFrom}; | 9 | use std::io::{Read, Seek, SeekFrom}; |
| 3 | use std::os::unix::process::{CommandExt, ExitStatusExt}; | 10 | use std::os::unix::process::{CommandExt, ExitStatusExt}; |
| @@ -32,11 +39,7 @@ impl Drop for TempGuard { | |||
| 32 | } | 39 | } |
| 33 | } | 40 | } |
| 34 | 41 | ||
| 35 | pub fn bash( | 42 | pub fn bash(args: &Value, timeout: Duration, cancel: &AtomicBool) -> Result<String, String> { |
| 36 | args: &Value, | ||
| 37 | timeout: Duration, | ||
| 38 | cancel: &AtomicBool, | ||
| 39 | ) -> Result<String, String> { | ||
| 40 | let cmd = match args | 43 | let cmd = match args |
| 41 | .get("cmd") | 44 | .get("cmd") |
| 42 | .or_else(|| args.get("command")) | 45 | .or_else(|| args.get("command")) |
| @@ -146,14 +149,14 @@ pub fn bash( | |||
| 146 | } else if aborted { | 149 | } else if aborted { |
| 147 | "[aborted by the user]".to_string() | 150 | "[aborted by the user]".to_string() |
| 148 | } else if timed_out { | 151 | } else if timed_out { |
| 149 | format!("[timed out after {:.1}s; process killed]", timeout.as_secs_f64()) | 152 | format!( |
| 153 | "[timed out after {:.1}s; process killed]", | ||
| 154 | timeout.as_secs_f64() | ||
| 155 | ) | ||
| 150 | } else { | 156 | } else { |
| 151 | match status.code() { | 157 | match status.code() { |
| 152 | Some(code) => format!("[exit {code}]"), | 158 | Some(code) => format!("[exit {code}]"), |
| 153 | None => format!( | 159 | None => format!("[killed by signal {}]", status.signal().unwrap_or_default()), |
| 154 | "[killed by signal {}]", | ||
| 155 | status.signal().unwrap_or_default() | ||
| 156 | ), | ||
| 157 | } | 160 | } |
| 158 | }; | 161 | }; |
| 159 | 162 | ||
