[master] 1be6ad1d5 Gain more confidence that our file descriptor tracking works

Nils Goroll nils.goroll at uplex.de
Thu Nov 22 12:29:14 UTC 2018


commit 1be6ad1d5a807038adcaa39168ce69a5a76bc8e1
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 5072db159..f6c9c810d 100644
--- a/bin/varnishd/mgt/mgt_child.c
+++ b/bin/varnishd/mgt/mgt_child.c
@@ -181,11 +181,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)
@@ -348,6 +352,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