/* Ping interval */
unsigned ping_interval;
+
+ /* Varnishd name */
+ char *name;
};
extern volatile struct params *params;
*/
#include <sys/types.h>
+#include <sys/stat.h>
#include <grp.h>
#include <pwd.h>
/*--------------------------------------------------------------------*/
+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.
"\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.
"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 }
};
#include "mgt.h"
#include "mgt_cli.h"
+#include "heritage.h"
#include "vss.h"
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) {
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) {
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);
}
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;
/* 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);
.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
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 .
.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 ,
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);
}
/*--------------------------------------------------------------------*/
" -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");
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;
char *p;
struct cli cli[1];
struct pidfh *pfh = NULL;
+ char buf[BUFSIZ];
setbuf(stdout, NULL);
setbuf(stderr, NULL);
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);
case 'h':
h_arg = optarg;
break;
+ case 'n':
+ n_arg = optarg;
+ break;
case 'P':
P_arg = optarg;
break;
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);
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();
.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
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
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
+#include <limits.h>
#include "libvarnish.h"
#include "shmlog.h"
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);
}
{
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);
}
}
- 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);
.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
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
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
+#include <limits.h>
#ifndef HAVE_DAEMON
#include "compat/daemon.h"
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);
}
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;
case 'D':
D_flag = 1;
break;
+ case 'n':
+ n_arg = optarg;
+ break;
case 'o':
o_flag = 1;
break;
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) {
.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
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
#include <string.h>
#include <time.h>
#include <unistd.h>
+#include <limits.h>
#include "libvarnish.h"
#include "shmlog.h"
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);
}
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);
case 'a':
append = 1;
break;
+ case 'n':
+ n_arg = optarg;
+ break;
case 'V':
varnish_version("varnishncsa");
exit(0);
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) {
.Sh SYNOPSIS
.Nm
.Op Fl 1
+.Op Fl n Ar varnish_name
.Op Fl V
.Op Fl w Ar delay
.Sh DESCRIPTION
.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
#include <unistd.h>
#include <curses.h>
#include <time.h>
+#include <limits.h>
#ifndef HAVE_CLOCK_GETTIME
#include "compat/clock_gettime.h"
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);
}
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);
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);
.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
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
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
+#include <limits.h>
#include "vsb.h"
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);
}
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);
case '1':
VSL_NonBlocking(vd, 1);
break;
+ case 'n':
+ n_arg = optarg;
+ break;
case 'f':
f_flag = 1;
break;
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();
#ifndef SHMLOG_H_INCLUDED
#define SHMLOG_H_INCLUDED
-#define SHMLOG_FILENAME "/tmp/_.vsl"
+#define SHMLOG_FILENAME "_.vsl"
#include <time.h>
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 */
/*--------------------------------------------------------------------*/
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);
}
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);
/*--------------------------------------------------------------------*/
int
-VSL_OpenLog(struct VSL_data *vd)
+VSL_OpenLog(struct VSL_data *vd, char *varnish_name)
{
unsigned char *p;
if (vd->fi != NULL)
return (0);
- if (vsl_shmem_map())
+ if (vsl_shmem_map(varnish_name))
return (1);
vd->head = vsl_lh;
}
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);
}