SIGVEC(2)

SIGVEC(2) πŸ’– the software signal facilities page, bestie

okay so this is sigvec(2) from the System Calls Manual, and it lives in the Standard C Library (libc, -lc). grab a snack, we're going in πŸ“


✨ NAME ✨

sigvec β€” software signal facilities πŸ’…


πŸ“š LIBRARY πŸ“š

Standard C Library (libc, -lc)


πŸŽ€ SYNOPSIS πŸŽ€

#include <signal.h>

struct sigvec {
        void     (*sv_handler)();
        int      sv_mask;
        int      sv_flags;
};

int
sigvec(int sig, struct sigvec *vec, struct sigvec *ovec);

πŸ’« DESCRIPTION πŸ’«

heads up bestie: this interface is made obsolete by sigaction(2). like, it still works, but it's giving vintage. πŸ‘‘

So. The system defines a whole set of signals that can be delivered to a process. Signal delivery is basically a hardware interrupt but make it ✨vibes✨: the signal gets blocked from happening again, the current process context is saved, and a brand new one is built. A process can name a handler that a signal gets delivered to, or say a signal should be blocked or ignored. A process can also say "hey system, just do the default action" when a signal shows up. Normally, signal handlers run on the current stack of the process. But that can be changed β€” on a per-handler basis β€” so signals get taken on a special signal stack. πŸ¦‹

All signals have the same priority. Signal routines execute with the signal that caused their invocation blocked, but other signals may still occur. There's a global signal mask that 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). You can change it with a sigblock(2) or sigsetmask(2) call, or it changes when a signal is delivered to the process.

When a signal condition arises for a process, the signal gets added to a set of signals pending for the process. If the signal isn't currently blocked by the process, it gets 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 resumes execution in the context from before the signal's delivery. If the process wants to resume in a different context, then it has to arrange to restore the previous context itself. no cap. 😀

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(2) or sigsetmask(2) 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.

The sigvec() function assigns a handler for a specific signal. If vec is non-zero, it specifies a handler routine and mask to be used when delivering the specified signal. Further, if the SV_ONSTACK bit is set in sv_flags, the system will deliver the signal to the process on a signal stack, specified with sigaltstack(2). If ovec is non-zero, the previous handling information for the signal is returned to the user. 🫢

Here's the full list of all signals, with names as in the include file <signal.h>:

  • SIGHUP β€” Default action: terminate process β€” terminal line hangup
  • SIGINT β€” Default action: terminate process β€” interrupt program
  • SIGQUIT β€” Default action: create core image β€” quit program
  • SIGILL β€” Default action: create core image β€” illegal instruction
  • SIGTRAP β€” Default action: create core image β€” trace trap
  • SIGABRT β€” Default action: create core image β€” abort(3) call (formerly SIGIOT)
  • SIGEMT β€” Default action: create core image β€” emulate instruction executed
  • SIGFPE β€” Default action: create core image β€” floating-point exception
  • SIGKILL β€” Default action: terminate process β€” kill program
  • SIGBUS β€” Default action: create core image β€” bus error
  • SIGSEGV β€” Default action: create core image β€” segmentation violation
  • SIGSYS β€” Default action: create core image β€” non-existent system call invoked
  • SIGPIPE β€” Default action: terminate process β€” write on a pipe with no reader
  • SIGALRM β€” Default action: terminate process β€” real-time timer expired
  • SIGTERM β€” Default action: terminate process β€” software termination signal
  • SIGURG β€” Default action: discard signal β€” urgent condition present on socket
  • SIGSTOP β€” Default action: stop process β€” stop (cannot be caught or ignored)
  • SIGTSTP β€” Default action: stop process β€” stop signal generated from keyboard
  • SIGCONT β€” Default action: discard signal β€” continue after stop
  • SIGCHLD β€” Default action: discard signal β€” child status has changed
  • SIGTTIN β€” Default action: stop process β€” background read attempted from control terminal
  • SIGTTOU β€” Default action: stop process β€” background write attempted to control terminal
  • SIGIO β€” Default action: discard signal β€” I/O is possible on a descriptor (see fcntl(2))
  • SIGXCPU β€” Default action: terminate process β€” cpu time limit exceeded (see setrlimit(2))
  • SIGXFSZ β€” Default action: terminate process β€” file size limit exceeded (see setrlimit(2))
  • SIGVTALRM β€” Default action: terminate process β€” virtual time alarm (see setitimer(2))
  • SIGPROF β€” Default action: terminate process β€” profiling timer alarm (see setitimer(2))
  • SIGWINCH β€” Default action: discard signal β€” Window size change
  • SIGINFO β€” Default action: discard signal β€” status request from keyboard
  • SIGUSR1 β€” Default action: terminate process β€” User defined signal 1
  • SIGUSR2 β€” Default action: terminate process β€” User defined signal 2

