[master] 555219dd6 Minor refactoring

Poul-Henning Kamp phk at FreeBSD.org
Tue Feb 1 08:46:08 UTC 2022


commit 555219dd66b62963ac1c812d4ffa808eccacf9c7
Author: Poul-Henning Kamp <phk at FreeBSD.org>
Date:   Tue Feb 1 08:21:12 2022 +0000

    Minor refactoring

diff --git a/bin/varnishd/mgt/mgt_main.c b/bin/varnishd/mgt/mgt_main.c
index 1473822ce..08053c5cc 100644
--- a/bin/varnishd/mgt/mgt_main.c
+++ b/bin/varnishd/mgt/mgt_main.c
@@ -460,6 +460,28 @@ mgt_b_conv(const char *b_arg)
 	VTAILQ_INSERT_TAIL(&f_args, fa, list);
 }
 
+static const char *
+create_bogo_n_arg(void)
+{
+	struct vsb *vsb;
+	char *p;
+
+	vsb = VSB_new_auto();
+	AN(vsb);
+	if (getenv("TMPDIR") != NULL)
+		VSB_printf(vsb, "%s", getenv("TMPDIR"));
+	else
+		VSB_cat(vsb, "/tmp");
+	VSB_cat(vsb, "/varnishd_C_XXXXXXX");
+	AZ(VSB_finish(vsb));
+	p = strdup(VSB_data(vsb));
+	AN(p);
+	VSB_destroy(&vsb);
+	AN(mkdtemp(p));
+	AZ(chmod(p, 0750));
+	return (p);
+}
+
 static struct vpf_fh *
 create_pid_file(pid_t *ppid, const char *fmt, ...)
 {
@@ -515,7 +537,6 @@ main(int argc, char * const *argv)
 	struct sigaction sac;
 	struct vev *e;
 	struct f_arg *fa;
-	struct vsb *vsb;
 	pid_t pid;
 
 	if (argc == 2 && !strcmp(argv[1], "--optstring")) {
@@ -761,24 +782,8 @@ main(int argc, char * const *argv)
 
 	assert(d_flag == 0 || F_flag == 0);
 
-	if (C_flag) {
-		if (n_arg == NULL) {
-			vsb = VSB_new_auto();
-			AN(vsb);
-			if (getenv("TMPDIR") != NULL)
-				VSB_printf(vsb, "%s", getenv("TMPDIR"));
-			else
-				VSB_cat(vsb, "/tmp");
-			VSB_cat(vsb, "/varnishd_C_XXXXXXX");
-			AZ(VSB_finish(vsb));
-			p = strdup(VSB_data(vsb));
-			AN(p);
-			VSB_destroy(&vsb);
-			AN(mkdtemp(p));
-			AZ(chmod(p, 0750));
-			n_arg = p;
-		}
-	}
+	if (C_flag && n_arg == NULL)
+		n_arg = create_bogo_n_arg();
 
 	if (S_arg != NULL && !strcmp(S_arg, "none")) {
 		fprintf(stderr,


More information about the varnish-commit mailing list