[master] e2ef91e Register an atexit handler that clears the master pid from the shmlog at exit.

Martin Blix Grydeland martin at varnish-cache.org
Tue Jun 7 10:05:42 CEST 2011


commit e2ef91e9587b4662d2f982aed9cc69f1fc236b4c
Author: Martin Blix Grydeland <martin at varnish-software.com>
Date:   Tue Jun 7 09:51:15 2011 +0200

    Register an atexit handler that clears the master pid from the shmlog at exit.

diff --git a/bin/varnishd/mgt_shmem.c b/bin/varnishd/mgt_shmem.c
index ceb5e7f..f28bc9b 100644
--- a/bin/varnishd/mgt_shmem.c
+++ b/bin/varnishd/mgt_shmem.c
@@ -193,6 +193,18 @@ vsl_buildnew(const char *fn, unsigned size, int fill)
 	AZ(ftruncate(vsl_fd, (off_t)size));
 }
 
+/*--------------------------------------------------------------------
+ * Exit handler that clears the owning pid from the SHMLOG
+ */
+
+static
+void
+mgt_shm_atexit(void)
+{
+	if (getpid() == VSM_head->master_pid)
+		VSM_head->master_pid = 0;
+}
+
 void
 mgt_SHM_Init(const char *l_arg)
 {
@@ -273,6 +285,7 @@ mgt_SHM_Init(const char *l_arg)
 	    MAP_HASSEMAPHORE | MAP_NOSYNC | MAP_SHARED,
 	    vsl_fd, 0);
 	VSM_head->master_pid = getpid();
+	AZ(atexit(mgt_shm_atexit));
 	xxxassert(VSM_head != MAP_FAILED);
 	(void)mlock((void*)VSM_head, size);
 



More information about the varnish-commit mailing list