Advanced Programming in the UNIX® Environment

(lily) #1
ptg10805159

Section 10.17 abortFunction 365


We test each of the global flags beforecallingreadand again ifreadreturns an
interrupted system call error.The problem occurs if either signal is caught between the
first twoifstatements and the subsequent call toread.Signals occurring in hereare
lost, as indicated by the code comment. The signal handlers arecalled, and they set the
appropriate global variable, but thereadnever returns (unless some data is ready to be
read).
What we would like to be able to do is the following sequence of steps, in order.


  1. BlockSIGINTandSIGALRM.

  2. Test the two global variables to see whether either signal has occurred and, if so,
    handle the condition.

  3. Callread(or any other system function) and unblock the two signals, as an
    atomic operation.


Thesigsuspendfunction helps us only if step 3 is apauseoperation.

10.17 abortFunction


We mentioned earlier that theabortfunction causes abnormal program termination.

#include <stdlib.h>
void abort(void);
This function never returns

This function sends theSIGABRTsignal to the caller.(Processes should not ignorethis
signal.) ISOCstates that calling abortwill deliver an unsuccessful termination
notification to the host environment by callingraise(SIGABRT).
ISO C requires that if the signal is caught and the signal handler returns,abortstill
doesn’t return to its caller.Ifthis signal is caught, the only way the signal handler can’t
return is if it callsexit,_exit,_Exit, longjmp,orsiglongjmp.(Section 10.15
discusses the differences betweenlongjmpandsiglongjmp.) POSIX.1 also specifies
thatabortoverrides the blocking or ignoring of the signal by the process.
The intent of letting the process catch theSIGABRTis to allow it to perform any
cleanup that it wants to do beforethe process terminates. If the process doesn’t
terminate itself from this signal handler,POSIX.1 states that, when the signal handler
returns,abortterminates the process.
The ISO C specification of this function leaves it up to the implementation as to
whether output streams areflushed and whether temporary files (Section 5.13) are
deleted. POSIX.1 goes further and allows an implementation to callfcloseon open
standardI/O streams beforeterminating if the call toabortterminates the process.

Earlier versions of System V generated theSIGIOTsignal from the abortfunction.
Furthermore, it was possible for a process to ignorethis signal or to catch it and return from
the signal handler, in which caseabortreturned to its caller.
Free download pdf