Advanced Programming in the UNIX® Environment

(lily) #1
ptg10805159

352 Signals Chapter 10


Normally,the signal handler is called as
void handler(intsigno);
but if theSA_SIGINFOflag is set, the signal handler is called as
void handler(intsigno,siginfo_t *info,void *context);
Thesiginfostructurecontains information about why the signal was generated.
An example of what it might look like is shown below.All POSIX.1-compliant
implementations must include at least the si_signo and si_code members.
Additionally,implementations that areXSI compliant contain at least the following
fields:
struct siginfo {
int si_signo; /* signal number */
int si_errno; /* if nonzero, errno value from errno.h */
int si_code; /* additional info (depends on signal) */
pid_t si_pid; /* sending process ID */
uid_t si_uid; /* sending process real user ID */
void *si_addr; /* address that caused the fault */
int si_status; /* exit value or signal number */
union sigval si_value; /* application-specific value */
/* possibly other fields also */
};

Thesigvalunion contains the following fields:
int sival_int;
void *sival_ptr;

Applications pass an integer value insi_value.sival_intor pass a pointer value in
si_value.sival_ptrwhen delivering signals.
Figure10.17 shows values ofsi_codefor various signals, as defined by the Single
UNIX Specification. Note that implementations may define additional code values.
If the signal isSIGCHLD,then thesi_pid,si_status,andsi_uidfields will be
set. If the signal isSIGBUS,SIGILL,SIGFPE,orSIGSEGV,then thesi_addrcontains
the address responsible for the fault, although the address might not be accurate. The
si_errnofield contains the error number corresponding to the condition that caused
the signal to be generated, although its use is implementation defined.
Thecontextargument to the signal handler is a typeless pointer that can be cast to a
ucontext_tstructureidentifying the process context at the time of signal delivery.
This structurecontains at least the following fields:
ucontext_t *uc_link; /* pointer to context resumed when */
/* this context returns */
sigset_t uc_sigmask; /* signals blocked when this context */
/* is active */
stack_t uc_stack; /* stack used by this context */
mcontext_t uc_mcontext; /* machine-specific representation of */
/* saved context */
Free download pdf