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 {
/* Ping interval */
unsigned ping_interval;
/* Varnishd name */
char *name;
};
extern volatile struct params *params;
......
......@@ -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 }
};
......
......@@ -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) {
......
......@@ -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);
......
......@@ -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);
......
......@@ -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 ,
......
......@@ -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();
......
......@@ -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
......
......@@ -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);
......
......@@ -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
......
......@@ -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) {
......
......@@ -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
......
......@@ -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) {
......
......@@ -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
......
......@@ -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);
......
......@@ -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
......
......@@ -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();
......
......@@ -36,7 +36,7 @@
#ifndef SHMLOG_H_INCLUDED
#define SHMLOG_H_INCLUDED
#define SHMLOG_FILENAME "/tmp/_.vsl"
#define SHMLOG_FILENAME "_.vsl"
#include <time.h>
......
......@@ -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 */
......
......@@ -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);
}
......
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