Paraslash Audio Streaming | |
About News Download Documentation Development |
Signal handling functions. More...
#include <signal.h>
#include <sys/types.h>
#include <regex.h>
#include "para.h"
#include "error.h"
#include "fd.h"
#include "list.h"
#include "string.h"
#include "sched.h"
Functions | |
struct signal_task * | signal_init_or_die (void) |
Initialize the paraslash signal subsystem. More... | |
int | para_reap_child (pid_t *pid) |
Reap one child. More... | |
void | para_sigaction (int sig, void(*handler)(int)) |
Install the given handler for the given signal. More... | |
void | para_install_sighandler (int sig) |
Install the generic signal handler for the given signal number. More... | |
void | para_block_signal (int sig) |
Block a signal for the caller. More... | |
void | para_unblock_signal (int sig) |
Unblock a signal. 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... | |
Signal handling functions.
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.
References PARA_NOTICE_LOG.
int para_reap_child | ( | pid_t * | pid | ) |
Reap one child.
pid | In 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.
References ERRNO_TO_PARA_ERROR, PARA_DEBUG_LOG, and PARA_WARNING_LOG.
void para_sigaction | ( | int | sig, |
void(*)(int) | handler | ||
) |
Install the given handler for the given signal.
sig | The number of the signal to catch. |
handler | to be installed, SIG_IGN , or SIG_DFL . |
This either succeeds or calls exit(EXIT_FAILURE).
References PARA_DEBUG_LOG, and PARA_EMERG_LOG.
Referenced by para_install_sighandler().
void para_install_sighandler | ( | int | sig | ) |
Install the generic signal handler for the given signal number.
sig | The number of the signal to catch. |
References para_sigaction().
void para_block_signal | ( | int | sig | ) |
Block a signal for the caller.
sig | The signal to block. |
This sets the given signal in the current signal mask of the calling process to prevent this signal from delivery.
References PARA_DEBUG_LOG.
void para_unblock_signal | ( | int | sig | ) |
Unblock a signal.
sig | The signal to unblock. |
This function removes the given signal from the current set of blocked signals.
References PARA_DEBUG_LOG.
int para_next_signal | ( | void | ) |
Return the number of the next pending signal.
References read_nonblock().
void signal_shutdown | ( | struct signal_task * | st | ) |
Close the write end of the signal pipe, deallocate resources.
st | The pointer obtained earlier from signal_init_or_die(). |