mirror of
https://github.com/Dasharo/systemd.git
synced 2026-03-06 15:02:31 -08:00
coredumpctl: propagate SIGTERM to the debugger process
If we're waiting for the debugger process to exit and receive SIGTERM, propagate it to all processes in our process group, including the debugger, so we can follow it up with a proper cleanup. Resolves: #28772
This commit is contained in:
committed by
Luca Boccassi
parent
c4efe0e51e
commit
b2603465d4
@@ -1153,10 +1153,24 @@ static int dump_core(int argc, char **argv, void *userdata) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void sigterm_handler(int signal, siginfo_t *info, void *ucontext) {
|
||||
assert(signal == SIGTERM);
|
||||
assert(info);
|
||||
|
||||
/* If the sender is not us, propagate the signal to all processes in
|
||||
* the same process group */
|
||||
if (pid_is_valid(info->si_pid) && info->si_pid != getpid_cached())
|
||||
(void) kill(0, signal);
|
||||
}
|
||||
|
||||
static int run_debug(int argc, char **argv, void *userdata) {
|
||||
_cleanup_(sd_journal_closep) sd_journal *j = NULL;
|
||||
_cleanup_free_ char *exe = NULL, *path = NULL;
|
||||
_cleanup_strv_free_ char **debugger_call = NULL;
|
||||
struct sigaction sa = {
|
||||
.sa_sigaction = sigterm_handler,
|
||||
.sa_flags = SA_SIGINFO,
|
||||
};
|
||||
bool unlink_path = false;
|
||||
const char *data, *fork_name;
|
||||
size_t len;
|
||||
@@ -1250,6 +1264,7 @@ static int run_debug(int argc, char **argv, void *userdata) {
|
||||
|
||||
/* Don't interfere with gdb and its handling of SIGINT. */
|
||||
(void) ignore_signals(SIGINT);
|
||||
(void) sigaction(SIGTERM, &sa, NULL);
|
||||
|
||||
fork_name = strjoina("(", debugger_call[0], ")");
|
||||
|
||||
@@ -1266,7 +1281,7 @@ static int run_debug(int argc, char **argv, void *userdata) {
|
||||
r = wait_for_terminate_and_check(debugger_call[0], pid, WAIT_LOG_ABNORMAL);
|
||||
|
||||
finish:
|
||||
(void) default_signals(SIGINT);
|
||||
(void) default_signals(SIGINT, SIGTERM);
|
||||
|
||||
if (unlink_path) {
|
||||
log_debug("Removed temporary file %s", path);
|
||||
|
||||
Reference in New Issue
Block a user