[6.0] 8564c979f Gain more confidence that our file descriptor tracking works

Dridi Boukelmoune dridi.boukelmoune at gmail.com
Wed Feb 6 10:11:10 UTC 2019


commit 8564c979f2379e33ec94162f12046382dd544ccd
Author: Nils Goroll <nils.goroll at uplex.de>
Date:   Thu Nov 22 13:14:19 2018 +0100

    Gain more confidence that our file descriptor tracking works
    
    Side note
    
            #define CLOSE_FD_UP_TO  mgt_max_fd
    
    exposes that we are currently missing to track some fds.

diff --git a/bin/varnishd/mgt/mgt_child.c b/bin/varnishd/mgt/mgt_child.c
index c5487d94e..3e1abc9f3 100644
--- a/bin/varnishd/mgt/mgt_child.c
+++ b/bin/varnishd/mgt/mgt_child.c
@@ -183,11 +183,15 @@ mch_cli_panic_clear(struct cli *cli, const char * const *av, void *priv)
  * This is likely to a bit on the low side, as libc and other libraries
  * has a tendency to cache file descriptors (syslog, resolver, etc.)
  * so we add a margin of 100 fds.
+ *
+ * for added safety, we check that we see no file descriptor open for
+ * another margin above the limit for which we close by design
  */
 
 static int		mgt_max_fd;
 
 #define CLOSE_FD_UP_TO	(mgt_max_fd + 100)
+#define CHECK_FD_UP_TO	(CLOSE_FD_UP_TO + 100)
 
 void
 MCH_TrackHighFd(int fd)
@@ -350,6 +354,10 @@ mgt_launch_child(struct cli *cli)
 			if (close(i) == 0)
 				VFIL_null_fd(i);
 		}
+		for (i = CLOSE_FD_UP_TO + 1; i <= CHECK_FD_UP_TO; i++) {
+			assert(close(i) == -1);
+			assert(errno == EBADF);
+		}
 
 		mgt_ProcTitle("Child");
 


More information about the varnish-commit mailing list