r4883 - in trunk/varnish-cache: include lib/libvarnishapi
phk at varnish-cache.org
phk at varnish-cache.org
Fri Jun 4 12:52:59 CEST 2010
Author: phk
Date: 2010-06-04 12:52:58 +0200 (Fri, 04 Jun 2010)
New Revision: 4883
Modified:
trunk/varnish-cache/include/varnishapi.h
trunk/varnish-cache/lib/libvarnishapi/base64.c
trunk/varnish-cache/lib/libvarnishapi/vsl.c
trunk/varnish-cache/lib/libvarnishapi/vsl.h
trunk/varnish-cache/lib/libvarnishapi/vsl_arg.c
trunk/varnish-cache/lib/libvarnishapi/vsl_log.c
Log:
cleanups
Modified: trunk/varnish-cache/include/varnishapi.h
===================================================================
--- trunk/varnish-cache/include/varnishapi.h 2010-06-04 09:46:24 UTC (rev 4882)
+++ trunk/varnish-cache/include/varnishapi.h 2010-06-04 10:52:58 UTC (rev 4883)
@@ -60,13 +60,13 @@
int VSL_Open(struct VSL_data *vd);
void VSL_Delete(struct VSL_data *vd);
struct varnish_stats *VSL_OpenStats(struct VSL_data *vd);
-const char *VSL_Name(struct VSL_data *vd);
+const char *VSL_Name(const struct VSL_data *vd);
extern const char *VSL_tags[256];
void *VSL_Find_Alloc(struct VSL_data *vd, const char *class, const char *type,
const char *ident, unsigned *lenp);
-struct shmalloc *vsl_iter0(struct VSL_data *vd);
-void vsl_itern(struct VSL_data *vd, struct shmalloc **pp);
+struct shmalloc *vsl_iter0(const struct VSL_data *vd);
+void vsl_itern(const struct VSL_data *vd, struct shmalloc **pp);
#define VSL_FOREACH(var, vd) \
for((var) = vsl_iter0((vd)); (var) != NULL; vsl_itern((vd), &(var)))
Modified: trunk/varnish-cache/lib/libvarnishapi/base64.c
===================================================================
--- trunk/varnish-cache/lib/libvarnishapi/base64.c 2010-06-04 09:46:24 UTC (rev 4882)
+++ trunk/varnish-cache/lib/libvarnishapi/base64.c 2010-06-04 10:52:58 UTC (rev 4883)
@@ -10,10 +10,9 @@
SVNID("$Id$")
#include <sys/types.h>
-#include <stdint.h>
#include "varnishapi.h"
-static const char *b64 =
+static const char b64[] =
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
static char i64[256];
Modified: trunk/varnish-cache/lib/libvarnishapi/vsl.c
===================================================================
--- trunk/varnish-cache/lib/libvarnishapi/vsl.c 2010-06-04 09:46:24 UTC (rev 4882)
+++ trunk/varnish-cache/lib/libvarnishapi/vsl.c 2010-06-04 10:52:58 UTC (rev 4883)
@@ -34,12 +34,11 @@
#include <sys/types.h>
#include <sys/mman.h>
+#include <sys/stat.h>
#include <assert.h>
-#include <ctype.h>
#include <errno.h>
#include <fcntl.h>
-#include <limits.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
@@ -98,6 +97,7 @@
vbit_destroy(vd->vbm_select);
free(vd->n_opt);
free(vd->rbuf);
+ free(vd->fname);
free(vd);
}
@@ -112,21 +112,28 @@
if (vd->vsl_lh != NULL)
return (0);
- vd->vsl_fd = open(vd->vsl, O_RDONLY);
+ vd->vsl_fd = open(vd->fname, O_RDONLY);
if (vd->vsl_fd < 0) {
fprintf(stderr, "Cannot open %s: %s\n",
- vd->vsl, strerror(errno));
+ vd->fname, strerror(errno));
return (1);
}
+
+ assert(fstat(vd->vsl_fd, &vd->fstat) == 0);
+ if (!S_ISREG(vd->fstat.st_mode)) {
+ fprintf(stderr, "%s is not a regular file\n", vd->fname);
+ return (1);
+ }
+
i = read(vd->vsl_fd, &slh, sizeof slh);
if (i != sizeof slh) {
fprintf(stderr, "Cannot read %s: %s\n",
- vd->vsl, strerror(errno));
+ vd->fname, strerror(errno));
return (1);
}
if (slh.magic != SHMLOGHEAD_MAGIC) {
fprintf(stderr, "Wrong magic number in file %s\n",
- vd->vsl);
+ vd->fname);
return (1);
}
@@ -134,7 +141,7 @@
PROT_READ, MAP_SHARED|MAP_HASSEMAPHORE, vd->vsl_fd, 0);
if (vd->vsl_lh == MAP_FAILED) {
fprintf(stderr, "Cannot mmap %s: %s\n",
- vd->vsl, strerror(errno));
+ vd->fname, strerror(errno));
return (1);
}
vd->vsl_end = (uint8_t *)vd->vsl_lh + slh.shm_size;
@@ -160,7 +167,7 @@
/*--------------------------------------------------------------------*/
struct shmalloc *
-vsl_iter0(struct VSL_data *vd)
+vsl_iter0(const struct VSL_data *vd)
{
CHECK_OBJ_NOTNULL(vd, VSL_MAGIC);
@@ -171,7 +178,7 @@
}
void
-vsl_itern(struct VSL_data *vd, struct shmalloc **pp)
+vsl_itern(const struct VSL_data *vd, struct shmalloc **pp)
{
CHECK_OBJ_NOTNULL(vd, VSL_MAGIC);
@@ -191,7 +198,7 @@
/*--------------------------------------------------------------------*/
static struct shmalloc *
-vsl_find_alloc(struct VSL_data *vd, const char *class, const char *type, const char *ident)
+vsl_find_alloc(const struct VSL_data *vd, const char *class, const char *type, const char *ident)
{
struct shmalloc *sha;
@@ -272,7 +279,7 @@
/*--------------------------------------------------------------------*/
const char *
-VSL_Name(struct VSL_data *vd)
+VSL_Name(const struct VSL_data *vd)
{
return (vd->n_opt);
Modified: trunk/varnish-cache/lib/libvarnishapi/vsl.h
===================================================================
--- trunk/varnish-cache/lib/libvarnishapi/vsl.h 2010-06-04 09:46:24 UTC (rev 4882)
+++ trunk/varnish-cache/lib/libvarnishapi/vsl.h 2010-06-04 10:52:58 UTC (rev 4883)
@@ -37,7 +37,8 @@
unsigned magic;
#define VSL_MAGIC 0x6e3bd69b
- char *vsl;
+ char *fname;
+ struct stat fstat;
int vsl_fd;
struct shmloghead *vsl_lh;
Modified: trunk/varnish-cache/lib/libvarnishapi/vsl_arg.c
===================================================================
--- trunk/varnish-cache/lib/libvarnishapi/vsl_arg.c 2010-06-04 09:46:24 UTC (rev 4882)
+++ trunk/varnish-cache/lib/libvarnishapi/vsl_arg.c 2010-06-04 10:52:58 UTC (rev 4883)
@@ -33,13 +33,12 @@
SVNID("$Id$")
#include <sys/types.h>
-#include <sys/mman.h>
+#include <sys/stat.h>
#include <assert.h>
#include <ctype.h>
#include <errno.h>
#include <fcntl.h>
-#include <limits.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
@@ -212,7 +211,7 @@
free(vd->n_opt);
vd->n_opt = strdup(opt);
assert(vd->n_opt != NULL);
- if (vin_n_arg(vd->n_opt, NULL, NULL, &vd->vsl)) {
+ if (vin_n_arg(vd->n_opt, NULL, NULL, &vd->fname)) {
fprintf(stderr, "Invalid instance name: %s\n",
strerror(errno));
return (-1);
Modified: trunk/varnish-cache/lib/libvarnishapi/vsl_log.c
===================================================================
--- trunk/varnish-cache/lib/libvarnishapi/vsl_log.c 2010-06-04 09:46:24 UTC (rev 4882)
+++ trunk/varnish-cache/lib/libvarnishapi/vsl_log.c 2010-06-04 10:52:58 UTC (rev 4883)
@@ -33,13 +33,9 @@
SVNID("$Id$")
#include <sys/types.h>
-#include <sys/mman.h>
+#include <sys/stat.h>
#include <assert.h>
-#include <ctype.h>
-#include <errno.h>
-#include <fcntl.h>
-#include <limits.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
More information about the varnish-commit
mailing list