abort?
Erik Trulsson
ertr1013 at student.uu.se
Sun Feb 10 11:03:06 UTC 2008
On Sun, Feb 10, 2008 at 12:23:54PM +0200, Cihan Kömeço??lu wrote:
> Hello list
>
> 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.
>
> Thanks
>
>
>
> void
> abort(void) /* POSIX-style abort() function */
> {
> sigset_t mask;
> struct sigaction action;
>
> /*
> * Caller can't ignore SIGABRT, if so reset to default.
> */
> sigaction(SIGABRT, NULL, &action);
> if (action.sa_handler == SIG_IGN) {
> action.sa_handler = SIG_DFL;
> sigaction(SIGABRT, &action, NULL);
> }
> if (action.sa_handler == SIG_DFL)
> fflush(NULL); /* flush all open stdio streams */
>
> /*
> * 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 */
>
> /*
> * If we're here, process caught SIGABRT and returned.
> */
> fflush(NULL); /* flush all open stdio streams */
> action.sa_handler = 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 ... */
> }
>
--
<Insert your favourite quote here.>
Erik Trulsson
ertr1013 at student.uu.se
More information about the freebsd-hackers
mailing list