Skip to Main Content United States    
PRODUCTS SUPPORT SOLUTIONS SERVICES
COMPAQ SOFTWARE
Compaq C

Compaq C
Run-Time Library Reference Manual for OpenVMS Systems


Previous Contents Index

If the previous action for a specified signal had been established by signal , the values of the fields returned in the structure pointed to by the o_action argument of sigaction are unspecified, and in particular o_action->sa_handler is not necessarily the same value passed to signal . However, if a pointer to the same structure or a copy thereof is passed to a subsequent call to sigaction by means of the action argument of sigaction ), the signal is handled as if the original call to signal were repeated.

If sigaction fails, no new signal handler is installed.

It is unspecified whether an attempt to set the action for a signal that cannot be caught or ignored to SIG_DFL is ignored or causes an error to be returned with errno set to EINVAL.

See Section 4.2 for more information on signal handling.

Note

The sigvec and signal functions are provided for compatibility to old UNIX systems; their function is a subset of that available with the sigaction function.

See also sigstack , sigvec , signal , wait , read , and write , in this section.


Return Values

0 Indicates success.
--1 Indicates an error; A new signal handler is not installed. errno is set to one of the following values:
  • EFAULT -- The action or o_action argument points to a location outside of the allocated address space of the process.
  • EINVAL -- The sig argument is not a valid signal number. Or an attempt was made to ignore or supply a handler for the SIGKILL, SIGSTOP, and SIGCONT signals.

sigaddset

Adds the specified individual signal.

Format

#include <signal.h>

int sigaddset (sigset_t *set, int sig_number);


Arguments

set

The signal set.

sig_number

The individual signal.

Description

This function manipulates sets of signals. This function operates on data objects that you can address by the application, not on any set of signals known to the system. For example, this function does not operate on the set blocked from delivery to a process or the set pending for a process.

The sigaddset function adds the individual signal specified by sig_number from the signal set specified by set.


Example

The following example shows how to generate and use a signal mask that blocks only the SIGINT signal from delivery.


       #include <signal.h> 
       int return_value; 
       sigset_t newset; 
         . . . 
       sigemptyset(&newset); 
       sigaddset(&newset, SIGINT); 
       return_value = sigprocmask (SIG_SETMASK, &newset, NULL); 


Return Values

0 Indicates success.
--1 Indicates an error; errno is set to one of the following values:
  • EINVAL -- The value of sig_number is not a valid signal number.

sigblock

Adds the signals in mask to the current set of signals being blocked from delivery.

Format

#include <signal.h>

int sigblock (int mask);


Argument

mask

The signals to be blocked.

Description

Signal i is blocked if the i -- 1 bit in mask is a 1. For example, to add the protection-violation signal to the set of blocked signals, use the following line:


sigblock(1 << (SIGBUS - 1)); 

You can express signals in mnemonics (such as SIGBUS for a protection violation) or numbers as defined in the <signal.h> header file, and you can express combinations of signals by using the bitwise OR operator (|).


Return Value

x Indicates the previous set of masked signals.

sigdelset

Deletes a specified individual signal.

Format

#include <signal.h>

int sigdelset (sigset_t *set, int sig_number;)


Arguments

set

The signal set.

sig_number

The individual signal.

Description

The sigdelset function deletes the individual signal specified by sig_number from the signal set specified by set.

This function operates on data objects that you can address by the application, not on any set of signals known to the system. For example, this function does not operate on the set blocked from delivery to a process or the set pending for a process.


Return Values

0 Indicates success.
--1 Indicates an error; errno is set to one of the following values:
  • EINVAL -- The value of sig_number is not a valid signal number.

sigemptyset

Initializes the signal set to exclude all signals.

Format

#include <signal.h>

int sigemptyset (sigset_t *set);


Arguments

set

The signal set.

Description

The sigemptyset function initializes the signal set pointed to by set such that you exclude all signals. A call to sigemptyset or sigfillset must be made at least once for each object of type sigset_t prior to any other use of that object.

This function operates on data objects that you can address by the application, not on any set of signals known to the system. For example, this function does not operate on the set blocked from delivery to a process or the set pending for a process.

See also sigfillset in this section.


Example

The following example shows how to generate and use a signal mask that blocks only the SIGINT signal from delivery.


       #include <signal.h> 
       int return_value; 
       sigset_t newset; 
         . . . 
       sigemptyset(&newset); 
       sigaddset(&newset, SIGINT); 
       return_value = sigprocmask (SIG_SETMASK, &newset, NULL); 


Return Values

0 Indicates success.
--1 Indicates an error; the global errno is set to indicate the error.

