[BusyBox] ash - signal handling problem?

Jean Wolter jw5 at os.inf.tu-dresden.de
Sat Jan 31 14:11:53 UTC 2004


Hello,

the current ash shows a strange behaviour regarding signal and error
handling. 

    1. If I press ctrl d to terminate my session it is silently
    ignored.

    2. If I log into a machine via ssh and the ssh client is killed
    via kill -9 ash ends up in a loop raising SIGINT and ignoring it
    afterwards (ash ignored the hup signal because it was set to
    ignore via trap "" 1).

The reason for this is onint (). It simply ignores the signal under
certain conditions:

        if (!(rootshell && iflag)) {
            signal(SIGINT, SIG_DFL);
            raise(SIGINT);
        }

A strace shows, that onint is called, detects that the signal is not
handled via trap and then just ignores it. To see this I have
instrumented ash like follows:

static void
onint(void) {
    int i;
    write (1, "onint", 5);
    intpending = 0;
    sigsetmask(0);
    i = EXSIG;
    if (gotsig[SIGINT - 1] && !trap[SIGINT]) {
        write (1, " onint 1 ", 9);
        if (!(rootshell && iflag)) {
          write (1, " onint 2 ", 9);
            signal(SIGINT, SIG_DFL);
            raise(SIGINT);
        }
        write (1, " onint 3 ", 9);
        i = EXINT;
    }
    write (1, " onint 4 ", 9);
    exraise(i);
    /* NOTREACHED */
}

The corresponding strace looks like follows; "onint 2", which would
actually lead to the end of the process is never reached, ash
endlessly raises SIGINT just to ignote it in the signal handler:

[4002b670] --- SIGHUP (Hangup) ---
[4002b670] --- SIGCONT (Continued) ---
[4002c120] ioctl(0, SNDCTL_TMR_START, {B38400 opost isig icanon echo
...}) = -1 
EIO (Input/output error)
[4002dbdc] rt_sigaction(SIGWINCH, {SIG_DFL}, {0x8068f30, [WINCH],
SA_RESTART|0x4
000000}, 8) = 0
[4002ba77] getpid()                     = 920
[4002bde5] kill(920, SIGINT)            = 0
[4002bde5] --- SIGINT (Interrupt) ---
[4002b6b4] write(1, "onsig", 5)         = -1 EIO (Input/output error)
[4002b6b4] write(1, "onint", 5)         = -1 EIO (Input/output error)
[4002dc28] rt_sigprocmask(SIG_SETMASK, [], ~[KILL STOP], 8) = 0
[4002b6b4] write(1, " onint 1 ", 9)     = -1 EIO (Input/output error)
[4002b6b4] write(1, " onint 3 ", 9)     = -1 EIO (Input/output error)
[4002b6b4] write(1, " onint 4 ", 9)     = -1 EIO (Input/output error)
[4002b6b4] write(2, "\n", 1)            = -1 EIO (Input/output error)
[4002cee4] wait4(-1, 0xbffffcc8, WNOHANG|WUNTRACED, NULL) = -1 ECHILD
(No child 
processes)
[4002c120] ioctl(0, SNDCTL_TMR_TIMEBASE, 0xbffffc3c) = -1 EIO
(Input/output erro
r)
[4002c120] ioctl(0, SNDCTL_TMR_START, {B50 -opost -isig -icanon -echo
...}) = -1
 EIO (Input/output error)
[4002dbdc] rt_sigaction(SIGWINCH, {0x8068f30, [WINCH],
SA_RESTART|0x4000000}, {S
IG_DFL}, 8) = 0
[4002b6b4] write(1, "fli4l 2.1.5 # ", 14) = -1 EIO (Input/output
error)
[4002b670] read(0, "", 1)               = 0
[4002c120] ioctl(0, SNDCTL_TMR_START, {B50 -opost -isig -icanon -echo
...}) = -1
 EIO (Input/output error)
[4002dbdc] rt_sigaction(SIGWINCH, {SIG_DFL}, {0x8068f30, [WINCH],
SA_RESTART|0x4
000000}, 8) = 0
[4002ba77] getpid()                     = 920
[4002bde5] kill(920, SIGINT)            = 0
[4002bde5] --- SIGINT (Interrupt) ---
[4002b6b4] write(1, "onsig", 5)         = -1 EIO (Input/output error)
[4002b6b4] write(1, "onint", 5)         = -1 EIO (Input/output error)
[4002dc28] rt_sigprocmask(SIG_SETMASK, [], ~[KILL STOP], 8) = 0
[4002b6b4] write(1, " onint 1 ", 9)     = -1 EIO (Input/output error)
[4002b6b4] write(1, " onint 3 ", 9)     = -1 EIO (Input/output error)
[4002b6b4] write(1, " onint 4 ", 9)     = -1 EIO (Input/output error)
[4002b6b4] write(2, "\n", 1)            = -1 EIO (Input/output error)
[4002cee4] wait4(-1, 0xbffffcc8, WNOHANG|WUNTRACED, NULL) = -1 ECHILD
(No child 
processes)
[4002c120] ioctl(0, SNDCTL_TMR_TIMEBASE, 0xbffffc3c) = -1 EIO
(Input/output erro
r)
[4002c120] ioctl(0, SNDCTL_TMR_START, {B4800 opost -isig -icanon -echo
...}) = -
1 EIO (Input/output error)
[4002dbdc] rt_sigaction(SIGWINCH, {0x8068f30, [WINCH],
SA_RESTART|0x4000000}, {S
IG_DFL}, 8) = 0
[4002b6b4] write(1, "fli4l 2.1.5 # fli4l 2.1.5 # ", 28) = -1 EIO
(Input/output e
rror)
[4002b670] read(0, "", 1)               = 0
[4002c120] ioctl(0, SNDCTL_TMR_START, {B4800 opost -isig -icanon echo
...}) = -1
 EIO (Input/output error)
[4002dbdc] rt_sigaction(SIGWINCH, {SIG_DFL}, {0x8068f30, [WINCH],
SA_RESTART|0x4
000000}, 8) = 0
[4002ba77] getpid()                     = 920
[4002bde5] kill(920, SIGINT)            = 0
...


Is this a bug or intended behaviour?

regards,
Jean



More information about the busybox mailing list