[4.0] 3826496 Don't rename the VSM file into place until we have started the child process during startup.

Lasse Karstensen lkarsten at varnish-software.com
Mon Sep 22 16:38:25 CEST 2014


commit 3826496b3a00e769ce580396a4f40efea423e491
Author: Poul-Henning Kamp <phk at FreeBSD.org>
Date:   Mon Sep 1 14:46:33 2014 +0000

    Don't rename the VSM file into place until we have started the
    child process during startup.
    
    Fixes #1407

diff --git a/bin/varnishd/mgt/mgt.h b/bin/varnishd/mgt/mgt.h
index 4f4a8f6..c57ac27 100644
--- a/bin/varnishd/mgt/mgt.h
+++ b/bin/varnishd/mgt/mgt.h
@@ -107,6 +107,7 @@ void mgt_SHM_Init(void);
 void mgt_SHM_static_alloc(const void *, ssize_t size,
     const char *class, const char *type, const char *ident);
 void mgt_SHM_Create(void);
+void mgt_SHM_Commit(void);
 void mgt_SHM_Destroy(int keep);
 void mgt_SHM_Size_Adjust(void);
 
diff --git a/bin/varnishd/mgt/mgt_child.c b/bin/varnishd/mgt/mgt_child.c
index 1fe8473..7c777de 100644
--- a/bin/varnishd/mgt/mgt_child.c
+++ b/bin/varnishd/mgt/mgt_child.c
@@ -570,6 +570,7 @@ mgt_reap_child(void)
 		mgt_SHM_Destroy(0);
 	}
 	mgt_SHM_Create();
+	mgt_SHM_Commit();
 
 	if (child_state == CH_RUNNING)
 		child_state = CH_DIED;
@@ -752,13 +753,15 @@ MGT_Run(void)
 		REPORT0(LOG_ERR, "No VCL loaded yet");
 	else if (!d_flag) {
 		mgt_launch_child(NULL);
-		if (child_state == CH_STOPPED) {
+		if (child_state != CH_RUNNING) {
 			// XXX correct? or 0?
 			exit_status = 2;
 			return;
 		}
 	}
 
+	mgt_SHM_Commit();
+
 	i = vev_schedule(mgt_evb);
 	if (i != 0)
 		REPORT(LOG_ERR, "vev_schedule() = %d", i);
diff --git a/bin/varnishd/mgt/mgt_shmem.c b/bin/varnishd/mgt/mgt_shmem.c
index ed020f7..dc1fa5c 100644
--- a/bin/varnishd/mgt/mgt_shmem.c
+++ b/bin/varnishd/mgt/mgt_shmem.c
@@ -246,17 +246,28 @@ mgt_SHM_Create(void)
 	AN(VSC_C_mgt);
 	*VSC_C_mgt = static_VSC_C_mgt;
 
+#ifdef __OpenBSD__
+	/* Commit changes, for OS's without coherent VM/buf */
+	AZ(msync(p, getpagesize(), MS_SYNC));
+#endif
+}
+
+/*--------------------------------------------------------------------
+ * Commit the VSM
+ */
+
+void
+mgt_SHM_Commit(void)
+{
+	char fnbuf[64];
+
+	bprintf(fnbuf, "%s.%jd", VSM_FILENAME, (intmax_t)getpid());
 	if (rename(fnbuf, VSM_FILENAME)) {
 		fprintf(stderr, "Rename failed %s -> %s: %s\n",
 		    fnbuf, VSM_FILENAME, strerror(errno));
 		(void)unlink(fnbuf);
 		exit(1);
 	}
-
-#ifdef __OpenBSD__
-	/* Commit changes, for OS's without coherent VM/buf */
-	AZ(msync(p, getpagesize(), MS_SYNC));
-#endif
 }
 
 /*--------------------------------------------------------------------



More information about the varnish-commit mailing list