]> git.decadent.org.uk Git - nfs-utils.git/blobdiff - utils/statd/statd.c
2001-03-21 H.J. Lu <hjl@lucon.org>
[nfs-utils.git] / utils / statd / statd.c
index e758707887963aca31ddfae79785e39e36bcadc3..3d90d641851aa26c86f5920b6bdd38976db8f9df 100644 (file)
@@ -11,6 +11,7 @@
 #include <limits.h>
 #include <signal.h>
 #include <unistd.h>
+#include <fcntl.h>
 #include <string.h>
 #include <getopt.h>
 #include <rpc/rpc.h>
@@ -216,7 +217,7 @@ int main (int argc, char **argv)
 #endif
        
        if (!(run_mode & MODE_NODAEMON)) {
-               int filedes;
+               int filedes, fdmax, tempfd;
 
                if ((pid = fork ()) < 0) {
                        perror ("Could not fork");
@@ -229,7 +230,12 @@ int main (int argc, char **argv)
                setsid ();
                chdir (DIR_BASE);
 
-               for (filedes = 0; filedes < sysconf (_SC_OPEN_MAX); filedes++) {
+               tempfd = open("/dev/null", O_RDWR);
+               close(0); dup2(tempfd, 0);
+               close(1); dup2(tempfd, 1);
+               close(2); dup2(tempfd, 2);
+               fdmax = sysconf (_SC_OPEN_MAX);
+               for (filedes = 3; filedes < fdmax; filedes++) {
                        close (filedes);
                }
        }