From ae79d159182044ad450f6c189c231f7ddbbdc918 Mon Sep 17 00:00:00 2001 From: Mattias Andrée Date: Mon, 28 Dec 2015 15:07:11 +0100 Subject: daemonise: support keeping arbitrary fd:s open MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Mattias Andrée --- include/unistd.h | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) (limited to 'include') diff --git a/include/unistd.h b/include/unistd.h index f4d699c..29a65c6 100644 --- a/include/unistd.h +++ b/include/unistd.h @@ -1075,6 +1075,12 @@ int daemon(int, int) */ #define DAEMONISE_KEEP_STDOUT 512 +/** + * Enables you to select additional + * file descritors to keep open. + */ +#define DAEMONISE_KEEP_FDS 1024 + /** * Daemonise the process. This means to: * @@ -1156,25 +1162,40 @@ int daemon(int, int) * - `DAEMONISE_CLOSE_STDERR` * - `DAEMONISE_KEEP_STDIN` * - `DAEMONISE_KEEP_STDOUT` + * - `DAEMONISE_KEEP_FDS` + * @parma ... Enabled if `DAEMONISE_KEEP_FDS` is used, + * do not add anything if `DAEMONISE_KEEP_FDS` + * is unused. This is a `-1`-terminated list + * of file descritors to keep open. 0, 1, and 2 + * are implied by `DAEMONISE_KEEP_STDIN`, + * `DAEMONISE_KEEP_STDOUT`, and `DAEMONISE_KEEP_STDERR`, + * respectively. All arguments are of type `int`. * @return Zero on success, -1 on error. * * @throws EEXIST The PID file already exists on the system. * Unless your daemon supervisor removs old * PID files, this could mean that the daemon * has exited without removing the PID file. + * @throws EINVAL `flags` contains an unsupported bit, both + * `DAEMONISE_KEEP_STDERR` and `DAEMONISE_CLOSE_STDERR` + * are set, or both `DAEMONISE_CLOSE_STDERR` and + * `DAEMONISE_KEEP_FDS` are set whilst `2` is + * in the list of file descriptor not to close. * @throws Any error specified for signal(3). * @throws Any error specified for sigemptyset(3). * @throws Any error specified for sigprocmask(3). * @throws Any error specified for chdir(3). * @throws Any error specified for pipe(3). + * @throws Any error specified for dup(3). * @throws Any error specified for dup2(3). * @throws Any error specified for fork(3). * @throws Any error specified for setsid(3). * @throws Any error specified for open(3). + * @throws Any error specified for malloc(3). * * @since Always. */ -int daemonise(const char*, int) +int daemonise(const char*, int, ...) __GCC_ONLY(__attribute__((__nonnull__, __warn_unused_result__))); /** -- cgit v1.2.3-70-g09d2