From 9cfed43fd0540a84fd75782f94e817fc4939c5ea Mon Sep 17 00:00:00 2001 From: lotodore Date: Tue, 28 Aug 2007 10:43:34 +0000 Subject: [PATCH] *sigh* some linux implementations have the function daemon. --- src/core/linux/daemon.c | 31 +++++++++++++++++-------------- src/pokerth_server.cpp | 7 +++++-- 2 files changed, 22 insertions(+), 16 deletions(-) diff --git a/src/core/linux/daemon.c b/src/core/linux/daemon.c index 35d22de1..454d8055 100644 --- a/src/core/linux/daemon.c +++ b/src/core/linux/daemon.c @@ -28,8 +28,10 @@ #include +#ifndef daemon + int -daemon() +daemon(int nochdir, int noclose) { int maxfd, fd = 0; @@ -61,22 +63,23 @@ daemon() } - chdir("/"); /* Change working directory. */ + if (!nochdir) + chdir("/"); /* Change working directory. */ - /* Close all open handles. */ - maxfd = sysconf(_SC_OPEN_MAX); - while (fd < maxfd) - close(fd++); + if (!noclose) + { + /* Close all open handles. */ + maxfd = sysconf(_SC_OPEN_MAX); + while (fd < maxfd) + close(fd++); - /* Use /dev/null as stdin/stdout/stderr. */ - open("/dev/null", O_RDWR); - dup(0); - dup(0); - - /* Set default permissions for created files. */ - umask(027); + /* Use /dev/null as stdin/stdout/stderr. */ + open("/dev/null", O_RDWR); + dup(0); + dup(0); + } return 0; } - +#endif diff --git a/src/pokerth_server.cpp b/src/pokerth_server.cpp index d6e80712..40141c75 100644 --- a/src/pokerth_server.cpp +++ b/src/pokerth_server.cpp @@ -58,7 +58,10 @@ TerminateHandler(int signal) // TODO: Hack #ifndef _WIN32 -int daemon(); + #include + #ifndef daemon + int daemon(int, int); + #endif #endif int @@ -70,7 +73,7 @@ main(int argc, char *argv[]) // TODO: Hack #ifndef _WIN32 - daemon(); + daemon(0, 0); #endif signal(SIGTERM, TerminateHandler);