[master] 4d5dd87 Don't use getdtablesize() for closing existing fd's it only represents the current limit.

Poul-Henning Kamp phk at FreeBSD.org
Wed Jan 6 14:51:54 CET 2016


commit 4d5dd87b0d2e17d647b7ebe81e96164b828244b1
Author: Poul-Henning Kamp <phk at FreeBSD.org>
Date:   Wed Jan 6 13:32:47 2016 +0000

    Don't use getdtablesize() for closing existing fd's it only
    represents the current limit.
    
    Also don't call it every iteration of the loop.

diff --git a/bin/varnishd/mgt/mgt_main.c b/bin/varnishd/mgt/mgt_main.c
index 1073b8e..25c7ce4 100644
--- a/bin/varnishd/mgt/mgt_main.c
+++ b/bin/varnishd/mgt/mgt_main.c
@@ -530,7 +530,7 @@ main(int argc, char * const *argv)
 	 * Start out by closing all unwanted file descriptors we might
 	 * have inherited from sloppy process control daemons.
 	 */
-	for (o = getdtablesize(); o > STDERR_FILENO; o--)
+	for (o = sysconf(_SC_OPEN_MAX); o > STDERR_FILENO; o--)
 		(void)close(o);
 
 	VRND_Seed();
diff --git a/bin/varnishtest/vtc_process.c b/bin/varnishtest/vtc_process.c
index c0a15c2..8770b5f 100644
--- a/bin/varnishtest/vtc_process.c
+++ b/bin/varnishtest/vtc_process.c
@@ -203,7 +203,7 @@ process_start(struct process *p)
 		assert(dup2(p->fds[0], 0) == 0);
 		assert(dup2(out_fd, 1) == 1);
 		assert(dup2(err_fd, 2) == 2);
-		for (i = 3; i <getdtablesize(); i++)
+		for (i = sysconf(_SC_OPEN_MAX); i > STDERR_FILENO; i--)
 			(void)close(i);
 		AZ(execl("/bin/sh", "/bin/sh", "-c", VSB_data(cl), (char*)0));
 		exit(1);



More information about the varnish-commit mailing list