From owner-freebsd-arch@FreeBSD.ORG Sat Sep 1 11:26:03 2007 Return-Path: Delivered-To: freebsd-arch@FreeBSD.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 3AD2C16A47D; Sat, 1 Sep 2007 11:26:03 +0000 (UTC) (envelope-from jilles@stack.nl) Received: from mx1.stack.nl (meestal-mk5.stack.nl [IPv6:2001:610:1108:5010::149]) by mx1.freebsd.org (Postfix) with ESMTP id D3A4E13C4FB; Sat, 1 Sep 2007 11:26:02 +0000 (UTC) (envelope-from jilles@stack.nl) Received: from snail.stack.nl (snail.stack.nl [IPv6:2001:610:1108:5010::131]) by mx1.stack.nl (Postfix) with ESMTP id 33B783F589; Sat, 1 Sep 2007 13:26:01 +0200 (CEST) Received: by snail.stack.nl (Postfix, from userid 1677) id 1DC97228C0; Sat, 1 Sep 2007 13:26:01 +0200 (CEST) Date: Sat, 1 Sep 2007 13:26:00 +0200 From: Jilles Tjoelker To: Joe Marcus Clarke Message-ID: <20070901112600.GA33832@stack.nl> References: <1188600721.1255.11.camel@shumai.marcuscom.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1188600721.1255.11.camel@shumai.marcuscom.com> X-Operating-System: FreeBSD 6.2-STABLE i386 User-Agent: Mutt/1.5.16 (2007-06-09) Cc: freebsd-arch@FreeBSD.org Subject: Re: Understanding interrupted system calls X-BeenThere: freebsd-arch@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Discussion related to FreeBSD architecture List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 01 Sep 2007 11:26:03 -0000 On Fri, Aug 31, 2007 at 06:52:01PM -0400, Joe Marcus Clarke wrote: > In my attempts to debug the problems with ConsoleKit and the > VT_WAITACTIVE ioctl, I delved into the tsleep/msleep code, and I think I > have a pretty good idea when it returns EINTR vs. ERESTART. However, > I'm curious as to why I have to do something like the following to allow > a process waiting in tsleep() to die when it receives a termination > signal (e.g. SIGTERM or SIGINT): > > struct sigaction sa; > > sa.sa_handler = SIG_DFL; > ... > sigaction (SIGTERM, &sa, NULL); > > Shouldn't the ps_sigintr set be initialized to the default set of > termination signals by default (e.g. in init_main.c proc0_init())? That > is, shouldn't the list of signals whose default action is to terminate > the process (according to signal(3)) be allowed to interrupt a system > call by default? If one then wants to restart the syscall, they can > explicitly do: > struct sigaction sa; > sa.sa_flags = SA_RESTART; > ... > sigaction (SIGTERM, &sa, NULL); > I'm just trying to get a better handle on why terminating a program that > is running the VT_WAITACTIVE ioctl leaves an unkillable process on > FreeBSD, but apparently just causes the program to terminate on Linux. The problem seems to be the following code in src/sys/dev/syscons/syscons.c, in case VT_WAITACTIVE in scioctl(): while ((error=tsleep(&scp->smode, PZERO|PCATCH, "waitvt", 0)) == ERESTART) ; If a signal is caught and system call restart is enabled for that signal, this makes it spin in a tight loop, waiting in vain for the signal to go away. The idea of ERESTART is that the syscall function returns it and then the signal handler is entered. If and when the signal handler returns, it will return to the system call instruction, restarting it (perhaps this is optimized to avoid the switch to userland and back). With EINTR, the signal handler would return to directly after the system call instruction. The fixed version would then be error = tsleep(&scp->smode, PZERO|PCATCH, "waitvt", 0); I have not tested this, however. The VT_WAITACTIVE implementation in pcvt (src/sys/i386/isa/pcvt/pcvt_ext.c) appears to have the same issue (in RELENG_6; pcvt has been removed from HEAD). -- Jilles Tjoelker