From 83ac63cea12d7b176008739ac5fdafd01f628bef Mon Sep 17 00:00:00 2001 From: Adam Dickmeiss Date: Sun, 18 Jan 2004 02:28:42 +0000 Subject: [PATCH] Fixed PID file so it is generated after fork (-r & -D) --- src/statserv.c | 45 ++++++++++++++++++++++----------------------- 1 file changed, 22 insertions(+), 23 deletions(-) diff --git a/src/statserv.c b/src/statserv.c index dd52b6a..ebd0b70 100644 --- a/src/statserv.c +++ b/src/statserv.c @@ -1,12 +1,11 @@ /* * Copyright (c) 1995-2004, Index Data * See the file LICENSE for details. - * Sebastian Hammer, Adam Dickmeiss * * NT threaded server code by * Chas Woodfield, Fretwell Downing Informatics. * - * $Id: statserv.c,v 1.4 2004-01-17 01:20:13 adam Exp $ + * $Id: statserv.c,v 1.5 2004-01-18 02:28:42 adam Exp $ */ #include @@ -743,6 +742,27 @@ int statserv_start(int argc, char **argv) inetd_connection(control_block.default_proto); else { + if (control_block.background) + { + switch (fork()) + { + case 0: + break; + case -1: + return 1; + default: + _exit(0); + } + + if (setsid() < 0) + return 1; + + close(0); + close(1); + close(2); + open("/dev/null",O_RDWR); + dup(0); dup(0); + } if (!pListener && *control_block.default_listen) add_listener(control_block.default_listen, control_block.default_proto); @@ -792,27 +812,6 @@ int statserv_start(int argc, char **argv) exit(1); } } - if (!control_block.inetd && control_block.background) - { - switch (fork()) - { - case 0: - break; - case -1: - return 1; - default: - _exit(0); - } - - if (setsid() < 0) - return 1; - - close(0); - close(1); - close(2); - open("/dev/null",O_RDWR); - dup(0); dup(0); - } /* UNIX */ #endif if ((pListener == NULL) && *control_block.default_listen) -- 1.7.10.4