Commit 5313844a authored by Poul-Henning Kamp's avatar Poul-Henning Kamp

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



git-svn-id: http://www.varnish-cache.org/svn/trunk@4520 d4fa192b-c00b-0410-8231-f00ffab90ce4
parent fcf772c2
......@@ -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 @@ VSL_Init(void)
loghead->starttime = TIM_real();
loghead->panicstr[0] = '\0';
memset(VSL_stats, 0, sizeof *VSL_stats);
loghead->child_pid = getpid();
}
/*--------------------------------------------------------------------*/
......@@ -333,6 +335,25 @@ vsl_goodold(int fd)
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 @@ vsl_buildnew(const char *fn, unsigned size)
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 @@ VSL_MgtInit(const char *fn, unsigned size)
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;
......
......@@ -39,6 +39,7 @@
#define SHMLOG_FILENAME "_.vsl"
#include <time.h>
#include <sys/types.h>
#include "stats.h"
......@@ -49,6 +50,8 @@ struct shmloghead {
unsigned hdrsize;
time_t starttime;
pid_t master_pid;
pid_t child_pid;
/*
* Byte offset into the file where the fifolog starts
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment