Saturday, October 22, 2011

sigaction structure

sigaction structure:

struct sigaction {
  /*
   * addr of signal handler, 
   */
   void (*sa_handler)(int);
  /* 
   * or SIG_IGN, or SIG_DFL 
   */
   sigset_t sa_mask;
  /* 
   * additional signals to block 
   */
   int sa_flags; 
  /* 
   * signal options, Figure 10.16 
   */
  /* 
   * alternate handler 
   */
   void (*sa_sigaction)(int, siginfo_t *, void *);
};

When changing the action for a signal, if the sa_handler field contains the address of a signal catching function (as opposed to the constants SIG_IGN or SIG_DFL), then the sa_mask field specifies a set of signals that are added to the signal mask of the process before the signal-catching function is called. If and when the signal-catching function returns, the signal mask of the process is reset to its previous value. This way, we are able to block certain signals whenever a signal handler is invoked. The operating system includes the signal being delivered in the signal mask when the handler is invoked. Hence, we are guaranteed that whenever we are processing a given signal, another
occurrence of that same signal is blocked until we're finished processing the first occurrence. Recall that additional occurrences of the same signal are usually not queued. If the signal occurs five times while it is blocked, when we unblock the signal, the signal-handling function for that signal will usually be invoked only one time.

Once we install an action for a given signal, that action remains installed until we explicitly change it by calling sigaction. Unlike earlier systems with their unreliable signals, POSIX.1 requires that a signal handler remain installed until explicitly changed.

The sa_flags field of the act structure specifies various options for the handling of this signal. Figure below details the meaning of these options when set. The SUS column contains • if the flag is defined as part of the base POSIX.1 specification, and XSI if it is defined as an XSI extension to the base.

The sa_sigaction field is an alternate signal handler used when the SA_SIGINFO flag is used withsigaction. Implementations might use the same storage for both the sa_sigaction field and the sa_handler field, so applications can use only one of these fields at a time.

Normally, the signal handler is called as 

void handler(int signo); 

but if the SA_SIGINFO flag is set, the signal handler is called as

void handler(int signo, siginfo_t *info, void *context);

Figure:
Option flags (sa_flags) for the handling of each signal


No comments:

Post a Comment