]> err.no Git - varnish/commitdiff
Added the -n option for specifying a name for varnishd. All files are now stored...
authorcecilihf <cecilihf@d4fa192b-c00b-0410-8231-f00ffab90ce4>
Fri, 15 Jun 2007 09:18:06 +0000 (09:18 +0000)
committercecilihf <cecilihf@d4fa192b-c00b-0410-8231-f00ffab90ce4>
Fri, 15 Jun 2007 09:18:06 +0000 (09:18 +0000)
<name> is either a specified name or the hostname. All the varnish tools have also been updated to let the user
specify the name of the varnish instance to use. The name must conform to the hostname standard, but a test
for this is not yet implemented.

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

20 files changed:
varnish-cache/bin/varnishd/heritage.h
varnish-cache/bin/varnishd/mgt_param.c
varnish-cache/bin/varnishd/mgt_vcc.c
varnish-cache/bin/varnishd/stevedore.h
varnish-cache/bin/varnishd/storage_file.c
varnish-cache/bin/varnishd/varnishd.1
varnish-cache/bin/varnishd/varnishd.c
varnish-cache/bin/varnishhist/varnishhist.1
varnish-cache/bin/varnishhist/varnishhist.c
varnish-cache/bin/varnishlog/varnishlog.1
varnish-cache/bin/varnishlog/varnishlog.c
varnish-cache/bin/varnishncsa/varnishncsa.1
varnish-cache/bin/varnishncsa/varnishncsa.c
varnish-cache/bin/varnishstat/varnishstat.1
varnish-cache/bin/varnishstat/varnishstat.c
varnish-cache/bin/varnishtop/varnishtop.1
varnish-cache/bin/varnishtop/varnishtop.c
varnish-cache/include/shmlog.h
varnish-cache/include/varnishapi.h
varnish-cache/lib/libvarnishapi/shmlog.c

index 06336babc476bf08c08e8ebb6f31e597f9b6172e..fd4e04b52dcd585664e5888864a05c1b96c3a5db 100644 (file)
@@ -119,6 +119,9 @@ struct params {
 
        /* Ping interval */
        unsigned                ping_interval;
+
+       /* Varnishd name */
+       char                    *name;
 };
 
 extern volatile struct params *params;
index c5c554bdab9e8bd7bf0304239b3adba94aeaad6d..f956f18e4e5fe67194091e3969122c8749a648dc 100644 (file)
@@ -30,6 +30,7 @@
  */
 
 #include <sys/types.h>
+#include <sys/stat.h>
 
 #include <grp.h>
 #include <pwd.h>
@@ -497,6 +498,65 @@ tweak_ping_interval(struct cli *cli, struct parspec *par, const char *arg)
 
 /*--------------------------------------------------------------------*/
 
