[master] 67f28d0e7 Use VUT_Usage() and (void) return of VUT_Main()

Poul-Henning Kamp phk at FreeBSD.org
Mon Oct 22 07:50:19 UTC 2018


commit 67f28d0e74f4d172be5cfa33ca70f26010623446
Author: Poul-Henning Kamp <phk at FreeBSD.org>
Date:   Mon Oct 22 07:11:52 2018 +0000

    Use VUT_Usage() and (void) return of VUT_Main()

diff --git a/bin/varnishhist/flint.lnt b/bin/varnishhist/flint.lnt
index 1342b8e4e..6399b0249 100644
--- a/bin/varnishhist/flint.lnt
+++ b/bin/varnishhist/flint.lnt
@@ -1,4 +1,3 @@
 -efile(451, "varnishhist_profiles.h")
 -efile(451, "varnishhist_options.h")
--sem(usage, r_no)
 -sem(profile_error, r_no)
diff --git a/bin/varnishhist/varnishhist.c b/bin/varnishhist/varnishhist.c
index c4f99a04a..21ca64666 100644
--- a/bin/varnishhist/varnishhist.c
+++ b/bin/varnishhist/varnishhist.c
@@ -473,18 +473,6 @@ do_curses(void *arg)
 
 /*--------------------------------------------------------------------*/
 
-static void v_noreturn_
-usage(int status)
-{
-	const char **opt;
-
-	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));
-	exit(status);
-}
-
 static void v_noreturn_
 profile_error(const char *s)
 {
@@ -519,7 +507,7 @@ main(int argc, char **argv)
 		switch (i) {
 		case 'h':
 			/* Usage help */
-			usage(0);
+			VUT_Usage(vut, &vopt_spec, 0);
 		case 'p':
 			ms_delay = lround(1e3 * strtod(optarg, NULL));
 			if (ms_delay <= 0)
@@ -602,12 +590,12 @@ main(int argc, char **argv)
 			break;
 		default:
 			if (!VUT_Arg(vut, i, optarg))
-				usage(1);
+				VUT_Usage(vut, &vopt_spec, 1);
 		}
 	}
 
 	if (optind != argc)
-		usage(1);
+		VUT_Usage(vut, &vopt_spec, 1);
 
 	/* Check for valid grouping mode */
 	assert(vut->g_arg < VSL_g__MAX);
@@ -661,7 +649,7 @@ main(int argc, char **argv)
 	vut->dispatch_f = accumulate;
 	vut->dispatch_priv = NULL;
 	vut->sighup_f = sighup;
-	VUT_Main(vut);
+	(void)VUT_Main(vut);
 	end_of_file = 1;
 	AZ(pthread_join(thr, NULL));
 	VUT_Fini(&vut);
diff --git a/bin/varnishlog/flint.lnt b/bin/varnishlog/flint.lnt
index 204e85028..509f2fe55 100644
--- a/bin/varnishlog/flint.lnt
+++ b/bin/varnishlog/flint.lnt
@@ -10,4 +10,3 @@
 
 -e788	// enum constant '___' not used within defaulted switch
 -e641	// Converting enum '___' to '___'
--sem(usage,r_no)
diff --git a/bin/varnishlog/varnishlog.c b/bin/varnishlog/varnishlog.c
index d80986b78..e3e2e4576 100644
--- a/bin/varnishlog/varnishlog.c
+++ b/bin/varnishlog/varnishlog.c
@@ -64,17 +64,6 @@ static struct log {
 	FILE		*fo;
 } LOG;
 
-static void v_noreturn_
-usage(int status)
-{
-	const char **opt;
-	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));
-	exit(status);
-}
-
 static void
 openout(int append)
 {
@@ -97,7 +86,7 @@ rotateout(struct VUT *v)
 	assert(v == vut);
 	AN(LOG.w_arg);
 	AN(LOG.fo);
-	fclose(LOG.fo);
+	(void)fclose(LOG.fo);
 	openout(1);
 	AN(LOG.fo);
 	return (0);
@@ -150,19 +139,19 @@ main(int argc, char * const *argv)
 			break;
 		case 'h':
 			/* Usage help */
-			usage(0);
+			VUT_Usage(vut, &vopt_spec, 0);
 		case 'w':
 			/* Write to file */
 			REPLACE(LOG.w_arg, optarg);
 			break;
 		default:
 			if (!VUT_Arg(vut, opt, optarg))
-				usage(1);
+				VUT_Usage(vut, &vopt_spec, 1);
 		}
 	}
 
 	if (optind != argc)
-		usage(1);
+		VUT_Usage(vut, &vopt_spec, 1);
 
 	if (vut->D_opt && !LOG.w_arg)
 		VUT_Error(vut, 1, "Missing -w option");
@@ -184,7 +173,7 @@ main(int argc, char * const *argv)
 
 	VUT_Signal(vut_sighandler);
 	VUT_Setup(vut);
-	VUT_Main(vut);
+	(void)VUT_Main(vut);
 	VUT_Fini(&vut);
 
 	(void)flushout(NULL);
diff --git a/bin/varnishstat/flint.lnt b/bin/varnishstat/flint.lnt
index 0dbb9d82c..b3160aab6 100644
--- a/bin/varnishstat/flint.lnt
+++ b/bin/varnishstat/flint.lnt
@@ -2,5 +2,3 @@
 +libh mgt_event.h
 
 -efile(451, varnishstat_options.h)
-
--sem(usage, r_no)
diff --git a/bin/varnishtop/varnishtop.c b/bin/varnishtop/varnishtop.c
index a4a77e7c9..afe0dad92 100644
--- a/bin/varnishtop/varnishtop.c
+++ b/bin/varnishtop/varnishtop.c
@@ -324,19 +324,6 @@ dump(void)
 	}
 }
 
-//lint -sem(usage, r_no)
-static void v_noreturn_
-usage(int status)
-{
-	const char **opt;
-
-	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));
-	exit(status);
-}
-
 int
 main(int argc, char **argv)
 {
@@ -358,7 +345,7 @@ main(int argc, char **argv)
 			break;
 		case 'h':
 			/* Usage help */
-			usage(0);
+			VUT_Usage(vut, &vopt_spec, 0);
 		case 'p':
 			errno = 0;
 			e = NULL;
@@ -371,12 +358,12 @@ main(int argc, char **argv)
 			break;
 		default:
 			if (!VUT_Arg(vut, o, optarg))
-				usage(1);
+				VUT_Usage(vut, &vopt_spec, 1);
 		}
 	}
 
 	if (optind != argc)
-		usage(1);
+		VUT_Usage(vut, &vopt_spec, 1);
 
 	VUT_Signal(vut_sighandler);
 	VUT_Setup(vut);


More information about the varnish-commit mailing list