Skip to contentSkip to conversation

Application command line arguments(parameters) reordering problem

Xenomai Andris 2 participants 10 messages Sep 7, 2017 – Sep 25, 2017

lore
Share & tools
lore

Andris

author
#0 lore raw

Hi!
I found that if I build user space application as Xenomai application and command line arguments(parameters) have format --parameter-first <value> --parameter-second <value> --parameter-X <value> (for example, --enable-some-feature 1 --test-period 500), then main function get these parameters not in the same order as in command line, but somehow reordered.
As example I will use in Xenomai v3.0.5 included application "latency" (xenomai/testsuite/latency/).
I add in main function some lines to print arguments:
int main(int argc, char *const *argv)
{
struct sigaction sa __attribute__((unused));
int c, ret, sig, cpu = 0;
pthread_attr_t tattr;
cpu_set_t cpus;
sigset_t mask;
printf("main: input arguments: argc=%d \n", argc);
for(int p=0; p<argc; p++)
printf("main: argv[%d]=%s \n",p,argv[p]);
.......
}
Now, what I get on output:
1) Pass parameters without "--parameter-name <value>" ./latency -p 250 -c 3 -P 90
main: input arguments: argc=7
main: argv[0]=/home/install/xenomai/testsuite/latency/.libs/latency
main: argv[1]=-p
main: argv[2]=250
main: argv[3]=-c
main: argv[4]=3
main: argv[5]=-P
main: argv[6]=90
2) Pass parameters with "--parameter-name <value>" (just pass some latency application unsupported parameters)
./latency --test-period 500 --enable-some-feature 1
main: input arguments: argc=5
main: argv[0]=/home/install/xenomai/testsuite/latency/.libs/latency
main: argv[1]=--test-period
main: argv[2]=--enable-some-feature
main: argv[3]=500
main: argv[4]=1
Why main function get these parameters reordered? Is this Xenomai bug? System configuration:
OS: Opensuse 42.2
kernel: 4.9.24.2
i-pipe patch: ipipe-core-4.9.24-x86-2.patch
xenomai: 3.0.5
gcc: 7.1.1 20170629
Thanks!

#1 lore raw
Quoted 7 lines · Andris

Hi!
I found that if I build user space application as Xenomai application and command line arguments(parameters) have format --parameter-first <value> --parameter-second <value> --parameter-X <value> (for example, --enable-some-feature 1 --test-period 500), then main function get these parameters not in the same order as in command line, but somehow reordered.

<snip>

Quoted 11 lines
   2) Pass parameters with "--parameter-name <value>" (just pass some
   latency application unsupported parameters)
   ./latency --test-period 500 --enable-some-feature 1
   main: input arguments: argc=5
   main: argv[0]=/home/install/xenomai/testsuite/latency/.libs/latency
   main: argv[1]=--test-period
   main: argv[2]=--enable-some-feature
   main: argv[3]=500
   main: argv[4]=1
   Why main function get these parameters reordered?

Is this Xenomai bug?

Xenomai uses getopt_long() internally, which unexpectedly alters the argument vector. The fine print that relates to this behavior can be found in this excerpt from the getopt_long() man page:
"If there are no more option characters, getopt[_long]() returns -1. Then optind is the index in argv of the first argv-element that is not an option."

To do that, getopt_long() reorganizes the arguments, moving all unhandled non-option words which do not start with a dash to the end of the vector, then sets optind to point at the head of this pack. This does not work particularly well when one has to parse the same vector multiple times, each time with a different set of options... Well, it looks like we need the patch below. If this works for your tests, I'll get it merged for 3.0.6.

Thanks,

lib/boilerplate/setup.c +36 -4
index 731504f..2f224e3 100644
@@ -376,6 +376,34 @@ void xenomai_usage(void)
         fprintf(stderr, "--help				display help\n");
 }
 