+static void
+tweak_name(struct cli *cli, struct parspec *par, const char* arg)
+{
+       struct stat st;
+       struct stat st_old;
+       char *path;
+       char *old_path;
+       int renaming;
+       (void)par;
+       
+       if (arg != NULL) {
+               /* Check that the new name follows hostname convention */
+               /* [a-zA-Z0-9.-] */
+               asprintf(&old_path, "/tmp/%s", master.name);
+               master.name = strdup(arg);
+               /* Create/rename the temporary varnish directory */
+               asprintf(&path, "/tmp/%s", arg);
+               renaming = (!stat(old_path, &st_old) && S_ISDIR(st_old.st_mode));
+               if (stat(path, &st)) {
+                       if (renaming) {
+                               if (renaming && rename(old_path, path)) {
+                                       cli_out(cli, 
+                                           "Error: Directory %s could not be "
+                                           "renamed to %s",
+                                           old_path, path);
+                                       cli_result(cli, CLIS_PARAM);
+                                       return;
+                               }
+                       } else {
+                               if (mkdir(path, 0600)) {
+                                       fprintf(stderr,
+                                           "Error: Directory %s could not be created",
+                                           path);
+                                       exit (2);
+                               }
+                       }
+               } else if (renaming) {
+                       cli_out(cli, "Error: Directory %s could not be "
+                           "renamed to %s", old_path, path);
+                       cli_result(cli, CLIS_PARAM);
+                       return;
+               }
+               stat(path, &st);
+               /* /tmp/varnishname should now be a directory */
+               if (!S_ISDIR(st.st_mode)) {
+                       fprintf(stderr,
+                           "Error: \"%s\" "
+                           "is not a directory\n", path);
+                       exit (2);
+               }
+               /* Everything is fine, store the (new) name */
+               master.name = strdup(arg);
+       }
+       else
+               cli_out(cli, "\"%s\"", master.name);
+}
+
+/*--------------------------------------------------------------------*/
+
 /*
  * Make sure to end all lines with either a space or newline of the
  * formatting will go haywire.
@@ -513,7 +573,6 @@ tweak_ping_interval(struct cli *cli, struct parspec *par, const char *arg)
        "\nNB: We don't know yet if it is a good idea to change " \
        "this parameter.  Caution advised.\n"
 
-
 /*
  * Remember to update varnishd.1 whenever you add / remove a parameter or
  * change its default value.
@@ -671,6 +730,12 @@ static struct parspec parspec[] = {
                "it possible to attach a debugger to the child.\n"
                MUST_RESTART,
                "3", "seconds" },
+       { "name", tweak_name,
+               "Name of varnishd instance. Must follow hostname "
+               "naming conventions. Makes it possible to run "
+               "multiple varnishd instances on one server.\n"
+               EXPERIMENTAL,
+               "hostname"}, 
        { NULL, NULL, NULL }
 };
 
index d336ab1e1bb33343035c05fee7c08c5a271e5f00..e8e288e6766deaa4e56d62bbc1e2fa0699b2d729 100644 (file)
@@ -52,6 +52,7 @@
 
 #include "mgt.h"
 #include "mgt_cli.h"
+#include "heritage.h"
 
 #include "vss.h"
 
@@ -144,7 +145,7 @@ mgt_CallCc(const char *source, struct vsb *sb)
        void *p;
 
        /* Create temporary C source file */
-       sf = strdup("/tmp/vcl.XXXXXXXX");
+       asprintf(&sf, "/tmp/%s/vcl.XXXXXXXX", params->name);
        assert(sf != NULL);
        sfd = mkstemp(sf);
        if (sfd < 0) {
@@ -168,16 +169,16 @@ mgt_CallCc(const char *source, struct vsb *sb)
        rewind(fs);
 
        /* Name the output shared library */
-       of = strdup("/tmp/vcl.XXXXXXXX");
+       asprintf(&of, "/tmp/%s/vcl.XXXXXXXX", params->name);
        assert(of != NULL);
        of = mktemp(of);
        assert(of != NULL);
 
        /* Attempt to open a pipe to the system C-compiler */
        sprintf(buf,
-           "ln -f %s /tmp/_.c ;"               /* XXX: for debugging */
+           "ln -f %s /tmp/%s/_.c ;"            /* XXX: for debugging */
            "exec cc -fpic -shared -Wl,-x -o %s -x c - < %s 2>&1",
-           sf, of, sf);
+           sf, params->name, of, sf);
 
        fo = popen(buf, "r");
        if (fo == NULL) {
index 3267aa101a2d6f4525f8e84049e5f54eebd836f3..8a96d5e8a9f8575707aef60d192561938ab1a4a9 100644 (file)
@@ -33,7 +33,7 @@ struct stevedore;
 struct sess;
 struct iovec;
 
-typedef void storage_init_f(struct stevedore *, const char *spec);
+typedef void storage_init_f(struct stevedore *, const char *spec, const char *name);
 typedef void storage_open_f(struct stevedore *);
 typedef struct storage *storage_alloc_f(struct stevedore *, size_t size);
 typedef void storage_trim_f(struct storage *, size_t size);
index bbe8a73815290f5155f41292fe312285ffd4832b..57baf0a1fa4a76b3f7705aa6fb1bb752d13fa9de 100644 (file)
@@ -242,7 +242,7 @@ smf_initfile(struct smf_sc *sc, const char *size, int newfile)
 }
 
 static void
-smf_init(struct stevedore *parent, const char *spec)
+smf_init(struct stevedore *parent, const char *spec, const char *varnish_name)
 {
        char *size;
        char *p, *q;
@@ -262,9 +262,8 @@ smf_init(struct stevedore *parent, const char *spec)
 
        /* If no size specified, use 50% of filesystem free space */
        if (spec == NULL || *spec == '\0')
-               spec = "/tmp,50%";
-
-       if (strchr(spec, ',') == NULL)
+               asprintf(&p, "/tmp/%s,50%%", varnish_name);
+       else if (strchr(spec, ',') == NULL)
                asprintf(&p, "%s,", spec);
        else
                p = strdup(spec);
index 8a1ae6d612acc4d67e3448d326fdf1c4b8f9a194..f42020bd80b49305dbfe099cc9161f87c63a24c2 100644 (file)
@@ -42,6 +42,7 @@
 .Op Fl f Ar config
 .Op Fl g Ar group
 .Op Fl h Ar type Ns Op , Ns Ar options
+.Op Fl n Ar name
 .Op Fl P Ar file
 .Op Fl p Ar param Ns = Ns Ar value
 .Op Fl s Ar type Ns Op , Ns Ar options
@@ -127,6 +128,10 @@ Specifies the hash algorithm.
 See
 .Sx Hash Algorithms
 for a list of supported algorithms.
+.It Fl n
+Specify a name for this instance. If 
+.Fl n
+is not specified, hostname is used. Files will be stored in /tmp/<name>/
 .It Fl P Ar file
 Write the process's PID to the specified
 .Ar file .
@@ -494,6 +499,11 @@ Note that this will generate large amounts of log data.
 .Pp
 The default is
 .Dv off .
+.It Va name
+The name if this varnishd instance. All temporary files are stored in
+/tmp/<name>/
+.Pp
+The default is the hostname
 .El
 .Sh SEE ALSO
 .Xr varnishlog 1 ,
index f9331dd84cb291356bb37fd23cf3516dd57e4f42..a639bbb1485497a952b20f5b3e49000ad179f0eb 100644 (file)
@@ -150,7 +150,7 @@ setup_storage(const char *s_arg)
        heritage.stevedore = malloc(sizeof *heritage.stevedore);
        *heritage.stevedore = *stp;
        if (stp->init != NULL)
-               stp->init(heritage.stevedore, q);
+               stp->init(heritage.stevedore, q, params->name);
 }
 
 /*--------------------------------------------------------------------*/
@@ -177,6 +177,7 @@ usage(void)
            "  -h classic  [default]");
        fprintf(stderr, "    %-28s # %s\n", "",
            "  -h classic,<buckets>");
+       fprintf(stderr, "    %-28s # %s\n", "-n name", "varnishd instance name");
        fprintf(stderr, "    %-28s # %s\n", "-P file", "PID file");
        fprintf(stderr, "    %-28s # %s\n", "-p param=value",
            "set parameter");
@@ -402,6 +403,7 @@ main(int argc, char *argv[])
        const char *b_arg = NULL;
        const char *f_arg = NULL;
        const char *h_arg = "classic";
+       char *n_arg = NULL;
        const char *P_arg = NULL;
        const char *s_arg = "file";
        const char *T_arg = NULL;
@@ -409,6 +411,7 @@ main(int argc, char *argv[])
        char *p;
        struct cli cli[1];
        struct pidfh *pfh = NULL;
+       char buf[BUFSIZ];
 
        setbuf(stdout, NULL);
        setbuf(stderr, NULL);
@@ -424,7 +427,7 @@ main(int argc, char *argv[])
        MCF_ParamInit(cli);
        cli_check(cli);
 
-       while ((o = getopt(argc, argv, "a:b:Cdf:g:h:P:p:s:T:t:u:Vw:")) != -1)
+       while ((o = getopt(argc, argv, "a:b:Cdf:g:h:n:P:p:s:T:t:u:Vw:")) != -1)
                switch (o) {
                case 'a':
                        MCF_ParamSet(cli, "listen_address", optarg);
@@ -448,6 +451,9 @@ main(int argc, char *argv[])
                case 'h':
                        h_arg = optarg;
                        break;
+               case 'n':
+                       n_arg = optarg;
+                       break;
                case 'P':
                        P_arg = optarg;
                        break;
@@ -498,7 +504,13 @@ main(int argc, char *argv[])
                fprintf(stderr, "One of -b or -f must be specified\n");
                usage();
        }
-
+       
+       if (n_arg == NULL) {
+               n_arg = malloc(HOST_NAME_MAX+1);
+               gethostname(n_arg, HOST_NAME_MAX+1);
+       }
+       MCF_ParamSet(cli, "name", n_arg);
+       
        if (P_arg && (pfh = vpf_open(P_arg, 0600, NULL)) == NULL) {
                perror(P_arg);
                exit(1);
@@ -512,7 +524,8 @@ main(int argc, char *argv[])
        setup_storage(s_arg);
        setup_hash(h_arg);
 
-       VSL_MgtInit(SHMLOG_FILENAME, 8*1024*1024);
+       sprintf(buf, "/tmp/%s/%s", params->name, SHMLOG_FILENAME);
+       VSL_MgtInit(buf, 8*1024*1024);
 
        if (d_flag == 1)
                DebugStunt();
index a8ddc0620fc4b3e9f8d58af493859463d3895539..45205f369b1673dec01f2a3b9aaf6a0e22181c4a 100644 (file)
@@ -42,6 +42,7 @@
 .Op Fl d
 .Op Fl I Ar regex
 .Op Fl i Ar tag
+.Op Fl n Ar varnish_name
 .Op Fl r Ar file
 .Op Fl V
 .Op Fl w Ar delay
@@ -100,6 +101,12 @@ If neither
 nor
 .Fl i
 is specified, all log entries are included.
+.It Fl n
+Specify the name of the varnishd to get logs from. If 
+.Fl n
+is not specified, hostname is used. If varnishd was started with
+.Fl n
+the option must be specified.
 .It Fl r Ar file
 Read log entries from
 .Ar file
index 0d3c612bb7577ca1d4f235b5ef1fd78388142b10..dfe71876f6c5be92d97671222dbb54b2086b3451 100644 (file)
@@ -40,6 +40,7 @@
 #include <stdlib.h>
 #include <string.h>
 #include <unistd.h>
+#include <limits.h>
 
 #include "libvarnish.h"
 #include "shmlog.h"
@@ -170,7 +171,7 @@ static void
 usage(void)
 {
        fprintf(stderr,
-           "usage: varnishhist %s [-V] [-w delay]\n", VSL_USAGE);
+           "usage: varnishhist %s [-n varnish_name] [-V] [-w delay]\n", VSL_USAGE);
        exit(1);
 }
 
@@ -179,11 +180,15 @@ main(int argc, char **argv)
 {
        int i, c, x;
        struct VSL_data *vd;
+       char *n_arg = NULL;
 
        vd = VSL_New();
 
-       while ((c = getopt(argc, argv, VSL_ARGS "Vw:")) != -1) {
+       while ((c = getopt(argc, argv, VSL_ARGS "n:Vw:")) != -1) {
                switch (c) {
+               case 'n':
+                       n_arg = optarg;
+                       break;
                case 'V':
                        varnish_version("varnishhist");
                        exit(0);
@@ -197,7 +202,12 @@ main(int argc, char **argv)
                }
        }
 
-       if (VSL_OpenLog(vd))
+       if (n_arg == NULL) {
+               n_arg = malloc(HOST_NAME_MAX+1);
+               gethostname(n_arg, HOST_NAME_MAX+1);
+       }
+       
+       if (VSL_OpenLog(vd, n_arg))
                exit (1);
 
        c_hist = 10.0 / log(10.0);
index be186980ea644bdbdda9817e3944b9370f77e971..a5bb9f7664c47f31ad595049ab7224d3ef5dd519 100644 (file)
@@ -46,6 +46,7 @@
 .Op Fl i Ar tag
 .Op Fl o
 .Op Fl P Ar file
+.Op Fl n Ar varnish_name
 .Op Fl r Ar file
 .Op Fl V
 .Op Fl w Ar file
@@ -106,6 +107,12 @@ If neither
 nor
 .Fl i
 is specified, all log entries are included.
+.It Fl n
+Specify the name of the varnishd to get logs from. If 
+.Fl n
+is not specified, hostname is used. If varnishd was started with
+.Fl n
+the option must be specified.
 .It Fl o
 Group log entries by request ID.
 This has no effect when writing to a file using the
index 144bd48ba8be6f8e8ebdf1e92edb51f27036e7dc..2b6e2f17b3c02e1748196763c4da31d9b702e3a1 100644 (file)
@@ -39,6 +39,7 @@
 #include <stdlib.h>
 #include <string.h>
 #include <unistd.h>
+#include <limits.h>
 
 #ifndef HAVE_DAEMON
 #include "compat/daemon.h"
@@ -273,7 +274,7 @@ static void
 usage(void)
 {
        fprintf(stderr,
-           "usage: varnishlog %s [-aDoV] [-P file] [-w file]\n", VSL_USAGE);
+           "usage: varnishlog %s [-aDoV] [-n varnish_name] [-P file] [-w file]\n", VSL_USAGE);
        exit(1);
 }
 
@@ -284,12 +285,13 @@ main(int argc, char **argv)
        int a_flag = 0, D_flag = 0, o_flag = 0;
        const char *P_arg = NULL;
        const char *w_arg = NULL;
+       char *n_arg = NULL;
        struct pidfh *pfh = NULL;
        struct VSL_data *vd;
 
        vd = VSL_New();
 
-       while ((c = getopt(argc, argv, VSL_ARGS "aDoP:Vw:")) != -1) {
+       while ((c = getopt(argc, argv, VSL_ARGS "aDon:P:Vw:")) != -1) {
                switch (c) {
                case 'a':
                        a_flag = 1;
@@ -297,6 +299,9 @@ main(int argc, char **argv)
                case 'D':
                        D_flag = 1;
                        break;
+               case 'n':
+                       n_arg = optarg;
+                       break;
                case 'o':
                        o_flag = 1;
                        break;
@@ -329,7 +334,12 @@ main(int argc, char **argv)
        if (o_flag && w_arg != NULL)
                usage();
 
-       if (VSL_OpenLog(vd))
+       if (n_arg == NULL) {
+               n_arg = malloc(HOST_NAME_MAX+1);
+               gethostname(n_arg, HOST_NAME_MAX+1);
+       }
+
+       if (VSL_OpenLog(vd, n_arg))
                exit(1);
 
        if (P_arg && (pfh = vpf_open(P_arg, 0600, NULL)) == NULL) {
index ce39e05d42412b5fbcc6dbb2dacdb50b2a5c9159..3569b1ed711dc2f65f624ddc2650d6a0bbef7665 100644 (file)
@@ -43,6 +43,7 @@
 .Op Fl d
 .Op Fl I Ar regex
 .Op Fl i Ar tag
+.Op Fl n Ar varnish_name
 .Op Fl r Ar file
 .Op Fl V
 .Op Fl w Ar file
@@ -101,6 +102,12 @@ If neither
 nor
 .Fl i
 is specified, all log entries are included.
+.It Fl n
+Specify the name of the varnishd to get logs from. If 
+.Fl n
+is not specified, hostname is used. If varnishd was started with
+.Fl n
+the option must be specified.
 .It Fl r Ar file
 Read log entries from
 .Ar file
index 15d9294a002bdb75d50b41d062bb46e59c4f0854..8d2308a6171fe3fb5e833efd5b6057d63eef3d3e 100644 (file)
@@ -67,6 +67,7 @@
 #include <string.h>
 #include <time.h>
 #include <unistd.h>
+#include <limits.h>
 
 #include "libvarnish.h"
 #include "shmlog.h"
@@ -433,7 +434,7 @@ static void
 usage(void)
 {
 
-       fprintf(stderr, "usage: varnishncsa %s [-aV] [-w file]\n", VSL_ARGS);
+       fprintf(stderr, "usage: varnishncsa %s [-aV] [-n varnish_name] [-w file]\n", VSL_ARGS);
        exit(1);
 }
 
@@ -443,12 +444,13 @@ main(int argc, char *argv[])
        int i, c;
        struct VSL_data *vd;
        const char *ofn = NULL;
+       char *n_arg = NULL;
        int append = 0;
        FILE *of;
 
        vd = VSL_New();
 
-       while ((c = getopt(argc, argv, VSL_ARGS "aVw:")) != -1) {
+       while ((c = getopt(argc, argv, VSL_ARGS "an:Vw:")) != -1) {
                i = VSL_Arg(vd, c, optarg);
                if (i < 0)
                        exit (1);
@@ -458,6 +460,9 @@ main(int argc, char *argv[])
                case 'a':
                        append = 1;
                        break;
+               case 'n':
+                       n_arg = optarg;
+                       break;
                case 'V':
                        varnish_version("varnishncsa");
                        exit(0);
@@ -470,8 +475,13 @@ main(int argc, char *argv[])
                        usage();
                }
        }
+       
+       if (n_arg == NULL) {
+               n_arg = malloc(HOST_NAME_MAX+1);
+               gethostname(n_arg, HOST_NAME_MAX+1);
+       }
 
-       if (VSL_OpenLog(vd))
+       if (VSL_OpenLog(vd, n_arg))
                exit(1);
 
        if (ofn) {
index e777d2eef55712b411f1778c49b0a898c8e3e766..42c2ca4cbc8f0265fa430c2bd5c23c2df2e27f84 100644 (file)
@@ -37,6 +37,7 @@
 .Sh SYNOPSIS
 .Nm
 .Op Fl 1
+.Op Fl n Ar varnish_name
 .Op Fl V
 .Op Fl w Ar delay
 .Sh DESCRIPTION
@@ -51,6 +52,12 @@ The following options are available:
 .It Fl 1
 Instead of presenting of a continuously updated display, print the
 statistics once and exit.
+.It Fl n
+Specify the name of the varnishd to get logs from. If 
+.Fl n
+is not specified, hostname is used. If varnishd was started with
+.Fl n
+the option must be specified.
 .It Fl V
 Display the version number and exit.
 .It Fl w Ar delay
index 408ae0db77cf45aee70f6446cb7122c10835be2d..43784ab07eec2ddd2fc6c87628eed69cb6ee5839 100644 (file)
@@ -38,6 +38,7 @@
 #include <unistd.h>
 #include <curses.h>
 #include <time.h>
+#include <limits.h>
 
 #ifndef HAVE_CLOCK_GETTIME
 #include "compat/clock_gettime.h"
@@ -130,7 +131,7 @@ do_curses(struct varnish_stats *VSL_stats, int delay)
 static void
 usage(void)
 {
-       fprintf(stderr, "usage: varnishstat [-1V] [-w delay]\n");
+       fprintf(stderr, "usage: varnishstat [-1V] [-n varnish_name] [-w delay]\n");
        exit(1);
 }
 
@@ -140,14 +141,16 @@ main(int argc, char **argv)
        int c;
        struct varnish_stats *VSL_stats;
        int delay = 1, once = 0;
+       char *n_arg = NULL;
 
-       VSL_stats = VSL_OpenStats();
-
-       while ((c = getopt(argc, argv, "1Vw:")) != -1) {
+       while ((c = getopt(argc, argv, "1n:Vw:")) != -1) {
                switch (c) {
                case '1':
                        once = 1;
                        break;
+               case 'n':
+                       n_arg = optarg;
+                       break;
                case 'V':
                        varnish_version("varnishstat");
                        exit(0);
@@ -158,6 +161,15 @@ main(int argc, char **argv)
                        usage();
                }
        }
+       
+       if (n_arg == NULL) {
+               n_arg = malloc(HOST_NAME_MAX+1);
+               gethostname(n_arg, HOST_NAME_MAX+1);
+       }
+
+       if (!(VSL_stats = VSL_OpenStats(n_arg))) {
+               exit(1);
+       }
 
        if (!once) {
                do_curses(VSL_stats, delay);
index 9119acf16892798f8de4c93f6c8f57211af8c5bc..961d028f6a5fa62ce46817b64202a926db34caa0 100644 (file)
@@ -44,6 +44,7 @@
 .Op Fl f
 .Op Fl I Ar regex
 .Op Fl i Ar tag
+.Op Fl n Ar varnish_name
 .Op Fl r Ar file
 .Op Fl V
 .Op Fl X Ar regex
@@ -116,6 +117,12 @@ If neither
 nor
 .Fl i
 is specified, all log entries are included.
+.It Fl n
+Specify the name of the varnishd to get logs from. If 
+.Fl n
+is not specified, hostname is used. If varnishd was started with
+.Fl n
+the option must be specified.
 .It Fl r Ar file
 Read log entries from
 .Ar file
index 555ec35fda099d98422342006218541c3060de47..dcbb11b70bed2968080bda4edd95b9ad45b57a76 100644 (file)
@@ -38,6 +38,7 @@
 #include <stdlib.h>
 #include <string.h>
 #include <unistd.h>
+#include <limits.h>
 
 #include "vsb.h"
 
@@ -63,7 +64,7 @@ static unsigned ntop;
 static void
 usage(void)
 {
-       fprintf(stderr, "usage: varnishtop %s [-1V]\n", VSL_USAGE);
+       fprintf(stderr, "usage: varnishtop %s [-1V] [-n varnish_name]\n", VSL_USAGE);
        exit(1);
 }
 
@@ -112,11 +113,11 @@ main(int argc, char **argv)
        unsigned u, v;
        struct top *tp, *tp2;
        int f_flag = 0;
-
+       char *n_arg = NULL;
 
        vd = VSL_New();
 
-       while ((c = getopt(argc, argv, VSL_ARGS "1fV")) != -1) {
+       while ((c = getopt(argc, argv, VSL_ARGS "1fn:V")) != -1) {
                i = VSL_Arg(vd, c, optarg);
                if (i < 0)
                        exit (1);
@@ -126,6 +127,9 @@ main(int argc, char **argv)
                case '1':
                        VSL_NonBlocking(vd, 1);
                        break;
+               case 'n':
+                       n_arg = optarg;
+                       break;
                case 'f':
                        f_flag = 1;
                        break;
@@ -136,8 +140,13 @@ main(int argc, char **argv)
                        usage();
                }
        }
+       
+       if (n_arg == NULL) {
+               n_arg = malloc(HOST_NAME_MAX+1);
+               gethostname(n_arg, HOST_NAME_MAX+1);
+       }
 
-       if (VSL_OpenLog(vd))
+       if (VSL_OpenLog(vd, n_arg))
                exit (1);
 
        initscr();
index 643b2157a28f79e65e0b17760f4c215940a71404..e2037a7f5fd66f100e5878238b7bc685d3ff5a8f 100644 (file)
@@ -36,7 +36,7 @@
 #ifndef SHMLOG_H_INCLUDED
 #define SHMLOG_H_INCLUDED
 
-#define SHMLOG_FILENAME                "/tmp/_.vsl"
+#define SHMLOG_FILENAME                "_.vsl"
 
 #include <time.h>
 
index ff6313315578886690b88e1b95f8f7fbeab23b75..2f2aa9f2209ac7be3f10a10afe49232ad25e1b64 100644 (file)
@@ -50,12 +50,12 @@ vsl_handler VSL_H_Print;
 struct VSL_data;
 struct VSL_data *VSL_New(void);
 void VSL_Select(struct VSL_data *vd, unsigned tag);
-int VSL_OpenLog(struct VSL_data *vd);
+int VSL_OpenLog(struct VSL_data *vd, char *varnish_name);
 void VSL_NonBlocking(struct VSL_data *vd, int nb);
 int VSL_Dispatch(struct VSL_data *vd, vsl_handler *func, void *priv);
 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);
+struct varnish_stats *VSL_OpenStats(char *varnish_name);
 extern const char *VSL_tags[256];
 
 /* varnish_debug.c */
index 00602de53bf7d817c871dcbe591f217ce7c9315c..4dcb1c85fa81a890f890f813f9f6ffe2d59bfc21 100644 (file)
@@ -102,29 +102,32 @@ const char *VSL_tags[256] = {
 /*--------------------------------------------------------------------*/
 
 static int
-vsl_shmem_map(void)
+vsl_shmem_map(char* varnish_name)
 {
        int i;
        struct shmloghead slh;
+       char buf[BUFSIZ];
 
        if (vsl_lh != NULL)
                return (0);
 
-       vsl_fd = open(SHMLOG_FILENAME, O_RDONLY);
+       sprintf(buf, "/tmp/%s/%s", varnish_name, SHMLOG_FILENAME);
+
+       vsl_fd = open(buf, O_RDONLY);
        if (vsl_fd < 0) {
                fprintf(stderr, "Cannot open %s: %s\n",
-                   SHMLOG_FILENAME, strerror(errno));
+                   buf, strerror(errno));
                return (1);
        }
        i = read(vsl_fd, &slh, sizeof slh);
        if (i != sizeof slh) {
                fprintf(stderr, "Cannot read %s: %s\n",
-                   SHMLOG_FILENAME, strerror(errno));
+                   buf, strerror(errno));
                return (1);
        }
        if (slh.magic != SHMLOGHEAD_MAGIC) {
                fprintf(stderr, "Wrong magic number in file %s\n",
-                   SHMLOG_FILENAME);
+                   buf);
                return (1);
        }
 
@@ -132,7 +135,7 @@ vsl_shmem_map(void)
            PROT_READ, MAP_SHARED|MAP_HASSEMAPHORE, vsl_fd, 0);
        if (vsl_lh == MAP_FAILED) {
                fprintf(stderr, "Cannot mmap %s: %s\n",
-                   SHMLOG_FILENAME, strerror(errno));
+                   buf, strerror(errno));
                return (1);
        }
        return (0);
@@ -167,7 +170,7 @@ VSL_Select(struct VSL_data *vd, unsigned tag)
 /*--------------------------------------------------------------------*/
 
 int
-VSL_OpenLog(struct VSL_data *vd)
+VSL_OpenLog(struct VSL_data *vd, char *varnish_name)
 {
        unsigned char *p;
 
@@ -175,7 +178,7 @@ VSL_OpenLog(struct VSL_data *vd)
        if (vd->fi != NULL)
                return (0);
 
-       if (vsl_shmem_map())
+       if (vsl_shmem_map(varnish_name))
                return (1);
 
        vd->head = vsl_lh;
@@ -474,10 +477,10 @@ VSL_Arg(struct VSL_data *vd, int arg, const char *opt)
 }
 
 struct varnish_stats *
-VSL_OpenStats(void)
+VSL_OpenStats(char *varnish_name)
 {
 
-       if (vsl_shmem_map())
+       if (vsl_shmem_map(varnish_name))
                return (NULL);
        return (&vsl_lh->stats);
 }