Commit 36edd7fc authored by Poul-Henning Kamp's avatar Poul-Henning Kamp

Better and more paranoid SHMEM creation logic


git-svn-id: http://www.varnish-cache.org/svn/trunk/varnish-cache@471 d4fa192b-c00b-0410-8231-f00ffab90ce4
parent 0ca4ff99
......@@ -141,19 +141,29 @@ void
VSL_MgtInit(const char *fn, unsigned size)
{
struct shmloghead slh;
int i;
heritage.vsl_fd = open(fn, O_RDWR | O_CREAT, 0644);
if (heritage.vsl_fd < 0) {
fprintf(stderr, "Could not open %s: %s\n",
fn, strerror(errno));
exit (1);
}
i = read(heritage.vsl_fd, &slh, sizeof slh);
if (i != sizeof slh || slh.magic != SHMLOGHEAD_MAGIC) {
int i = 0;
heritage.vsl_fd = open(fn, O_RDWR, 0644);
if (heritage.vsl_fd >= 0)
i = read(heritage.vsl_fd, &slh, sizeof slh);
if (heritage.vsl_fd < 0 || i != sizeof slh ||
slh.magic != SHMLOGHEAD_MAGIC ||
slh.hdrsize != sizeof slh) {
/* XXX more checks */
if (heritage.vsl_fd >= 0);
close(heritage.vsl_fd);
unlink(fn);
heritage.vsl_fd = open(fn, O_RDWR | O_CREAT, 0644);
if (heritage.vsl_fd < 0) {
fprintf(stderr, "Could not open %s: %s\n",
fn, strerror(errno));
exit (1);
}
memset(&slh, 0, sizeof slh);
slh.magic = SHMLOGHEAD_MAGIC;
slh.hdrsize = sizeof slh;
slh.size = size;
slh.ptr = 0;
slh.start = sizeof slh;
......
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