Allow CK to terminate on FreeBSD

Joe Marcus Clarke marcus at marcuscom.com
Fri Aug 31 14:17:54 PDT 2007


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

-- 
PGP Key : http://www.marcuscom.com/pgp.asc
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 187 bytes
Desc: This is a digitally signed message part
Url : http://lists.freedesktop.org/archives/hal/attachments/20070831/439617ae/attachment-0001.pgp 


More information about the hal mailing list