Arthur de Jong

Open Source / Free Software developer

summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--configure.ac6
-rw-r--r--nslcd/daemonize.c18
2 files changed, 21 insertions, 3 deletions
diff --git a/configure.ac b/configure.ac
index 27d8e56..a80dff6 100644
--- a/configure.ac
+++ b/configure.ac
@@ -2,7 +2,7 @@
#
# Copyright (C) 2006 Luke Howard
# Copyright (C) 2006 West Consulting
-# Copyright (C) 2006, 2007, 2008, 2009, 2010, 2011, 2012, 2013 Arthur de Jong
+# Copyright (C) 2006-2014 Arthur de Jong
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
@@ -23,7 +23,7 @@ AC_PREREQ(2.61)
AC_COPYRIGHT(
[Copyright (C) 2006 Luke Howard
Copyright (C) 2006 West Consulting
-Copyright (C) 2006, 2007, 2008, 2009, 2010, 2011, 2012, 2013 Arthur de Jong
+Copyright (C) 2006-2014 Arthur de Jong
This configure script is derived from configure.ac which is free software;
you can redistribute it and/or modify it under the terms of the GNU Lesser
@@ -726,7 +726,7 @@ then
pthread_save_LIBS="$LIBS"
CFLAGS="$CFLAGS $PTHREAD_CFLAGS"
LIBS="$LIBS $PTHREAD_LIBS"
- AC_CHECK_FUNCS([pthread_mutex_lock pthread_join pthread_timedjoin_np])
+ AC_CHECK_FUNCS([pthread_mutex_lock pthread_join pthread_timedjoin_np pthread_atfork])
CFLAGS="$pthread_save_CFLAGS"
LIBS="$pthread_save_LIBS"
diff --git a/nslcd/daemonize.c b/nslcd/daemonize.c
index c9fb5e4..342c61c 100644
--- a/nslcd/daemonize.c
+++ b/nslcd/daemonize.c
@@ -29,6 +29,9 @@
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
+#ifdef HAVE_PTHREAD_H
+#include <pthread.h>
+#endif /* HAVE_PTHREAD_H */
#include "daemonize.h"
@@ -105,6 +108,15 @@ static int wait_for_response(int fd)
_exit(rc);
}
+static void closefd(void)
+{
+ if (daemonizefd >= 0)
+ {
+ close(daemonizefd);
+ daemonizefd = -1;
+ }
+}
+
int daemonize_daemon(void)
{
int pipefds[2];
@@ -165,6 +177,12 @@ int daemonize_daemon(void)
_exit(EXIT_SUCCESS);
}
daemonizefd = pipefds[1];
+ /* close the file descriptor on exec (ignore errors) */
+ fcntl(daemonizefd, F_SETFD, FD_CLOEXEC);
+#ifdef HAVE_PTHREAD_ATFORK
+ /* handle any other forks by closing daemonizefd first */
+ (void)pthread_atfork(NULL, NULL, closefd);
+#endif /* HAVE_PTHREAD_ATFORK */
return 0;
}