Skip to content

Commit d44cbd1

Browse files
committed
fix(cli): treat script SIGINT as normal shutdown
1 parent e09c04f commit d44cbd1

2 files changed

Lines changed: 31 additions & 0 deletions

File tree

src/commands/RunCommand.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -555,8 +555,16 @@ namespace
555555
if (opt.singleCpp)
556556
{
557557
int rc = vix::commands::RunCommand::detail::run_single_cpp(opt);
558+
559+
if (rc == 130)
560+
{
561+
hint("ℹ Program interrupted by user (SIGINT).");
562+
return 0;
563+
}
564+
558565
if (rc < 0)
559566
return -rc;
567+
560568
return rc;
561569
}
562570

src/commands/run/detail/DirectScriptRunner.cpp

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,10 @@
2727
#include <string>
2828
#include <system_error>
2929

30+
#ifndef _WIN32
31+
#include <signal.h>
32+
#endif
33+
3034
namespace vix::commands::RunCommand::detail
3135
{
3236
namespace process = vix::cli::commands::helpers;
@@ -63,6 +67,19 @@ namespace vix::commands::RunCommand::detail
6367
#endif
6468
}
6569

70+
#ifndef _WIN32
71+
bool is_user_interrupt_result(const LiveRunResult &result) noexcept
72+
{
73+
return result.exitCode == 130 ||
74+
(result.terminatedBySignal && result.termSignal == SIGINT);
75+
}
76+
#else
77+
bool is_user_interrupt_result(const LiveRunResult &result) noexcept
78+
{
79+
return result.exitCode == 130;
80+
}
81+
#endif
82+
6683
/**
6784
* @brief Return a filesystem-safe executable name.
6885
*/
@@ -516,6 +533,12 @@ namespace vix::commands::RunCommand::detail
516533
opt.enableSanitizers || opt.enableUbsanOnly,
517534
false);
518535

536+
if (is_user_interrupt_result(run))
537+
{
538+
hint("ℹ Program interrupted by user (SIGINT).");
539+
return 0;
540+
}
541+
519542
handle_runtime_exit_code(run.exitCode, "run", run.failureHandled);
520543
return run.exitCode;
521544
}

0 commit comments

Comments
 (0)