summaryrefslogtreecommitdiff
path: root/daemon.c
diff options
context:
space:
mode:
authorBrad Fitzpatrick <brad@danga.com>2006-09-04 04:08:03 +0000
committerBrad Fitzpatrick <brad@danga.com>2006-09-04 04:08:03 +0000
commit86969ea43d6718411cc3653faeb0c49090a1c4cf (patch)
treeddb9da202b62f152141ff060900b69052572109e /daemon.c
parent85688dac534a831db220485a5691e380f54ce2f5 (diff)
downloadmemcached-86969ea43d6718411cc3653faeb0c49090a1c4cf.tar.gz
restore blank lines I over-zealously destroyed earlier.
git-svn-id: http://code.sixapart.com/svn/memcached/trunk/server@335 b0b603af-a30f-0410-a34e-baf09ae79d0b
Diffstat (limited to 'daemon.c')
-rw-r--r--daemon.c7
1 files changed, 7 insertions, 0 deletions
diff --git a/daemon.c b/daemon.c
index a2502e0..b80c53e 100644
--- a/daemon.c
+++ b/daemon.c
@@ -28,18 +28,22 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
+
#if defined __SUNPRO_C || defined __DECC || defined __HP_cc
# pragma ident "@(#)$Header: /cvsroot/wikipedia/willow/src/bin/willow/daemon.c,v 1.1 2005/05/02 19:15:21 kateturner Exp $"
# pragma ident "$NetBSD: daemon.c,v 1.9 2003/08/07 16:42:46 agc Exp $"
#endif
+
#include <fcntl.h>
#include <stdlib.h>
#include <unistd.h>
+
int
daemon(nochdir, noclose)
int nochdir, noclose;
{
int fd;
+
switch (fork()) {
case -1:
return (-1);
@@ -48,10 +52,13 @@ daemon(nochdir, noclose)
default:
_exit(0);
}
+
if (setsid() == -1)
return (-1);
+
if (!nochdir)
(void)chdir("/");
+
if (!noclose && (fd = open("/dev/null", O_RDWR, 0)) != -1) {
(void)dup2(fd, STDIN_FILENO);
(void)dup2(fd, STDOUT_FILENO);