Skip to content

Commit

Permalink
AbortHandler: better handle errors resuming parent process
Browse files Browse the repository at this point in the history
Report error and forcefully kill parent process when unable to resume it.
  • Loading branch information
FooBarWidget committed Oct 4, 2024
1 parent da90316 commit 74e8ed1
Showing 1 changed file with 59 additions and 4 deletions.
63 changes: 59 additions & 4 deletions src/agent/Shared/Fundamentals/AbortHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1080,19 +1080,55 @@ abortHandler(int signo, siginfo_t *info, void *_unused) {
// with SIGPIPE as a result, so we ignore SIGPIPE again.
ignoreSigpipe();
dumpDiagnostics(state);
// The child process may or may or may not resume the original process.
// We do it ourselves just to be sure.
kill(state.pid, SIGCONT);

pos = state.messageBuf;
pos = ASSU::appendData(pos, end, state.messagePrefix);
pos = ASSU::appendData(pos, end, " ] Triggering original signal handler");
pos = ASSU::appendData(pos, end, "\n");
write_nowarn(STDERR_FILENO, state.messageBuf, pos - state.messageBuf);

int ret = kill(state.pid, SIGCONT);
if (ret == -1) {
int e = errno;
pos = state.messageBuf;
pos = ASSU::appendData(pos, end, state.messagePrefix);
pos = ASSU::appendData(pos, end, " ] Could not continue original process: kill() failed with errno=");
pos = ASSU::appendInteger<int, 10>(pos, end, e);
pos = ASSU::appendData(pos, end, "\n");
write_nowarn(STDERR_FILENO, state.messageBuf, pos - state.messageBuf);

kill(state.pid, SIGKILL);
}

_exit(0);

} else if (child == -1) {
int e = errno;
pos = state.messageBuf;
pos = ASSU::appendData(pos, end, state.messagePrefix);
pos = ASSU::appendData(pos, end, "] Could not fork a child process for dumping diagnostics: fork() failed with errno=");
pos = ASSU::appendData(pos, end, " ] Could not fork a child process for dumping diagnostics: fork() failed with errno=");
pos = ASSU::appendInteger<int, 10>(pos, end, e);
pos = ASSU::appendData(pos, end, "\n");
write_nowarn(STDERR_FILENO, state.messageBuf, pos - state.messageBuf);

pos = state.messageBuf;
pos = ASSU::appendData(pos, end, state.messagePrefix);
pos = ASSU::appendData(pos, end, " ] Triggering original signal handler");
pos = ASSU::appendData(pos, end, "\n");
write_nowarn(STDERR_FILENO, state.messageBuf, pos - state.messageBuf);

int ret = kill(state.pid, SIGCONT);
if (ret == -1) {
int e = errno;
pos = state.messageBuf;
pos = ASSU::appendData(pos, end, state.messagePrefix);
pos = ASSU::appendData(pos, end, " ] Could not continue original process: kill() failed with errno=");
pos = ASSU::appendInteger<int, 10>(pos, end, e);
pos = ASSU::appendData(pos, end, "\n");
write_nowarn(STDERR_FILENO, state.messageBuf, pos - state.messageBuf);

kill(state.pid, SIGKILL);
}
_exit(1);

} else {
Expand All @@ -1109,6 +1145,25 @@ abortHandler(int signo, siginfo_t *info, void *_unused) {
pos = ASSU::appendData(pos, end, "\n");
write_nowarn(STDERR_FILENO, state.messageBuf, pos - state.messageBuf);

pos = state.messageBuf;
pos = ASSU::appendData(pos, end, state.messagePrefix);
pos = ASSU::appendData(pos, end, " ] Triggering original signal handler");
pos = ASSU::appendData(pos, end, "\n");
write_nowarn(STDERR_FILENO, state.messageBuf, pos - state.messageBuf);

int ret = kill(state.pid, SIGCONT);
if (ret == -1) {
int e = errno;
pos = state.messageBuf;
pos = ASSU::appendData(pos, end, state.messagePrefix);
pos = ASSU::appendData(pos, end, " ] Could not continue original process: kill() failed with errno=");
pos = ASSU::appendInteger<int, 10>(pos, end, e);
pos = ASSU::appendData(pos, end, "\n");
write_nowarn(STDERR_FILENO, state.messageBuf, pos - state.messageBuf);

kill(state.pid, SIGKILL);
}

} else {
raise(SIGSTOP);
// Will continue after the child process has done its job.
Expand Down

0 comments on commit 74e8ed1

Please sign in to comment.