.TH "dfork.h" 3 "Mon Dec 21 2020" "Version 0.14" "libdaemon" \" -*- nroff -*- .ad l .nh .SH NAME dfork.h \- Contains an API for doing a daemonizing fork()\&. .SH SYNOPSIS .br .PP \fC#include \fP .br .SS "Macros" .in +1c .ti -1c .RI "#define \fBDAEMON_CLOSE_ALL_AVAILABLE\fP 1" .br .RI "This variable is defined to 1 iff \fBdaemon_close_all()\fP and \fBdaemon_close_allv()\fP are supported\&. " .ti -1c .RI "#define \fBDAEMON_UNBLOCK_SIGS_AVAILABLE\fP 1" .br .RI "This variable is defined to 1 iff \fBdaemon_unblock_sigs()\fP and \fBdaemon_unblock_sigsv()\fP are supported\&. " .ti -1c .RI "#define \fBDAEMON_RESET_SIGS_AVAILABLE\fP 1" .br .RI "This variable is defined to 1 iff \fBdaemon_reset_sigs()\fP and \fBdaemon_reset_sigsv()\fP are supported\&. " .in -1c .SS "Functions" .in +1c .ti -1c .RI "pid_t \fBdaemon_fork\fP (void)" .br .RI "Does a daemonizing fork()\&. " .ti -1c .RI "int \fBdaemon_retval_init\fP (void)" .br .RI "Allocate and initialize resources required by the daemon_retval_xxx() functions\&. " .ti -1c .RI "void \fBdaemon_retval_done\fP (void)" .br .RI "Frees the resources allocated by \fBdaemon_retval_init()\fP\&. " .ti -1c .RI "int \fBdaemon_retval_wait\fP (int timeout)" .br .RI "Return the value sent by the child via the \fBdaemon_retval_send()\fP function, but wait only the specified number of seconds before timing out and returning a negative number\&. " .ti -1c .RI "int \fBdaemon_retval_send\fP (int s)" .br .RI "Send the specified integer to the parent process\&. " .ti -1c .RI "int \fBdaemon_close_all\fP (int except_fd,\&.\&.\&.)" .br .RI "Close all file descriptors except those passed\&. " .ti -1c .RI "int \fBdaemon_close_allv\fP (const int except_fds[])" .br .RI "Same as daemon_close_all but takes an array of fds, terminated by -1\&. " .ti -1c .RI "int \fBdaemon_unblock_sigs\fP (int except,\&.\&.\&.)" .br .RI "Unblock all signals except those passed\&. " .ti -1c .RI "int \fBdaemon_unblock_sigsv\fP (const int except[])" .br .RI "Same as \fBdaemon_unblock_sigs()\fP but takes an array of signals, terminated by -1\&. " .ti -1c .RI "int \fBdaemon_reset_sigs\fP (int except,\&.\&.\&.)" .br .RI "Reset all signal handlers except those passed\&. " .ti -1c .RI "int \fBdaemon_reset_sigsv\fP (const int except[])" .br .RI "Same as \fBdaemon_reset_sigs()\fP but takes an array of signals, terminated by -1\&. " .in -1c .SH "Detailed Description" .PP Contains an API for doing a daemonizing fork()\&. You may daemonize by calling \fBdaemon_fork()\fP, 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\&. .PP Definition in file \fBdfork\&.h\fP\&. .SH "Macro Definition Documentation" .PP .SS "#define DAEMON_CLOSE_ALL_AVAILABLE 1" .PP This variable is defined to 1 iff \fBdaemon_close_all()\fP and \fBdaemon_close_allv()\fP are supported\&. .PP \fBSince\fP .RS 4 0\&.11 .RE .PP \fBSee also\fP .RS 4 \fBdaemon_close_all()\fP, \fBdaemon_close_allv()\fP .RE .PP .PP Definition at line 106 of file dfork\&.h\&. .SS "#define DAEMON_RESET_SIGS_AVAILABLE 1" .PP This variable is defined to 1 iff \fBdaemon_reset_sigs()\fP and \fBdaemon_reset_sigsv()\fP are supported\&. .PP \fBSince\fP .RS 4 0\&.13 .RE .PP \fBSee also\fP .RS 4 \fBdaemon_reset_sigs()\fP, \fBdaemon_reset_sigsv()\fP .RE .PP .PP Definition at line 142 of file dfork\&.h\&. .SS "#define DAEMON_UNBLOCK_SIGS_AVAILABLE 1" .PP This variable is defined to 1 iff \fBdaemon_unblock_sigs()\fP and \fBdaemon_unblock_sigsv()\fP are supported\&. .PP \fBSince\fP .RS 4 0\&.13 .RE .PP \fBSee also\fP .RS 4 \fBdaemon_unblock_sigs()\fP, \fBdaemon_unblock_sigsv()\fP .RE .PP .PP Definition at line 124 of file dfork\&.h\&. .SH "Function Documentation" .PP .SS "int daemon_close_all (int except_fd, \&.\&.\&.)" .PP Close all file descriptors except those passed\&. List needs to be terminated by -1\&. FDs 0, 1, 2 will be kept open anyway\&. .PP \fBSince\fP .RS 4 0\&.11 .RE .PP \fBSee also\fP .RS 4 \fBDAEMON_CLOSE_ALL_AVAILABLE\fP .RE .PP .PP \fBExamples\fP .in +1c \fBtestd\&.c\fP\&. .SS "int daemon_close_allv (const int except_fds[])" .PP Same as daemon_close_all but takes an array of fds, terminated by -1\&. .PP \fBSince\fP .RS 4 0\&.11 .RE .PP \fBSee also\fP .RS 4 \fBDAEMON_CLOSE_ALL_AVAILABLE\fP .RE .PP .SS "pid_t daemon_fork (void)" .PP 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\&. .PP \fBReturns\fP .RS 4 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\&. .RE .PP .PP \fBExamples\fP .in +1c \fBtestd\&.c\fP\&. .SS "int daemon_reset_sigs (int except, \&.\&.\&.)" .PP Reset all signal handlers except those passed\&. List needs to be terminated by -1\&. .PP \fBSince\fP .RS 4 0\&.13 .RE .PP \fBSee also\fP .RS 4 \fBDAEMON_RESET_SIGS_AVAILABLE\fP .RE .PP .PP \fBExamples\fP .in +1c \fBtestd\&.c\fP\&. .SS "int daemon_reset_sigsv (const int except[])" .PP Same as \fBdaemon_reset_sigs()\fP but takes an array of signals, terminated by -1\&. .PP \fBSince\fP .RS 4 0\&.13 .RE .PP \fBSee also\fP .RS 4 \fBDAEMON_RESET_SIGS_AVAILABLE\fP .RE .PP .SS "void daemon_retval_done (void)" .PP Frees the resources allocated by \fBdaemon_retval_init()\fP\&. This should be called if neither \fBdaemon_retval_wait()\fP nor \fBdaemon_retval_send()\fP is called in the current process\&. The resources allocated by \fBdaemon_retval_init()\fP should be freed in both parent and daemon process\&. This may be achieved by using \fBdaemon_retval_wait()\fP resp\&. \fBdaemon_retval_send()\fP, or by using \fBdaemon_retval_done()\fP\&. .PP \fBExamples\fP .in +1c \fBtestd\&.c\fP\&. .SS "int daemon_retval_init (void)" .PP 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\&. .PP \fBReturns\fP .RS 4 zero on success, nonzero on failure\&. .RE .PP .PP \fBExamples\fP .in +1c \fBtestd\&.c\fP\&. .SS "int daemon_retval_send (int s)" .PP 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 \fBdaemon_retval_done()\fP in the daemon is ignored\&. .PP \fBParameters\fP .RS 4 \fIs\fP The integer to pass to \fBdaemon_retval_wait()\fP in the parent process .RE .PP \fBReturns\fP .RS 4 Zero on success, nonzero on failure\&. .RE .PP .PP \fBExamples\fP .in +1c \fBtestd\&.c\fP\&. .SS "int daemon_retval_wait (int timeout)" .PP Return the value sent by the child via the \fBdaemon_retval_send()\fP 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 \fBdaemon_retval_done()\fP in the parent is ignored\&. .PP \fBParameters\fP .RS 4 \fItimeout\fP Thetimeout in seconds .RE .PP \fBReturns\fP .RS 4 The integer passed \fBdaemon_retval_send()\fP in the daemon process, or -1 on failure\&. .RE .PP .PP \fBExamples\fP .in +1c \fBtestd\&.c\fP\&. .SS "int daemon_unblock_sigs (int except, \&.\&.\&.)" .PP Unblock all signals except those passed\&. List needs to be terminated by -1\&. .PP \fBSince\fP .RS 4 0\&.13 .RE .PP \fBSee also\fP .RS 4 \fBDAEMON_UNBLOCK_SIGS_AVAILABLE\fP .RE .PP .PP \fBExamples\fP .in +1c \fBtestd\&.c\fP\&. .SS "int daemon_unblock_sigsv (const int except[])" .PP Same as \fBdaemon_unblock_sigs()\fP but takes an array of signals, terminated by -1\&. .PP \fBSince\fP .RS 4 0\&.13 .RE .PP \fBSee also\fP .RS 4 \fBDAEMON_UNBLOCK_SIGS_AVAILABLE\fP .RE .PP .SH "Author" .PP Generated automatically by Doxygen for libdaemon from the source code\&.