sigfillset

Initializes the signal set to include all signals.

Format

#include <signal.h>

int sigfillset (sigset_t *set);


Arguments

set

The signal set.

Description

The sigfillset function initializes the signal set pointed to by set such that you include all signals. A call to sigemptyset or sigfillset must be made at least once for each object of type sigset_t prior to any other use of that object.

This function operates on data objects that you can address by the application, not on any set of signals known to the system. For example, this function does not operate on the set blocked from delivery to a process or the set pending for a process.

See also sigemptyset in this section.


Return Values

0 Indicates success.
--1 Indicates an error; errno is set to one of the following values:
  • EINVAL -- The value of the sig_number argument is not a valid signal number.

sigismember

Tests whether a specified signal is a member of the signal set.

Format

#include <signal.h>

int sigismember (const sigset_t *set, int sig_number);


Arguments

set

The signal set.

sig_number

The individual signal.

Description

The sigismember function tests whether sig_number is a member of the signal set pointed to by set.

This function operates on data objects that you can address by the application, not on any set of signals known to the system. For example, this function does not operate on the set blocked from delivery to a process or the set pending for a process.


Return Values

1 Indicates success. The specified signal is a member of the specified set.
0 Indicates an error. The specified signal is not a member of the specified set.

siglongjmp

Nonlocal goto with signal handling.

Format

#include <setjmp.h>

void siglongjmp (sigjmp_buf env, int value);


Arguments

env

An address for a sigjmp_buf structure.

value

A nonzero value.

Description

This function restores the environment saved by the most recent call to sigsetjmp in the same process with the corresponding sigjmp_buf argument.

All accessible objects have values when siglongjmp is called, with one exception: values of objects of automatic storage duration that changed between the sigsetjmp call and siglongjmp call are indeterminate.

Because it bypasses the usual function call and return mechanisms, siglongjmp executes correctly during interrupts, signals, and any of their associated functions. However, if you invoke siglongjmp from a nested signal handler (for example, from a function invoked as a result of a signal raised during the handling of another signal), the behavior is undefined.

The siglongjmp function restores the saved signal mask only if you initialize the env argument by a call to sigsetjmp with a nonzero savemask argument.

After siglongjmp is completed, program execution continues as if the corresponding call of sigsetjmp just returned the value specified by value. The siglongjmp function cannot cause sigsetjmp to return 0 (zero); if value is 0, sigsetjmp returns 1

See also sigsetjmp in this section.


sigmask

Constructs the mask for a given signal number.

Format

#include <signal.h>

int sigmask (signum);


Argument

signum

The signal number for which the mask is to be constructed.

Description

This function is used to contruct the mask for a given signum. This mask can be used with the sigblock function.


Return Value

x The mask constructed for signum

signal

Allows you to specify the way in which the signal sig is to be handled: use the default handling for the signal, ignore the signal, or call the signal handler at the address specified.

Format

#include <signal.h>

void (*signal (int sig, void (*func) (int))) (int);


Arguments

sig

The number or mnemonic associated with a signal. This argument is usually one of the mnemonics defined in the <signal.h> header file.

func

Either the action to take when the signal is raised, or the address of a function needed to handle the signal.

Description

If func is the constant SIG_DFL, the action for the given signal is reset to the default action, which is to terminate the receiving process. If the argument is SIG_IGN, the signal is ignored. Not all signals can be ignored.

If func is neither SIG_DFL nor SIG_IGN, it specifies the address of a signal-handling function. When the signal is raised, the addressed function is called with sig as its argument. When the addressed function returns, the interrupted process continues at the point of interruption. (This is called catching a signal. Signals are reset to SIG_DFL after they are caught, except as shown in Chapter 4.)

You must call the signal function each time you want to catch a signal.

See Section 4.2 for more information on signal handling.

To cause a OpenVMS exception or a signal to generate a UNIX style signal, user OpenVMS condition handlers must return SS$_RESIGNAL upon receiving any exception that they do not want to handle. Returning SS$_CONTINUE prevents the correct generation of a UNIX style signal. See Chapter 4 for a list of OpenVMS exceptions that correspond to UNIX signals.


Return Values

x The address of the function previously established to handle the signal.
SIG_ERR Indicates that the sig argument is out of range.

sigpause

Assigns mask to the current set of masked signals and then waits for a signal.

Format

#include <signal.h>

int sigpause (int mask);


Argument

mask

The signals to be blocked.

Description

See the sigblock function in this section for information about the mask argument.

