Skip to contentSkip to conversation

test specific command line options

LTP Han Pingtian 3 participants 4 messages Jul 28, 2016 – Aug 1, 2016 Library code

lore
Share & tools
lore
#0 lore raw

Hi,

From the doc I read:

... The 'arg' is where 'optarg' is stored upon match. If option has no parameter it's set to non-'NULL' value if option was present.

But looks like if a option was present which has no parameter, the 'arg' will set to NULL?

Thanks in advance.

#1 lore raw

----- Original Message -----

Quoted 7 lines

From: "Han Pingtian" <[email protected]>
To: [email protected]
Sent: Thursday, 28 July, 2016 10:12:49 AM
Subject: [LTP] test specific command line options

Hi,

Quoted 7 lines

From the doc I read:

... The 'arg' is where 'optarg' is stored upon match. If option has no parameter it's set to non-'NULL' value if option was present.

But looks like if a option was present which has no parameter, the 'arg' will set to NULL?

You're right, that looks like a BUG. If you don't provide colon, then "arg" stays NULL, but doc say it should be non-NULL:

lib/tst_test.c +5 -1
index 4f417ea345e7..0b99bedd8d81 100644
@@ -384,6 +384,7 @@ static void parse_topt(unsigned int topts_len, int opt, char *optarg)
 {
        unsigned int i;
        struct tst_option *toptions = tst_test->options;
+       static char *match = "";
 
        for (i = 0; i < topts_len; i++) {
                if (toptions[i].optstr[0] == opt)
@@ -393,7 +394,10 @@ static void parse_topt(unsigned int topts_len, int opt, char *optarg)
        if (i >= topts_len)
                tst_brk(TBROK, "Invalid option '%c' (should not happen)", opt);
 
-       *(toptions[i].arg) = optarg;
+       if (optarg)
+               *(toptions[i].arg) = optarg;
+       else
+               *(toptions[i].arg) = match;
 }
 
 /* see self_exec.c */

Regards,
Jan

Quoted 7 lines

Thanks in advance.

--
Mailing list info: https://lists.linux.it/listinfo/ltp

#2 lore raw

Hi!

Quoted 10 lines
Quoted 7 lines

From the doc I read:

... The 'arg' is where 'optarg' is stored upon match. If option has no parameter it's set to non-'NULL' value if option was present.

But looks like if a option was present which has no parameter, the 'arg' will set to NULL?

You're right, that looks like a BUG. If you don't provide colon, then "arg" stays NULL, but doc say it should be non-NULL:

Looks like my mistake.

Quoted 13 lines
lib/tst_test.c +1 -0
index 4f417ea345e7..0b99bedd8d81 100644
@@ -384,6 +384,7 @@ static void parse_topt(unsigned int topts_len, int opt, char *optarg)
 {
        unsigned int i;
        struct tst_option *toptions = tst_test->options;
+       static char *match = "";
 
        for (i = 0; i < topts_len; i++) {
                if (toptions[i].optstr[0] == opt)

lib/tst_test.c static void parse_topt(unsigned int topts_len, int opt, char *optarg) · line 400

Quoted 8 lines
lib/tst_test.c +4 -1
@@ -393,7 +394,10 @@ static void parse_topt(unsigned int topts_len, int opt, char *optarg)
        if (i >= topts_len)
                tst_brk(TBROK, "Invalid option '%c' (should not happen)", opt);
 
-       *(toptions[i].arg) = optarg;
+       if (optarg)
+               *(toptions[i].arg) = optarg;
+       else
+               *(toptions[i].arg) = match;

I would do something as:

	*(toptions[i].arg) = optarg ? optarg : "";
Signature · 2 lines
Cyril Hrubis
[email protected]
#3 lore raw

----- Original Message -----

Quoted 47 lines

From: "Cyril Hrubis" <[email protected]>
To: "Jan Stancek" <[email protected]>
Cc: "Han Pingtian" <[email protected]>, [email protected]
Sent: Monday, 1 August, 2016 11:23:56 AM
Subject: Re: [LTP] test specific command line options

Hi!

Quoted 10 lines
Quoted 7 lines

From the doc I read:

... The 'arg' is where 'optarg' is stored upon match. If option has no parameter it's set to non-'NULL' value if option was present.

But looks like if a option was present which has no parameter, the 'arg' will set to NULL?

You're right, that looks like a BUG. If you don't provide colon, then "arg" stays NULL, but doc say it should be non-NULL:

Looks like my mistake.

Quoted 14 lines
lib/tst_test.c +1 -0
index 4f417ea345e7..0b99bedd8d81 100644
@@ -384,6 +384,7 @@ static void parse_topt(unsigned int topts_len, int opt,
 char *optarg)
 {
        unsigned int i;
        struct tst_option *toptions = tst_test->options;
+       static char *match = "";
 
        for (i = 0; i < topts_len; i++) {
                if (toptions[i].optstr[0] == opt)

lib/tst_test.c static void parse_topt(unsigned int topts_len, int · line 402

Quoted 10 lines
lib/tst_test.c +4 -1
@@ -393,7 +394,10 @@ static void parse_topt(unsigned int topts_len, int
 opt, char *optarg)
        if (i >= topts_len)
                tst_brk(TBROK, "Invalid option '%c' (should not happen)",
                opt);
 
-       *(toptions[i].arg) = optarg;
+       if (optarg)
+               *(toptions[i].arg) = optarg;
+       else
+               *(toptions[i].arg) = match;

I would do something as:

Quoted 1 line
	*(toptions[i].arg) = optarg ? optarg : "";

I pushed your version.

Regards,
Jan