Commit 02923e29 authored by Poul-Henning Kamp's avatar Poul-Henning Kamp

Better error handling, limit how long time we wait for initialization

to complete.



git-svn-id: http://www.varnish-cache.org/svn/trunk/varnish-cache@4964 d4fa192b-c00b-0410-8231-f00ffab90ce4
parent c2b442fa
...@@ -142,7 +142,7 @@ VSM_Delete(struct VSM_data *vd) ...@@ -142,7 +142,7 @@ VSM_Delete(struct VSM_data *vd)
static int static int
vsm_open(struct VSM_data *vd, int diag) vsm_open(struct VSM_data *vd, int diag)
{ {
int i; int i, j;
struct vsm_head slh; struct vsm_head slh;
CHECK_OBJ_NOTNULL(vd, VSM_MAGIC); CHECK_OBJ_NOTNULL(vd, VSM_MAGIC);
...@@ -161,6 +161,8 @@ vsm_open(struct VSM_data *vd, int diag) ...@@ -161,6 +161,8 @@ vsm_open(struct VSM_data *vd, int diag)
if (diag) if (diag)
vd->diag(vd->priv, "%s is not a regular file\n", vd->diag(vd->priv, "%s is not a regular file\n",
vd->fname); vd->fname);
AZ(close(vd->vsm_fd));
vd->vsm_fd = -1;
return (1); return (1);
} }
...@@ -169,12 +171,16 @@ vsm_open(struct VSM_data *vd, int diag) ...@@ -169,12 +171,16 @@ vsm_open(struct VSM_data *vd, int diag)
if (diag) if (diag)
vd->diag(vd->priv, "Cannot read %s: %s\n", vd->diag(vd->priv, "Cannot read %s: %s\n",
vd->fname, strerror(errno)); vd->fname, strerror(errno));
AZ(close(vd->vsm_fd));
vd->vsm_fd = -1;
return (1); return (1);
} }
if (slh.magic != VSM_HEAD_MAGIC) { if (slh.magic != VSM_HEAD_MAGIC) {
if (diag) if (diag)
vd->diag(vd->priv, "Wrong magic number in file %s\n", vd->diag(vd->priv, "Wrong magic number in file %s\n",
vd->fname); vd->fname);
AZ(close(vd->vsm_fd));
vd->vsm_fd = -1;
return (1); return (1);
} }
...@@ -188,8 +194,17 @@ vsm_open(struct VSM_data *vd, int diag) ...@@ -188,8 +194,17 @@ vsm_open(struct VSM_data *vd, int diag)
} }
vd->vsm_end = (uint8_t *)vd->vsm_head + slh.shm_size; vd->vsm_end = (uint8_t *)vd->vsm_head + slh.shm_size;
while(slh.alloc_seq == 0) for (j = 0; j < 20 && slh.alloc_seq == 0; j++)
(void)usleep(50000); /* XXX limit total sleep */ (void)usleep(50000);
if (slh.alloc_seq == 0) {
if (diag)
vd->diag(vd->priv, "File not initialized %s\n",
vd->fname);
assert(0 == munmap((void*)vd->vsm_head, slh.shm_size));
AZ(close(vd->vsm_fd));
vd->vsm_fd = -1;
return (1);
}
vd->alloc_seq = slh.alloc_seq; vd->alloc_seq = slh.alloc_seq;
if (vd->vsl != NULL) if (vd->vsl != NULL)
......
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