help-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Help-bash] readline does not always handle SIGTERM on reboot


From: john smith
Subject: Re: [Help-bash] readline does not always handle SIGTERM on reboot
Date: Fri, 6 Apr 2018 18:08:58 +0200

On Fri, Apr 6, 2018 at 4:39 PM, Chet Ramey <address@hidden> wrote:
> On 4/6/18 10:25 AM, john smith wrote:
>> On Fri, Apr 6, 2018 at 3:47 PM, Chet Ramey <address@hidden> wrote:
>>> On 4/6/18 9:11 AM, john smith wrote:
>>>> Hello,
>>>>
>>>> I'm using bash 4.4.18 with busybox.  When reboot is done SIGTERM is
>>>> sent to all processes by busybox init.  The problem is that while
>>>> SIGTERM is always handled by sigterm_sighandler() in bash at reboot
>>>> it's not always handled by rl_getc().  I did 10 attempts and SIGTERM
>>>> has been not handled by rl_getc() in 8 cases.  It's problematic
>>>> because rl_get() returns EOF on SIGTERM and it makes bash perform
>>>> logout and save history.
>>>>
>>>> When I start a new session via telnet and kill a previously started
>>>> bash session opened on serial console I can see that SIGTERM is
>>>> handled in rl_getc() every time.
>>>>
>>>> What can be the reson rl_getc() does not handle SIGTERM on reboot?
>>>
>>> What does `handled' mean?
>>
>> Sorry for not being clear enough.  By not handled I mean that this
>> part rl_getc() is not run because apparently _rl_caught_signal is 0:
>>
>> #if defined (SIGHUP)
>>       else if (_rl_caught_signal == SIGHUP || _rl_caught_signal == SIGTERM)
>> #else
>>       else if (_rl_caught_signal == SIGTERM)
>> #endif
>>     return (RL_ISSTATE (RL_STATE_READCMD) ? READERR : EOF);
>
> Then readline is not active when the SIGTERM arrives, or its signal
> handlers are not installed.

Hmm, maybe I don't understand something.  I wrote the following tiny
program that does the same as busybox init:

#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <signal.h>
#include <unistd.h>
#include <sys/reboot.h>

int main(void)
{
    kill(-1, SIGTERM);

    return EXIT_SUCCESS;
}

If I run it in the ttyS0 serial console I also can't see `logout'
string and other debug messages I added to rl_getc() what means that
readline does not handle SIGTERM.  However, if I run the same program
from telnet session from another machine on my network i can see
`logout' string and my debug messages what means that readline session
active on the serial console gets and handles sigterm.  i know that
`kill $$' is not allowed in the interactive session so maybe the
behavior is actually correct?

The only thing that bothers me is why some attempts of reboot done in
the serial console succeed?

-- 
<address@hidden>



reply via email to

[Prev in Thread] Current Thread [Next in Thread]