[5.2] f155b00 Name VUT global options accordingly
PÃ¥l Hermunn Johansen
hermunn at varnish-software.com
Fri Sep 15 11:17:26 UTC 2017
commit f155b007503161f224cb131556d19059c09910a9
Author: Dridi Boukelmoune <dridi.boukelmoune at gmail.com>
Date: Tue Sep 5 12:31:51 2017 +0200
Name VUT global options accordingly
The API is responsible for checking that global options aren't used more
than once, despite it being handled (soon) in individual VUT setups.
diff --git a/bin/varnishhist/varnishhist_options.h b/bin/varnishhist/varnishhist_options.h
index a4f70cd..7ad374b 100644
--- a/bin/varnishhist/varnishhist_options.h
+++ b/bin/varnishhist/varnishhist_options.h
@@ -93,4 +93,4 @@ VUT_OPT_q
VUT_OPT_r
VUT_OPT_t
VSL_OPT_T
-VUT_OPT_V
+VUT_GLOBAL_OPT_V
diff --git a/bin/varnishlog/varnishlog_options.h b/bin/varnishlog/varnishlog_options.h
index 4847268..417b764 100644
--- a/bin/varnishlog/varnishlog_options.h
+++ b/bin/varnishlog/varnishlog_options.h
@@ -59,7 +59,7 @@ VSL_OPT_b
VSL_OPT_c
VSL_OPT_C
VUT_OPT_d
-VUT_OPT_D
+VUT_GLOBAL_OPT_D
VUT_OPT_g
VUT_OPT_h
VSL_OPT_i
@@ -67,13 +67,13 @@ VSL_OPT_I
VUT_OPT_k
VSL_OPT_L
VUT_OPT_n
-VUT_OPT_P
+VUT_GLOBAL_OPT_P
VUT_OPT_q
VUT_OPT_r
VUT_OPT_t
VSL_OPT_T
VSL_OPT_v
-VUT_OPT_V
+VUT_GLOBAL_OPT_V
LOG_OPT_w
VSL_OPT_x
VSL_OPT_X
diff --git a/bin/varnishncsa/varnishncsa_options.h b/bin/varnishncsa/varnishncsa_options.h
index 6fe13de..16bcdb1 100644
--- a/bin/varnishncsa/varnishncsa_options.h
+++ b/bin/varnishncsa/varnishncsa_options.h
@@ -78,16 +78,16 @@ NCSA_OPT_b
NCSA_OPT_c
VSL_OPT_C
VUT_OPT_d
-VUT_OPT_D
+VUT_GLOBAL_OPT_D
NCSA_OPT_F
NCSA_OPT_f
NCSA_OPT_g
VUT_OPT_h
VSL_OPT_L
VUT_OPT_n
-VUT_OPT_P
+VUT_GLOBAL_OPT_P
VUT_OPT_q
VUT_OPT_r
VUT_OPT_t
-VUT_OPT_V
+VUT_GLOBAL_OPT_V
NCSA_OPT_w
diff --git a/bin/varnishstat/varnishstat.c b/bin/varnishstat/varnishstat.c
index af20e65..a1e70fa 100644
--- a/bin/varnishstat/varnishstat.c
+++ b/bin/varnishstat/varnishstat.c
@@ -274,9 +274,6 @@ main(int argc, char * const *argv)
case 'l':
f_list = 1;
break;
- case 'V':
- VCS_Message("varnishstat");
- exit(0);
case 'x':
xml = 1;
break;
@@ -286,6 +283,9 @@ main(int argc, char * const *argv)
case 'f':
AN(VSC_Arg(vsc, opt, optarg));
break;
+ case 'V':
+ AN(VUT_Arg(opt, optarg));
+ break;
default:
i = VSM_Arg(vd, opt, optarg);
if (i < 0)
diff --git a/bin/varnishstat/varnishstat_options.h b/bin/varnishstat/varnishstat_options.h
index 5307a1d..a1ea33b 100644
--- a/bin/varnishstat/varnishstat_options.h
+++ b/bin/varnishstat/varnishstat_options.h
@@ -65,5 +65,5 @@ STAT_OPT_j
STAT_OPT_l
VUT_OPT_n
VUT_OPT_t
-VUT_OPT_V
+VUT_GLOBAL_OPT_V
STAT_OPT_x
diff --git a/bin/varnishtop/varnishtop_options.h b/bin/varnishtop/varnishtop_options.h
index 1cf0e20..dcad737 100644
--- a/bin/varnishtop/varnishtop_options.h
+++ b/bin/varnishtop/varnishtop_options.h
@@ -72,4 +72,4 @@ VUT_OPT_t
VSL_OPT_T
VSL_OPT_x
VSL_OPT_X
-VUT_OPT_V
+VUT_GLOBAL_OPT_V
diff --git a/include/vut.h b/include/vut.h
index 703faa4..b214cdb 100644
--- a/include/vut.h
+++ b/include/vut.h
@@ -51,7 +51,6 @@ struct VUT {
struct VSL_data *vsl;
struct vsm *vsm;
struct VSLQ *vslq;
- struct vpf_fh *pfh;
int sighup;
int sigint;
int sigusr1;
diff --git a/include/vut_options.h b/include/vut_options.h
index 9f0ad78..d6941e1 100644
--- a/include/vut_options.h
+++ b/include/vut_options.h
@@ -29,16 +29,26 @@
/* VUT options */
+#define VUT_GLOBAL_OPT_D \
+ VOPT("D", "[-D]", "Daemonize", \
+ "Daemonize." \
+ )
+
+#define VUT_GLOBAL_OPT_P \
+ VOPT("P:", "[-P <file>]", "PID file", \
+ "Write the process' PID to the specified file." \
+ )
+
+#define VUT_GLOBAL_OPT_V \
+ VOPT("V", "[-V]", "Version", \
+ "Print version information and exit." \
+ )
+
#define VUT_OPT_d \
VOPT("d", "[-d]", "Process old log entries and exit", \
"Process log records at the head of the log and exit." \
)
-#define VUT_OPT_D \
- VOPT("D", "[-D]", "Daemonize", \
- "Daemonize." \
- )
-
#define VUT_OPT_g \
VOPT("g:", "[-g <session|request|vxid|raw>]", "Grouping mode (default: vxid)", \
"The grouping of the log records. The default is to group" \
@@ -63,11 +73,6 @@
" the host name is used." \
)
-#define VUT_OPT_P \
- VOPT("P:", "[-P <file>]", "PID file", \
- "Write the process' PID to the specified file." \
- )
-
#define VUT_OPT_q \
VOPT("q:", "[-q <query>]", "VSL query", \
"Specifies the VSL query to use." \
@@ -90,8 +95,3 @@
" indefinetely for the Varnish instance to appear. " \
" Defaults to 5 seconds." \
)
-
-#define VUT_OPT_V \
- VOPT("V", "[-V]", "Version", \
- "Print version information and exit." \
- )
diff --git a/lib/libvarnishapi/vut.c b/lib/libvarnishapi/vut.c
index 4057c3f..1797dab 100644
--- a/lib/libvarnishapi/vut.c
+++ b/lib/libvarnishapi/vut.c
@@ -61,12 +61,24 @@ struct VUT VUT;
static int vut_synopsis(const struct vopt_spec *);
static int vut_options(const struct vopt_spec *);
+static struct vpf_fh *pfh;
+static unsigned daemonized;
+
+static int
+vut_daemon(void)
+{
+ if (daemonized)
+ VUT_Error(1, "Already running as a daemon");
+ daemonized = 1;
+ return (varnish_daemon(0, 0));
+}
+
static void
vut_vpf_remove(void)
{
- if (VUT.pfh) {
- AZ(VPF_Remove(VUT.pfh));
- VUT.pfh = NULL;
+ if (pfh != NULL) {
+ AZ(VPF_Remove(pfh));
+ pfh = NULL;
}
}
@@ -250,19 +262,21 @@ VUT_Setup(void)
/* Open PID file */
if (VUT.P_arg) {
- AZ(VUT.pfh);
- VUT.pfh = VPF_Open(VUT.P_arg, 0644, NULL);
- if (VUT.pfh == NULL)
+ if (pfh != NULL)
+ VUT_Error(1, "PID file already created");
+ pfh = VPF_Open(VUT.P_arg, 0644, NULL);
+ if (pfh == NULL)
VUT_Error(1, "%s: %s", VUT.P_arg, strerror(errno));
}
/* Daemon mode */
- if (VUT.D_opt && varnish_daemon(0, 0) == -1)
+ if (VUT.D_opt && vut_daemon() == -1)
VUT_Error(1, "Daemon mode: %s", strerror(errno));
/* Write PID and setup exit handler */
- if (VUT.pfh != NULL) {
- AZ(VPF_Write(VUT.pfh));
+ if (VUT.P_arg) {
+ AN(pfh);
+ AZ(VPF_Write(pfh));
AZ(atexit(vut_vpf_remove));
}
}
@@ -279,7 +293,7 @@ VUT_Fini(void)
free(VUT.t_arg);
vut_vpf_remove();
- AZ(VUT.pfh);
+ AZ(pfh);
if (VUT.vslq)
VSLQ_Delete(&VUT.vslq);
More information about the varnish-commit
mailing list