Only convert a signal number to a name if we are going to use it.

It is mostly used for debug logging.
This commit is contained in:
Todd C. Miller
2023-03-21 15:50:39 -06:00
parent adb84293ab
commit 1772fc7b66
2 changed files with 56 additions and 41 deletions

View File

@@ -71,23 +71,25 @@ struct monitor_closure {
static void
deliver_signal(struct monitor_closure *mc, int signo, bool from_parent)
{
char signame[SIG2STR_MAX];
debug_decl(deliver_signal, SUDO_DEBUG_EXEC);
/* Avoid killing more than a single process or process group. */
if (mc->cmnd_pid <= 0)
debug_return;
if (signo == SIGCONT_FG)
(void)strlcpy(signame, "CONT_FG", sizeof(signame));
else if (signo == SIGCONT_BG)
(void)strlcpy(signame, "CONT_BG", sizeof(signame));
else if (sig2str(signo, signame) == -1)
(void)snprintf(signame, sizeof(signame), "%d", signo);
if (sudo_debug_needed(SUDO_DEBUG_INFO)) {
char signame[SIG2STR_MAX];
if (signo == SIGCONT_FG)
(void)strlcpy(signame, "CONT_FG", sizeof(signame));
else if (signo == SIGCONT_BG)
(void)strlcpy(signame, "CONT_BG", sizeof(signame));
else if (sig2str(signo, signame) == -1)
(void)snprintf(signame, sizeof(signame), "%d", signo);
sudo_debug_printf(SUDO_DEBUG_INFO, "received SIG%s%s",
signame, from_parent ? " from parent" : "");
}
/* Handle signal from parent or monitor. */
sudo_debug_printf(SUDO_DEBUG_INFO, "received SIG%s%s",
signame, from_parent ? " from parent" : "");
switch (signo) {
case SIGALRM:
terminate_command(mc->cmnd_pid, true);