From f83a5c48b5df25fe92e3b013f9e292d1b52e215f Mon Sep 17 00:00:00 2001 From: Mattias Andrée Date: Thu, 31 Dec 2015 01:24:44 +0100 Subject: m MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Mattias Andrée --- include/unistd.h | 11 ++++++++--- src/unistd/daemonise.c | 12 +++++++----- 2 files changed, 15 insertions(+), 8 deletions(-) diff --git a/include/unistd.h b/include/unistd.h index 8479ae9..5ca2358 100644 --- a/include/unistd.h +++ b/include/unistd.h @@ -1046,6 +1046,8 @@ int daemon(int, int) /** * Do not create a PID file. + * + * Cannot be combined with `DAEMONISE_NEW_PID`. */ #define DAEMONISE_NO_PID_FILE 32 @@ -1053,7 +1055,7 @@ int daemon(int, int) * Do not close stderr even if it is * a terminal device. * - * Cannot be combined with `DAEMONISE_KEEP_STDERR`. + * Cannot be combined with `DAEMONISE_CLOSE_STDERR`. */ #define DAEMONISE_KEEP_STDERR 64 @@ -1086,6 +1088,8 @@ int daemon(int, int) * rather than failing. It is a bad idea to do * this unless you already made sure that the * daemon is not already running. + * + * Cannot be combined with `DAEMONISE_NO_PID_FILE`. */ #define DAEMONISE_NEW_PID 2048 @@ -1187,8 +1191,9 @@ int daemon(int, int) * 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 + * are set, both `DAEMONISE_NO_PID_FILE` and + * `DAEMONISE_NEW_PID`, 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). diff --git a/src/unistd/daemonise.c b/src/unistd/daemonise.c index 9df70da..e7ae471 100644 --- a/src/unistd/daemonise.c +++ b/src/unistd/daemonise.c @@ -177,8 +177,9 @@ static int dup_at_least_3(int old) * 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 + * are set, both `DAEMONISE_NO_PID_FILE` and + * `DAEMONISE_NEW_PID`, 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). @@ -215,9 +216,10 @@ int daemonise(const char* name, int flags, ...) /* Validate flags. */ if (flags & (int)~(2048L * 2 - 1)) return errno = EINVAL, -1; - if (flags & DAEMONISE_KEEP_STDERR) - if (flags & DAEMONISE_CLOSE_STDERR) - return errno = EINVAL, -1; + if ((flags & DAEMONISE_KEEP_STDERR) && (flags & DAEMONISE_CLOSE_STDERR)) + return errno = EINVAL, -1; + if ((flags & DAEMONISE_NO_PID_FILE) && (flags & DAEMONISE_NEW_PID)) + return errno = EINVAL, -1; /* Find out which file descriptors not too close. */ -- cgit v1.2.3-70-g09d2