Commit 3b21ff69 authored by Poul-Henning Kamp's avatar Poul-Henning Kamp

Expose VSL_Find_Alloc()

Properly handle the case where the looked for allocation is not found.



git-svn-id: http://www.varnish-cache.org/svn/trunk/varnish-cache@4807 d4fa192b-c00b-0410-8231-f00ffab90ce4
parent c6284349
......@@ -62,5 +62,8 @@ void VSL_Delete(struct VSL_data *vd);
struct varnish_stats *VSL_OpenStats(struct VSL_data *vd);
const char *VSL_Name(struct VSL_data *vd);
extern const char *VSL_tags[256];
void *VSL_Find_Alloc(struct VSL_data *vd, const char *type, const char *ident,
unsigned *lenp);
#endif
......@@ -144,6 +144,7 @@ VSL_Open(struct VSL_data *vd)
logname, strerror(errno));
return (1);
}
vd->vsl_end = (uint8_t *)vd->vsl_lh + slh.shm_size;
return (0);
}
......@@ -169,7 +170,7 @@ vsl_find_alloc(struct VSL_data *vd, const char *type, const char *ident)
struct shmalloc *sha;
assert (vd->vsl_lh != NULL);
for(sha = &vd->vsl_lh->head; ; sha = SHA_NEXT(sha)) {
for(sha = &vd->vsl_lh->head; (void*)sha < vd->vsl_end; sha = SHA_NEXT(sha)) {
CHECK_OBJ_NOTNULL(sha, SHMALLOC_MAGIC);
if (strcmp(sha->type, type))
continue;
......@@ -182,6 +183,25 @@ vsl_find_alloc(struct VSL_data *vd, const char *type, const char *ident)
/*--------------------------------------------------------------------*/
void *
VSL_Find_Alloc(struct VSL_data *vd, const char *type, const char *ident,
unsigned *lenp)
{
struct shmalloc *sha;
CHECK_OBJ_NOTNULL(vd, VSL_MAGIC);
if (VSL_Open(vd))
return (NULL);
sha = vsl_find_alloc(vd, type, ident);
if (sha == NULL)
return (NULL);
if (lenp != NULL)
*lenp = sha->len - sizeof *sha;
return (SHA_PTR(sha));
}
/*--------------------------------------------------------------------*/
struct varnish_stats *
VSL_OpenStats(struct VSL_data *vd)
{
......
......@@ -40,6 +40,7 @@ struct VSL_data {
int vsl_fd;
struct shmloghead *vsl_lh;
void *vsl_end;
unsigned char *log_start;
unsigned char *log_end;
......
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