Commit 1b9ec978 authored by Cecilie Fritzvold's avatar Cecilie Fritzvold

Added the -n option for specifying a name for varnishd. All files are now...

Added the -n option for specifying a name for varnishd. All files are now stored under /tmp/<name> where 
<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: http://www.varnish-cache.org/svn/trunk/varnish-cache@1521 d4fa192b-c00b-0410-8231-f00ffab90ce4
parent cf9bb621
...@@ -119,6 +119,9 @@ struct params { ...@@ -119,6 +119,9 @@ struct params {
/* Ping interval */ /* Ping interval */
unsigned ping_interval; unsigned ping_interval;
/* Varnishd name */
char *name;
}; };
extern volatile struct params *params; extern volatile struct params *params;
......
...@@ -30,6 +30,7 @@ ...@@ -30,6 +30,7 @@
*/ */
#include <sys/types.h> #include <sys/types.h>
#include <sys/stat.h>
#include <grp.h> #include <grp.h>
#include <pwd.h> #include <pwd.h>
...@@ -497,6 +498,65 @@ tweak_ping_interval(struct cli *cli, struct parspec *par, const char *arg) ...@@ -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 * Make sure to end all lines with either a space or newline of the
* formatting will go haywire. * formatting will go haywire.
...@@ -513,7 +573,6 @@ tweak_ping_interval(struct cli *cli, struct parspec *par, const char *arg) ...@@ -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 " \ "\nNB: We don't know yet if it is a good idea to change " \
"this parameter. Caution advised.\n" "this parameter. Caution advised.\n"
/* /*
* Remember to update varnishd.1 whenever you add / remove a parameter or * Remember to update varnishd.1 whenever you add / remove a parameter or
* change its default value. * change its default value.
...@@ -671,6 +730,12 @@ static struct parspec parspec[] = { ...@@ -671,6 +730,12 @@ static struct parspec parspec[] = {
"it possible to attach a debugger to the child.\n" "it possible to attach a debugger to the child.\n"
MUST_RESTART, MUST_RESTART,
"3", "seconds" }, "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 } { NULL, NULL, NULL }
}; };
......
...@@ -52,6 +52,7 @@ ...@@ -52,6 +52,7 @@
#include "mgt.h" #include "mgt.h"
#include "mgt_cli.h" #include "mgt_cli.h"
#include "heritage.h"
#include "vss.h" #include "vss.h"
...@@ -144,7 +145,7 @@ mgt_CallCc(const char *source, struct vsb *sb) ...@@ -144,7 +145,7 @@ mgt_CallCc(const char *source, struct vsb *sb)
void *p; void *p;
/* Create temporary C source file */ /* Create temporary C source file */
sf = strdup("/tmp/vcl.XXXXXXXX"); asprintf(&sf, "/tmp/%s/vcl.XXXXXXXX", params->name);
assert(sf != NULL); assert(sf != NULL);
sfd = mkstemp(sf); sfd = mkstemp(sf);
if (sfd < 0) { if (sfd < 0) {
...@@ -168,16 +169,16 @@ mgt_CallCc(const char *source, struct vsb *sb) ...@@ -168,16 +169,16 @@ mgt_CallCc(const char *source, struct vsb *sb)
rewind(fs); rewind(fs);
/* Name the output shared library */ /* Name the output shared library */
of = strdup("/tmp/vcl.XXXXXXXX"); asprintf(&of, "/tmp/%s/vcl.XXXXXXXX", params->name);
assert(of != NULL); assert(of != NULL);
of = mktemp(of); of = mktemp(of);
assert(of != NULL); assert(of != NULL);
/* Attempt to open a pipe to the system C-compiler */ /* Attempt to open a pipe to the system C-compiler */
sprintf(buf, 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", "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"); fo = popen(buf, "r");
if (fo == NULL) { if (fo == NULL) {
......
...@@ -33,7 +33,7 @@ struct stevedore; ...@@ -33,7 +33,7 @@ struct stevedore;
struct sess; struct sess;
struct iovec; 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 void storage_open_f(struct stevedore *);
typedef struct storage *storage_alloc_f(struct stevedore *, size_t size); typedef struct storage *storage_alloc_f(struct stevedore *, size_t size);
typedef void storage_trim_f(struct storage *, size_t size); typedef void storage_trim_f(struct storage *, size_t size);
......
...@@ -242,7 +242,7 @@ smf_initfile(struct smf_sc *sc, const char *size, int newfile) ...@@ -242,7 +242,7 @@ smf_initfile(struct smf_sc *sc, const char *size, int newfile)
} }
static void 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 *size;
char *p, *q; char *p, *q;
...@@ -262,9 +262,8 @@ smf_init(struct stevedore *parent, const char *spec) ...@@ -262,9 +262,8 @@ smf_init(struct stevedore *parent, const char *spec)
/* If no size specified, use 50% of filesystem free space */ /* If no size specified, use 50% of filesystem free space */
if (spec == NULL || *spec == '\0') if (spec == NULL || *spec == '\0')
spec = "/tmp,50%"; asprintf(&p, "/tmp/%s,50%%", varnish_name);
else if (strchr(spec, ',') == NULL)
if (strchr(spec, ',') == NULL)
asprintf(&p, "%s,", spec); asprintf(&p, "%s,", spec);
else else
p = strdup(spec); p = strdup(spec);
......
...@@ -42,6 +42,7 @@ ...@@ -42,6 +42,7 @@
.Op Fl f Ar config .Op Fl f Ar config
.Op Fl g Ar group .Op Fl g Ar group
.Op Fl h Ar type Ns Op , Ns Ar options .Op Fl h Ar type Ns Op , Ns Ar options
.Op Fl n Ar name
.Op Fl P Ar file .Op Fl P Ar file
.Op Fl p Ar param Ns = Ns Ar value .Op Fl p Ar param Ns = Ns Ar value
.Op Fl s Ar type Ns Op , Ns Ar options .Op Fl s Ar type Ns Op , Ns Ar options
...@@ -127,6 +128,10 @@ Specifies the hash algorithm. ...@@ -127,6 +128,10 @@ Specifies the hash algorithm.
See See
.Sx Hash Algorithms .Sx Hash Algorithms
for a list of supported 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 .It Fl P Ar file
Write the process's PID to the specified Write the process's PID to the specified
.Ar file . .Ar file .
...@@ -494,6 +499,11 @@ Note that this will generate large amounts of log data. ...@@ -494,6 +499,11 @@ Note that this will generate large amounts of log data.
.Pp .Pp
The default is The default is
.Dv off . .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 .El
.Sh SEE ALSO .Sh SEE ALSO
.Xr varnishlog 1 , .Xr varnishlog 1 ,
......
...@@ -150,7 +150,7 @@ setup_storage(const char *s_arg) ...@@ -150,7 +150,7 @@ setup_storage(const char *s_arg)
heritage.stevedore = malloc(sizeof *heritage.stevedore); heritage.stevedore = malloc(sizeof *heritage.stevedore);
*heritage.stevedore = *stp; *heritage.stevedore = *stp;
if (stp->init != NULL) if (stp->init != NULL)
stp->init(heritage.stevedore, q); stp->init(heritage.stevedore, q, params->name);
} }
/*--------------------------------------------------------------------*/ /*--------------------------------------------------------------------*/
...@@ -177,6 +177,7 @@ usage(void) ...@@ -177,6 +177,7 @@ usage(void)
" -h classic [default]"); " -h classic [default]");
fprintf(stderr, " %-28s # %s\n", "", fprintf(stderr, " %-28s # %s\n", "",
" -h classic,<buckets>"); " -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 file", "PID file");
fprintf(stderr, " %-28s # %s\n", "-p param=value", fprintf(stderr, " %-28s # %s\n", "-p param=value",
"set parameter"); "set parameter");
...@@ -402,6 +403,7 @@ main(int argc, char *argv[]) ...@@ -402,6 +403,7 @@ main(int argc, char *argv[])
const char *b_arg = NULL; const char *b_arg = NULL;
const char *f_arg = NULL; const char *f_arg = NULL;
const char *h_arg = "classic"; const char *h_arg = "classic";
char *n_arg = NULL;
const char *P_arg = NULL; const char *P_arg = NULL;
const char *s_arg = "file"; const char *s_arg = "file";
const char *T_arg = NULL; const char *T_arg = NULL;
...@@ -409,6 +411,7 @@ main(int argc, char *argv[]) ...@@ -409,6 +411,7 @@ main(int argc, char *argv[])
char *p; char *p;
struct cli cli[1]; struct cli cli[1];
struct pidfh *pfh = NULL; struct pidfh *pfh = NULL;
char buf[BUFSIZ];
setbuf(stdout, NULL); setbuf(stdout, NULL);
setbuf(stderr, NULL); setbuf(stderr, NULL);
...@@ -424,7 +427,7 @@ main(int argc, char *argv[]) ...@@ -424,7 +427,7 @@ main(int argc, char *argv[])
MCF_ParamInit(cli); MCF_ParamInit(cli);
cli_check(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) { switch (o) {
case 'a': case 'a':
MCF_ParamSet(cli, "listen_address", optarg); MCF_ParamSet(cli, "listen_address", optarg);
...@@ -448,6 +451,9 @@ main(int argc, char *argv[]) ...@@ -448,6 +451,9 @@ main(int argc, char *argv[])
case 'h': case 'h':
h_arg = optarg; h_arg = optarg;
break; break;
case 'n':
n_arg = optarg;
break;
case 'P': case 'P':
P_arg = optarg; P_arg = optarg;
break; break;
...@@ -499,6 +505,12 @@ main(int argc, char *argv[]) ...@@ -499,6 +505,12 @@ main(int argc, char *argv[])
usage(); 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) { if (P_arg && (pfh = vpf_open(P_arg, 0600, NULL)) == NULL) {
perror(P_arg); perror(P_arg);
exit(1); exit(1);
...@@ -512,7 +524,8 @@ main(int argc, char *argv[]) ...@@ -512,7 +524,8 @@ main(int argc, char *argv[])
setup_storage(s_arg); setup_storage(s_arg);
setup_hash(h_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) if (d_flag == 1)
DebugStunt(); DebugStunt();
......
...@@ -42,6 +42,7 @@ ...@@ -42,6 +42,7 @@
.Op Fl d .Op Fl d
.Op Fl I Ar regex .Op Fl I Ar regex
.Op Fl i Ar tag .Op Fl i Ar tag
.Op Fl n Ar varnish_name
.Op Fl r Ar file .Op Fl r Ar file
.Op Fl V .Op Fl V
.Op Fl w Ar delay .Op Fl w Ar delay
...@@ -100,6 +101,12 @@ If neither ...@@ -100,6 +101,12 @@ If neither
nor nor
.Fl i .Fl i
is specified, all log entries are included. 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 .It Fl r Ar file
Read log entries from Read log entries from
.Ar file .Ar file
......
...@@ -40,6 +40,7 @@ ...@@ -40,6 +40,7 @@
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include <unistd.h> #include <unistd.h>
#include <limits.h>
#include "libvarnish.h" #include "libvarnish.h"
#include "shmlog.h" #include "shmlog.h"
...@@ -170,7 +171,7 @@ static void ...@@ -170,7 +171,7 @@ static void
usage(void) usage(void)
{ {
fprintf(stderr, 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); exit(1);
} }
...@@ -179,11 +180,15 @@ main(int argc, char **argv) ...@@ -179,11 +180,15 @@ main(int argc, char **argv)
{ {
int i, c, x; int i, c, x;
struct VSL_data *vd; struct VSL_data *vd;
char *n_arg = NULL;
vd = VSL_New(); vd = VSL_New();
while ((c = getopt(argc, argv, VSL_ARGS "Vw:")) != -1) { while ((c = getopt(argc, argv, VSL_ARGS "n:Vw:")) != -1) {
switch (c) { switch (c) {
case 'n':
n_arg = optarg;
break;
case 'V': case 'V':
varnish_version("varnishhist"); varnish_version("varnishhist");
exit(0); exit(0);
...@@ -197,7 +202,12 @@ main(int argc, char **argv) ...@@ -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); exit (1);
c_hist = 10.0 / log(10.0); c_hist = 10.0 / log(10.0);
......
...@@ -46,6 +46,7 @@ ...@@ -46,6 +46,7 @@
.Op Fl i Ar tag .Op Fl i Ar tag
.Op Fl o .Op Fl o
.Op Fl P Ar file .Op Fl P Ar file
.Op Fl n Ar varnish_name
.Op Fl r Ar file .Op Fl r Ar file
.Op Fl V .Op Fl V
.Op Fl w Ar file .Op Fl w Ar file
...@@ -106,6 +107,12 @@ If neither ...@@ -106,6 +107,12 @@ If neither
nor nor
.Fl i .Fl i
is specified, all log entries are included. 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 .It Fl o
Group log entries by request ID. Group log entries by request ID.
This has no effect when writing to a file using the This has no effect when writing to a file using the
......
...@@ -39,6 +39,7 @@ ...@@ -39,6 +39,7 @@
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include <unistd.h> #include <unistd.h>
#include <limits.h>
#ifndef HAVE_DAEMON #ifndef HAVE_DAEMON
#include "compat/daemon.h" #include "compat/daemon.h"
...@@ -273,7 +274,7 @@ static void ...@@ -273,7 +274,7 @@ static void
usage(void) usage(void)
{ {
fprintf(stderr, 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); exit(1);
} }
...@@ -284,12 +285,13 @@ main(int argc, char **argv) ...@@ -284,12 +285,13 @@ main(int argc, char **argv)
int a_flag = 0, D_flag = 0, o_flag = 0; int a_flag = 0, D_flag = 0, o_flag = 0;
const char *P_arg = NULL; const char *P_arg = NULL;
const char *w_arg = NULL; const char *w_arg = NULL;
char *n_arg = NULL;
struct pidfh *pfh = NULL; struct pidfh *pfh = NULL;
struct VSL_data *vd; struct VSL_data *vd;
vd = VSL_New(); 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) { switch (c) {
case 'a': case 'a':
a_flag = 1; a_flag = 1;
...@@ -297,6 +299,9 @@ main(int argc, char **argv) ...@@ -297,6 +299,9 @@ main(int argc, char **argv)
case 'D': case 'D':
D_flag = 1; D_flag = 1;
break; break;
case 'n':
n_arg = optarg;
break;
case 'o': case 'o':
o_flag = 1; o_flag = 1;
break; break;
...@@ -329,7 +334,12 @@ main(int argc, char **argv) ...@@ -329,7 +334,12 @@ main(int argc, char **argv)
if (o_flag && w_arg != NULL) if (o_flag && w_arg != NULL)
usage(); 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); exit(1);
if (P_arg && (pfh = vpf_open(P_arg, 0600, NULL)) == NULL) { if (P_arg && (pfh = vpf_open(P_arg, 0600, NULL)) == NULL) {
......
...@@ -43,6 +43,7 @@ ...@@ -43,6 +43,7 @@
.Op Fl d .Op Fl d
.Op Fl I Ar regex .Op Fl I Ar regex
.Op Fl i Ar tag .Op Fl i Ar tag
.Op Fl n Ar varnish_name
.Op Fl r Ar file .Op Fl r Ar file
.Op Fl V .Op Fl V
.Op Fl w Ar file .Op Fl w Ar file
...@@ -101,6 +102,12 @@ If neither ...@@ -101,6 +102,12 @@ If neither
nor nor
.Fl i .Fl i
is specified, all log entries are included. 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 .It Fl r Ar file
Read log entries from Read log entries from
.Ar file .Ar file
......
...@@ -67,6 +67,7 @@ ...@@ -67,6 +67,7 @@
#include <string.h> #include <string.h>
#include <time.h> #include <time.h>
#include <unistd.h> #include <unistd.h>
#include <limits.h>
#include "libvarnish.h" #include "libvarnish.h"
#include "shmlog.h" #include "shmlog.h"
...@@ -433,7 +434,7 @@ static void ...@@ -433,7 +434,7 @@ static void
usage(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); exit(1);
} }
...@@ -443,12 +444,13 @@ main(int argc, char *argv[]) ...@@ -443,12 +444,13 @@ main(int argc, char *argv[])
int i, c; int i, c;
struct VSL_data *vd; struct VSL_data *vd;
const char *ofn = NULL; const char *ofn = NULL;
char *n_arg = NULL;
int append = 0; int append = 0;
FILE *of; FILE *of;
vd = VSL_New(); 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); i = VSL_Arg(vd, c, optarg);
if (i < 0) if (i < 0)
exit (1); exit (1);
...@@ -458,6 +460,9 @@ main(int argc, char *argv[]) ...@@ -458,6 +460,9 @@ main(int argc, char *argv[])
case 'a': case 'a':
append = 1; append = 1;
break; break;
case 'n':
n_arg = optarg;
break;
case 'V': case 'V':
varnish_version("varnishncsa"); varnish_version("varnishncsa");
exit(0); exit(0);
...@@ -471,7 +476,12 @@ main(int argc, char *argv[]) ...@@ -471,7 +476,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); exit(1);
if (ofn) { if (ofn) {
......
...@@ -37,6 +37,7 @@ ...@@ -37,6 +37,7 @@
.Sh SYNOPSIS .Sh SYNOPSIS
.Nm .Nm
.Op Fl 1 .Op Fl 1
.Op Fl n Ar varnish_name
.Op Fl V .Op Fl V
.Op Fl w Ar delay .Op Fl w Ar delay
.Sh DESCRIPTION .Sh DESCRIPTION
...@@ -51,6 +52,12 @@ The following options are available: ...@@ -51,6 +52,12 @@ The following options are available:
.It Fl 1 .It Fl 1
Instead of presenting of a continuously updated display, print the Instead of presenting of a continuously updated display, print the
statistics once and exit. 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 .It Fl V
Display the version number and exit. Display the version number and exit.
.It Fl w Ar delay .It Fl w Ar delay
......
...@@ -38,6 +38,7 @@ ...@@ -38,6 +38,7 @@
#include <unistd.h> #include <unistd.h>
#include <curses.h> #include <curses.h>
#include <time.h> #include <time.h>
#include <limits.h>
#ifndef HAVE_CLOCK_GETTIME #ifndef HAVE_CLOCK_GETTIME
#include "compat/clock_gettime.h" #include "compat/clock_gettime.h"
...@@ -130,7 +131,7 @@ do_curses(struct varnish_stats *VSL_stats, int delay) ...@@ -130,7 +131,7 @@ do_curses(struct varnish_stats *VSL_stats, int delay)
static void static void
usage(void) usage(void)
{ {
fprintf(stderr, "usage: varnishstat [-1V] [-w delay]\n"); fprintf(stderr, "usage: varnishstat [-1V] [-n varnish_name] [-w delay]\n");
exit(1); exit(1);
} }
...@@ -140,14 +141,16 @@ main(int argc, char **argv) ...@@ -140,14 +141,16 @@ main(int argc, char **argv)
int c; int c;
struct varnish_stats *VSL_stats; struct varnish_stats *VSL_stats;
int delay = 1, once = 0; int delay = 1, once = 0;
char *n_arg = NULL;
VSL_stats = VSL_OpenStats(); while ((c = getopt(argc, argv, "1n:Vw:")) != -1) {
while ((c = getopt(argc, argv, "1Vw:")) != -1) {
switch (c) { switch (c) {
case '1': case '1':
once = 1; once = 1;
break; break;
case 'n':
n_arg = optarg;
break;
case 'V': case 'V':
varnish_version("varnishstat"); varnish_version("varnishstat");
exit(0); exit(0);
...@@ -159,6 +162,15 @@ main(int argc, char **argv) ...@@ -159,6 +162,15 @@ main(int argc, char **argv)
} }
} }
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) { if (!once) {
do_curses(VSL_stats, delay); do_curses(VSL_stats, delay);
} else { } else {
......
...@@ -44,6 +44,7 @@ ...@@ -44,6 +44,7 @@
.Op Fl f .Op Fl f
.Op Fl I Ar regex .Op Fl I Ar regex
.Op Fl i Ar tag .Op Fl i Ar tag
.Op Fl n Ar varnish_name
.Op Fl r Ar file .Op Fl r Ar file
.Op Fl V .Op Fl V
.Op Fl X Ar regex .Op Fl X Ar regex
...@@ -116,6 +117,12 @@ If neither ...@@ -116,6 +117,12 @@ If neither
nor nor
.Fl i .Fl i
is specified, all log entries are included. 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 .It Fl r Ar file
Read log entries from Read log entries from
.Ar file .Ar file
......
...@@ -38,6 +38,7 @@ ...@@ -38,6 +38,7 @@
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include <unistd.h> #include <unistd.h>
#include <limits.h>
#include "vsb.h" #include "vsb.h"
...@@ -63,7 +64,7 @@ static unsigned ntop; ...@@ -63,7 +64,7 @@ static unsigned ntop;
static void static void
usage(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); exit(1);
} }
...@@ -112,11 +113,11 @@ main(int argc, char **argv) ...@@ -112,11 +113,11 @@ main(int argc, char **argv)
unsigned u, v; unsigned u, v;
struct top *tp, *tp2; struct top *tp, *tp2;
int f_flag = 0; int f_flag = 0;
char *n_arg = NULL;
vd = VSL_New(); 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); i = VSL_Arg(vd, c, optarg);
if (i < 0) if (i < 0)
exit (1); exit (1);
...@@ -126,6 +127,9 @@ main(int argc, char **argv) ...@@ -126,6 +127,9 @@ main(int argc, char **argv)
case '1': case '1':
VSL_NonBlocking(vd, 1); VSL_NonBlocking(vd, 1);
break; break;
case 'n':
n_arg = optarg;
break;
case 'f': case 'f':
f_flag = 1; f_flag = 1;
break; break;
...@@ -137,7 +141,12 @@ main(int argc, char **argv) ...@@ -137,7 +141,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); exit (1);
initscr(); initscr();
......
...@@ -36,7 +36,7 @@ ...@@ -36,7 +36,7 @@
#ifndef SHMLOG_H_INCLUDED #ifndef SHMLOG_H_INCLUDED
#define SHMLOG_H_INCLUDED #define SHMLOG_H_INCLUDED
#define SHMLOG_FILENAME "/tmp/_.vsl" #define SHMLOG_FILENAME "_.vsl"
#include <time.h> #include <time.h>
......
...@@ -50,12 +50,12 @@ vsl_handler VSL_H_Print; ...@@ -50,12 +50,12 @@ vsl_handler VSL_H_Print;
struct VSL_data; struct VSL_data;
struct VSL_data *VSL_New(void); struct VSL_data *VSL_New(void);
void VSL_Select(struct VSL_data *vd, unsigned tag); 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); void VSL_NonBlocking(struct VSL_data *vd, int nb);
int VSL_Dispatch(struct VSL_data *vd, vsl_handler *func, void *priv); int VSL_Dispatch(struct VSL_data *vd, vsl_handler *func, void *priv);
int VSL_NextLog(struct VSL_data *lh, unsigned char **pp); int VSL_NextLog(struct VSL_data *lh, unsigned char **pp);
int VSL_Arg(struct VSL_data *vd, int arg, const char *opt); 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]; extern const char *VSL_tags[256];
/* varnish_debug.c */ /* varnish_debug.c */
......
...@@ -102,29 +102,32 @@ const char *VSL_tags[256] = { ...@@ -102,29 +102,32 @@ const char *VSL_tags[256] = {
/*--------------------------------------------------------------------*/ /*--------------------------------------------------------------------*/
static int static int
vsl_shmem_map(void) vsl_shmem_map(char* varnish_name)
{ {
int i; int i;
struct shmloghead slh; struct shmloghead slh;
char buf[BUFSIZ];
if (vsl_lh != NULL) if (vsl_lh != NULL)
return (0); 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) { if (vsl_fd < 0) {
fprintf(stderr, "Cannot open %s: %s\n", fprintf(stderr, "Cannot open %s: %s\n",
SHMLOG_FILENAME, strerror(errno)); buf, strerror(errno));
return (1); return (1);
} }
i = read(vsl_fd, &slh, sizeof slh); i = read(vsl_fd, &slh, sizeof slh);
if (i != sizeof slh) { if (i != sizeof slh) {
fprintf(stderr, "Cannot read %s: %s\n", fprintf(stderr, "Cannot read %s: %s\n",
SHMLOG_FILENAME, strerror(errno)); buf, strerror(errno));
return (1); return (1);
} }
if (slh.magic != SHMLOGHEAD_MAGIC) { if (slh.magic != SHMLOGHEAD_MAGIC) {
fprintf(stderr, "Wrong magic number in file %s\n", fprintf(stderr, "Wrong magic number in file %s\n",
SHMLOG_FILENAME); buf);
return (1); return (1);
} }
...@@ -132,7 +135,7 @@ vsl_shmem_map(void) ...@@ -132,7 +135,7 @@ vsl_shmem_map(void)
PROT_READ, MAP_SHARED|MAP_HASSEMAPHORE, vsl_fd, 0); PROT_READ, MAP_SHARED|MAP_HASSEMAPHORE, vsl_fd, 0);
if (vsl_lh == MAP_FAILED) { if (vsl_lh == MAP_FAILED) {
fprintf(stderr, "Cannot mmap %s: %s\n", fprintf(stderr, "Cannot mmap %s: %s\n",
SHMLOG_FILENAME, strerror(errno)); buf, strerror(errno));
return (1); return (1);
} }
return (0); return (0);
...@@ -167,7 +170,7 @@ VSL_Select(struct VSL_data *vd, unsigned tag) ...@@ -167,7 +170,7 @@ VSL_Select(struct VSL_data *vd, unsigned tag)
/*--------------------------------------------------------------------*/ /*--------------------------------------------------------------------*/
int int
VSL_OpenLog(struct VSL_data *vd) VSL_OpenLog(struct VSL_data *vd, char *varnish_name)
{ {
unsigned char *p; unsigned char *p;
...@@ -175,7 +178,7 @@ VSL_OpenLog(struct VSL_data *vd) ...@@ -175,7 +178,7 @@ VSL_OpenLog(struct VSL_data *vd)
if (vd->fi != NULL) if (vd->fi != NULL)
return (0); return (0);
if (vsl_shmem_map()) if (vsl_shmem_map(varnish_name))
return (1); return (1);
vd->head = vsl_lh; vd->head = vsl_lh;
...@@ -474,10 +477,10 @@ VSL_Arg(struct VSL_data *vd, int arg, const char *opt) ...@@ -474,10 +477,10 @@ VSL_Arg(struct VSL_data *vd, int arg, const char *opt)
} }
struct varnish_stats * struct varnish_stats *
VSL_OpenStats(void) VSL_OpenStats(char *varnish_name)
{ {
if (vsl_shmem_map()) if (vsl_shmem_map(varnish_name))
return (NULL); return (NULL);
return (&vsl_lh->stats); return (&vsl_lh->stats);
} }
......
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