diff options
author | Fritz Elfert <felfert@to.com> | 2002-02-15 08:40:26 +0000 |
---|---|---|
committer | Fritz Elfert <felfert@to.com> | 2002-02-15 08:40:26 +0000 |
commit | 217be020a262b94065b4df0cc9e6735cc47b3a80 (patch) | |
tree | 48a045dcd5ec05eafabfe85853c946a93fe8268a /ncpd | |
parent | dd84853bc078366d6b345066b3915170d52b93ce (diff) | |
download | plptools-217be020a262b94065b4df0cc9e6735cc47b3a80.tar.gz plptools-217be020a262b94065b4df0cc9e6735cc47b3a80.tar.bz2 plptools-217be020a262b94065b4df0cc9e6735cc47b3a80.zip |
Correct daemonizing
Diffstat (limited to 'ncpd')
-rw-r--r-- | ncpd/main.cc | 15 |
1 files changed, 14 insertions, 1 deletions
diff --git a/ncpd/main.cc b/ncpd/main.cc index 50931c6..465c003 100644 --- a/ncpd/main.cc +++ b/ncpd/main.cc @@ -31,6 +31,9 @@ #include <stdlib.h> #include <signal.h> #include <errno.h> +#include <sys/types.h> +#include <sys/stat.h> +#include <fcntl.h> #include "ncp.h" #include "bufferstore.h" @@ -208,7 +211,17 @@ main(int argc, char **argv) syslog(LOG_INFO, "daemon started. Listening at 127.0.0.1:%d, using device %s\n", sockNum, serialDevice); - close(0); close(1); close(2); + setsid(); + chdir("/"); + int devnull = + open("/dev/null", O_RDWR, 0); + if (devnull != -1) { + dup2(devnull, STDIN_FILENO); + dup2(devnull, STDOUT_FILENO); + dup2(devnull, STDERR_FILENO); + if (devnull > 2) + close(devnull); + } } ncp *a = new ncp(serialDevice, baudRate, iow); int numScp = 0; |