[sudo-users] How sudo handles signals
Todd C. Miller
Todd.Miller at courtesan.com
Tue Dec 27 13:13:37 EST 2011
Your test program uses stdio functions in the signal handler which
is unsafe (stdio's state can become corrupted by this). Can you
try the following? If the process really is getting an extra SIGINT
from the sudo process it should print:
SIGINT received from kernel
SIGINT received from user process
sometimes when you hit control-C. You will get a compiler warning
on line 32 but you can safely ignore this.
- todd
#include <stdio.h>
#include <stdlib.h>
#include <fcntl.h>
#include <unistd.h>
#include <signal.h>
#include <string.h>
#define MESSAGE_USER "SIGINT received from user process\n"
#define MESSAGE_KERNEL "SIGINT received from kernel\n"
void
sigint(int signo, siginfo_t *info, void *context)
{
if (info->si_code <= 0)
write(STDOUT_FILENO, MESSAGE_USER, sizeof(MESSAGE_USER) - 1);
else
write(STDOUT_FILENO, MESSAGE_KERNEL, sizeof(MESSAGE_KERNEL) - 1);
}
int
main(int argc, char *argv[])
{
struct sigaction sa;
sigset_t mask;
sigemptyset(&mask);
memset(&sa, 0, sizeof(sa));
sigemptyset(&sa.sa_mask);
sa.sa_flags = SA_RESTART|SA_SIGINFO;
sa.sa_handler = sigint;
sigaction(SIGINT, &sa, NULL);
for (;;) {
sigsuspend(&mask);
}
/* NOTREACHED */
exit(1);
}
More information about the sudo-users
mailing list