r1521 - in trunk/varnish-cache: bin/varnishd bin/varnishhist bin/varnishlog bin/varnishncsa bin/varnishstat bin/varnishtop include lib/libvarnishapi

cecilihf at projects.linpro.no cecilihf at projects.linpro.no
Fri Jun 15 11:18:06 CEST 2007


Author: cecilihf
Date: 2007-06-15 11:18:06 +0200 (Fri, 15 Jun 2007)
New Revision: 1521

Modified:
   trunk/varnish-cache/bin/varnishd/heritage.h
   trunk/varnish-cache/bin/varnishd/mgt_param.c
   trunk/varnish-cache/bin/varnishd/mgt_vcc.c
   trunk/varnish-cache/bin/varnishd/stevedore.h
   trunk/varnish-cache/bin/varnishd/storage_file.c
   trunk/varnish-cache/bin/varnishd/varnishd.1
   trunk/varnish-cache/bin/varnishd/varnishd.c
   trunk/varnish-cache/bin/varnishhist/varnishhist.1
   trunk/varnish-cache/bin/varnishhist/varnishhist.c
   trunk/varnish-cache/bin/varnishlog/varnishlog.1
   trunk/varnish-cache/bin/varnishlog/varnishlog.c
   trunk/varnish-cache/bin/varnishncsa/varnishncsa.1
   trunk/varnish-cache/bin/varnishncsa/varnishncsa.c
   trunk/varnish-cache/bin/varnishstat/varnishstat.1
   trunk/varnish-cache/bin/varnishstat/varnishstat.c
   trunk/varnish-cache/bin/varnishtop/varnishtop.1
   trunk/varnish-cache/bin/varnishtop/varnishtop.c
   trunk/varnish-cache/include/shmlog.h
   trunk/varnish-cache/include/varnishapi.h
   trunk/varnish-cache/lib/libvarnishapi/shmlog.c
Log:
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.



Modified: trunk/varnish-cache/bin/varnishd/heritage.h
===================================================================
--- trunk/varnish-cache/bin/varnishd/heritage.h	2007-06-15 09:03:34 UTC (rev 1520)
+++ trunk/varnish-cache/bin/varnishd/heritage.h	2007-06-15 09:18:06 UTC (rev 1521)
@@ -119,6 +119,9 @@
 
 	/* Ping interval */
 	unsigned		ping_interval;
+
+	/* Varnishd name */
+	char			*name;
 };
 
 extern volatile struct params *params;

Modified: trunk/varnish-cache/bin/varnishd/mgt_param.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/mgt_param.c	2007-06-15 09:03:34 UTC (rev 1520)
+++ trunk/varnish-cache/bin/varnishd/mgt_param.c	2007-06-15 09:18:06 UTC (rev 1521)
@@ -30,6 +30,7 @@
  */
 
 #include <sys/types.h>
+#include <sys/stat.h>
 
 #include <grp.h>
 #include <pwd.h>
@@ -497,6 +498,65 @@
 
 /*--------------------------------------------------------------------*/
 
+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 @@
 	"\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 @@
 		"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 }
 };
 

Modified: trunk/varnish-cache/bin/varnishd/mgt_vcc.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/mgt_vcc.c	2007-06-15 09:03:34 UTC (rev 1520)
+++ trunk/varnish-cache/bin/varnishd/mgt_vcc.c	2007-06-15 09:18:06 UTC (rev 1521)
@@ -52,6 +52,7 @@
 
 #include "mgt.h"
 #include "mgt_cli.h"
+#include "heritage.h"
 
 #include "vss.h"
 
@@ -144,7 +145,7 @@
 	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 @@
 	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) {

Modified: trunk/varnish-cache/bin/varnishd/stevedore.h
===================================================================
--- trunk/varnish-cache/bin/varnishd/stevedore.h	2007-06-15 09:03:34 UTC (rev 1520)
+++ trunk/varnish-cache/bin/varnishd/stevedore.h	2007-06-15 09:18:06 UTC (rev 1521)
@@ -33,7 +33,7 @@
 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);

