From 138799ade907978baa8887b504bb14bd85fa4b71 Mon Sep 17 00:00:00 2001 From: des Date: Fri, 15 Jun 2007 10:40:53 +0000 Subject: [PATCH] Slight improvements on Cecilie's commit: correct nroff style and man page wording, constify varnish_name, move default name logic into VSL_Open*(). git-svn-id: svn+ssh://projects.linpro.no/svn/varnish/trunk@1525 d4fa192b-c00b-0410-8231-f00ffab90ce4 --- varnish-cache/bin/varnishd/mgt_param.c | 10 +++++----- varnish-cache/bin/varnishd/varnishd.1 | 22 ++++++++++++--------- varnish-cache/bin/varnishd/varnishd.c | 11 ++--------- varnish-cache/bin/varnishhist/varnishhist.1 | 11 ++++++----- varnish-cache/bin/varnishhist/varnishhist.c | 7 +------ varnish-cache/bin/varnishlog/varnishlog.1 | 11 ++++++----- varnish-cache/bin/varnishlog/varnishlog.c | 7 +------ varnish-cache/bin/varnishncsa/varnishncsa.1 | 11 ++++++----- varnish-cache/bin/varnishncsa/varnishncsa.c | 7 +------ varnish-cache/bin/varnishstat/varnishstat.1 | 11 ++++++----- varnish-cache/bin/varnishstat/varnishstat.c | 10 ++-------- varnish-cache/bin/varnishtop/varnishtop.1 | 11 ++++++----- varnish-cache/bin/varnishtop/varnishtop.c | 7 +------ varnish-cache/include/varnishapi.h | 4 ++-- varnish-cache/lib/libvarnishapi/shmlog.c | 13 ++++++++---- 15 files changed, 67 insertions(+), 86 deletions(-) diff --git a/varnish-cache/bin/varnishd/mgt_param.c b/varnish-cache/bin/varnishd/mgt_param.c index 3d59ad29..c2a85018 100644 --- a/varnish-cache/bin/varnishd/mgt_param.c +++ b/varnish-cache/bin/varnishd/mgt_param.c @@ -507,7 +507,7 @@ tweak_name(struct cli *cli, struct parspec *par, const char* arg) char *old_path; int renaming; (void)par; - + if (arg != NULL) { /* Check that the new name follows hostname convention */ /* [a-zA-Z0-9.-] */ @@ -518,7 +518,7 @@ tweak_name(struct cli *cli, struct parspec *par, const char* arg) if (stat(path, &st)) { if (renaming) { if (renaming && rename(old_path, path)) { - cli_out(cli, + cli_out(cli, "Error: Directory %s could not be " "renamed to %s", old_path, path); @@ -578,12 +578,12 @@ tweak_name(struct cli *cli, struct parspec *par, const char* arg) */ static struct parspec parspec[] = { { "user", tweak_user, - "The unprivileged user to run as. Setting this will " + "The unprivileged user to run as. Setting this will " "also set \"group\" to the specified user's primary group.\n" MUST_RESTART, "nobody" }, { "group", tweak_group, - "The unprivileged group to run as.\n" + "The unprivileged group to run as.\n" MUST_RESTART, "nogroup" }, { "default_ttl", tweak_default_ttl, @@ -734,7 +734,7 @@ static struct parspec parspec[] = { "naming conventions. Makes it possible to run " "multiple varnishd instances on one server.\n" EXPERIMENTAL, - "hostname"}, + "hostname" }, { NULL, NULL, NULL } }; diff --git a/varnish-cache/bin/varnishd/varnishd.1 b/varnish-cache/bin/varnishd/varnishd.1 index f42020bd..0a822145 100644 --- a/varnish-cache/bin/varnishd/varnishd.1 +++ b/varnish-cache/bin/varnishd/varnishd.1 @@ -28,7 +28,7 @@ .\" .\" $Id$ .\" -.Dd May 30, 2007 +.Dd June 15, 2007 .Dt VARNISHD 1 .Os .Sh NAME @@ -129,9 +129,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// +Specify a name for this instance. +This is a shortcut for specifying the +.Va name +run-time parameter. .It Fl P Ar file Write the process's PID to the specified .Ar file . @@ -401,6 +402,14 @@ The default is 0.0.0.0:80. The depth of the TCP listen queue. .Pp The default is 512. +.It Va name +The name of this +.Nm +instance. +All temporary files are stored in +.Pa /tmp/ Ns Va name . +.Pp +The default is the hostname. .It Va overflow_max The maximum depth of the overflow queue as a percentage of .Va thread_pool_max . @@ -499,11 +508,6 @@ 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// -.Pp -The default is the hostname .El .Sh SEE ALSO .Xr varnishlog 1 , diff --git a/varnish-cache/bin/varnishd/varnishd.c b/varnish-cache/bin/varnishd/varnishd.c index a639bbb1..f5cc3cf5 100644 --- a/varnish-cache/bin/varnishd/varnishd.c +++ b/varnish-cache/bin/varnishd/varnishd.c @@ -403,7 +403,6 @@ 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; @@ -452,7 +451,7 @@ main(int argc, char *argv[]) h_arg = optarg; break; case 'n': - n_arg = optarg; + MCF_ParamSet(cli, "name", optarg); break; case 'P': P_arg = optarg; @@ -504,13 +503,7 @@ 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); diff --git a/varnish-cache/bin/varnishhist/varnishhist.1 b/varnish-cache/bin/varnishhist/varnishhist.1 index 45205f36..5a4cf2fe 100644 --- a/varnish-cache/bin/varnishhist/varnishhist.1 +++ b/varnish-cache/bin/varnishhist/varnishhist.1 @@ -28,7 +28,7 @@ .\" .\" $Id$ .\" -.Dd September 20, 2006 +.Dd June 15, 2007 .Dt VARNISHHIST 1 .Os .Sh NAME @@ -102,11 +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 +Specifies the name of the +.Nm varnishd +instance 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. +is not specified, the host name is used. .It Fl r Ar file Read log entries from .Ar file diff --git a/varnish-cache/bin/varnishhist/varnishhist.c b/varnish-cache/bin/varnishhist/varnishhist.c index dfe71876..d9a60024 100644 --- a/varnish-cache/bin/varnishhist/varnishhist.c +++ b/varnish-cache/bin/varnishhist/varnishhist.c @@ -180,7 +180,7 @@ main(int argc, char **argv) { int i, c, x; struct VSL_data *vd; - char *n_arg = NULL; + const char *n_arg = NULL; vd = VSL_New(); @@ -202,11 +202,6 @@ 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_OpenLog(vd, n_arg)) exit (1); diff --git a/varnish-cache/bin/varnishlog/varnishlog.1 b/varnish-cache/bin/varnishlog/varnishlog.1 index a5bb9f76..9e8387fa 100644 --- a/varnish-cache/bin/varnishlog/varnishlog.1 +++ b/varnish-cache/bin/varnishlog/varnishlog.1 @@ -28,7 +28,7 @@ .\" .\" $Id$ .\" -.Dd May 11, 2007 +.Dd June 15, 2007 .Dt VARNISHLOG 1 .Os .Sh NAME @@ -108,11 +108,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 +Specifies the name of the +.Nm varnishd +instance to get logs from. +If .Fl n -the option must be specified. +is not specified, the host name is used. .It Fl o Group log entries by request ID. This has no effect when writing to a file using the diff --git a/varnish-cache/bin/varnishlog/varnishlog.c b/varnish-cache/bin/varnishlog/varnishlog.c index 2b6e2f17..b0400ff0 100644 --- a/varnish-cache/bin/varnishlog/varnishlog.c +++ b/varnish-cache/bin/varnishlog/varnishlog.c @@ -285,7 +285,7 @@ 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; + const char *n_arg = NULL; struct pidfh *pfh = NULL; struct VSL_data *vd; @@ -334,11 +334,6 @@ main(int argc, char **argv) if (o_flag && w_arg != NULL) usage(); - 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); diff --git a/varnish-cache/bin/varnishncsa/varnishncsa.1 b/varnish-cache/bin/varnishncsa/varnishncsa.1 index 3569b1ed..d1c76056 100644 --- a/varnish-cache/bin/varnishncsa/varnishncsa.1 +++ b/varnish-cache/bin/varnishncsa/varnishncsa.1 @@ -28,7 +28,7 @@ .\" .\" $Id$ .\" -.Dd April 21, 2007 +.Dd June 15, 2007 .Dt VARNISHNCSA 1 .Os .Sh NAME @@ -103,11 +103,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 +Specifies the name of the +.Nm varnishd +instance to get logs from. +If .Fl n -the option must be specified. +is not specified, the host name is used. .It Fl r Ar file Read log entries from .Ar file diff --git a/varnish-cache/bin/varnishncsa/varnishncsa.c b/varnish-cache/bin/varnishncsa/varnishncsa.c index 8d2308a6..92642292 100644 --- a/varnish-cache/bin/varnishncsa/varnishncsa.c +++ b/varnish-cache/bin/varnishncsa/varnishncsa.c @@ -444,7 +444,7 @@ main(int argc, char *argv[]) int i, c; struct VSL_data *vd; const char *ofn = NULL; - char *n_arg = NULL; + const char *n_arg = NULL; int append = 0; FILE *of; @@ -475,11 +475,6 @@ 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, n_arg)) exit(1); diff --git a/varnish-cache/bin/varnishstat/varnishstat.1 b/varnish-cache/bin/varnishstat/varnishstat.1 index 42c2ca4c..6e9310e8 100644 --- a/varnish-cache/bin/varnishstat/varnishstat.1 +++ b/varnish-cache/bin/varnishstat/varnishstat.1 @@ -28,7 +28,7 @@ .\" .\" $Id$ .\" -.Dd September 20, 2006 +.Dd June 15, 2007 .Dt VARNISHSTAT 1 .Os .Sh NAME @@ -53,11 +53,12 @@ The following options are available: 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 +Specifies the name of the +.Nm varnishd +instance 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. +is not specified, the host name is used. .It Fl V Display the version number and exit. .It Fl w Ar delay diff --git a/varnish-cache/bin/varnishstat/varnishstat.c b/varnish-cache/bin/varnishstat/varnishstat.c index 43784ab0..7486f05e 100644 --- a/varnish-cache/bin/varnishstat/varnishstat.c +++ b/varnish-cache/bin/varnishstat/varnishstat.c @@ -141,7 +141,7 @@ main(int argc, char **argv) int c; struct varnish_stats *VSL_stats; int delay = 1, once = 0; - char *n_arg = NULL; + const char *n_arg = NULL; while ((c = getopt(argc, argv, "1n:Vw:")) != -1) { switch (c) { @@ -161,15 +161,9 @@ 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))) { + if ((VSL_stats = VSL_OpenStats(n_arg)) == NULL) exit(1); - } if (!once) { do_curses(VSL_stats, delay); diff --git a/varnish-cache/bin/varnishtop/varnishtop.1 b/varnish-cache/bin/varnishtop/varnishtop.1 index 961d028f..6c3d685f 100644 --- a/varnish-cache/bin/varnishtop/varnishtop.1 +++ b/varnish-cache/bin/varnishtop/varnishtop.1 @@ -28,7 +28,7 @@ .\" .\" $Id$ .\" -.Dd September 20, 2006 +.Dd June 15, 2007 .Dt VARNISHTOP 1 .Os .Sh NAME @@ -118,11 +118,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 +Specifies the name of the +.Nm varnishd +instance 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. +is not specified, the host name is used. .It Fl r Ar file Read log entries from .Ar file diff --git a/varnish-cache/bin/varnishtop/varnishtop.c b/varnish-cache/bin/varnishtop/varnishtop.c index dcbb11b7..462139ef 100644 --- a/varnish-cache/bin/varnishtop/varnishtop.c +++ b/varnish-cache/bin/varnishtop/varnishtop.c @@ -113,7 +113,7 @@ main(int argc, char **argv) unsigned u, v; struct top *tp, *tp2; int f_flag = 0; - char *n_arg = NULL; + const char *n_arg = NULL; vd = VSL_New(); @@ -140,11 +140,6 @@ 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, n_arg)) exit (1); diff --git a/varnish-cache/include/varnishapi.h b/varnish-cache/include/varnishapi.h index 2f2aa9f2..e3854e34 100644 --- a/varnish-cache/include/varnishapi.h +++ b/varnish-cache/include/varnishapi.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, char *varnish_name); +int VSL_OpenLog(struct VSL_data *vd, const 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(char *varnish_name); +struct varnish_stats *VSL_OpenStats(const char *varnish_name); extern const char *VSL_tags[256]; /* varnish_debug.c */ diff --git a/varnish-cache/lib/libvarnishapi/shmlog.c b/varnish-cache/lib/libvarnishapi/shmlog.c index 4dcb1c85..090ef2b0 100644 --- a/varnish-cache/lib/libvarnishapi/shmlog.c +++ b/varnish-cache/lib/libvarnishapi/shmlog.c @@ -102,7 +102,7 @@ const char *VSL_tags[256] = { /*--------------------------------------------------------------------*/ static int -vsl_shmem_map(char* varnish_name) +vsl_shmem_map(const char *varnish_name) { int i; struct shmloghead slh; @@ -170,16 +170,21 @@ VSL_Select(struct VSL_data *vd, unsigned tag) /*--------------------------------------------------------------------*/ int -VSL_OpenLog(struct VSL_data *vd, char *varnish_name) +VSL_OpenLog(struct VSL_data *vd, const char *varnish_name) { + char hostname[1024]; unsigned char *p; CHECK_OBJ_NOTNULL(vd, VSL_MAGIC); if (vd->fi != NULL) return (0); + if (varnish_name == NULL) { + gethostname(hostname, sizeof hostname); + varnish_name = hostname; + } if (vsl_shmem_map(varnish_name)) - return (1); + return (-1); vd->head = vsl_lh; vd->logstart = (unsigned char *)vsl_lh + vsl_lh->start; @@ -477,7 +482,7 @@ VSL_Arg(struct VSL_data *vd, int arg, const char *opt) } struct varnish_stats * -VSL_OpenStats(char *varnish_name) +VSL_OpenStats(const char *varnish_name) { if (vsl_shmem_map(varnish_name)) -- 2.39.5