+static int do_getopt(int argc, char **argv,
+		     const struct option *options,
+		     int *lindexp)
+{
+	char **_argv;
+	int c, n;
+
+	/*
+	 * getopt_long() reorders the argument vector after reaching
+	 * its end, moving all unhandled non-option words (i.e. not
+	 * prefixed by a dash) after command switches, then pointing
+	 * optind at the beginning of this pack. We don't want to
+	 * alter the user vector this way, so always work on a copy.
+	 */
+
+	_argv = malloc(sizeof(char *) * argc);
+	if (_argv == NULL)
+		return -ENOMEM;
+
+	for (n = 0; n < argc; n++)
+		_argv[n] = argv[n];
+
+	c = getopt_long(argc, _argv, "", options, lindexp);
+	free(_argv);
+
+	return c < 0 ? 0 : c;
+}
+
 static int parse_base_options(int *argcp, int *largcp, char **uargv,
 			      const struct option *options,
 			      int base_opt_start)
@@ -395,8 +423,10 @@ static int parse_base_options(int *argcp, int *largcp, char **uargv,
 
 	for (;;) {
 		lindex = -1;
-		c = getopt_long(*largcp, uargv, "", options, &lindex);
-		if (c == EOF)
+		c = do_getopt(*largcp, uargv, options, &lindex);
+		if (c < 0)
+			return c;
+		if (!c)
 			break;
 		if (lindex == -1)
 			continue;
@@ -472,8 +502,10 @@ static int parse_setup_options(int *argcp, int largc, char **uargv,
 
 	for (;;) {
 		lindex = -1;
-		c = getopt_long(largc, uargv, "", options, &lindex);
-		if (c == EOF)
+		c = do_getopt(largc, uargv, options, &lindex);
+		if (c < 0)
+			return ret;
+		if (!c)
 			break;
 		if (lindex == -1)
 			continue; /* Not handled here. */
Signature · 1 line
Philippe.
author
#2 lore raw

Thanks!
But this patch resolve problem only if all command line arguments starts with "--", but if command line is with mixed arguments, for example:
./app -p 250 --enable-feature 1
then the problem still exist.
I'm playing with Intel DPDK and Xenomai and I would like to pass command line arguments directly to DPDK. DPDK expect to get command line in following format:
<eal options> -- <application specific options>
for example:
./app -l 0-3 -n 3 -- -p 0x1 -q 1

----- Reply to message -----
Subject: Re: [Xenomai] Application command line arguments(parameters) reordering problem
Date: 7 September 2017 at 12:14:20
From: Philippe Gerum [1]<[email protected]>
To: Andris [2]<[email protected]>

On 09/07/2017 08:36 AM, Andris wrote:
> Hi!
> I found that if I build user space application as Xenomai application
> and command line arguments(parameters) have format --parameter-first
> <value> --parameter-second <value> --parameter-X <value> (for example,
> --enable-some-feature 1 --test-period 500), then main function get > these parameters not in the same order as in command line, but somehow
> reordered.
<snip>
> 2) Pass parameters with "--parameter-name <value>" (just pass some > latency application unsupported parameters)
> ./latency --test-period 500 --enable-some-feature 1
> main: input arguments: argc=5
> main:
argv[0]=/home/install/xenomai/testsuite/latency/.libs/latency > main: argv[1]=--test-period
> main: argv[2]=--enable-some-feature
> main: argv[3]=500
> main: argv[4]=1
> Why main function get these parameters reordered?
> Is this Xenomai bug?
Xenomai uses getopt_long() internally, which unexpectedly alters the argument vector. The fine print that relates to this behavior can be found in this excerpt from the getopt_long() man page:
"If there are no more option characters, getopt[_long]() returns -1. Then optind is the index in argv of the first argv-element that is not an option."
To do that, getopt_long() reorganizes the arguments, moving all unhandled non-option words which do not start with a dash to the end of the vector, then sets optind to point at the head of this pack. This does not work particularly well when one has to parse the same vector multiple times, each time with a different set of options... Well, it looks like we need the patch below. If this works for your tests, I'll get it merged for 3.0.6.
Thanks,
diff --git a/lib/boilerplate/setup.c b/lib/boilerplate/setup.c index 731504f..2f224e3 100644
--- a/lib/boilerplate/setup.c
+++ b/lib/boilerplate/setup.c
@@ -376,6 +376,34 @@ void xenomai_usage(void) fprintf(stderr, "--help display help\n");
}
+static int do_getopt(int argc, char **argv,
+ const struct option *options,
+ int *lindexp)
+{
+ char **_argv;
+ int c, n;
+
+ /*
+ * getopt_long() reorders the argument vector after reaching
+ * its end, moving all unhandled non-option words (i.e. not
+ * prefixed by a dash) after command switches, then pointing
+ * optind at the beginning of this pack. We don't want to
+ * alter the user vector this way, so always work on a copy.
+ */
+
+ _argv = malloc(sizeof(char *) * argc);
+ if (_argv == NULL)
+ return -ENOMEM;
+
+ for (n = 0; n < argc; n++)
+ _argv[n] = argv[n];
+
+ c = getopt_long(argc, _argv, "", options, lindexp);
+ free(_argv);
+
+ return c < 0 ? 0 : c;
+}
+
static int parse_base_options(int *argcp, int *largcp, char **uargv, const struct option *options,
int base_opt_start)
@@ -395,8 +423,10 @@ static int parse_base_options(int *argcp, int *largcp, char **uargv,
for (;;) {
lindex = -1;
- c = getopt_long(*largcp, uargv, "", options, &lindex);
- if (c == EOF)
+ c = do_getopt(*largcp, uargv, options, &lindex);
+ if (c < 0)
+ return c;
+ if (!c)
break;
if (lindex == -1)
continue;
@@ -472,8 +502,10 @@ static int parse_setup_options(int *argcp, int largc, char **uargv,
for (;;) {
lindex = -1;
- c = getopt_long(largc, uargv, "", options, &lindex);
- if (c == EOF)
+ c = do_getopt(largc, uargv, options, &lindex);
+ if (c < 0)
+ return ret;
+ if (!c)
break;
if (lindex == -1)
continue; /* Not handled here. */
--
Philippe.

~~~~~~~~~~~~~~~~~~~
Best regards,
Andris

References

1. mailto:[email protected]
2. mailto:[email protected]

#3 lore raw
Quoted 5 lines · Andris

Thanks!
But this patch resolve problem only if all command line arguments starts with "--", but if command line is with mixed arguments, for example:
./app -p 250 --enable-feature 1
then the problem still exist.

Just checked, it does not here. Are you sure?

Quoted 7 lines

I'm playing with Intel DPDK and Xenomai and I would like to pass command line arguments directly to DPDK. DPDK expect to get command line in following format:
<eal options> -- <application specific options>
for example:
./app -l 0-3 -n 3 -- -p 0x1 -q 1

There is still an issue with this form though, since the double-dash separator moves at the head of the vector.

Signature · 1 line
Philippe.
#4 lore raw
Quoted 17 lines · Philippe Gerum
Quoted 5 lines · Andris

Thanks!
But this patch resolve problem only if all command line arguments starts with "--", but if command line is with mixed arguments, for example:
./app -p 250 --enable-feature 1
then the problem still exist.

Just checked, it does not here. Are you sure?

Quoted 7 lines

I'm playing with Intel DPDK and Xenomai and I would like to pass command line arguments directly to DPDK. DPDK expect to get command line in following format:
<eal options> -- <application specific options>
for example:
./app -l 0-3 -n 3 -- -p 0x1 -q 1

Quoted 3 lines

There is still an issue with this form though, since the double-dash separator moves at the head of the vector.

Besides, the patch I sent has quite undesirable side-effects. Please drop it, this needs more work.

Signature · 1 line
Philippe.
author
#5 lore raw
In reply to Philippe Gerum

Subject: Re: [Xenomai] Application command line
arguments(parameters) reordering problem

Date: 8 September 2017 at 12:06:50
From:  Philippe Gerum <[email protected]>
To:  Andris <[email protected]>
Quoted 3 lines · Andris
Quoted 2 lines

Thanks!
But this patch resolve problem only if all

command line arguments starts

Quoted 1 line
Quoted 1 line

with "--", but if command line is with mixed

arguments, for example:

Quoted 4 lines
Quoted 2 lines

./app -p 250 --enable-feature 1
then the problem still exist.

Just checked, it does not here. Are you sure?

Yes, parameters are reordered, first always is
parameter starting with "--".
argv[0]: app
argv[1]: --enable-feature
argv[2]: 1
argv[3]: -p
argv[4]: 250

But this possibly is not a problem.

Andris

#6 lore raw
Quoted 24 lines · Andris

Subject: Re: [Xenomai] Application command line
arguments(parameters) reordering problem

Date: 8 September 2017 at 12:06:50
From:  Philippe Gerum <[email protected]>
To:  Andris <[email protected]>
Quoted 3 lines · Andris
Quoted 2 lines

Thanks!
But this patch resolve problem only if all

command line arguments starts

Quoted 1 line
Quoted 1 line

with "--", but if command line is with mixed

arguments, for example:

Quoted 4 lines
Quoted 2 lines

./app -p 250 --enable-feature 1
then the problem still exist.

Just checked, it does not here. Are you sure?

Yes, parameters are reordered, first always is
parameter starting with "--".
argv[0]: app
argv[1]: --enable-feature
argv[2]: 1
argv[3]: -p
argv[4]: 250

Quoted 2 lines

But this possibly is not a problem.

Ok, the whole thing needs a review. I'll follow up on this.

Thanks,

Signature · 1 line
Philippe.
#7 lore raw
Quoted 25 lines · Philippe Gerum
Quoted 24 lines · Andris

Subject: Re: [Xenomai] Application command line
arguments(parameters) reordering problem

Date: 8 September 2017 at 12:06:50
From:  Philippe Gerum <[email protected]>
To:  Andris <[email protected]>
Quoted 3 lines · Andris
Quoted 2 lines

Thanks!
But this patch resolve problem only if all

command line arguments starts

Quoted 1 line
Quoted 1 line

with "--", but if command line is with mixed

arguments, for example:

Quoted 4 lines
Quoted 2 lines

./app -p 250 --enable-feature 1
then the problem still exist.

Just checked, it does not here. Are you sure?

Yes, parameters are reordered, first always is
parameter starting with "--".
argv[0]: app
argv[1]: --enable-feature
argv[2]: 1
argv[3]: -p
argv[4]: 250

Quoted 7 lines
Quoted 2 lines

But this possibly is not a problem.

Ok, the whole thing needs a review. I'll follow up on this.

Thanks,

Please try this patch:

commit 5c3a997983d7b1fe29d225075ddb94f2c63ee016

Author: Philippe Gerum <[email protected]>
Date:   Fri Sep 8 12:08:05 2017 +0200

boilerplate/setup: do not alter order of parameters

- firstly, keep short options in parsed vector
- secondly, disable getopt's parameter shuffling

lib/boilerplate/setup.c +27 -47
index 731504f..f749828 100644
@@ -232,10 +232,10 @@ fail:
 	return -EINVAL;
 }
 
-static inline char **prep_args(int argc, char *const argv[], int *largcp)
+static inline char **prep_args(int argc, char *const argv[])
 {
-	int in, out, n, maybe_arg, lim;
-	char **uargv, *p;
+	char **uargv;
+	int n;
 
 	uargv = malloc(argc * sizeof(char *));
 	if (uargv == NULL)
@@ -247,43 +247,18 @@ static inline char **prep_args(int argc, char *const argv[], int *largcp)
 			return NULL;
 	}
 
-	lim = argc;
-	in = maybe_arg = 0;
-	while (in < lim) {
-		if ((uargv[in][0] == '-' && uargv[in][1] != '-') ||
-		    (maybe_arg && uargv[in][0] != '-')) {
-			p = strdup(uargv[in]);
-			for (n = in, out = in + 1; out < argc; out++, n++) {
-				free(uargv[n]);
-				uargv[n] = strdup(uargv[out]);
-			}
-			free(uargv[argc - 1]);
-			uargv[argc - 1] = p;
-			if (*p == '-')
-				maybe_arg = 1;
-			lim--;
-		} else {
-			in++;
-			maybe_arg = 0;
-		}
-	}
-
-	*largcp = lim;
-
 	return uargv;
 }
 
-static inline void pack_args(int *argcp, int *largcp, char **argv)
+static inline void pack_args(int *argcp, char **argv)
 {
 	int in, out;
 
 	for (in = out = 0; in < *argcp; in++) {
 		if (*argv[in])
 			argv[out++] = argv[in];
-		else {
+		else
 			free(argv[in]);
-			(*largcp)--;
-		}
 	}
 
 	*argcp = out;
@@ -376,7 +351,7 @@ void xenomai_usage(void)
         fprintf(stderr, "--help				display help\n");
 }
 
-static int parse_base_options(int *argcp, int *largcp, char **uargv,
+static int parse_base_options(int *argcp, char **uargv,
 			      const struct option *options,
 			      int base_opt_start)
 {
@@ -395,7 +370,7 @@ static int parse_base_options(int *argcp, int *largcp, char **uargv,
 
 	for (;;) {
 		lindex = -1;
-		c = getopt_long(*largcp, uargv, "", options, &lindex);
+		c = getopt_long(*argcp, uargv, "-", options, &lindex);
 		if (c == EOF)
 			break;
 		if (lindex == -1)
@@ -442,13 +417,14 @@ static int parse_base_options(int *argcp, int *largcp, char **uargv,
 		 * (including any companion argument), pack_args()
 		 * will expunge all options we have already handled.
 		 *
-		 * NOTE: this code relies on the fact that only long
-		 * options with double-dash markers can be parsed here
-		 * after prep_args() did its job (we do not support
-		 * -foo as a long option). This is aimed at reserving
-		 * use of short options to the application layer,
-		 * sharing only the long option namespace with the
-		 * Xenomai core libs.
+		 * NOTE: only options with double-dash prefix may have
+		 * been recognized by getopt_long() as Xenomai
+		 * ones. This reserves short options to the
+		 * application layer, sharing only the long option
+		 * namespace with the Xenomai core libs. In addition,
+		 * the user can delimit the start of the application
+		 * arguments, preceeding them by the '--' separator on
+		 * the command line.
 		 */
 		n = optind - 1;
 		if (uargv[n][0] != '-' || uargv[n][1] != '-')
@@ -457,14 +433,14 @@ static int parse_base_options(int *argcp, int *largcp, char **uargv,
 		uargv[n][0] = '\0'; /* Clear the option switch. */
 	}
 
-	pack_args(argcp, largcp, uargv);
+	pack_args(argcp, uargv);
 
 	optind = 0;
 
 	return 0;
 }
 
-static int parse_setup_options(int *argcp, int largc, char **uargv,
+static int parse_setup_options(int *argcp, char **uargv,
 			       const struct option *options)
 {
 	struct setup_descriptor *setup;
@@ -472,7 +448,11 @@ static int parse_setup_options(int *argcp, int largc, char **uargv,
 
 	for (;;) {
 		lindex = -1;
-		c = getopt_long(largc, uargv, "", options, &lindex);
+		/*
+		 * We want to keep the original order of parameters in
+		 * the vector, disable getopt's parameter shuffling.
+		 */
+		c = getopt_long(*argcp, uargv, "-", options, &lindex);
 		if (c == EOF)
 			break;
 		if (lindex == -1)
@@ -498,7 +478,7 @@ static int parse_setup_options(int *argcp, int largc, char **uargv,
 		uargv[n][0] = '\0'; /* Clear the option switch. */
 	}
 
-	pack_args(argcp, &largc, uargv);
+	pack_args(argcp, uargv);
 
 	optind = 0;
 
@@ -507,8 +487,8 @@ static int parse_setup_options(int *argcp, int largc, char **uargv,
 
 static void __xenomai_init(int *argcp, char *const **argvp, const char *me)
 {
-	int ret, largc, base_opt_start;
 	struct setup_descriptor *setup;
+	int ret, base_opt_start;
 	struct option *options;
 	struct service svc;
 	char **uargv;
@@ -528,7 +508,7 @@ static void __xenomai_init(int *argcp, char *const **argvp, const char *me)
 	 * will be expunged from Xenomai's base options as we discover
 	 * them.
 	 */
-	uargv = prep_args(*argcp, *argvp, &largc);
+	uargv = prep_args(*argcp, *argvp);
 	if (uargv == NULL) {
 		ret = -ENOMEM;
 		goto fail;
@@ -552,7 +532,7 @@ static void __xenomai_init(int *argcp, char *const **argvp, const char *me)
 	 * Parse the base options first, to bootstrap the core with
 	 * the right config values.
 	 */
-	ret = parse_base_options(argcp, &largc, uargv,
+	ret = parse_base_options(argcp, uargv,
 				 options, base_opt_start);
 	if (ret)
 		goto fail;
@@ -600,7 +580,7 @@ setup:
 			}
 		}
 		
-		ret = parse_setup_options(argcp, largc, uargv, options);
+		ret = parse_setup_options(argcp, uargv, options);
 		if (ret)
 			goto fail;
 
Signature · 1 line
Philippe.
author
#8 lore raw

Quoted 11 lines
Quoted 11 lines
Quoted 11 lines
Quoted 2 lines

Just checked, it does not here. Are you sure?

Yes, parameters are reordered, first always is
parameter starting with "--".
argv[0]: app
argv[1]: --enable-feature
argv[2]: 1
argv[3]: -p
argv[4]: 250

Quoted 4 lines
Quoted 4 lines
Quoted 2 lines

But this possibly is not a problem.

Ok, the whole thing needs a review. I'll

follow up on this.

Quoted 5 lines
Quoted 3 lines

Thanks,

Please try this patch:

Thanks!
But I can try this patch only after 2 weeks, I will be out of office. Maybe my colleague can try it.

author
#9 lore raw
In reply to Philippe Gerum
Quoted 5 lines

Please try this patch:

commit 5c3a997983d7b1fe29d225075ddb94f2c63ee016
Author: Philippe Gerum <[email protected]>
Date: Fri Sep 8 12:08:05 2017 +0200

Thanks! It seems that now it works as expected.

Review

Quoted 6 lines

boilerplate/setup: do not alter order of parameters

- firstly, keep short options in parsed vector
- secondly, disable getopt's parameter shuffling

(quoted diff) +0 -0

b/lib/boilerplate/setup.c

lib/boilerplate/setup.c fail: · line 235

Quoted 8 lines

index 731504f..f749828 100644

lib/boilerplate/setup.c +0 -1
@@ -232,10 +232,10 @@ fail:
 return -EINVAL;
 }
 
-static inline char **prep_args(int argc, char

*const argv[], int *largcp)

lib/boilerplate/setup.c fail: · line 235

Quoted 1 line
lib/boilerplate/setup.c +1 -0
+static inline char **prep_args(int argc, char

*const argv[])

lib/boilerplate/setup.c static inline char

Quoted 9 lines
lib/boilerplate/setup.c +2 -2
 {
- int in, out, n, maybe_arg, lim;
- char **uargv, *p;
+ char **uargv;
+ int n;
 
 uargv = malloc(argc * sizeof(char *));
 if (uargv == NULL)
@@ -247,43 +247,18 @@ static inline char

**prep_args(int argc, char *const argv[], int *largcp)

lib/boilerplate/setup.c static inline char **prep_args(int argc, char *const argv[], int *largcp)

Quoted 7 lines
lib/boilerplate/setup.c +0 -4
 return NULL;
 }
 
- lim = argc;
- in = maybe_arg = 0;
- while (in < lim) {
- if ((uargv[in][0] == '-' && uargv[in][1] !=

'-') ||

lib/boilerplate/setup.c static inline char **prep_args(int argc, char *const argv[], int *largcp)

Quoted 3 lines
lib/boilerplate/setup.c +0 -3
- (maybe_arg && uargv[in][0] != '-')) {
- p = strdup(uargv[in]);
- for (n = in, out = in + 1; out < argc; out++,

n++) {

Quoted 10 lines
lib/boilerplate/setup.c +0 -10
- free(uargv[n]);
- uargv[n] = strdup(uargv[out]);
- }
- free(uargv[argc - 1]);
- uargv[argc - 1] = p;
- if (*p == '-')
- maybe_arg = 1;
- lim--;
- } else {
- in++;

lib/boilerplate/setup.c static inline char **prep_args(int argc, char *const argv[], int *largcp)

Quoted 10 lines
lib/boilerplate/setup.c +0 -7
- maybe_arg = 0;
- }
- }
-
- *largcp = lim;
-
 return uargv;
 }
 
-static inline void pack_args(int *argcp, int

*largcp, char **argv)

lib/boilerplate/setup.c static inline char · line 253

Quoted 1 line
lib/boilerplate/setup.c +1 -0
+static inline void pack_args(int *argcp, char

**argv)

Quoted 15 lines
lib/boilerplate/setup.c +1 -3
 {
 int in, out;
 
 for (in = out = 0; in < *argcp; in++) {
 if (*argv[in])
 argv[out++] = argv[in];
- else {
+ else
 free(argv[in]);
- (*largcp)--;
- }
 }
 
 *argcp = out;

lib/boilerplate/setup.c void xenomai_usage(void) · line 379

Quoted 4 lines
lib/boilerplate/setup.c +0 -1
@@ -376,7 +351,7 @@ void xenomai_usage(void)
 fprintf(stderr, "--help display help\n");
 }
 
-static int parse_base_options(int *argcp, int

*largcp, char **uargv,

lib/boilerplate/setup.c void xenomai_usage(void) · line 354

Quoted 1 line
lib/boilerplate/setup.c +1 -0
+static int parse_base_options(int *argcp, char

**uargv,

lib/boilerplate/setup.c static int

Quoted 4 lines
lib/boilerplate/setup.c +0 -0
 const struct option *options,
 int base_opt_start)
 {
@@ -395,7 +370,7 @@ static int

parse_base_options(int *argcp, int *largcp, char
**uargv,

lib/boilerplate/setup.c static int parse_base_options(int *argcp, int *largcp, char **uargv,

Quoted 3 lines
lib/boilerplate/setup.c +0 -1
 for (;;) {
 lindex = -1;
- c = getopt_long(*largcp, uargv, "", options,

&lindex);

lib/boilerplate/setup.c static int · line 372

Quoted 1 line
lib/boilerplate/setup.c +1 -0
+ c = getopt_long(*argcp, uargv, "-", options,

&lindex);

lib/boilerplate/setup.c static int

Quoted 4 lines
lib/boilerplate/setup.c +0 -0
 if (c == EOF)
 break;
 if (lindex == -1)
@@ -442,13 +417,14 @@ static int

parse_base_options(int *argcp, int *largcp, char
**uargv,

lib/boilerplate/setup.c static int parse_base_options(int *argcp, int *largcp, char **uargv,

Quoted 4 lines
lib/boilerplate/setup.c +0 -1
 * (including any companion argument), pack_args()
 * will expunge all options we have already handled.
 *
- * NOTE: this code relies on the fact that only

long

lib/boilerplate/setup.c static int · line 446

Quoted 1 line
lib/boilerplate/setup.c +0 -1
- * options with double-dash markers can be

parsed here

lib/boilerplate/setup.c static int · line 448

Quoted 2 lines
lib/boilerplate/setup.c +0 -2
- * after prep_args() did its job (we do not support
- * -foo as a long option). This is aimed at

reserving

lib/boilerplate/setup.c static int parse_base_options(int *argcp, int *largcp, char **uargv,

Quoted 4 lines
lib/boilerplate/setup.c +1 -3
- * use of short options to the application layer,
- * sharing only the long option namespace with the
- * Xenomai core libs.
+ * NOTE: only options with double-dash prefix

may have

lib/boilerplate/setup.c static int parse_base_options(int *argcp, int *largcp, char **uargv,

Quoted 4 lines
lib/boilerplate/setup.c +4 -0
+ * been recognized by getopt_long() as Xenomai
+ * ones. This reserves short options to the
+ * application layer, sharing only the long option
+ * namespace with the Xenomai core libs. In

addition,

lib/boilerplate/setup.c static int · line 425

Quoted 1 line
lib/boilerplate/setup.c +1 -0
+ * the user can delimit the start of the

application

lib/boilerplate/setup.c static int · line 426

Quoted 1 line
lib/boilerplate/setup.c +1 -0
+ * arguments, preceeding them by the '--'

separator on

lib/boilerplate/setup.c static int

Quoted 5 lines
lib/boilerplate/setup.c +1 -0
+ * the command line.
 */
 n = optind - 1;
 if (uargv[n][0] != '-' || uargv[n][1] != '-')
@@ -457,14 +433,14 @@ static int

parse_base_options(int *argcp, int *largcp, char
**uargv,

Quoted 6 lines

uargv[n][0] = '\0'; /* Clear the option switch. */ }

- pack_args(argcp, largcp, uargv);
+ pack_args(argcp, uargv);

Quoted 6 lines

optind = 0;

return 0;
}

-static int parse_setup_options(int *argcp, int

largc, char **uargv,

Quoted 1 line

+static int parse_setup_options(int *argcp, char

**uargv,

lib/boilerplate/setup.c static int

Quoted 4 lines

const struct option *options)
{
struct setup_descriptor *setup;

lib/boilerplate/setup.c +0 -0
@@ -472,7 +448,11 @@ static int

parse_setup_options(int *argcp, int largc, char
**uargv,

lib/boilerplate/setup.c static int parse_base_options(int *argcp, int *largcp, char **uargv,

Quoted 3 lines
lib/boilerplate/setup.c +0 -1
 for (;;) {
 lindex = -1;
- c = getopt_long(largc, uargv, "", options,

&lindex);

lib/boilerplate/setup.c static int · line 451

Quoted 2 lines
lib/boilerplate/setup.c +2 -0
+ /*
+ * We want to keep the original order of

parameters in

lib/boilerplate/setup.c static int · line 452

Quoted 1 line
lib/boilerplate/setup.c +1 -0
+ * the vector, disable getopt's parameter

shuffling.

lib/boilerplate/setup.c static int · line 454

Quoted 2 lines
lib/boilerplate/setup.c +2 -0
+ */
+ c = getopt_long(*argcp, uargv, "-", options,

&lindex);

lib/boilerplate/setup.c static int

Quoted 4 lines
lib/boilerplate/setup.c +0 -0
 if (c == EOF)
 break;
 if (lindex == -1)
@@ -498,7 +478,7 @@ static int

parse_setup_options(int *argcp, int largc, char
**uargv,

lib/boilerplate/setup.c static int

Quoted 9 lines

uargv[n][0] = '\0'; /* Clear the option switch. */ }

- pack_args(argcp, &largc, uargv);
+ pack_args(argcp, uargv);

optind = 0;

lib/boilerplate/setup.c +0 -0
@@ -507,8 +487,8 @@ static int

parse_setup_options(int *argcp, int largc, char
**uargv,

Quoted 1 line

static void __xenomai_init(int *argcp, char

*const **argvp, const char *me)

lib/boilerplate/setup.c static void

Quoted 8 lines

{
- int ret, largc, base_opt_start; struct setup_descriptor *setup;
+ int ret, base_opt_start;
struct option *options;
struct service svc;
char **uargv;

lib/boilerplate/setup.c +0 -0
@@ -528,7 +508,7 @@ static void

__xenomai_init(int *argcp, char *const **argvp,
const char *me)

lib/boilerplate/setup.c static void · line 508

Quoted 1 line
lib/boilerplate/setup.c +0 -0
 * will be expunged from Xenomai's base options

as we discover

lib/boilerplate/setup.c static void

Quoted 8 lines
lib/boilerplate/setup.c +1 -1
 * them.
 */
- uargv = prep_args(*argcp, *argvp, &largc);
+ uargv = prep_args(*argcp, *argvp);
 if (uargv == NULL) {
 ret = -ENOMEM;
 goto fail;
@@ -552,7 +532,7 @@ static void

__xenomai_init(int *argcp, char *const **argvp,
const char *me)

lib/boilerplate/setup.c static void · line 532

Quoted 1 line
lib/boilerplate/setup.c +0 -0
 * Parse the base options first, to bootstrap the

core with

lib/boilerplate/setup.c setup: · line 603

Quoted 12 lines
lib/boilerplate/setup.c +1 -2
 * the right config values.
 */
- ret = parse_base_options(argcp, &largc, uargv,
+ ret = parse_base_options(argcp, uargv,
 options, base_opt_start);
 if (ret)
 goto fail;
@@ -600,7 +580,7 @@ setup:
 }
 }
 
- ret = parse_setup_options(argcp, largc, uargv,

options);

Quoted 6 lines
lib/boilerplate/setup.c +1 -1
+ ret = parse_setup_options(argcp, uargv, options);
 if (ret)
 goto fail;
 
--

Philippe.

~~~~~~~~~~~~~~~~~~~
Best regards,
Andris