Modified: trunk/varnish-cache/bin/varnishd/storage_file.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/storage_file.c	2007-06-15 09:03:34 UTC (rev 1520)
+++ trunk/varnish-cache/bin/varnishd/storage_file.c	2007-06-15 09:18:06 UTC (rev 1521)
@@ -242,7 +242,7 @@
 }
 
 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 @@
 
 	/* 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);

Modified: trunk/varnish-cache/bin/varnishd/varnishd.1
===================================================================
--- trunk/varnish-cache/bin/varnishd/varnishd.1	2007-06-15 09:03:34 UTC (rev 1520)
+++ trunk/varnish-cache/bin/varnishd/varnishd.1	2007-06-15 09:18:06 UTC (rev 1521)
@@ -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 @@
 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 @@
 .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 ,

Modified: trunk/varnish-cache/bin/varnishd/varnishd.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/varnishd.c	2007-06-15 09:03:34 UTC (rev 1520)
+++ trunk/varnish-cache/bin/varnishd/varnishd.c	2007-06-15 09:18:06 UTC (rev 1521)
@@ -150,7 +150,7 @@
 	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 @@
 	    "  -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 @@
 	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 @@
 	char *p;
 	struct cli cli[1];
 	struct pidfh *pfh = NULL;
+	char buf[BUFSIZ];
 
 	setbuf(stdout, NULL);
 	setbuf(stderr, NULL);
@@ -424,7 +427,7 @@
 	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 @@
 		case 'h':
 			h_arg = optarg;
 			break;
+		case 'n':
+			n_arg = optarg;
+			break;
 		case 'P':
 			P_arg = optarg;
 			break;
@@ -498,7 +504,13 @@
 		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 @@
 	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();

Modified: trunk/varnish-cache/bin/varnishhist/varnishhist.1
===================================================================
--- trunk/varnish-cache/bin/varnishhist/varnishhist.1	2007-06-15 09:03:34 UTC (rev 1520)
+++ trunk/varnish-cache/bin/varnishhist/varnishhist.1	2007-06-15 09:18:06 UTC (rev 1521)
@@ -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 @@
 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

Modified: trunk/varnish-cache/bin/varnishhist/varnishhist.c
===================================================================
--- trunk/varnish-cache/bin/varnishhist/varnishhist.c	2007-06-15 09:03:34 UTC (rev 1520)
+++ trunk/varnish-cache/bin/varnishhist/varnishhist.c	2007-06-15 09:18:06 UTC (rev 1521)
@@ -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 @@
 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 @@
 {
 	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 @@
 		}
 	}
 
-	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);

Modified: trunk/varnish-cache/bin/varnishlog/varnishlog.1
===================================================================
--- trunk/varnish-cache/bin/varnishlog/varnishlog.1	2007-06-15 09:03:34 UTC (rev 1520)
+++ trunk/varnish-cache/bin/varnishlog/varnishlog.1	2007-06-15 09:18:06 UTC (rev 1521)
@@ -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 @@
 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

Modified: trunk/varnish-cache/bin/varnishlog/varnishlog.c
===================================================================
--- trunk/varnish-cache/bin/varnishlog/varnishlog.c	2007-06-15 09:03:34 UTC (rev 1520)
+++ trunk/varnish-cache/bin/varnishlog/varnishlog.c	2007-06-15 09:18:06 UTC (rev 1521)
@@ -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 @@
 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 @@
 	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 @@
 		case 'D':
 			D_flag = 1;
 			break;
+		case 'n':
+			n_arg = optarg;
+			break;
 		case 'o':
 			o_flag = 1;
 			break;
@@ -329,7 +334,12 @@
 	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) {

Modified: trunk/varnish-cache/bin/varnishncsa/varnishncsa.1
===================================================================
--- trunk/varnish-cache/bin/varnishncsa/varnishncsa.1	2007-06-15 09:03:34 UTC (rev 1520)
+++ trunk/varnish-cache/bin/varnishncsa/varnishncsa.1	2007-06-15 09:18:06 UTC (rev 1521)
@@ -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 @@
 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

Modified: trunk/varnish-cache/bin/varnishncsa/varnishncsa.c
===================================================================
--- trunk/varnish-cache/bin/varnishncsa/varnishncsa.c	2007-06-15 09:03:34 UTC (rev 1520)
+++ trunk/varnish-cache/bin/varnishncsa/varnishncsa.c	2007-06-15 09:18:06 UTC (rev 1521)
@@ -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 @@
 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 @@
 	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 @@
 		case 'a':
 			append = 1;
 			break;
+		case 'n':
+			n_arg = optarg;
+			break;
 		case 'V':
 			varnish_version("varnishncsa");
 			exit(0);
@@ -470,8 +475,13 @@
 			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) {

Modified: trunk/varnish-cache/bin/varnishstat/varnishstat.1
===================================================================
--- trunk/varnish-cache/bin/varnishstat/varnishstat.1	2007-06-15 09:03:34 UTC (rev 1520)
+++ trunk/varnish-cache/bin/varnishstat/varnishstat.1	2007-06-15 09:18:06 UTC (rev 1521)
@@ -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 @@
 .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

Modified: trunk/varnish-cache/bin/varnishstat/varnishstat.c
===================================================================
--- trunk/varnish-cache/bin/varnishstat/varnishstat.c	2007-06-15 09:03:34 UTC (rev 1520)
+++ trunk/varnish-cache/bin/varnishstat/varnishstat.c	2007-06-15 09:18:06 UTC (rev 1521)
@@ -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 @@
 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 @@
 	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,7 +161,16 @@
 			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);
 	} else {

Modified: trunk/varnish-cache/bin/varnishtop/varnishtop.1
===================================================================
--- trunk/varnish-cache/bin/varnishtop/varnishtop.1	2007-06-15 09:03:34 UTC (rev 1520)
+++ trunk/varnish-cache/bin/varnishtop/varnishtop.1	2007-06-15 09:18:06 UTC (rev 1521)
@@ -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 @@
 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

Modified: trunk/varnish-cache/bin/varnishtop/varnishtop.c
===================================================================
--- trunk/varnish-cache/bin/varnishtop/varnishtop.c	2007-06-15 09:03:34 UTC (rev 1520)
+++ trunk/varnish-cache/bin/varnishtop/varnishtop.c	2007-06-15 09:18:06 UTC (rev 1521)
@@ -38,6 +38,7 @@
 #include <stdlib.h>
 #include <string.h>
 #include <unistd.h>
+#include <limits.h>
 
 #include "vsb.h"
 
@@ -63,7 +64,7 @@
 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 @@
 	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 @@
 		case '1':
 			VSL_NonBlocking(vd, 1);
 			break;
+		case 'n':
+			n_arg = optarg;
+			break;
 		case 'f':
 			f_flag = 1;
 			break;
@@ -136,8 +140,13 @@
 			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();

Modified: trunk/varnish-cache/include/shmlog.h
===================================================================
--- trunk/varnish-cache/include/shmlog.h	2007-06-15 09:03:34 UTC (rev 1520)
+++ trunk/varnish-cache/include/shmlog.h	2007-06-15 09:18:06 UTC (rev 1521)
@@ -36,7 +36,7 @@
 #ifndef SHMLOG_H_INCLUDED
 #define SHMLOG_H_INCLUDED
 
-#define SHMLOG_FILENAME		"/tmp/_.vsl"
+#define SHMLOG_FILENAME		"_.vsl"
 
 #include <time.h>
 

Modified: trunk/varnish-cache/include/varnishapi.h
===================================================================
--- trunk/varnish-cache/include/varnishapi.h	2007-06-15 09:03:34 UTC (rev 1520)
+++ trunk/varnish-cache/include/varnishapi.h	2007-06-15 09:18:06 UTC (rev 1521)
@@ -50,12 +50,12 @@
 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 */

Modified: trunk/varnish-cache/lib/libvarnishapi/shmlog.c
===================================================================
--- trunk/varnish-cache/lib/libvarnishapi/shmlog.c	2007-06-15 09:03:34 UTC (rev 1520)
+++ trunk/varnish-cache/lib/libvarnishapi/shmlog.c	2007-06-15 09:18:06 UTC (rev 1521)
@@ -102,29 +102,32 @@
 /*--------------------------------------------------------------------*/
 
 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 @@
 	    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 @@
 /*--------------------------------------------------------------------*/
 
 int
-VSL_OpenLog(struct VSL_data *vd)
+VSL_OpenLog(struct VSL_data *vd, char *varnish_name)
 {
 	unsigned char *p;
 
@@ -175,7 +178,7 @@
 	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 @@
 }
 
 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);
 }




More information about the varnish-commit mailing list