Date: Sun, 10 Feb 2008 12:02:59 +0100 From: Erik Trulsson <ertr1013@student.uu.se> To: Cihan =?iso-8859-1?B?S/ZtZedvPz9sdQ==?= <cihan@enderunix.org> Cc: freebsd-hackers@freebsd.org Subject: Re: abort? Message-ID: <20080210110259.GA3652@owl.midgard.homeip.net> In-Reply-To: <1623050662.20080210122354@enderunix.org> References: <1623050662.20080210122354@enderunix.org>
next in thread | previous in thread | raw e-mail | index | archive | help
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 <Insert your favourite quote here.> Erik Trulsson ertr1013@student.uu.se
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20080210110259.GA3652>