logo
Free, unlimited AI code reviews that run on commit
git-lrc git-lrc GitHub Install Now We'd appreciate a star git-lrc - Free, unlimited AI code reviews that run on commit | Product Hunt git-lrc - Free, unlimited AI code reviews that run on commit | Product Hunt

dfork.h - Contains an API for doing a daemonizing fork().

Author

Generated automatically by Doxygen for libdaemon from the source code. libdaemon Version 0.14 dfork.h(3)

Detailed Description

Contains an API for doing a daemonizing fork(). You may daemonize by calling daemon_fork(), a function similar to the plain fork(). If you want to return a return value of the initialization procedure of the child from the parent, you may use the daemon_retval_xxx() functions. Definition in file dfork.h.

Function Documentation

intdaemon_close_all(intexcept_fd,...) Close all file descriptors except those passed. List needs to be terminated by -1. FDs 0, 1, 2 will be kept open anyway. Since 0.11 SeealsoDAEMON_CLOSE_ALL_AVAILABLEExamplestestd.c. intdaemon_close_allv(constintexcept_fds[]) Same as daemon_close_all but takes an array of fds, terminated by -1. Since 0.11 SeealsoDAEMON_CLOSE_ALL_AVAILABLEpid_tdaemon_fork(void) Does a daemonizing fork(). For the new daemon process STDIN, STDOUT, STDERR are connected to /dev/null, the process is a session leader, the current directory is changed to /, the umask is set to 777. Returns On success, the PID of the child process is returned in the parent's thread of execution, and a 0 is returned in the child's thread of execution. On failure, -1 will be returned in the parent's context, no child process will be created, and errno will be set appropriately. Examplestestd.c. intdaemon_reset_sigs(intexcept,...) Reset all signal handlers except those passed. List needs to be terminated by -1. Since 0.13 SeealsoDAEMON_RESET_SIGS_AVAILABLEExamplestestd.c. intdaemon_reset_sigsv(constintexcept[]) Same as daemon_reset_sigs() but takes an array of signals, terminated by -1. Since 0.13 SeealsoDAEMON_RESET_SIGS_AVAILABLEvoiddaemon_retval_done(void) Frees the resources allocated by daemon_retval_init(). This should be called if neither daemon_retval_wait() nor daemon_retval_send() is called in the current process. The resources allocated by daemon_retval_init() should be freed in both parent and daemon process. This may be achieved by using daemon_retval_wait() resp. daemon_retval_send(), or by using daemon_retval_done(). Examplestestd.c. intdaemon_retval_init(void) Allocate and initialize resources required by the daemon_retval_xxx() functions. These functions allow the child to send a value to the parent after completing its initialisation. Call this in the parent before forking. Returns zero on success, nonzero on failure. Examplestestd.c. intdaemon_retval_send(ints) Send the specified integer to the parent process. Do not send -1 because this signifies a library error. Should be called just once from the daemon process only. A subsequent call to daemon_retval_done() in the daemon is ignored. Parameterss The integer to pass to daemon_retval_wait() in the parent process Returns Zero on success, nonzero on failure. Examplestestd.c. intdaemon_retval_wait(inttimeout) Return the value sent by the child via the daemon_retval_send() function, but wait only the specified number of seconds before timing out and returning a negative number. Should be called just once from the parent process only. A subsequent call to daemon_retval_done() in the parent is ignored. Parameterstimeout Thetimeout in seconds Returns The integer passed daemon_retval_send() in the daemon process, or -1 on failure. Examplestestd.c. intdaemon_unblock_sigs(intexcept,...) Unblock all signals except those passed. List needs to be terminated by -1. Since 0.13 SeealsoDAEMON_UNBLOCK_SIGS_AVAILABLEExamplestestd.c. intdaemon_unblock_sigsv(constintexcept[]) Same as daemon_unblock_sigs() but takes an array of signals, terminated by -1. Since 0.13 SeealsoDAEMON_UNBLOCK_SIGS_AVAILABLE

Macro Definition Documentation

#defineDAEMON_CLOSE_ALL_AVAILABLE1 This variable is defined to 1 iff daemon_close_all() and daemon_close_allv() are supported. Since 0.11 Seealsodaemon_close_all(), daemon_close_allv() Definition at line 106 of file dfork.h. #defineDAEMON_RESET_SIGS_AVAILABLE1 This variable is defined to 1 iff daemon_reset_sigs() and daemon_reset_sigsv() are supported. Since 0.13 Seealsodaemon_reset_sigs(), daemon_reset_sigsv() Definition at line 142 of file dfork.h. #defineDAEMON_UNBLOCK_SIGS_AVAILABLE1 This variable is defined to 1 iff daemon_unblock_sigs() and daemon_unblock_sigsv() are supported. Since 0.13 Seealsodaemon_unblock_sigs(), daemon_unblock_sigsv() Definition at line 124 of file dfork.h.

Name

dfork.h - Contains an API for doing a daemonizing fork().

Synopsis

#include <sys/types.h> Macros #define DAEMON_CLOSE_ALL_AVAILABLE 1 This variable is defined to 1 iff daemon_close_all() and daemon_close_allv() are supported. #define DAEMON_UNBLOCK_SIGS_AVAILABLE 1 This variable is defined to 1 iff daemon_unblock_sigs() and daemon_unblock_sigsv() are supported. #define DAEMON_RESET_SIGS_AVAILABLE 1 This variable is defined to 1 iff daemon_reset_sigs() and daemon_reset_sigsv() are supported. Functions pid_t daemon_fork (void) Does a daemonizing fork(). int daemon_retval_init (void) Allocate and initialize resources required by the daemon_retval_xxx() functions. void daemon_retval_done (void) Frees the resources allocated by daemon_retval_init(). int daemon_retval_wait (int timeout) Return the value sent by the child via the daemon_retval_send() function, but wait only the specified number of seconds before timing out and returning a negative number. int daemon_retval_send (int s) Send the specified integer to the parent process. int daemon_close_all (int except_fd,...) Close all file descriptors except those passed. int daemon_close_allv (const int except_fds[]) Same as daemon_close_all but takes an array of fds, terminated by -1. int daemon_unblock_sigs (int except,...) Unblock all signals except those passed. int daemon_unblock_sigsv (const int except[]) Same as daemon_unblock_sigs() but takes an array of signals, terminated by -1. int daemon_reset_sigs (int except,...) Reset all signal handlers except those passed. int daemon_reset_sigsv (const int except[]) Same as daemon_reset_sigs() but takes an array of signals, terminated by -1.

See Also