diff mbox series

[ethtool,1/6] ethtool: move option parsing related code into function

Message ID 20190117230313.20248-1-nicholas.d.nunley@intel.com
State Changes Requested
Delegated to: John Linville
Headers show
Series [ethtool,1/6] ethtool: move option parsing related code into function | expand

Commit Message

Nunley, Nicholas D Jan. 17, 2019, 11:03 p.m. UTC
Move option parsing code into find_option function.

No behavior changes.

Based on patch by Kan Liang <kan.liang@intel.com>

Signed-off-by: Nicholas Nunley <nicholas.d.nunley@intel.com>
---
 ethtool.c | 49 +++++++++++++++++++++++++++++++------------------
 1 file changed, 31 insertions(+), 18 deletions(-)

Comments

John W. Linville Jan. 30, 2019, 9:08 p.m. UTC | #1
On Thu, Jan 17, 2019 at 03:03:08PM -0800, Nicholas Nunley wrote:
> Move option parsing code into find_option function.
> 
> No behavior changes.
> 
> Based on patch by Kan Liang <kan.liang@intel.com>
> 
> Signed-off-by: Nicholas Nunley <nicholas.d.nunley@intel.com>

Well, after looking at this series for a while I had decided to apply it. But when I applied it and did a 'make distcheck', I got this:

...

gcc -DTEST_ETHTOOL -g -O2   -o test-features test_features-test-features.o test_features-test-common.o test_features-ethtool.o test_features-rxclass.o test_features-amd8111e.o test_features-de2104x.o test_features-dsa.o test_features-e100.o test_features-e1000.o test_features-et131x.o test_features-igb.o test_features-fec_8xx.o test_features-ibm_emac.o test_features-ixgb.o test_features-ixgbe.o test_features-natsemi.o test_features-pcnet32.o test_features-realtek.o test_features-tg3.o test_features-marvell.o test_features-vioc.o test_features-smsc911x.o test_features-at76c50x-usb.o test_features-sfc.o test_features-stmmac.o test_features-sff-common.o test_features-sfpid.o test_features-sfpdiag.o test_features-ixgbevf.o test_features-tse.o test_features-vmxnet3.o test_features-qsfp.o test_features-fjes.o test_features-lan78xx.o -lm 
make[2]: Leaving directory '/home/linville/git/ethtool/ethtool-4.19/_build/sub'
make  check-TESTS
make[2]: Entering directory '/home/linville/git/ethtool/ethtool-4.19/_build/sub'
make[3]: Entering directory '/home/linville/git/ethtool/ethtool-4.19/_build/sub'
FAIL: test-cmdline
PASS: test-features
============================================================================
Testsuite summary for ethtool 4.19
============================================================================
# TOTAL: 2
# PASS:  1
# SKIP:  0
# XFAIL: 0
# FAIL:  1
# XPASS: 0
# ERROR: 0
============================================================================
See ./test-suite.log
Please report to netdev@vger.kernel.org
============================================================================
make[3]: *** [Makefile:1942: test-suite.log] Error 1
make[3]: Leaving directory '/home/linville/git/ethtool/ethtool-4.19/_build/sub'
make[2]: *** [Makefile:2050: check-TESTS] Error 2
make[2]: Leaving directory '/home/linville/git/ethtool/ethtool-4.19/_build/sub'
make[1]: *** [Makefile:2264: check-am] Error 2
make[1]: Leaving directory '/home/linville/git/ethtool/ethtool-4.19/_build/sub'
make: *** [Makefile:2186: distcheck] Error 1

...

I'll attach ./ethtool-4.19/_build/sub/test-suite.log to this
message. Obviously we need whatever additional changes are needed to
get 'make check-TESTS' to pass legitimately.

