[master] 4e0c8ae Use argv[0] as the VUT.progname
Dridi Boukelmoune
dridi.boukelmoune at gmail.com
Wed Sep 13 22:21:04 UTC 2017
commit 4e0c8ae1cab06189c8540e877b81950c325f8648
Author: Dridi Boukelmoune <dridi.boukelmoune at gmail.com>
Date: Tue Apr 18 09:24:52 2017 +0200
Use argv[0] as the VUT.progname
This gives users a consistent usage/help message depending on whether
they run VUTs from the PATH or from a specific location. In order to
kill some of the redundancy, a VUT_InitProg macro does the $0 magic.
diff --git a/bin/varnishhist/varnishhist.c b/bin/varnishhist/varnishhist.c
index 417c97e..fbf1f39 100644
--- a/bin/varnishhist/varnishhist.c
+++ b/bin/varnishhist/varnishhist.c
@@ -57,8 +57,6 @@
#define HIST_N 2000 /* how far back we remember */
#define HIST_RES 100 /* bucket resolution */
-static const char progname[] = "varnishhist";
-
static int hist_low;
static int hist_high;
static int hist_range;
@@ -471,7 +469,7 @@ usage(int status)
{
const char **opt;
- fprintf(stderr, "Usage: %s <options>\n\n", progname);
+ fprintf(stderr, "Usage: %s <options>\n\n", VUT.progname);
fprintf(stderr, "Options:\n");
for (opt = vopt_spec.vopt_usage; *opt != NULL; opt += 2)
fprintf(stderr, " %-25s %s\n", *opt, *(opt + 1));
@@ -497,7 +495,7 @@ main(int argc, char **argv)
struct profile cli_p = {0};
cli_p.name = 0;
- VUT_Init(progname, argc, argv, &vopt_spec);
+ VUT_InitProg(argc, argv, &vopt_spec);
AZ(pthread_cond_init(&timebend_cv, NULL));
while ((i = getopt(argc, argv, vopt_spec.vopt_optstring)) != -1) {
diff --git a/bin/varnishlog/varnishlog.c b/bin/varnishlog/varnishlog.c
index 8018f7b..3050a6e 100644
--- a/bin/varnishlog/varnishlog.c
+++ b/bin/varnishlog/varnishlog.c
@@ -50,8 +50,6 @@
#include "vut.h"
#include "miniobj.h"
-static const char progname[] = "varnishlog";
-
static struct log {
/* Options */
int a_opt;
@@ -66,7 +64,7 @@ static void __attribute__((__noreturn__))
usage(int status)
{
const char **opt;
- fprintf(stderr, "Usage: %s <options>\n\n", progname);
+ fprintf(stderr, "Usage: %s <options>\n\n", VUT.progname);
fprintf(stderr, "Options:\n");
for (opt = vopt_spec.vopt_usage; *opt != NULL; opt += 2)
fprintf(stderr, " %-25s %s\n", *opt, *(opt + 1));
@@ -121,7 +119,7 @@ main(int argc, char * const *argv)
{
int opt;
- VUT_Init(progname, argc, argv, &vopt_spec);
+ VUT_InitProg(argc, argv, &vopt_spec);
memset(&LOG, 0, sizeof LOG);
while ((opt = getopt(argc, argv, vopt_spec.vopt_optstring)) != -1) {
diff --git a/bin/varnishncsa/varnishncsa.c b/bin/varnishncsa/varnishncsa.c
index 0fa722f..58f5234 100644
--- a/bin/varnishncsa/varnishncsa.c
+++ b/bin/varnishncsa/varnishncsa.c
@@ -69,8 +69,6 @@
#define TIME_FMT "[%d/%b/%Y:%T %z]"
#define FORMAT "%h %l %u %t \"%r\" %s %b \"%{Referer}i\" \"%{User-agent}i\""
-static const char progname[] = "varnishncsa";
-
struct format;
enum e_frag {
@@ -165,7 +163,7 @@ usage(int status)
{
const char **opt;
- fprintf(stderr, "Usage: %s <options>\n\n", progname);
+ fprintf(stderr, "Usage: %s <options>\n\n", VUT.progname);
fprintf(stderr, "Options:\n");
for (opt = vopt_spec.vopt_usage; *opt != NULL; opt += 2)
fprintf(stderr, " %-25s %s\n", *opt, *(opt + 1));
@@ -1144,7 +1142,7 @@ main(int argc, char * const *argv)
signed char opt;
char *format = NULL;
- VUT_Init(progname, argc, argv, &vopt_spec);
+ VUT_InitProg(argc, argv, &vopt_spec);
memset(&CTX, 0, sizeof CTX);
VTAILQ_INIT(&CTX.format);
VTAILQ_INIT(&CTX.watch_vcl_log);
diff --git a/bin/varnishstat/varnishstat.c b/bin/varnishstat/varnishstat.c
index aa268c9..af20e65 100644
--- a/bin/varnishstat/varnishstat.c
+++ b/bin/varnishstat/varnishstat.c
@@ -49,8 +49,6 @@
#include "varnishstat.h"
-static const char progname[] = "varnishstat";
-
/*--------------------------------------------------------------------*/
static int __match_proto__(VSC_iter_f)
@@ -243,7 +241,7 @@ usage(int status)
{
const char **opt;
- fprintf(stderr, "Usage: %s <options>\n\n", progname);
+ fprintf(stderr, "Usage: %s <options>\n\n", VUT.progname);
fprintf(stderr, "Options:\n");
for (opt = vopt_spec.vopt_usage; *opt != NULL; opt +=2)
fprintf(stderr, " %-25s %s\n", *opt, *(opt + 1));
@@ -259,7 +257,7 @@ main(int argc, char * const *argv)
int i;
struct vsc *vsc;
- VUT_Init(progname, argc, argv, &vopt_spec);
+ VUT_InitProg(argc, argv, &vopt_spec);
vd = VSM_New();
AN(vd);
vsc = VSC_New();
diff --git a/bin/varnishtest/tests/u00003.vtc b/bin/varnishtest/tests/u00003.vtc
index e824961..f73530d 100644
--- a/bin/varnishtest/tests/u00003.vtc
+++ b/bin/varnishtest/tests/u00003.vtc
@@ -61,7 +61,7 @@ shell -match {^\d+.\d+.\d+.\d+ - user \[../.../20[1-9][0-9]:..:..:.. (?#
shell "grep -q /2 ${tmpdir}/ncsa.log"
# command line
-shell -expect "Usage: varnishncsa <options>" \
+shell -match "Usage: .*varnishncsa <options>" \
"varnishncsa -h"
shell -expect "Copyright (c) 2006 Verdens Gang AS" \
"varnishncsa -V"
@@ -107,7 +107,7 @@ shell -err -expect "Invalid grouping mode: session" \
{varnishncsa -g session}
shell -err -expect "Can't open output file (No such file or directory)" \
{varnishncsa -w /nonexistent/file}
-shell -err -expect "Usage: varnishncsa <options>" \
+shell -err -match "Usage: .*varnishncsa <options>" \
{varnishncsa extra}
# -b
diff --git a/bin/varnishtest/tests/u00004.vtc b/bin/varnishtest/tests/u00004.vtc
index 811b370..4bdc41f 100644
--- a/bin/varnishtest/tests/u00004.vtc
+++ b/bin/varnishtest/tests/u00004.vtc
@@ -14,9 +14,9 @@ client c1 {
shell -expect "fetch" "varnishtop -n ${v1_name} -1 -d"
-shell -expect "Usage: varnishtop <options>" \
+shell -match "Usage: .*varnishtop <options>" \
"varnishtop -h"
shell -expect "Copyright (c) 2006 Verdens Gang AS" \
"varnishtop -V"
-shell -err -expect "Usage: varnishtop <options>" \
+shell -err -match "Usage: .*varnishtop <options>" \
"varnishtop extra"
diff --git a/bin/varnishtest/tests/u00005.vtc b/bin/varnishtest/tests/u00005.vtc
index 52242be..415307c 100644
--- a/bin/varnishtest/tests/u00005.vtc
+++ b/bin/varnishtest/tests/u00005.vtc
@@ -29,13 +29,13 @@ shell -expect "MGT.uptime" \
shell -match "^MGT" \
"varnishstat -1 -n ${v1_name} -f ^foo"
-shell -expect "Usage: varnishstat <options>" \
+shell -match "Usage: .*varnishstat <options>" \
"varnishstat -h"
shell -expect "Varnishstat -f option fields:" \
"varnishstat -n ${v1_name} -l"
shell -expect "Copyright (c) 2006 Verdens Gang AS" \
"varnishstat -V"
-shell -err -expect "Usage: varnishstat <options>" \
+shell -err -match "Usage: .*varnishstat <options>" \
"varnishstat extra"
shell -err -expect "-t: Invalid argument: -1" \
"varnishstat -t -1"
diff --git a/bin/varnishtest/tests/u00006.vtc b/bin/varnishtest/tests/u00006.vtc
index e87e4da..2d16bca 100644
--- a/bin/varnishtest/tests/u00006.vtc
+++ b/bin/varnishtest/tests/u00006.vtc
@@ -15,11 +15,11 @@ shell {
-w ${tmpdir}/vlog.bin
}
-shell -expect "Usage: varnishlog <options>" \
+shell -match "Usage: .*varnishlog <options>" \
"varnishlog -h"
shell -expect "Copyright (c) 2006 Verdens Gang AS" \
"varnishlog -V"
-shell -err -expect "Usage: varnishlog <options>" \
+shell -err -match "Usage: .*varnishlog <options>" \
"varnishlog extra"
shell -err -expect "Missing -w option" \
"varnishlog -D"
diff --git a/bin/varnishtest/tests/u00007.vtc b/bin/varnishtest/tests/u00007.vtc
index 80d956c..8a095d5 100644
--- a/bin/varnishtest/tests/u00007.vtc
+++ b/bin/varnishtest/tests/u00007.vtc
@@ -7,11 +7,11 @@ server s1 {
varnish v1 -vcl+backend {} -start
-shell -expect "Usage: varnishhist <options>" \
+shell -match "Usage: .*varnishhist <options>" \
"varnishhist -h"
shell -expect "Copyright (c) 2006 Verdens Gang AS" \
"varnishhist -V"
-shell -err -expect "Usage: varnishhist <options>" \
+shell -err -match "Usage: .*varnishhist <options>" \
"varnishhist extra"
shell -err -expect "-p: invalid '0'" \
"varnishhist -p 0"
diff --git a/bin/varnishtop/varnishtop.c b/bin/varnishtop/varnishtop.c
index 39600ce..5639b22 100644
--- a/bin/varnishtop/varnishtop.c
+++ b/bin/varnishtop/varnishtop.c
@@ -71,7 +71,6 @@ struct top {
double count;
};
-static const char progname[] = "varnishtop";
static float period = 60; /* seconds */
static int end_of_file = 0;
static unsigned ntop;
@@ -318,7 +317,7 @@ usage(int status)
{
const char **opt;
- fprintf(stderr, "Usage: %s <options>\n\n", progname);
+ fprintf(stderr, "Usage: %s <options>\n\n", VUT.progname);
fprintf(stderr, "Options:\n");
for (opt = vopt_spec.vopt_usage; *opt != NULL; opt +=2)
fprintf(stderr, " %-25s %s\n", *opt, *(opt + 1));
@@ -331,7 +330,7 @@ main(int argc, char **argv)
int o, once = 0;
pthread_t thr;
- VUT_Init(progname, argc, argv, &vopt_spec);
+ VUT_InitProg(argc, argv, &vopt_spec);
while ((o = getopt(argc, argv, vopt_spec.vopt_optstring)) != -1) {
switch (o) {
diff --git a/include/vut.h b/include/vut.h
index aab3608..703faa4 100644
--- a/include/vut.h
+++ b/include/vut.h
@@ -71,6 +71,8 @@ void VUT_Error(int status, const char *fmt, ...)
int VUT_Arg(int opt, const char *arg);
+#define VUT_InitProg(argc, argv, spec) VUT_Init(argv[0], argc, argv, spec)
+
void VUT_Init(const char *progname, int argc, char * const *argv,
const struct vopt_spec *);
More information about the varnish-commit
mailing list