Module: sys.signal

Source: ./sys/signal.reef


Overview

sys/signal - Signal handling

Provides Unix signal handling capabilities. Signals are used for inter-process communication and handling events like Ctrl+C.

Example - Handle SIGINT (Ctrl+C): signal_handle(SIGINT()) while true if signal_received(SIGINT()) println("Caught Ctrl+C, exiting...") break end if // Do work... end while

Example - Ignore SIGPIPE: signal_ignore(SIGPIPE())


Functions

fn SIGINT(): int

Signal constant functions

fn SIGTERM(): int

fn SIGHUP(): int

fn SIGQUIT(): int

fn SIGKILL(): int

fn SIGSTOP(): int

fn SIGCONT(): int

fn SIGCHLD(): int

fn SIGUSR1(): int

fn SIGUSR2(): int

fn SIGPIPE(): int

fn SIGALRM(): int

fn signal_handle(signum: int): bool

Register to handle a signal (sets a flag when received) Returns true on success NOTE: SIGURG is reserved for GC suspension -- installing a handler for it here would override the collector's own handler, so this returns false for SIGURG instead.

fn signal_ignore(signum: int): bool

Ignore a signal Returns true on success NOTE: ignoring SIGURG would break GC suspension; refused.

fn signal_default(signum: int): bool

Reset signal to default behavior Returns true on success NOTE: resetting SIGURG to default would break GC suspension; refused.

fn signal_received(signum: int): bool

Check if signal was received (clears the flag) Returns true if signal was received since last check

fn signal_name(signum: int): string

Get the name of a signal

fn SIGRTMIN(): int

SIGRTMIN constant (real-time signal base)

fn SIGRTMIN_offset(n: int): int

SIGRTMIN + offset

fn signal_block(signum: int): bool

Block a signal (prevent delivery) NOTE: SIGURG is reserved by the runtime as the GC stop-the-world suspension channel. Calling this with SIGURG returns false (the underlying reef_signal_block refuses it with EINVAL) rather than blocking it, since that would hang the collector.

fn signal_unblock(signum: int): bool

Unblock a signal (allow delivery) SIGURG is NOT refused here -- unblocking it is always safe.

fn signal_wait(signals: [int]): int

Wait for one of a set of signals Returns the signal number received NOTE: if SIGURG is included in signals, this returns -1 (EINVAL) instead of waiting -- sigwait()ing on SIGURG could consume a GC-suspend signal meant for the collector.

fn selfpipe_create(): option.Option[[int]]

Create a self-pipe for async-signal-safe signal delivery Returns [read_fd, write_fd] 0.9.2 C16: Some(fds) on success, None when the pipe could not be created.

This DISCARDED the runtime's return value. reef_sys.c returns -1 without touching the buffer, reef_heaps zero-fills it, and new [int](2) always reports length 2 -- so a caller's if fds.length() < 2 guard could NEVER fire, and on failure the caller got fds = [0, 0]. Reproduced under fd exhaustion: selfpipe_register(SIGALRM, 0) SUCCEEDED and installed a handler that write(2)s the signal byte to FD 0, overwriting the first byte of an unrelated O_RDWR stream, and selfpipe_read(0) then returned a byte of that stream as a signal number.

DELIBERATELY NO selfpipe_create_or -- see fd_pipe. None means the syscall failed; a defaulted fd pair would have the signal handler writing to a descriptor nobody opened (measured pre-fix: it wrote to FD 0).

fn selfpipe_register(signum: int, write_fd: int): bool

Register a signal to write to self-pipe WARNING: Do not register GC signals (SIGUSR1/SIGUSR2 or SIGRTMIN+0/1)

fn selfpipe_read(read_fd: int): int

Read a signal number from self-pipe Returns signal number, or -1 if pipe is empty


Procedures

proc signal_init()

Initialize signal handling system


Generated by reefc doc