aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorMattias Andrée <maandree@member.fsf.org>2015-12-31 01:20:14 +0100
committerMattias Andrée <maandree@member.fsf.org>2015-12-31 01:20:14 +0100
commit12ce1683a5901ffa00b96f5805855e568a3c6054 (patch)
tree98550f60bd200eb74ac4a499387ed4c06c957835 /src
parentm bug fix (diff)
downloadslibc-12ce1683a5901ffa00b96f5805855e568a3c6054.tar.gz
slibc-12ce1683a5901ffa00b96f5805855e568a3c6054.tar.bz2
slibc-12ce1683a5901ffa00b96f5805855e568a3c6054.tar.xz
daemonise: add option to override pid file
Signed-off-by: Mattias Andrée <maandree@member.fsf.org>
Diffstat (limited to '')
-rw-r--r--src/unistd/daemonise.c5
1 files changed, 3 insertions, 2 deletions
diff --git a/src/unistd/daemonise.c b/src/unistd/daemonise.c
index f05e118..9df70da 100644
--- a/src/unistd/daemonise.c
+++ b/src/unistd/daemonise.c
@@ -161,6 +161,7 @@ static int dup_at_least_3(int old)
* - `DAEMONISE_KEEP_STDIN`
* - `DAEMONISE_KEEP_STDOUT`
* - `DAEMONISE_KEEP_FDS`
+ * - `DAEMONISE_NEW_PID`
* @param ... Enabled if `DAEMONISE_KEEP_FDS` is used,
* do not add anything if `DAEMONISE_KEEP_FDS`
* is unused. This is a `-1`-terminated list
@@ -212,7 +213,7 @@ int daemonise(const char* name, int flags, ...)
/* Validate flags. */
- if (flags & ~2047)
+ if (flags & (int)~(2048L * 2 - 1))
return errno = EINVAL, -1;
if (flags & DAEMONISE_KEEP_STDERR)
if (flags & DAEMONISE_CLOSE_STDERR)
@@ -332,7 +333,7 @@ int daemonise(const char* name, int flags, ...)
t (__pidfile == NULL);
stpcpy(stpcpy(stpcpy(__pidfile, "/run/"), name), ".pid");
}
- fd = open(__pidfile, O_WRONLY | O_CREAT | O_EXCL, 0644);
+ fd = open(__pidfile, O_WRONLY | O_CREAT | ((flags & DAEMONISE_NEW_PID) ? 0 : O_EXCL), 0644);
if (fd == -1)
{
saved_errno = errno;