[master] f584f90 Disallow starting without either -b <backend> or -f <vcl_file> in all other modes than -d.

Poul-Henning Kamp phk at FreeBSD.org
Sat Jan 14 21:27:05 CET 2017


commit f584f901bd2330d36a9c6e22efea8142d85e01a3
Author: Poul-Henning Kamp <phk at FreeBSD.org>
Date:   Sat Jan 14 20:25:32 2017 +0000

    Disallow starting without either -b <backend> or -f <vcl_file> in
    all other modes than -d.
    
    Allow -f '' as an override for people who really want this.

diff --git a/bin/varnishd/mgt/mgt_main.c b/bin/varnishd/mgt/mgt_main.c
index eb5cbb8..e0997ce 100644
--- a/bin/varnishd/mgt/mgt_main.c
+++ b/bin/varnishd/mgt/mgt_main.c
@@ -436,6 +436,7 @@ main(int argc, char * const *argv)
 	int o, eric_fd = -1;
 	unsigned C_flag = 0;
 	unsigned F_flag = 0;
+	unsigned V_flag = 0;
 	const char *b_arg = NULL;
 	const char *f_arg = NULL;
 	const char *i_arg = NULL;
@@ -460,6 +461,9 @@ main(int argc, char * const *argv)
 	struct sigaction sac;
 	struct vev *e;
 
+	setbuf(stdout, NULL);
+	setbuf(stderr, NULL);
+
 	mgt_tests();
 
 	mgt_initialize(cli);
@@ -490,6 +494,9 @@ main(int argc, char * const *argv)
 		case 'j':
 			j_arg = optarg;
 			break;
+		case 'V':
+			V_flag = 1;
+			break;
 		case 'x':
 			x_arg = optarg;
 			break;
@@ -501,6 +508,12 @@ main(int argc, char * const *argv)
 	if (argc != optind)
 		ARGV_ERR("Too many arguments (%s...)\n", argv[optind]);
 
+	if (V_flag) {
+		if (argc != 2)
+			ARGV_ERR("-V is incompatible with everything else\n");
+		VCS_Message("varnishd");
+		exit(0);
+	}
 	if (x_arg != NULL) {
 		if (argc != 3)
 			ARGV_ERR("-x is incompatible with everything else\n");
@@ -514,7 +527,7 @@ main(int argc, char * const *argv)
 	if (d_flag && F_flag)
 		ARGV_ERR("Only one of -d or -F can be specified\n");
 
-	if (C_flag && b_arg == NULL && f_arg == NULL)
+	if (C_flag && b_arg == NULL && (f_arg == NULL || *f_arg == '\0'))
 		ARGV_ERR("-C needs either -b <backend> or -f <vcl_file>\n");
 
 	if (d_flag && C_flag)
@@ -523,6 +536,12 @@ main(int argc, char * const *argv)
 	if (F_flag && C_flag)
 		ARGV_ERR("-F makes no sense with -C\n");
 
+	if (!d_flag && b_arg == NULL && f_arg == NULL)
+		ARGV_ERR("Neither -b nor -f given. (use -f '' to override)\n");
+
+	if (f_arg != NULL && *f_arg == '\0')
+		f_arg = NULL;
+
 	/*
 	 * Start out by closing all unwanted file descriptors we might
 	 * have inherited from sloppy process control daemons.
@@ -530,9 +549,6 @@ main(int argc, char * const *argv)
 	VSUB_closefrom(STDERR_FILENO + 1);
 	MCH_TrackHighFd(STDERR_FILENO);
 
-	setbuf(stdout, NULL);
-	setbuf(stderr, NULL);
-
 	/*
 	 * Have Eric Daemonize us if need be
 	 */
@@ -542,10 +558,6 @@ main(int argc, char * const *argv)
 		mgt_pid = getpid();
 	}
 
-#ifdef HAVE_SETPROCTITLE
-	setproctitle("Varnish-Mgr %s", heritage.name);
-#endif
-
 	/* Set up the mgt counters */
 	memset(&static_VSC_C_mgt, 0, sizeof static_VSC_C_mgt);
 	VSC_C_mgt = &static_VSC_C_mgt;
