From e3785771efee83707606a3086fa97ff6632c6cd0 Mon Sep 17 00:00:00 2001 From: Mattias Andrée Date: Sun, 20 Dec 2015 20:38:39 +0100 Subject: add daemon MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Mattias Andrée --- include/unistd.h | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) (limited to 'include') diff --git a/include/unistd.h b/include/unistd.h index 2d7ee16..3812c8c 100644 --- a/include/unistd.h +++ b/include/unistd.h @@ -800,6 +800,7 @@ int fexecv(int, char* const[]); */ int fexecve(int, char* const[], char* const[]); + #if defined(__PLAN9_SOURCE) || defined(__SLIBC_SOURCE) /** * Search the environment variable $PATH for an executable @@ -918,6 +919,48 @@ char* searchpath3(const char*, const char*, const char*) #endif +#if defined(__BSD_SOURCE) || defined(__XOPEN_SOURCE) +/** + * Detach the process from the controlling terminal + * and run in the background. + * + * The function shall change the working directory + * to '/' to avoid block a mountpoint from being + * unmounted. It shall also change direct stdin, + * stdout, and stderr to '/dev/null'. It shall + * then double-fork, and between the fork, become + * a session leader, temporarily, so that the + * it no longer has a controlling terminal. + * + * Note well, this function does not implement a + * reliable or particularly correct mechanism for + * daemonising a process. It shall not be used! + * Note, the GNU implementation is slightly + * different because of a bug. + * + * @param nochdir The not change working directory to '/'. + * @param noclose The not redirect stdin, stdout, and stderr to '/dev/null'. + * @return Zero on success, -1 on error. + * + * @throws EACCES If `nochdir` is zero, and the user is denied access to '/'. + * @throws Any error specified for open(3). + * @throws Any error specified for dup2(3). + * @throws Any error specified for fork(3). + * @throws Any error specified for setsid(3). + * + * @since Always. + */ +int daemon(int, int) + __deprecated("Portable programs should implement this mechanism " + "manually. Non-portable programs may use 'daemonise'."); +#endif + + +#if defined(__SLIBC_SOURCE) +int daemonise(const char* int); /* TODO */ +#endif + + #endif -- cgit v1.2.3-70-g09d2