Add ctrlc cancel to shell tool
This commit is contained in:
+10
-2
@@ -10,6 +10,7 @@
|
||||
#include <unistd.h>
|
||||
#include <signal.h>
|
||||
#include <cstring>
|
||||
#include "utility.hpp"
|
||||
|
||||
Tool make_shell_tool(bool safe) {
|
||||
std::string tool_name = safe ? "run_shell" : "run_dangerous_shell";
|
||||
@@ -96,8 +97,10 @@ Tool make_shell_tool(bool safe) {
|
||||
int res = poll(&pfd, 1, 1000);
|
||||
|
||||
if (res == 0) {
|
||||
if (std::chrono::steady_clock::now() - start_time
|
||||
< std::chrono::seconds(params.timeout_seconds))
|
||||
auto diff = std::chrono::steady_clock::now() - start_time;
|
||||
|
||||
if (diff < std::chrono::seconds(params.timeout_seconds) &&
|
||||
!ctrlc_request)
|
||||
{
|
||||
continue; // Not timed out yet
|
||||
}
|
||||
@@ -146,6 +149,11 @@ Tool make_shell_tool(bool safe) {
|
||||
int status;
|
||||
waitpid(pid, &status, 0);
|
||||
|
||||
if (ctrlc_request)
|
||||
{
|
||||
return "[user requested halt of program]\n" + output;
|
||||
}
|
||||
|
||||
if (timed_out) {
|
||||
return "[timed out after " + std::to_string(params.timeout_seconds) + "s]\n" + output;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user