bglibs
Functions
selfpipe: Safe child exit management.

Functions

int selfpipe_init (void)
 
void selfpipe_close (void)
 
void selfpipe_catch_signal (int)
 

Detailed Description

Function Documentation

◆ selfpipe_catch_signal()

void selfpipe_catch_signal ( int  signal)

Catch a signal and write it to the self-pipe.

This routine can be used with sig_*_catch() to send other signals through the self-pipe.

Referenced by selfpipe_init().

◆ selfpipe_close()

void selfpipe_close ( void  )

Shut down the self-pipe.

References obuf_endl(), obuf_put2s(), obuf_puti(), outbuf, and selfpipe_init().

◆ selfpipe_init()

int selfpipe_init ( void  )

Set up a self-pipe for catching child exit events.

This function opens up a pipe within the program used to safely handle exiting child processes. Every time a child exits, a single byte is written to the pipe. The resulting file descriptor is statically assigned, so do not call this function more than once within a single program. The file descriptor is set to non-blocking mode to prevent blocking when reading from it.

To use the file descriptor, use either poll or select to determine when it is readable. When it becomes readable, read the data written to it (and throw it away), and use wait or equivalent to catch the exit value from the child process(es).

Returns
-1 if an error occurred, otherwise the return value is the file descriptor opened for reading.

References selfpipe_catch_signal().

Referenced by selfpipe_close().