John
Kirsher, Jeffrey T Jan. 31, 2019, 6:30 a.m. UTC | #2
On Wed, 2019-01-30 at 16:08 -0500, John W. Linville wrote:
> On Thu, Jan 17, 2019 at 03:03:08PM -0800, Nicholas Nunley wrote:
> > Move option parsing code into find_option function.
> > 
> > No behavior changes.
> > 
> > Based on patch by Kan Liang <kan.liang@intel.com>
> > 
> > Signed-off-by: Nicholas Nunley <nicholas.d.nunley@intel.com>
> 
> Well, after looking at this series for a while I had decided to apply it.
> But when I applied it and did a 'make distcheck', I got this:
> 
> ...
> 
> gcc -DTEST_ETHTOOL -g -O2   -o test-features test_features-test-
> features.o test_features-test-common.o test_features-ethtool.o
> test_features-rxclass.o test_features-amd8111e.o test_features-de2104x.o
> test_features-dsa.o test_features-e100.o test_features-e1000.o
> test_features-et131x.o test_features-igb.o test_features-fec_8xx.o
> test_features-ibm_emac.o test_features-ixgb.o test_features-ixgbe.o
> test_features-natsemi.o test_features-pcnet32.o test_features-realtek.o
> test_features-tg3.o test_features-marvell.o test_features-vioc.o
> test_features-smsc911x.o test_features-at76c50x-usb.o test_features-sfc.o 
> test_features-stmmac.o test_features-sff-common.o test_features-sfpid.o
> test_features-sfpdiag.o test_features-ixgbevf.o test_features-tse.o
> test_features-vmxnet3.o test_features-qsfp.o test_features-fjes.o
> test_features-lan78xx.o -lm 
> make[2]: Leaving directory '/home/linville/git/ethtool/ethtool-
> 4.19/_build/sub'
> make  check-TESTS
> make[2]: Entering directory '/home/linville/git/ethtool/ethtool-
> 4.19/_build/sub'
> make[3]: Entering directory '/home/linville/git/ethtool/ethtool-
> 4.19/_build/sub'
> FAIL: test-cmdline
> PASS: test-features
> =========================================================================
> ===
> Testsuite summary for ethtool 4.19
> =========================================================================
> ===
> # TOTAL: 2
> # PASS:  1
> # SKIP:  0
> # XFAIL: 0
> # FAIL:  1
> # XPASS: 0
> # ERROR: 0
> =========================================================================
> ===
> See ./test-suite.log
> Please report to netdev@vger.kernel.org
> =========================================================================
> ===
> make[3]: *** [Makefile:1942: test-suite.log] Error 1
> make[3]: Leaving directory '/home/linville/git/ethtool/ethtool-
> 4.19/_build/sub'
> make[2]: *** [Makefile:2050: check-TESTS] Error 2
> make[2]: Leaving directory '/home/linville/git/ethtool/ethtool-
> 4.19/_build/sub'
> make[1]: *** [Makefile:2264: check-am] Error 2
> make[1]: Leaving directory '/home/linville/git/ethtool/ethtool-
> 4.19/_build/sub'
> make: *** [Makefile:2186: distcheck] Error 1
> 
> ...
> 
> I'll attach ./ethtool-4.19/_build/sub/test-suite.log to this
> message. Obviously we need whatever additional changes are needed to
> get 'make check-TESTS' to pass legitimately.

Interesting that we did not see this in testing.  I will work with Nick to
provide an updated patch, resolves your distcheck failure.
diff mbox series

Patch

diff --git a/ethtool.c b/ethtool.c
index 2f7e96b..1e4c3bb 100644
--- a/ethtool.c
+++ b/ethtool.c
@@ -5265,6 +5265,29 @@  static int show_usage(struct cmd_context *ctx)
 	return 0;
 }
 
+static int find_option(int argc, char **argp)
+{
+	const char *opt;
+	size_t len;
+	int k;
+
+	for (k = 0; args[k].opts; k++) {
+		opt = args[k].opts;
+		for (;;) {
+			len = strcspn(opt, "|");
+			if (strncmp(*argp, opt, len) == 0 &&
+			    (*argp)[len] == 0)
+				return k;
+
+			if (opt[len] == 0)
+				break;
+			opt += len + 1;
+		}
+	}
+
+	return -1;
+}
+
 int main(int argc, char **argp)
 {
 	int (*func)(struct cmd_context *);
@@ -5284,24 +5307,14 @@  int main(int argc, char **argp)
 	 */
 	if (argc == 0)
 		exit_bad_args();
-	for (k = 0; args[k].opts; k++) {
-		const char *opt;
-		size_t len;
-		opt = args[k].opts;
-		for (;;) {
-			len = strcspn(opt, "|");
-			if (strncmp(*argp, opt, len) == 0 &&
-			    (*argp)[len] == 0) {
-				argp++;
-				argc--;
-				func = args[k].func;
-				want_device = args[k].want_device;
-				goto opt_found;
-			}
-			if (opt[len] == 0)
-				break;
-			opt += len + 1;
-		}
+
+	k = find_option(argc, argp);
+	if (k > 0) {
+		argp++;
+		argc--;
+		func = args[k].func;
+		want_device = args[k].want_device;
+		goto opt_found;
 	}
 	if ((*argp)[0] == '-')
 		exit_bad_args();