]> err.no Git - varnish/commitdiff
Work on logtailer api a bit:
authorphk <phk@d4fa192b-c00b-0410-8231-f00ffab90ce4>
Fri, 21 Jul 2006 15:25:09 +0000 (15:25 +0000)
committerphk <phk@d4fa192b-c00b-0410-8231-f00ffab90ce4>
Fri, 21 Jul 2006 15:25:09 +0000 (15:25 +0000)
By default, start at the last entry in shared memory.  To dump the
entire segment from the start, specify '-d' option.

Terminate programs when '-r $file' reaches EOF

git-svn-id: svn+ssh://projects.linpro.no/svn/varnish/trunk@539 d4fa192b-c00b-0410-8231-f00ffab90ce4

varnish-cache/bin/varnishlog/varnishlog.c
varnish-cache/bin/varnishtop/varnishtop.c
varnish-cache/include/varnishapi.h
varnish-cache/lib/libvarnishapi/shmlog.c

index 11049dec218e6343612da061f57d60f1b887faf8..2ccce6c7e3bc6bb4046fc28f28ade07e9863c0cf 100644 (file)
@@ -240,8 +240,10 @@ main(int argc, char **argv)
        v = 0;
 
        while (1) {
-               p = VSL_NextLog(vd);
-               if (p == NULL) {
+               i = VSL_NextLog(vd, &p);
+               if (i < 0)
+                       break;
+               if (i == 0) {
                        if (w_opt == NULL) {
                                if (o_flag && ++v == 100)
                                        clean_order();
index a1886a1ec839c7fae79051d51a66bd497a6245e4..4e9c5d61919defda3ab889c1c3cadc8ca2961a12 100644 (file)
@@ -110,8 +110,10 @@ main(int argc, char **argv)
        initscr();
        v = 0;
        while (1) {
-               p = VSL_NextLog(vd);
-               if (p == NULL) {
+               i = VSL_NextLog(vd, &p);
+               if (i < 0)
+                       break;
+               if (i == 0) {
                        upd();
                        usleep(50000);
                        continue;
index a8721e929599cef57f54bbdce3250803078aa096..747315ce8cf595267874064216ae5c4d5c62134c 100644 (file)
@@ -8,11 +8,11 @@
 #define V_DEAD __attribute__ ((noreturn))
 
 /* shmlog.c */
-#define VSL_ARGS       "bcr:i:x:CI:X:"
+#define VSL_ARGS       "bcdr:i:x:CI:X:"
 struct VSL_data;
 struct VSL_data *VSL_New(void);
 int VSL_OpenLog(struct VSL_data *vd);
-unsigned char *VSL_NextLog(struct VSL_data *lh);
+int VSL_NextLog(struct VSL_data *lh, unsigned char **pp);
 int VSL_Arg(struct VSL_data *vd, int arg, const char *opt);
 struct varnish_stats *VSL_OpenStats(void);
 const char *VSL_tags[256];
index 12657f7dd48fae0ecdd2a737038d320bd30ec8cd..a2927152ab73a6bbb416a7bc9c058071ab107a83 100644 (file)
@@ -26,6 +26,7 @@ struct VSL_data {
 
        int                     b_opt;
        int                     c_opt;
+       int                     d_opt;
 
        int                     ix_opt;
        unsigned char           supr[256];
@@ -44,6 +45,7 @@ struct VSL_data {
 static int vsl_fd;
 static struct shmloghead *vsl_lh;
 
+static int vsl_nextlog(struct VSL_data *vd, unsigned char **pp);
 
 /*--------------------------------------------------------------------*/
 
@@ -107,7 +109,7 @@ VSL_New(void)
 int
 VSL_OpenLog(struct VSL_data *vd)
 {
-
+       unsigned char *p;
 
        if (vd->fi != NULL)
                return (0);
@@ -119,13 +121,17 @@ VSL_OpenLog(struct VSL_data *vd)
        vd->logstart = (unsigned char *)vsl_lh + vsl_lh->start;
        vd->logend = vd->logstart + vsl_lh->size;
        vd->ptr = vd->logstart;
+
+       if (!vd->d_opt)
+               while (vsl_nextlog(vd, &p) == 1)
+                       continue;
        return (0);
 }
 
 /*--------------------------------------------------------------------*/
 
-static unsigned char *
-vsl_nextlog(struct VSL_data *vd)
+static int
+vsl_nextlog(struct VSL_data *vd, unsigned char **pp)
 {
        unsigned char *p;
        int i;
@@ -133,13 +139,14 @@ vsl_nextlog(struct VSL_data *vd)
        if (vd->fi != NULL) {
                i = fread(vd->rbuf, 4, 1, vd->fi);
                if (i != 1)
-                       return (NULL);
+                       return (-1);
                if (vd->rbuf[1] > 0) {
                        i = fread(vd->rbuf + 4, vd->rbuf[1], 1, vd->fi);
                        if (i != 1)
-                               return (NULL);
+                               return (-1);
                }
-               return (vd->rbuf);
+               *pp = vd->rbuf;
+               return (1);
        }
 
        p = vd->ptr;
@@ -150,15 +157,16 @@ vsl_nextlog(struct VSL_data *vd)
                }
                if (*p == SLT_ENDMARKER) {
                        vd->ptr = p;
-                       return (NULL);
+                       return (0);
                }
                vd->ptr = p + p[1] + 4;
-               return (p);
+               *pp = p;
+               return (1);
        }
 }
 
-unsigned char *
-VSL_NextLog(struct VSL_data *vd)
+int
+VSL_NextLog(struct VSL_data *vd, unsigned char **pp)
 {
        unsigned char *p;
        regmatch_t rm;
@@ -166,9 +174,9 @@ VSL_NextLog(struct VSL_data *vd)
        int i;
 
        while (1) {
-               p = vsl_nextlog(vd);
-               if (p == NULL)
-                       return (p);
+               i = vsl_nextlog(vd, &p);
+               if (i != 1)
+                       return (i);
                u = (p[2] << 8) | p[3];
                switch(p[0]) {
                case SLT_SessionOpen:
@@ -200,7 +208,8 @@ VSL_NextLog(struct VSL_data *vd)
                        if (i != REG_NOMATCH)
                                continue;
                }
-               return (p);
+               *pp = p;
+               return (1);
        }
 }
 
@@ -310,6 +319,7 @@ VSL_Arg(struct VSL_data *vd, int arg, const char *opt)
        switch (arg) {
        case 'b': vd->b_opt = !vd->b_opt; return (1);
        case 'c': vd->c_opt = !vd->c_opt; return (1);
+       case 'd': vd->d_opt = !vd->d_opt; return (1);
        case 'i': case 'x': return (vsl_ix_arg(vd, opt, arg));
        case 'r': return (vsl_r_arg(vd, opt));
        case 'I': case 'X': return (vsl_IX_arg(vd, opt, arg));