From ae0014d6f4d67d43aa92cb638aa95319eebf419c Mon Sep 17 00:00:00 2001 From: "Todd C. Miller" Date: Mon, 28 Jul 2014 20:25:46 -0600 Subject: [PATCH] Attempt to handle systems with SA_SIGINFO but that lack SI_USER. --- src/exec.c | 4 ++-- src/exec_pty.c | 2 +- src/sudo_exec.h | 11 +++++++++++ 3 files changed, 14 insertions(+), 3 deletions(-) diff --git a/src/exec.c b/src/exec.c index 0c5163db2..275ee7585 100644 --- a/src/exec.c +++ b/src/exec.c @@ -870,7 +870,7 @@ handler(int s, siginfo_t *info, void *context) * kill itself. For example, this can happen with some versions of * reboot that call kill(-1, SIGTERM) to kill all other processes. */ - if (info != NULL && info->si_code == SI_USER) { + if (USER_SIGNALED(info)) { pid_t si_pgrp = getpgid(info->si_pid); if (si_pgrp != (pid_t)-1) { if (si_pgrp == ppgrp || si_pgrp == cmnd_pid) @@ -926,7 +926,7 @@ handler_user_only(int s, siginfo_t *info, void *context) * often trap ^Z and send SIGTSTP to their own pgrp, so we don't * want to send an extra SIGTSTP. */ - if (info == NULL || info->si_code != SI_USER) + if (!USER_SIGNALED(info)) return; if ((si_pgrp = getpgid(info->si_pid)) != (pid_t)-1) { if (si_pgrp == ppgrp || si_pgrp == cmnd_pid) diff --git a/src/exec_pty.c b/src/exec_pty.c index 9facbfb68..e6c97525d 100644 --- a/src/exec_pty.c +++ b/src/exec_pty.c @@ -141,7 +141,7 @@ mon_handler(int s, siginfo_t *info, void *context) * itself. This can happen with, e.g., BSD-derived versions of * reboot that call kill(-1, SIGTERM) to kill all other processes. */ - if (info != NULL && info->si_code == SI_USER) { + if (USER_SIGNALED(info)) { pid_t si_pgrp = getpgid(info->si_pid); if (si_pgrp != (pid_t)-1) { if (si_pgrp == cmnd_pgrp) diff --git a/src/sudo_exec.h b/src/sudo_exec.h index 9be208e36..4c09e4649 100644 --- a/src/sudo_exec.h +++ b/src/sudo_exec.h @@ -24,6 +24,17 @@ # define MSG_WAITALL 0 #endif +/* + * Some older systems support siginfo but predate SI_USER. + */ +#ifdef SA_SIGINFO +# ifdef SI_USER +# define USER_SIGNALED(_info) ((_info) != NULL && (_info)->si_code == SI_USER) +# else +# define USER_SIGNALED(_info) ((_info) != NULL && (_info)->si_code <= 0) +# endif +#endif + /* * Special values to indicate whether continuing in foreground or background. */ -- 2.40.0