When control returns to sigpause , the function restores the previous set of masked signals, sets errno to EINTR, and returns --1 to indicate an interrupt. The value EINTR is defined in the <errno.h> header file.


Return Value

--1 Indicates an interrupt. errno is set to EINTR.

sigpending

Examines pending signals.

Format

#include <signal.h>

int sigpending (sigset_t *set);


Arguments

set

A pointer to a sigset_t structure.

Description

This function stores the set of signals that are blocked from delivery and pending to the calling process in the location pointed to by the set argument.

Call either the sigemptyset or the sigfillset function at least once for each object of type sigset_t prior to any other use of that object. If you do not initialize an object in this way and supply an argument to the sigpending function, the result is undefined.

See sigemptyset , and sigfillset in this section.


Return Values

0 Indicates success.
--1 Indicates an error; errno is set to the following value:
  • SIGSEGV -- Bad mask argument.

sigprocmask

Sets the current signal mask.

Format

#include <signal.h>

int sigprocmask (int how, const sigset_t *set, sigset_t *o_set);


Arguments

how

An integer value that indicates how to change the set of masked signals. Use one of the following values:
SIG_BLOCK The resulting set is the union of the current set and the signal set pointed to by the set argument.
SIG_UNBLOCK The resulting set is the intersection of the current set and the complement of the signal set pointed to by the set argument.
SIG_SETMASK The resulting set is the signal set pointed to by the set argument.

set

The signal set. If the value of the set argument is:
  • Not NULL -- It points to a set of signals used to change the currently blocked set.
  • NULL -- The value of the how argument is not significant, and the process signal mask is unchanged, so you can use the call to inquire about currently blocked signals.

o_set

A non-NULL pointer to the location where the signal mask in effect at the time of the call is stored.

Description

This function is used to examine or change the signal mask of the calling process.

Typically, use the sigprocmask SIG_BLOCK value to block signals during a critical section of code, then use the sigprocmask SIG_SETMASK value to restore the mask to the previous value returned by the sigprocmask SIG_BLOCK value.

If there are any unblocked signals pending after the call to the sigprocmask function, at least one of those signals is delivered before the sigprocmask function returns.

You cannot block SIGKILL or SIGSTOP signals with the sigprocmask function. If a program attempts to block one of these signals, the sigprocmask function gives no indication of the error.


Example

The following example shows how to set the signal mask to block only the SIGINT signal from delivery:


  #include <signal.h> 
 
  int return_value; 
  sigset_t newset; 
   . . . 
  sigemptyset(&newset); 
  sigaddset(&newset, SIGINT); 
  return_value = sigprocmask (SIG_SETMASK, &newset, NULL); 


Return Values

0 Indicates success.
--1 Indicates an error. The signal mask of the process is unchanged. errno is set to one of the following values:
  • EINVAL -- The value of the how argument is not equal to one of the defined values.
  • EFAULT -- The set or o_set argument points to a location outside the allocated address space of the process.

sigsetjmp

Sets jump point for a nonlocal goto.

Format

#include <setjmp.h>

init sigsetjmp (sigjmp_buf env, int savemask);


Arguments

env

An address for a sigjmp_buf structure.

savemask

An integer value that specifies whether you need to save the current signal mask.

Description

This function saves its calling environment in its env argument for later use by the siglongjmp function.

If the value of savemask is not 0 (zero), sigsetjmp also saves the process' current signal mask as part of the calling environment.

See also siglongjmp in this section.


Restrictions

You cannot invoke the longjmp function from an OpenVMS condition handler. However, you may invoke longjmp from a signal handler that has been established for any signal supported by the Compaq C RTL, subject to the following nesting restrictions:
  • The longjmp function will not work if you invoke it from nested signal handlers. The result of the longjmp function, when invoked from a signal handler that has been entered as a result of an exception generated in another signal handler, is undefined.
  • Do not invoke the sigsetjmp function from a signal handler unless the associated longjmp is to be issued before the handling of that signal is completed.
  • Do not invoke the longjmp function from within an exit handler (established with atexit or SYS$DCLEXH). Exit handlers are invoked after image tear-down, so the destination address of the longjmp no longer exists.
  • Invoking longjmp from within a signal handler to return to the main thread of execution might leave your program in an inconsistent state. Possible side effects include the inability to perform I/O or to receive any more UNIX signals. Use siglongjmp instead.

Return Values

0 Indicates success.
nonzero The return is a call to the siglongjmp function.


Previous Next Contents Index
Buy Online or Call 1.800.888.0220      privacy statement and legal notices 
STORES CONTACT US SEARCH PRODUCTS SOLUTIONS OPTIONS DEVELOPERS