]> git.decadent.org.uk Git - nfs-utils.git/commitdiff
mydaemon: remove closeall() calls from mydaemon()
authorSteve Dickson <steved@redhat.com>
Mon, 29 Jun 2009 14:44:20 +0000 (10:44 -0400)
committerSteve Dickson <steved@redhat.com>
Mon, 29 Jun 2009 14:44:20 +0000 (10:44 -0400)
idmapd and svcgssd have a mydaemon() routine that uses closeall() to
close file descriptors. Unfortunately, they aren't using it correctly
and it ends up closing the pipe that the child process uses to talk to
its parent.

Fix this by not using closeall() in this routine and instead, just close
the file descriptors that we know need to be closed. If /dev/null can't
be opened for some reason, then just have the child exit with a non-zero
error.

Signed-off-by: Jeff Layton <jlayton@redhat.com>
Signed-off-by: Steve Dickson <steved@redhat.com>
utils/gssd/svcgssd.c
utils/idmapd/idmapd.c

index 69d2a6966946b287fed1bcdfef0849cb5a844dfb..729b6a6d3b80a86034e6887fd3a0e87c3113a9fa 100644 (file)
@@ -117,10 +117,16 @@ mydaemon(int nochdir, int noclose)
 
        if (noclose == 0) {
                tempfd = open("/dev/null", O_RDWR);
-               dup2(tempfd, 0);
-               dup2(tempfd, 1);
-               dup2(tempfd, 2);
-               closeall(3);
+               if (tempfd >= 0) {
+                       dup2(tempfd, 0);
+                       dup2(tempfd, 1);
+                       dup2(tempfd, 2);
+                       close(tempfd);
+               } else {
+                       printerr(1, "mydaemon: can't open /dev/null: errno %d "
+                                   "(%s)\n", errno, strerror(errno));
+                       exit(1);
+               }
        }
 
        return;
index b690e21fae9697a4e9ec6d0dc5221759576cacb3..9cbe96c4095a46d81d2847521f9838d81c043993 100644 (file)
@@ -978,9 +978,12 @@ mydaemon(int nochdir, int noclose)
                        dup2(tempfd, 0);
                        dup2(tempfd, 1);
                        dup2(tempfd, 2);
-                       closeall(3);
-               } else
-                       closeall(0);
+                       close(tempfd);
+               } else {
+                       err(1, "mydaemon: can't open /dev/null: errno %d",
+                              errno);
+                       exit(1);
+               }
        }
 
        return;