Allow CK to terminate on FreeBSD

Remco Treffkorn remco at rvt.com
Tue Sep 4 14:24:18 PDT 2007


On Friday 31 August 2007, Joe Marcus Clarke wrote:
> On Fri, 2007-08-31 at 12:49 -0700, Remco Treffkorn wrote:
> > On Friday 31 August 2007, Joe Marcus Clarke wrote:
> > > I dug into the FreeBSD kernel some more, and found that if signal
> > > handlers are registered, the tsleep() function will know which signals
> > > are allowed to interrupt the ioctl syscall, thus causing it to return
> > > EINTR.  Based on this, I put together this patch which fixes the
> > > termination problem.  It may not be the ideal place for the signal
> > > handler registration, but it does the job.
> > >
> > > I can send a formal git patch once people have a chance to comment.
> > >
> > > Joe
> >
> > So, the VT_WAITACTIVE ioctl returns EINTR when SIGTERM is sent to the
> > process? The signal handler should now have been called already.
>
> It does now.  Before a signal handler is registered, there are no
> signals in the sigintr set that can interrupt a syscall.
>
> > For me that sounds like fixing a symptom, since we really don't
> > understand what the problem is.
>
> I know what the problem is now.  When VT_WAITACTIVE is called in
> FreeBSD, the kernel puts the thread to sleep using the tsleep()
> function.  This function will only return if the condition is met, or it
> is interrupted.  If it is interrupted, but the signal is not in the
> sigintr set, tsleep() will return ERESTART, and the ioctl will continue
> to call tsleep() (it won't return to the caller since the caller didn't
> indicate it wanted the syscall to be interrupted).
>
> Once a signal handler is registered for a signal, the sigintr set
> becomes populated.  Now, tsleep() will check if the signal received is
> in the set.  If it is, it returns EINTR, and the ioctl returns EINTR to
> its caller (i.e. CK).  The result is the waiting thread continues.
>
> > Also, returning with EINTR only means the process received a signal. Does
> > not have to be SIGTERM.
>
> Correct.  However, since we had to explicitly register handlers for
> those signals we wanted to cause aborts, we can safely assume that if
> ioctl returns EINTR in this case (at least on FreeBSD) our process has
> received one of SIGTERM, SIGQUIT, SIGHUP, or SIGINT, and we should die.
>
> Joe

I had some time to think about it, and it still disturbs me.
The diff only had the BSD conditional in it. Where is the signal handler for 
SIGTERM, SIGQUIT, SIGHUP, and SIGINT? Why not just exit from there?

You will then never even get to the goto.

How is SIGKILL handled? You indicated BDS had a bug. Are you still saying 
that?

Sorry if I am a bit dense.

Cheers,
Remco

-- 
Remco Treffkorn (RT445)
HAM DC2XT
remco at rvt.com   (831) 685-1201



More information about the hal mailing list