walters / rpms / nfs-utils

Forked from rpms/nfs-utils 6 years ago
Clone
3524d8a
commit 1aa4121ba599de836702d7b2d38cad63e6a09044
3524d8a
Author: Steve Dickson <steved@redhat.com>
3524d8a
Date:   Mon Jun 29 10:44:20 2009 -0400
3524d8a
3524d8a
    mydaemon: remove closeall() calls from mydaemon()
3524d8a
    
3524d8a
    idmapd and svcgssd have a mydaemon() routine that uses closeall() to
3524d8a
    close file descriptors. Unfortunately, they aren't using it correctly
3524d8a
    and it ends up closing the pipe that the child process uses to talk to
3524d8a
    its parent.
3524d8a
    
3524d8a
    Fix this by not using closeall() in this routine and instead, just close
3524d8a
    the file descriptors that we know need to be closed. If /dev/null can't
3524d8a
    be opened for some reason, then just have the child exit with a non-zero
3524d8a
    error.
3524d8a
    
3524d8a
    Signed-off-by: Jeff Layton <jlayton@redhat.com>
3524d8a
    Signed-off-by: Steve Dickson <steved@redhat.com>
3524d8a
3524d8a
diff --git a/utils/gssd/svcgssd.c b/utils/gssd/svcgssd.c
3524d8a
index 69d2a69..729b6a6 100644
3524d8a
--- a/utils/gssd/svcgssd.c
3524d8a
+++ b/utils/gssd/svcgssd.c
3524d8a
@@ -117,10 +117,16 @@ mydaemon(int nochdir, int noclose)
3524d8a
 
3524d8a
 	if (noclose == 0) {
3524d8a
 		tempfd = open("/dev/null", O_RDWR);
3524d8a
-		dup2(tempfd, 0);
3524d8a
-		dup2(tempfd, 1);
3524d8a
-		dup2(tempfd, 2);
3524d8a
-		closeall(3);
3524d8a
+		if (tempfd >= 0) {
3524d8a
+			dup2(tempfd, 0);
3524d8a
+			dup2(tempfd, 1);
3524d8a
+			dup2(tempfd, 2);
3524d8a
+			close(tempfd);
3524d8a
+		} else {
3524d8a
+			printerr(1, "mydaemon: can't open /dev/null: errno %d "
3524d8a
+				    "(%s)\n", errno, strerror(errno));
3524d8a
+			exit(1);
3524d8a
+		}
3524d8a
 	}
3524d8a
 
3524d8a
 	return;
3524d8a
diff --git a/utils/idmapd/idmapd.c b/utils/idmapd/idmapd.c
3524d8a
index b690e21..9cbe96c 100644
3524d8a
--- a/utils/idmapd/idmapd.c
3524d8a
+++ b/utils/idmapd/idmapd.c
3524d8a
@@ -978,9 +978,12 @@ mydaemon(int nochdir, int noclose)
3524d8a
 			dup2(tempfd, 0);
3524d8a
 			dup2(tempfd, 1);
3524d8a
 			dup2(tempfd, 2);
3524d8a
-			closeall(3);
3524d8a
-		} else
3524d8a
-			closeall(0);
3524d8a
+			close(tempfd);
3524d8a
+		} else {
3524d8a
+			err(1, "mydaemon: can't open /dev/null: errno %d",
3524d8a
+			       errno);
3524d8a
+			exit(1);
3524d8a
+		}
3524d8a
 	}
3524d8a
 
3524d8a
 	return;