[sudo-users] How sudo handles signals

Nuno Gonçalves nunojpg at gmail.com
Thu Dec 29 21:10:39 EST 2011


Yup...Sometimes it prints tens of kernel only messages, but if I keep
pressing CTRL+C continuously the process messages appear!
Doesn't this happen on your computer?

^CSIGINT received from kernel
^CSIGINT received from kernel
^CSIGINT received from kernel
^CSIGINT received from kernel
^CSIGINT received from kernel
^CSIGINT received from kernel
SIGINT received from user process
^CSIGINT received from kernel
SIGINT received from user process
^CSIGINT received from kernel
SIGINT received from user process
^CSIGINT received from kernel
SIGINT received from user process
^CSIGINT received from kernel
SIGINT received from user process
^CSIGINT received from kernel
SIGINT received from user process
^CSIGINT received from kernel
SIGINT received from user process
^CSIGINT received from kernel
SIGINT received from user process
^CSIGINT received from kernel
^CSIGINT received from kernel

This machine:
nuno at flores1:~$ uname -a
Linux flores1 3.0.0-14-generic #23-Ubuntu SMP Mon Nov 21 20:28:43 UTC
2011 x86_64 x86_64 x86_64 GNU/Linux
nuno at flores1:~$ sudo -V
Sudo version 1.7.4p6
nuno at flores1:~$

Regards,
Nuno

2011/12/27 Todd C. Miller <Todd.Miller at courtesan.com>:
> 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