summaryrefslogtreecommitdiffstats
path: root/src/tools/shell.rs
diff options
context:
space:
mode:
authorsalmonik <salmon@2137697.xyz>2026-11-23 20:36:22 +0100
committersalmonik <salmon@2137697.xyz>2026-11-23 20:36:22 +0100
commite803aa488c3a95193d3e3ae358b640c299f8f121 (patch)
tree0af80401445159ca40a8ab3d7bbf39094ab5db77 /src/tools/shell.rs
parent0.12.1: accept `command` as an alias for `cmd` in bash (diff)
downloadagent686-e803aa488c3a95193d3e3ae358b640c299f8f121.tar.gz
agent686-e803aa488c3a95193d3e3ae358b640c299f8f121.zip
License
Diffstat (limited to '')
-rw-r--r--src/tools/shell.rs23
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
1use std::fs::File; 8use std::fs::File;
2use std::io::{Read, Seek, SeekFrom}; 9use std::io::{Read, Seek, SeekFrom};
3use std::os::unix::process::{CommandExt, ExitStatusExt}; 10use std::os::unix::process::{CommandExt, ExitStatusExt};
@@ -32,11 +39,7 @@ impl Drop for TempGuard {
32 } 39 }
33} 40}
34 41
35pub fn bash( 42pub 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