SIGVECTOR(2) — HP-UX
NAME
sigvector − software signal facilities
SYNOPSIS
#include <signal.h>
sigvector(sig, vec, ovec)
int sig;
struct sigvec *vec, *ovec;
DESCRIPTION
The system defines a set of signals that can be delivered to a process. The set of signals is defined in signal(2), along with the meaning and side-effects of each signal. This manual page, along with those for sigblock(2), sigsetmask(2), sigpause(2), and sigspace(2) define an alternate mechanism for handling these signals that assures the delivery of signals and integrity of signal handling procedures. The facilities described here should not be used in the same program as signal(2).
With this interface, signal delivery resembles the occurrence of a hardware interrupt: the signal is blocked from further occurrence, the current process context is saved, and a new one is built. A process can specify a handler to which a signal is delivered, or specify that a signal is to be blocked or ignored. A process can also specify that a default action is to be taken by the system when a signal occurs. It is possible to assure a minimum amount of stack space for processing signals using the sigspace(2) call.
All signals have the same priority. Signal routines execute with the signal that caused their invocation blocked, but other signals can yet occur. A global signal mask defines the set of signals currently blocked from delivery to a process. The signal mask for a process is initialized from that of its parent (normally 0). It can be changed with a sigblock(2), sigsetmask(2), or sigpause(2) call, or when a signal is delivered to the process.
When a signal condition arises for a process, the signal is added to a set of signals pending for the process. If the signal is not currently blocked by the process, it is delivered to the process. When a signal is delivered, the current state of the process is saved, a new signal mask is calculated (as described below), and the signal handler is invoked. The call to the handler is arranged so that if the signal handling routine returns normally, the process will resume execution in the context from before the signal’s delivery. If the process wishes to resume in a different context, it must arrange to restore the previous context itself.
When a signal is delivered to a process, a new signal mask is installed for the duration of the process’ signal handler (or until a sigblock or sigsetmask call is made). This mask is formed by taking the current signal mask, adding the signal to be delivered, and or’ing in the signal mask associated with the handler to be invoked. When the user’s signal handler returns normally, the original mask is restored.
Sigvector assigns a handler for a specific signal. Vec and ovec are pointers to sigvec structures that include the following elements:
| int | (*sv_handler)(); |
| long | sv_mask; |
| long | sv_flags; |
If vec is non-zero, it specifies a handler routine, a mask to be used when delivering the specified signal, and a set of flags that can modify the delivery of the signal. If ovec is non-zero, the previous handling information for the signal is returned to the user. If vec is zero, signal handling is unchanged: thus, the call can be used to enquire about the current handling of a given signal. If vec and ovec point to the same structure, the value of vec is read prior to being overwritten.
The sv_flags field can be used to modify the receipt of signals. The following flag bits are defined:
| SV_ONSTACK | Use the sigspace allocated space |
| SV_BSDSIG | Use the Berkeley signal semantics |
If SV_ONSTACK is set, then the system will use, or permit the use of, the space reserved for signal processing in the sigspace(2) system call.
If SV_BSDSIG is set, then the signal will be given the Berkeley semantics. The following signals are affected by this flag.
SIGCLD In addition to being sent when a child process dies, the signal will also be sent when any child’s status changes from running to stopped. This would normally be used by a program such as csh when maintaining process groups under Berkeley Job Control.
Once a signal handler is installed, it remains installed until another sigvector call is made, or an exec(2) is performed. The default action for a signal can be reinstated by setting sv_handler to SIG_DFL; this default is usually termination. If sv_handler is SIG_IGN the signal is usually subsequently ignored, and pending instances of the signal are discarded. The exact meaning of SIG_DFL and SIG_IGN for each signal is discussed in signal(2). Unlike signal(2), there is no category of "reset when caught" signals.
Certain system calls can be interrupted by a signal, the remainder will complete before the signal is serviced. The scp pointer described in signal(2) is always non-null if sigvector is supported. Scp points to a machine-dependent sigcontext structure. All implementations of this structure include the fields:
| int | sc_syscall; |
| char | sc_syscall_action; |
The value SYS_NOTSYSCALL for the sc_syscall field indicates that the signal is not interrupting a system call; any other value indicates which system call it is interrupting. If a signal that is being caught occurs during one of the interruptable calls, the signal handler is immediately invoked. If the signal handler is exited in a normal way, the value of the sc_syscall_action field is inspected; if it is SIG_RETURN the system call is aborted and the interrupted program continues past the call with the result of the interrupted call being -1 and errno set to EINTR. If the value of the sc_syscall_action field is SIG_RESTART, the call is restarted. A call is restarted if, in the case of a read or write, it had transferred no data. If some data had been transferred, the operation is considered to have completed with a partial transfer, and the sc_syscall value is SYS_NOTSYSCALL. Other values are undefined and reserved for future use.
Exiting the handler abnormally (such as with longjmp on setjmp(3C)) will abort the call, and the user is responsible for the context of further execution. The value of scp->sc_syscall_action is ignored when the value of scp->sc_syscall is SYS_NOTSYSCALL. Scp->sc_syscall_action is always initialized to SIG_RETURN before invocation of a signal handler. When an interruptable call is interrupted by multiple signals, if any signal handler returns a value of SIG_RETURN in scp->sc_syscall_action, all subsequent signal handlers are passed a value of SYS_NOTSYSCALL in scp->sc_syscall.
The interruptable system calls, and corresponding values for scp->sc_syscall are listed below.
| Call | sc_syscall value |
| ------ | ---------------- |
| read (slow devices) | SYS_READ |
| readv (slow devices) | SYS_READV |
| write (slow devices) | SYS_WRITE |
| writev (slow devices) | SYS_WRITEV |
| open (slow devices) | SYS_OPEN |
| ioctl (slow requests) | SYS_IOCTL |
| wait | SYS_WAIT |
| select | SYS_SELECT |
| pause | SYS_PAUSE |
| sigpause | SYS_SIGPAUSE |
| semop | SYS_SEMOP |
| msgsnd | SYS_MSGSND |
| msgrcv | SYS_MSGRCV |
Note that read, write or ioctl on fast devices (disks) is not interruptable, but IO to a slow device (teletype) is. Additional system calls, for example those used for networking, can also be interruptable on some implementations. In these cases additional values can be specified for scp->sc_syscall. Programs that look at the values of scp->sc_syscall should always compare them to these symbolic constants; the numerical values represented by these constants may vary among implementations.
After a fork(2) or vfork(2) the child inherits all signals, the signal mask, and the reserved signal stack space.
Exec(2) resets all caught signals to the default action, ignored signals remain ignored, the signal mask remains the same, and the reserved signal stack space is released.
NOTES
The mask specified in vec is not allowed to block those signals that cannot be ignored, as defined in signal(2). This is enforced silently by the system.
If sigvector is called to catch SIGCLD in a process that currently has terminated (zombie) children, a SIGCLD signal is delivered to the calling process immediately, or as soon as SIGCLD is unblocked if it is currently blocked. Thus, in a process that spawns multiple children and catches SIGCLD, it is sometimes advisable to re-install the handler for SIGCLD after each invocation in case there are multiple zombies present. This is true even though the handling of the signal is not reset by the system as with signal(2), because deaths of multiple processes while SIGCLD is blocked in the handler will only result in delivery of a single signal. Note that the function must re-install itself after it has called wait(2) or wait3(2). Otherwise the presence of the child that caused the original signal will always cause another signal to be delivered.
RETURN VALUE
A 0 value indicated that the call succeeded. A −1 return value indicates an error occurred and errno is set to indicate the reason.
ERRORS
Sigvector will fail and no new signal handler will be installed if one of the following occurs:
[EFAULT] Either vec or ovec points to memory that is not a valid part of the process address space. The reliable detection of this error will be implementation dependent.
[EINVAL] Sig is not a valid signal number.
[EINVAL] An attempt is made to ignore or supply a handler for a signal that cannot be caught or ignored, see signal(2).
WARNINGS
Restarting a select(2) call can sometimes cause unexpected results. If the select call has a timeout specified, the timeout is restarted with the call, ignoring any portion that had elapsed prior to interruption by the signal. Normally this simply extends the timeout and is not a problem. However, if a handler repeatedly catches signals and the timeout specified to select is longer than the time between those signals, restarting the select call effectively renders the timeout infinite.
HARDWARE DEPENDENCIES
Integral PC
Interruptible and restartable kernel calls are not supported. SELECT, READY, and WRITEV are not supported.
Series 200, 300, 500
The SV_BSDSIG flag is not supported.
AUTHOR
Sigvector was developed by HP, and the University of California, Berkeley.
SEE ALSO
kill(1), kill(2), ptrace(2), sigblock(2), signal(2), sigpause(2), sigsetmask(2), sigspace(2), setjmp(3C), termio(7).
Hewlett-Packard Company — Version B.1, May 11, 2021