@@ -191,11 +191,13 @@ namespace vix::commands::RunCommand::detail
191191
192192 namespace
193193 {
194- static volatile sig_atomic_t g_sigint_requested = 0 ;
194+ static volatile sig_atomic_t g_signal_requested = 0 ;
195+ static volatile sig_atomic_t g_requested_signal = 0 ;
195196
196- void on_sigint (int )
197+ void on_runtime_signal (int sig )
197198 {
198- g_sigint_requested = 1 ;
199+ g_signal_requested = 1 ;
200+ g_requested_signal = sig;
199201 }
200202
201203 bool is_runtime_crash_noise_line (std::string_view line) noexcept
@@ -236,28 +238,58 @@ namespace vix::commands::RunCommand::detail
236238 return out;
237239 }
238240
239- struct SigintGuard
241+ struct RuntimeSignalGuard
240242 {
241- struct sigaction oldAction{};
242- bool installed = false ;
243+ struct sigaction oldInt{};
244+ struct sigaction oldTerm{};
245+ struct sigaction oldHup{};
243246
244- SigintGuard ()
247+ bool installedInt = false ;
248+ bool installedTerm = false ;
249+ bool installedHup = false ;
250+
251+ RuntimeSignalGuard ()
245252 {
246- g_sigint_requested = 0 ;
253+ g_signal_requested = 0 ;
254+ g_requested_signal = 0 ;
247255
248256 struct sigaction sa{};
249- sa.sa_handler = on_sigint ;
257+ sa.sa_handler = on_runtime_signal ;
250258 sigemptyset (&sa.sa_mask );
251259 sa.sa_flags = 0 ;
252260
253- if (sigaction (SIGINT , &sa, &oldAction) == 0 )
254- installed = true ;
261+ if (sigaction (SIGINT , &sa, &oldInt) == 0 )
262+ {
263+ installedInt = true ;
264+ }
265+
266+ if (sigaction (SIGTERM , &sa, &oldTerm) == 0 )
267+ {
268+ installedTerm = true ;
269+ }
270+
271+ if (sigaction (SIGHUP , &sa, &oldHup) == 0 )
272+ {
273+ installedHup = true ;
274+ }
255275 }
256276
257- ~SigintGuard ()
277+ ~RuntimeSignalGuard ()
258278 {
259- if (installed)
260- sigaction (SIGINT , &oldAction, nullptr );
279+ if (installedInt)
280+ {
281+ sigaction (SIGINT , &oldInt, nullptr );
282+ }
283+
284+ if (installedTerm)
285+ {
286+ sigaction (SIGTERM , &oldTerm, nullptr );
287+ }
288+
289+ if (installedHup)
290+ {
291+ sigaction (SIGHUP , &oldHup, nullptr );
292+ }
261293 }
262294 };
263295
@@ -1297,7 +1329,7 @@ namespace vix::commands::RunCommand::detail
12971329 bool captureOnly,
12981330 vix::commands::replay::ReplayCapture *replayCapture)
12991331 {
1300- SigintGuard sigGuard ;
1332+ RuntimeSignalGuard signalGuard ;
13011333 LiveRunResult result;
13021334
13031335 PtySession pty;
@@ -1465,10 +1497,15 @@ namespace vix::commands::RunCommand::detail
14651497
14661498 while (running)
14671499 {
1468- if (!sentInt && g_sigint_requested )
1500+ if (!sentInt && g_signal_requested )
14691501 {
1470- userInterrupted = true ;
1471- kill_group_or_pid (pid, SIGINT );
1502+ const int requestedSignal =
1503+ g_requested_signal > 0 ? static_cast <int >(g_requested_signal) : SIGTERM ;
1504+
1505+ userInterrupted = requestedSignal == SIGINT ;
1506+
1507+ kill_group_or_pid (pid, requestedSignal);
1508+
14721509 sentInt = true ;
14731510 intTime = std::chrono::steady_clock::now ();
14741511 }
0 commit comments