From owner-freebsd-hackers@FreeBSD.ORG Sun Feb 10 11:03:06 2008 Return-Path: Delivered-To: freebsd-hackers@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 4F35E16A419 for ; Sun, 10 Feb 2008 11:03:06 +0000 (UTC) (envelope-from erikt@midgard.homeip.net) Received: from ch-smtp01.sth.basefarm.net (ch-smtp01.sth.basefarm.net [80.76.149.212]) by mx1.freebsd.org (Postfix) with ESMTP id C8EDB13C478 for ; Sun, 10 Feb 2008 11:03:05 +0000 (UTC) (envelope-from erikt@midgard.homeip.net) Received: from c83-253-25-183.bredband.comhem.se ([83.253.25.183]:50487 helo=falcon.midgard.homeip.net) by ch-smtp01.sth.basefarm.net with esmtp (Exim 4.68) (envelope-from ) id 1JO9xg-00013d-5l for freebsd-hackers@freebsd.org; Sun, 10 Feb 2008 12:03:05 +0100 Received: (qmail 1908 invoked from network); 10 Feb 2008 12:02:59 +0100 Received: from owl.midgard.homeip.net (10.1.5.7) by falcon.midgard.homeip.net with ESMTP; 10 Feb 2008 12:02:59 +0100 Received: (qmail 3881 invoked by uid 1001); 10 Feb 2008 12:02:59 +0100 Date: Sun, 10 Feb 2008 12:02:59 +0100 From: Erik Trulsson To: Cihan =?iso-8859-1?B?S/ZtZedvPz9sdQ==?= Message-ID: <20080210110259.GA3652@owl.midgard.homeip.net> Mail-Followup-To: Cihan =?iso-8859-1?B?S/ZtZedvPz9sdQ==?= , freebsd-hackers@freebsd.org References: <1623050662.20080210122354@enderunix.org> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable In-Reply-To: <1623050662.20080210122354@enderunix.org> User-Agent: Mutt/1.5.17 (2007-11-01) X-Originating-IP: 83.253.25.183 X-Scan-Result: No virus found in message 1JO9xg-00013d-5l. X-Scan-Signature: ch-smtp01.sth.basefarm.net 1JO9xg-00013d-5l ea76ae9bd2e1c4703299c57ba1f1ed17 Cc: freebsd-hackers@freebsd.org Subject: Re: abort? X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 10 Feb 2008 11:03:06 -0000 On Sun, Feb 10, 2008 at 12:23:54PM +0200, Cihan K=F6me=E7o??lu wrote: > Hello list >=20 > I cant understand why kill function is called two times to send > sigabort signal. One signal to send is enough, isn't it? The program might have installed a signal handler for SIGABRT. The signal is sent a second time if and only if the process did catch the SIGABRT signal *and* the signal handler returned. Before the signal is sent the first time the implementation below makes sure that SIGABRT is neither ignored nor blocked. Before the second time it sends the signal it also makes sure the signal is not caught. According to the specification for abort() a program is allowed to catch the SIGABRT signal, but if the signal handler returns then the program will be aborted anyway. PS. I am curious: Which abort() implementation is it you have quoted below? As far as I can tell it is not identical to any that has been included in FreeBSD. >=20 > Thanks >=20 >=20 >=20 > void > abort(void) /* POSIX-style abort() function */ > { > sigset_t mask; > struct sigaction action; >=20 > /* > * Caller can't ignore SIGABRT, if so reset to default. > */ > sigaction(SIGABRT, NULL, &action); > if (action.sa_handler =3D=3D SIG_IGN) { > action.sa_handler =3D SIG_DFL; > sigaction(SIGABRT, &action, NULL); > } > if (action.sa_handler =3D=3D SIG_DFL) > fflush(NULL); /* flush all open stdio streams */ >=20 > /* > * Caller can't block SIGABRT; make sure it's unblocked. > */ > sigfillset(&mask); > sigdelset(&mask, SIGABRT); /* mask has only SIGABRT turned off */ > sigprocmask(SIG_SETMASK, &mask, NULL); > kill(getpid(), SIGABRT); /* send the signal */ >=20 > /* > * If we're here, process caught SIGABRT and returned. > */ > fflush(NULL); /* flush all open stdio streams */ > action.sa_handler =3D SIG_DFL; > sigaction(SIGABRT, &action, NULL); /* reset to default */ > sigprocmask(SIG_SETMASK, &mask, NULL); /* just in case ... */ > kill(getpid(), SIGABRT); /* and one more time */ > exit(1); /* this should never be executed ... */ > } > =20 --=20 Erik Trulsson ertr1013@student.uu.se