Skip to content

Commit f0cb00d

Browse files
committed
cli(run): detect signal termination and disable core dumps
Properly report SIGSEGV/SIGABRT via exit codes, expose terminatedBySignal info, and prevent core dumps by setting RLIMIT_CORE before exec.
1 parent 9fff0f8 commit f0cb00d

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

include/vix/cli/commands/run/RunDetail.hpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,9 @@ namespace vix::commands::RunCommand::detail
119119
std::string stderrText;
120120
bool failureHandled = false;
121121
bool printed_live = false;
122+
123+
bool terminatedBySignal = false;
124+
int termSignal = 0;
122125
};
123126

124127
LiveRunResult run_cmd_live_filtered_capture(

src/commands/run/RunProcess.cpp

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
#include <sys/select.h>
3030
#include <sys/types.h>
3131
#include <sys/wait.h>
32+
#include <sys/resource.h>
3233
#include <unistd.h>
3334
#endif
3435

@@ -612,6 +613,13 @@ namespace vix::commands::RunCommand::detail
612613
if (::getenv("VIX_MODE") == nullptr)
613614
::setenv("VIX_MODE", "run", 1);
614615

616+
#ifdef RLIMIT_CORE
617+
struct rlimit rl;
618+
rl.rlim_cur = 0;
619+
rl.rlim_max = 0;
620+
::setrlimit(RLIMIT_CORE, &rl);
621+
#endif
622+
615623
::execl("/bin/sh", "sh", "-c", cmd.c_str(), (char *)nullptr);
616624
_exit(127);
617625
}
@@ -1140,7 +1148,18 @@ namespace vix::commands::RunCommand::detail
11401148
return result;
11411149
}
11421150

1143-
result.exitCode = haveStatus ? normalize_exit_code(finalStatus) : 1;
1151+
if (haveStatus && WIFSIGNALED(finalStatus))
1152+
{
1153+
const int sig = WTERMSIG(finalStatus);
1154+
result.terminatedBySignal = true;
1155+
result.termSignal = sig;
1156+
1157+
result.exitCode = 128 + sig;
1158+
}
1159+
else
1160+
{
1161+
result.exitCode = haveStatus ? normalize_exit_code(finalStatus) : 1;
1162+
}
11441163

11451164
if (!captureOnly &&
11461165
printedRealOutput &&

0 commit comments

Comments
 (0)