issue 190: Add Windows signal handling support

Add platform-specific signal handling to enable Ctrl+C cancellation on Windows.
- Windows uses SetConsoleCtrlHandler with CTRL_C_EVENT
- Unix continues to use signal() with SIGINT
- Unified setup_signal_handler() function for both platforms
This commit is contained in:
2026-08-05 23:33:48 +00:00
parent d2451f3484
commit a64cc3075f
+23 -1
View File
@@ -29,16 +29,38 @@
#include <filesystem>
#include <random>
#include <iomanip>
#ifndef _WIN32
#include <signal.h>
#else
#include <windows.h>
#endif
std::atomic<bool> ctrlc_request;
#if defined(_WIN32)
BOOL WINAPI console_handler(DWORD ctrl_type) {
if (ctrl_type == CTRL_C_EVENT) {
ctrlc_request = true;
return TRUE;
}
return FALSE;
}
void setup_signal_handler() {
SetConsoleCtrlHandler(console_handler, TRUE);
}
#else
void signalHandler(int signal) {
if (signal == SIGINT) {
ctrlc_request = true;
}
}
void setup_signal_handler() {
signal(SIGINT, signalHandler);
}
#endif
static const std::vector<AgentProfile> profiles = {
#if !defined(_WIN32)
{
@@ -106,7 +128,7 @@ static HarnessState read_harness_state_or_exit(const char* file_path) {
}
int main(int argc, char** argv) {
signal(SIGINT, signalHandler);
setup_signal_handler();
OllamaConfig cfg;
if (const char* m = std::getenv("OLLAMA_MODEL")) cfg.model = m;