Commit 4e0c8ae1 authored by Dridi Boukelmoune's avatar Dridi Boukelmoune

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.
parent f9039e84
...@@ -57,8 +57,6 @@ ...@@ -57,8 +57,6 @@
#define HIST_N 2000 /* how far back we remember */ #define HIST_N 2000 /* how far back we remember */
#define HIST_RES 100 /* bucket resolution */ #define HIST_RES 100 /* bucket resolution */
static const char progname[] = "varnishhist";
static int hist_low; static int hist_low;
static int hist_high; static int hist_high;
static int hist_range; static int hist_range;
...@@ -471,7 +469,7 @@ usage(int status) ...@@ -471,7 +469,7 @@ usage(int status)
{ {
const char **opt; const char **opt;
fprintf(stderr, "Usage: %s <options>\n\n", progname); fprintf(stderr, "Usage: %s <options>\n\n", VUT.progname);
fprintf(stderr, "Options:\n"); fprintf(stderr, "Options:\n");
for (opt = vopt_spec.vopt_usage; *opt != NULL; opt += 2) for (opt = vopt_spec.vopt_usage; *opt != NULL; opt += 2)
fprintf(stderr, " %-25s %s\n", *opt, *(opt + 1)); fprintf(stderr, " %-25s %s\n", *opt, *(opt + 1));
...@@ -497,7 +495,7 @@ main(int argc, char **argv) ...@@ -497,7 +495,7 @@ main(int argc, char **argv)
struct profile cli_p = {0}; struct profile cli_p = {0};
cli_p.name = 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)); AZ(pthread_cond_init(&timebend_cv, NULL));
while ((i = getopt(argc, argv, vopt_spec.vopt_optstring)) != -1) { while ((i = getopt(argc, argv, vopt_spec.vopt_optstring)) != -1) {
......
...@@ -50,8 +50,6 @@ ...@@ -50,8 +50,6 @@
#include "vut.h" #include "vut.h"
#include "miniobj.h" #include "miniobj.h"
static const char progname[] = "varnishlog";
static struct log { static struct log {
/* Options */ /* Options */
int a_opt; int a_opt;
...@@ -66,7 +64,7 @@ static void __attribute__((__noreturn__)) ...@@ -66,7 +64,7 @@ static void __attribute__((__noreturn__))
usage(int status) usage(int status)
{ {
const char **opt; const char **opt;
fprintf(stderr, "Usage: %s <options>\n\n", progname); fprintf(stderr, "Usage: %s <options>\n\n", VUT.progname);
fprintf(stderr, "Options:\n"); fprintf(stderr, "Options:\n");
for (opt = vopt_spec.vopt_usage; *opt != NULL; opt += 2) for (opt = vopt_spec.vopt_usage; *opt != NULL; opt += 2)
fprintf(stderr, " %-25s %s\n", *opt, *(opt + 1)); fprintf(stderr, " %-25s %s\n", *opt, *(opt + 1));
...@@ -121,7 +119,7 @@ main(int argc, char * const *argv) ...@@ -121,7 +119,7 @@ main(int argc, char * const *argv)
{ {
int opt; int opt;
VUT_Init(progname, argc, argv, &vopt_spec); VUT_InitProg(argc, argv, &vopt_spec);
memset(&LOG, 0, sizeof LOG); memset(&LOG, 0, sizeof LOG);
while ((opt = getopt(argc, argv, vopt_spec.vopt_optstring)) != -1) { while ((opt = getopt(argc, argv, vopt_spec.vopt_optstring)) != -1) {
......
...@@ -69,8 +69,6 @@ ...@@ -69,8 +69,6 @@
#define TIME_FMT "[%d/%b/%Y:%T %z]" #define TIME_FMT "[%d/%b/%Y:%T %z]"
#define FORMAT "%h %l %u %t \"%r\" %s %b \"%{Referer}i\" \"%{User-agent}i\"" #define FORMAT "%h %l %u %t \"%r\" %s %b \"%{Referer}i\" \"%{User-agent}i\""
static const char progname[] = "varnishncsa";
struct format; struct format;
enum e_frag { enum e_frag {
...@@ -165,7 +163,7 @@ usage(int status) ...@@ -165,7 +163,7 @@ usage(int status)
{ {
const char **opt; const char **opt;
fprintf(stderr, "Usage: %s <options>\n\n", progname); fprintf(stderr, "Usage: %s <options>\n\n", VUT.progname);
fprintf(stderr, "Options:\n"); fprintf(stderr, "Options:\n");
for (opt = vopt_spec.vopt_usage; *opt != NULL; opt += 2) for (opt = vopt_spec.vopt_usage; *opt != NULL; opt += 2)
fprintf(stderr, " %-25s %s\n", *opt, *(opt + 1)); fprintf(stderr, " %-25s %s\n", *opt, *(opt + 1));
...@@ -1144,7 +1142,7 @@ main(int argc, char * const *argv) ...@@ -1144,7 +1142,7 @@ main(int argc, char * const *argv)
signed char opt; signed char opt;
char *format = NULL; char *format = NULL;
VUT_Init(progname, argc, argv, &vopt_spec); VUT_InitProg(argc, argv, &vopt_spec);
memset(&CTX, 0, sizeof CTX); memset(&CTX, 0, sizeof CTX);
VTAILQ_INIT(&CTX.format); VTAILQ_INIT(&CTX.format);
VTAILQ_INIT(&CTX.watch_vcl_log); VTAILQ_INIT(&CTX.watch_vcl_log);
......
...@@ -49,8 +49,6 @@ ...@@ -49,8 +49,6 @@
#include "varnishstat.h" #include "varnishstat.h"
static const char progname[] = "varnishstat";
/*--------------------------------------------------------------------*/ /*--------------------------------------------------------------------*/
static int __match_proto__(VSC_iter_f) static int __match_proto__(VSC_iter_f)
...@@ -243,7 +241,7 @@ usage(int status) ...@@ -243,7 +241,7 @@ usage(int status)
{ {
const char **opt; const char **opt;
fprintf(stderr, "Usage: %s <options>\n\n", progname); fprintf(stderr, "Usage: %s <options>\n\n", VUT.progname);
fprintf(stderr, "Options:\n"); fprintf(stderr, "Options:\n");
for (opt = vopt_spec.vopt_usage; *opt != NULL; opt +=2) for (opt = vopt_spec.vopt_usage; *opt != NULL; opt +=2)
fprintf(stderr, " %-25s %s\n", *opt, *(opt + 1)); fprintf(stderr, " %-25s %s\n", *opt, *(opt + 1));
...@@ -259,7 +257,7 @@ main(int argc, char * const *argv) ...@@ -259,7 +257,7 @@ main(int argc, char * const *argv)
int i; int i;
struct vsc *vsc; struct vsc *vsc;
VUT_Init(progname, argc, argv, &vopt_spec); VUT_InitProg(argc, argv, &vopt_spec);
vd = VSM_New(); vd = VSM_New();
AN(vd); AN(vd);
vsc = VSC_New(); vsc = VSC_New();
......
...@@ -61,7 +61,7 @@ shell -match {^\d+.\d+.\d+.\d+ - user \[../.../20[1-9][0-9]:..:..:.. (?# ...@@ -61,7 +61,7 @@ shell -match {^\d+.\d+.\d+.\d+ - user \[../.../20[1-9][0-9]:..:..:.. (?#
shell "grep -q /2 ${tmpdir}/ncsa.log" shell "grep -q /2 ${tmpdir}/ncsa.log"
# command line # command line
shell -expect "Usage: varnishncsa <options>" \ shell -match "Usage: .*varnishncsa <options>" \
"varnishncsa -h" "varnishncsa -h"
shell -expect "Copyright (c) 2006 Verdens Gang AS" \ shell -expect "Copyright (c) 2006 Verdens Gang AS" \
"varnishncsa -V" "varnishncsa -V"
...@@ -107,7 +107,7 @@ shell -err -expect "Invalid grouping mode: session" \ ...@@ -107,7 +107,7 @@ shell -err -expect "Invalid grouping mode: session" \
{varnishncsa -g session} {varnishncsa -g session}
shell -err -expect "Can't open output file (No such file or directory)" \ shell -err -expect "Can't open output file (No such file or directory)" \
{varnishncsa -w /nonexistent/file} {varnishncsa -w /nonexistent/file}
shell -err -expect "Usage: varnishncsa <options>" \ shell -err -match "Usage: .*varnishncsa <options>" \
{varnishncsa extra} {varnishncsa extra}
# -b # -b
......
...@@ -14,9 +14,9 @@ client c1 { ...@@ -14,9 +14,9 @@ client c1 {
shell -expect "fetch" "varnishtop -n ${v1_name} -1 -d" shell -expect "fetch" "varnishtop -n ${v1_name} -1 -d"
shell -expect "Usage: varnishtop <options>" \ shell -match "Usage: .*varnishtop <options>" \
"varnishtop -h" "varnishtop -h"
shell -expect "Copyright (c) 2006 Verdens Gang AS" \ shell -expect "Copyright (c) 2006 Verdens Gang AS" \
"varnishtop -V" "varnishtop -V"
shell -err -expect "Usage: varnishtop <options>" \ shell -err -match "Usage: .*varnishtop <options>" \
"varnishtop extra" "varnishtop extra"
...@@ -29,13 +29,13 @@ shell -expect "MGT.uptime" \ ...@@ -29,13 +29,13 @@ shell -expect "MGT.uptime" \
shell -match "^MGT" \ shell -match "^MGT" \
"varnishstat -1 -n ${v1_name} -f ^foo" "varnishstat -1 -n ${v1_name} -f ^foo"
shell -expect "Usage: varnishstat <options>" \ shell -match "Usage: .*varnishstat <options>" \
"varnishstat -h" "varnishstat -h"
shell -expect "Varnishstat -f option fields:" \ shell -expect "Varnishstat -f option fields:" \
"varnishstat -n ${v1_name} -l" "varnishstat -n ${v1_name} -l"
shell -expect "Copyright (c) 2006 Verdens Gang AS" \ shell -expect "Copyright (c) 2006 Verdens Gang AS" \
"varnishstat -V" "varnishstat -V"
shell -err -expect "Usage: varnishstat <options>" \ shell -err -match "Usage: .*varnishstat <options>" \
"varnishstat extra" "varnishstat extra"
shell -err -expect "-t: Invalid argument: -1" \ shell -err -expect "-t: Invalid argument: -1" \
"varnishstat -t -1" "varnishstat -t -1"
......
...@@ -15,11 +15,11 @@ shell { ...@@ -15,11 +15,11 @@ shell {
-w ${tmpdir}/vlog.bin -w ${tmpdir}/vlog.bin
} }
shell -expect "Usage: varnishlog <options>" \ shell -match "Usage: .*varnishlog <options>" \
"varnishlog -h" "varnishlog -h"
shell -expect "Copyright (c) 2006 Verdens Gang AS" \ shell -expect "Copyright (c) 2006 Verdens Gang AS" \
"varnishlog -V" "varnishlog -V"
shell -err -expect "Usage: varnishlog <options>" \ shell -err -match "Usage: .*varnishlog <options>" \
"varnishlog extra" "varnishlog extra"
shell -err -expect "Missing -w option" \ shell -err -expect "Missing -w option" \
"varnishlog -D" "varnishlog -D"
......
...@@ -7,11 +7,11 @@ server s1 { ...@@ -7,11 +7,11 @@ server s1 {
varnish v1 -vcl+backend {} -start varnish v1 -vcl+backend {} -start
shell -expect "Usage: varnishhist <options>" \ shell -match "Usage: .*varnishhist <options>" \
"varnishhist -h" "varnishhist -h"
shell -expect "Copyright (c) 2006 Verdens Gang AS" \ shell -expect "Copyright (c) 2006 Verdens Gang AS" \
"varnishhist -V" "varnishhist -V"
shell -err -expect "Usage: varnishhist <options>" \ shell -err -match "Usage: .*varnishhist <options>" \
"varnishhist extra" "varnishhist extra"
shell -err -expect "-p: invalid '0'" \ shell -err -expect "-p: invalid '0'" \
"varnishhist -p 0" "varnishhist -p 0"
......
...@@ -71,7 +71,6 @@ struct top { ...@@ -71,7 +71,6 @@ struct top {
double count; double count;
}; };
static const char progname[] = "varnishtop";
static float period = 60; /* seconds */ static float period = 60; /* seconds */
static int end_of_file = 0; static int end_of_file = 0;
static unsigned ntop; static unsigned ntop;
...@@ -318,7 +317,7 @@ usage(int status) ...@@ -318,7 +317,7 @@ usage(int status)
{ {
const char **opt; const char **opt;
fprintf(stderr, "Usage: %s <options>\n\n", progname); fprintf(stderr, "Usage: %s <options>\n\n", VUT.progname);
fprintf(stderr, "Options:\n"); fprintf(stderr, "Options:\n");
for (opt = vopt_spec.vopt_usage; *opt != NULL; opt +=2) for (opt = vopt_spec.vopt_usage; *opt != NULL; opt +=2)
fprintf(stderr, " %-25s %s\n", *opt, *(opt + 1)); fprintf(stderr, " %-25s %s\n", *opt, *(opt + 1));
...@@ -331,7 +330,7 @@ main(int argc, char **argv) ...@@ -331,7 +330,7 @@ main(int argc, char **argv)
int o, once = 0; int o, once = 0;
pthread_t thr; 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) { while ((o = getopt(argc, argv, vopt_spec.vopt_optstring)) != -1) {
switch (o) { switch (o) {
......
...@@ -71,6 +71,8 @@ void VUT_Error(int status, const char *fmt, ...) ...@@ -71,6 +71,8 @@ void VUT_Error(int status, const char *fmt, ...)
int VUT_Arg(int opt, const char *arg); 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, void VUT_Init(const char *progname, int argc, char * const *argv,
const struct vopt_spec *); const struct vopt_spec *);
......
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