r4520 - in trunk/varnish-cache: bin/varnishd include
phk at projects.linpro.no
phk at projects.linpro.no
Mon Feb 1 14:06:32 CET 2010
Author: phk
Date: 2010-02-01 14:06:31 +0100 (Mon, 01 Feb 2010)
New Revision: 4520
Modified:
trunk/varnish-cache/bin/varnishd/shmlog.c
trunk/varnish-cache/include/shmlog.h
Log:
Add the master and child pid's to the SHMFILE.
If the master pid is active when we start, we issue a message about
this, (with a hint about -n) and exit.
If the master pid is not active, but the child pid is, we issue a
message about it presumably being busy dying, dump the SHMFILE and
create a new one. (This only saves our bacon, if the dying
process manages to close the listening sockets before we need them).
This should end any confusion that might arise from accidentally
running multiple varnishes at the same time.
Fixes #620
Modified: trunk/varnish-cache/bin/varnishd/shmlog.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/shmlog.c 2010-02-01 12:44:07 UTC (rev 4519)
+++ trunk/varnish-cache/bin/varnishd/shmlog.c 2010-02-01 13:06:31 UTC (rev 4520)
@@ -32,6 +32,7 @@
#include "svnid.h"
SVNID("$Id$")
+#include <signal.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
@@ -313,6 +314,7 @@
loghead->starttime = TIM_real();
loghead->panicstr[0] = '\0';
memset(VSL_stats, 0, sizeof *VSL_stats);
+ loghead->child_pid = getpid();
}
/*--------------------------------------------------------------------*/
@@ -333,6 +335,25 @@
return (0);
if (slh.start != sizeof slh + sizeof *params)
return (0);
+
+ if (!kill(slh.master_pid, 0)) {
+ fprintf(stderr,
+ "SHMFILE owned by running varnishd master (pid=%jd)\n",
+ (intmax_t)slh.master_pid);
+ fprintf(stderr,
+ "(Use unique -n arguments if you want multiple "
+ "instances.)\n");
+ exit(2);
+ }
+
+ if (slh.child_pid != 0 && !kill(slh.child_pid, 0)) {
+ fprintf(stderr,
+ "SHMFILE used by orphan varnishd child process (pid=%jd)\n",
+ (intmax_t)slh.child_pid);
+ fprintf(stderr, "(We assume that process is busy dying.)\n");
+ return (0);
+ }
+
/* XXX more checks */
heritage.vsl_size = slh.size + slh.start;
return (1);
@@ -345,7 +366,7 @@
int i;
(void)unlink(fn);
- heritage.vsl_fd = open(fn, O_RDWR | O_CREAT, 0644);
+ heritage.vsl_fd = open(fn, O_RDWR | O_CREAT | O_EXCL, 0644);
if (heritage.vsl_fd < 0) {
fprintf(stderr, "Could not open %s: %s\n",
fn, strerror(errno));
@@ -384,6 +405,7 @@
PROT_READ|PROT_WRITE,
MAP_HASSEMAPHORE | MAP_NOSYNC | MAP_SHARED,
heritage.vsl_fd, 0);
+ loghead->master_pid = getpid();
xxxassert(loghead != MAP_FAILED);
(void)mlock(loghead, heritage.vsl_size);
VSL_stats = &loghead->stats;
Modified: trunk/varnish-cache/include/shmlog.h
===================================================================
--- trunk/varnish-cache/include/shmlog.h 2010-02-01 12:44:07 UTC (rev 4519)
+++ trunk/varnish-cache/include/shmlog.h 2010-02-01 13:06:31 UTC (rev 4520)
@@ -39,6 +39,7 @@
#define SHMLOG_FILENAME "_.vsl"
#include <time.h>
+#include <sys/types.h>
#include "stats.h"
@@ -49,6 +50,8 @@
unsigned hdrsize;
time_t starttime;
+ pid_t master_pid;
+ pid_t child_pid;
/*
* Byte offset into the file where the fifolog starts
More information about the varnish-commit
mailing list