paraslash Paraslash Audio Streaming
About   News   Download   Documentation   Development

Data Structures | Functions
signal.h File Reference

exported symbols from signal.c More...

Data Structures

struct  signal_task
 Task for signal handling. More...
 

Functions

_static_inline_ void signal_pre_monitor (struct sched *s, void *context)
 Monitor the signal fd for reading. More...
 
struct signal_tasksignal_init_or_die (void)
 Initialize the paraslash signal subsystem. More...
 
void para_sigaction (int sig, void(*handler)(int))
 Install the given handler for the given signal. More...
 
void para_install_sighandler (int)
 Install the generic signal handler for the given signal number. More...
 
int para_reap_child (pid_t *pid)
 Reap one child. More...
 
int para_next_signal (void)
 Return the number of the next pending signal. More...
 
void signal_shutdown (struct signal_task *st)
 Close the write end of the signal pipe, deallocate resources. More...
 
void para_block_signal (int sig)
 Block a signal for the caller. More...
 
void para_unblock_signal (int sig)
 Unblock a signal. More...
 

Detailed Description

exported symbols from signal.c

Function Documentation

◆ signal_pre_monitor()

_static_inline_ void signal_pre_monitor ( struct sched s,
void *  context 
)

Monitor the signal fd for reading.

Parameters
sThe scheduler instance.
contextSignal task pointer.

This convenience helper is called from several programs which need to handle signals, including para_server and para_audiod. These programs set up a signal pipe and a signal task structure, and use this function to tell the scheduler to monitor the read end of the pipe.

Although the second parameter must be in fact a pointer to a signal_task structure, the parameter is specified as void * here to match the signature declared in struct task_info.

References signal_task::fd, and sched_monitor_readfd().

◆ signal_init_or_die()

struct signal_task* signal_init_or_die ( void  )

Initialize the paraslash signal subsystem.

This function creates a pipe, the signal pipe, to deliver pending signals to the application (Bernstein's trick). It should be called during the application's startup part, followed by subsequent calls to para_install_sighandler() for each signal that should be caught.

A generic signal handler is used for all signals simultaneously. When a signal arrives, the signal handler writes the number of the signal received to one end of the signal pipe. The application can test for pending signals by checking if the file descriptor of the other end of the signal pipe is ready for reading.

Returns
This function either succeeds or calls exit(3) to terminate the current process. On success, a signal task structure is returned.

References PARA_NOTICE_LOG.

◆ para_sigaction()

void para_sigaction ( int  sig,
void(*)(int)  handler 
)

Install the given handler for the given signal.

Parameters
sigThe number of the signal to catch.
handlerto be installed, SIG_IGN, or SIG_DFL.

This either succeeds or calls exit(EXIT_FAILURE).

See also
sigaction(2).

References PARA_DEBUG_LOG, and PARA_EMERG_LOG.

Referenced by para_install_sighandler().

◆ para_install_sighandler()

void para_install_sighandler ( int  sig)

Install the generic signal handler for the given signal number.

Parameters
sigThe number of the signal to catch.
See also
signal(2), sigaction(2).

References para_sigaction().

◆ para_reap_child()

int para_reap_child ( pid_t *  pid)

Reap one child.

Parameters
pidIn case a child died, its pid is returned here.

Call waitpid() and print a log message containing the pid and the cause of the child's death.

Returns
A (negative) paraslash error code on errors, zero, if no child died, one otherwise. If and only if the function returns one, the content of pid is meaningful.
See also
waitpid(2).

References ERRNO_TO_PARA_ERROR, PARA_DEBUG_LOG, and PARA_WARNING_LOG.

◆ para_next_signal()

int para_next_signal ( void  )

Return the number of the next pending signal.

Returns
On success, the number of the received signal is returned. If there is no signal currently pending, the function returns zero. On read errors from the signal pipe, the process is terminated.

References read_nonblock().

◆ signal_shutdown()

void signal_shutdown ( struct signal_task st)

Close the write end of the signal pipe, deallocate resources.

Parameters
stThe pointer obtained earlier from signal_init_or_die().

◆ para_block_signal()

void para_block_signal ( int  sig)

Block a signal for the caller.

Parameters
sigThe signal to block.

This sets the given signal in the current signal mask of the calling process to prevent this signal from delivery.

See also
para_unblock_signal(), sigprocmask(2), sigaddset(3).

References PARA_DEBUG_LOG.

◆ para_unblock_signal()

void para_unblock_signal ( int  sig)

Unblock a signal.

Parameters
sigThe signal to unblock.

This function removes the given signal from the current set of blocked signals.

See also
para_block_signal(), sigprocmask(2), sigaddset(3).

References PARA_DEBUG_LOG.