]> err.no Git - varnish/commitdiff
Forgot to add shmlog.c (reminded by des@)
authorphk <phk@d4fa192b-c00b-0410-8231-f00ffab90ce4>
Fri, 30 Jun 2006 20:22:58 +0000 (20:22 +0000)
committerphk <phk@d4fa192b-c00b-0410-8231-f00ffab90ce4>
Fri, 30 Jun 2006 20:22:58 +0000 (20:22 +0000)
git-svn-id: svn+ssh://projects.linpro.no/svn/varnish/trunk@276 d4fa192b-c00b-0410-8231-f00ffab90ce4

varnish-cache/lib/libvarnishapi/shmlog.c [new file with mode: 0644]

diff --git a/varnish-cache/lib/libvarnishapi/shmlog.c b/varnish-cache/lib/libvarnishapi/shmlog.c
new file mode 100644 (file)
index 0000000..88a1fd5
--- /dev/null
@@ -0,0 +1,77 @@
+/*
+ * $Id: varnishlog.c 153 2006-04-25 08:17:43Z phk $
+ */
+
+#include <stdio.h>
+#include <errno.h>
+#include <string.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <fcntl.h>
+#include <sys/mman.h>
+
+#include "shmlog.h"
+#include "varnishapi.h"
+
+static unsigned char *logstart, *logend;
+
+struct shmloghead *
+VSL_OpenLog(void)
+{
+       int fd;
+       int i;
+       struct shmloghead slh, *lh;
+
+       fd = open(SHMLOG_FILENAME, O_RDONLY);
+       if (fd < 0) {
+               fprintf(stderr, "Cannot open %s: %s\n",
+                   SHMLOG_FILENAME, strerror(errno));
+               exit (1);
+       }
+       i = read(fd, &slh, sizeof slh);
+       if (i != sizeof slh) {
+               fprintf(stderr, "Cannot read %s: %s\n",
+                   SHMLOG_FILENAME, strerror(errno));
+               exit (1);
+       }
+       if (slh.magic != SHMLOGHEAD_MAGIC) {
+               fprintf(stderr, "Wrong magic number in file %s\n",
+                   SHMLOG_FILENAME);
+               exit (1);
+       }
+
+       lh = mmap(NULL, slh.size + sizeof slh,
+           PROT_READ, MAP_HASSEMAPHORE, fd, 0);
+       if (lh == MAP_FAILED) {
+               fprintf(stderr, "Cannot mmap %s: %s\n",
+                   SHMLOG_FILENAME, strerror(errno));
+               exit (1);
+       }
+
+       logstart = (unsigned char *)lh + lh->start;
+       logend = logstart + lh->size;
+
+       return (lh);
+}
+
+unsigned char *
+VSL_NextLog(struct shmloghead *lh, unsigned char **pp)
+{
+       unsigned char *p;
+
+       p = *pp;
+       if (p == NULL)
+               p = logstart;
+       while (1) {
+               if (*p == SLT_WRAPMARKER) {
+                       p = logstart;
+                       continue;
+               }
+               if (*p == SLT_ENDMARKER) {
+                       *pp = p;
+                       return (NULL);
+               }
+               *pp = p + p[1] + 4;
+               return (p);
+       }
+}