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 @@
#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) {
......
......@@ -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) {
......
......@@ -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);
......
......@@ -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();
......
......@@ -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
......
......@@ -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"
......@@ -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"
......
......@@ -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"
......
......@@ -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"
......
......@@ -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) {
......
......@@ -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 *);
......
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