Thread (49 messages) 49 messages, 4 authors, 2021-02-10

Re: [rt-tests v2 08/18] pip_stress: Add command line parser

From: John Kacur <jkacur@redhat.com>
Date: 2020-10-23 17:33:45


On Wed, 7 Oct 2020, Daniel Wagner wrote:
quoted hunk ↗ jump to hunk
Add a default command line parser to print at least the current
version.

Signed-off-by: Daniel Wagner <redacted>
---
 src/pi_tests/pip_stress.c | 34 +++++++++++++++++++++++++++++-----
 1 file changed, 29 insertions(+), 5 deletions(-)
diff --git a/src/pi_tests/pip_stress.c b/src/pi_tests/pip_stress.c
index c9dbd992e15d..74cf53dcfa7a 100644
--- a/src/pi_tests/pip_stress.c
+++ b/src/pi_tests/pip_stress.c
@@ -67,12 +67,17 @@ struct State *statep;
 const int policy = SCHED_FIFO;
 const int prio_min;	/* Initialized for the minimum priority of policy */
 
-struct option long_options[] = {
-    { "usleep", required_argument, 0, 0 },
-    { 0,        0,                 0, 0 },
-};
+static void usage(int error)
+{
+	printf("pip_stress V %1.2f\n", VERSION);
+	printf("Usage:\n"
+	       "pip_stress <options>\n"\
+	       "-h	--help                  Show this help menu.\n"
+	       );
+	exit(error);
+}
 
-int main(void)
+int main(int argc, char *argv[])
 {
 	void *mptr;	/* memory pointer */
 	pid_t pid1, pid2;
@@ -80,6 +85,25 @@ int main(void)
 	int res;
 	int *minimum_priority = (int*)&prio_min;
 
+	for (;;) {
+		struct option long_options[] = {
+			{ "help",	no_argument,		NULL,	'h' },
+			{ NULL,		0,			NULL,	0 },
+		};
+
+		int c = getopt_long(argc, argv, "s:h", long_options, NULL);
+		if (c == -1)
+			break;
+		switch (c) {
+		case 'h':
+			usage(0);
+			break;
+		default:
+			usage(1);
+			break;
+		};
+	}
+
 	*minimum_priority = sched_get_priority_min(policy);
 
 	if (check_privs())
-- 
2.28.0
Uglifying my beautiful program in the name conformity?

Ugh, ok fine

Signed-off-by: John Kacur <jkacur@redhat.com>
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help