Once a signal handler is installed, it stays installed until another sigvec() call is made, or an execve(2) is performed. You can reset a signal-specific default action by setting sv_handler to SIG_DFL. The defaults are process termination (possibly with core dump), no action, stopping the process, or continuing the process β€” check the signal list above for each signal's default action. If sv_handler is SIG_IGN, current and pending instances of the signal are ignored and discarded. πŸ’€

If a signal is caught during the system calls listed below, the call is normally restarted. You can force the call to terminate prematurely with an EINTR error return by setting the SV_INTERRUPT bit in sv_flags. The affected system calls include read(2), write(2), sendto(2), recvfrom(2), sendmsg(2) and recvmsg(2) on a communications channel or a slow device (such as a terminal, but not a regular file) and during a wait(2) or ioctl(2). However, calls that have already committed are not restarted β€” instead they return a partial success (for example, a short read count). 😭

After a fork(2) or vfork(2), all signals, the signal mask, the signal stack, and the restart/interrupt flags are inherited by the child. 🌸

The execve(2) system call reinstates the default action for all signals which were caught and resets all signals to be caught on the user stack. Ignored signals remain ignored; the signal mask remains the same; signals that interrupt system calls continue to do so.


πŸ“ NOTES πŸ“

The mask specified in vec is not allowed to block SIGKILL or SIGSTOP. This is done silently by the system. πŸ™ˆ

The SV_INTERRUPT flag is not available in 4.2BSD, hence it should not be used if backward compatibility is needed.


🎯 RETURN VALUES 🎯

The sigvec() function returns the value 0 if successful; otherwise the value -1 is returned and the global variable errno is set to indicate the error. slay or fail, no in-between πŸ’…


🌈 EXAMPLES 🌈

On the VAX-11, the handler routine can be declared:

void handler(sig, code, scp)
int sig, code;
struct sigcontext *scp;

Here sig is the signal number, into which the hardware faults and traps are mapped as defined below. The code argument is either a constant as given below or, for compatibility mode faults, the code provided by the hardware (Compatibility mode faults are distinguished from the other SIGILL traps by having PSL_CM set in the psl). The scp argument is a pointer to the sigcontext structure (defined in <signal.h>), used to restore the context from before the signal.


🚨 ERRORS 🚨

The sigvec() function 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.
  • [EINVAL] β€” The sig argument is not a valid signal number.
  • [EINVAL] β€” An attempt is made to ignore or supply a handler for SIGKILL or SIGSTOP.

πŸ‘€ SEE ALSO πŸ‘€

kill(1), kill(2), ptrace(2), sigaction(2), sigaltstack(2), sigblock(2), sigpause(2), sigprocmask(2), sigsetmask(2), sigsuspend(2), setjmp(3), siginterrupt(3), signal(3), sigsetops(3), tty(4)


πŸ’€ BUGS πŸ’€

This manual page is still confusing. (literally same, bestie 😭)


okay that's the whole page, mwah πŸ’– this one came from Debian, dated April 19, 1994 β€” yeah it's giving 90s but the signal handling still hits. go forth and sigvec() responsibly, ily, bye βœ¨πŸ¦‹πŸŽ€

πŸ“¦ where this page comes from