@@ -576,6 +588,7 @@ main(int argc, char * const *argv)
 		case 'f':
 		case 'F':
 		case 'j':
+		case 'V':
 		case 'x':
 			/* Handled in first pass */
 			break;
@@ -642,10 +655,6 @@ main(int argc, char * const *argv)
 		case 't':
 			MCF_ParamSet(cli, "default_ttl", optarg);
 			break;
-		case 'V':
-			/* XXX: we should print the ident here */
-			VCS_Message("varnishd");
-			exit(0);
 		case 'W':
 			W_arg = optarg;
 			break;
@@ -695,6 +704,10 @@ main(int argc, char * const *argv)
 	if (VIN_N_Arg(n_arg, &heritage.name, &dirname, NULL) != 0)
 		ARGV_ERR("Invalid instance (-n) name: %s\n", strerror(errno));
 
+#ifdef HAVE_SETPROCTITLE
+	setproctitle("Varnish-Mgr %s", heritage.name);
+#endif
+
 	identify(i_arg);
 
 	if (VJ_make_workdir(dirname))
@@ -735,16 +748,6 @@ main(int argc, char * const *argv)
 
 	assert(! VTAILQ_EMPTY(&heritage.socks));
 
-	if (!d_flag) {
-		if (b_arg == NULL && f_arg == NULL) {
-			fprintf(stderr,
-			    "Warning: Neither -b nor -f given,"
-			    " won't start a worker child.\n"
-			    "         Master process started,"
-			    " use varnishadm to control it.\n");
-		}
-	}
-
 	HSH_config(h_arg);
 
 	Wait_config(W_arg);
diff --git a/bin/varnishtest/tests/a00009.vtc b/bin/varnishtest/tests/a00009.vtc
index 27db34b..023f4ea 100644
--- a/bin/varnishtest/tests/a00009.vtc
+++ b/bin/varnishtest/tests/a00009.vtc
@@ -12,8 +12,8 @@ err_shell {VCL version declaration missing} {
 	echo 'bad vcl' > ${tmpdir}/t.vcl
 	varnishd -C -f ${tmpdir}/t.vcl -n ${tmpdir} 2>&1
 }
-err_shell {-spersistent has been deprecated} "varnishd -spersistent 2>&1"
-err_shell {Unknown jail method "xyz"} "varnishd -jxyz 2>&1"
+err_shell {-spersistent has been deprecated} "varnishd -spersistent -f '' 2>&1"
+err_shell {Unknown jail method "xyz"} "varnishd -jxyz -f '' 2>&1"
 err_shell {-x is incompatible with everything else} "varnishd -d -x foo 2>&1"
 err_shell {Invalid -x argument} "varnishd -x foo 2>&1"
 err_shell {Too many arguments} "varnishd foo 2>&1"
@@ -24,10 +24,10 @@ err_shell {-C needs either -b <backend> or -f <vcl_file>} \
 err_shell {-d makes no sense with -C} "varnishd -C -b 127.0.0.1:80 -d 2>&1"
 err_shell {-F makes no sense with -C} "varnishd -C -b 127.0.0.1:80 -F 2>&1"
 err_shell {usage: varnishd [options]} "varnishd -? 2>&1"
-err_shell {Invalid backslash sequence} {varnishd -l 'xyz\kk,xyz\foo' 2>&1}
-err_shell {Invalid backslash sequence} {varnishd -l 'ab\8cd' 2>&1}
-err_shell {Copyright (c) 2006} "varnishd -V 2>&1"
+err_shell {Invalid backslash sequence} {varnishd -l 'xyz\kk,xyz\foo' -f '' 2>&1}
+err_shell {Invalid backslash sequence} {varnishd -l 'ab\8cd' -f '' 2>&1}
+err_shell {Copyright (c) 2006} "varnishd -V 2>&1 ; exit 1"
 err_shell {usage: varnishd [options]} "varnishd -A 2>&1"
 err_shell {Cannot open -S file} {
-	varnishd -S ${tmpdir}/nonexistent -n ${tmpdir}/v0 2>&1
+	varnishd -S ${tmpdir}/nonexistent -n ${tmpdir}/v0 -f '' 2>&1
 }



More information about the varnish-commit mailing list