Skip to content

Various getopt nitpicks - #453

Closed
evelikov wants to merge 5 commits into
kmod-project:masterfrom
evelikov:getopt
Closed

Various getopt nitpicks#453
evelikov wants to merge 5 commits into
kmod-project:masterfrom
evelikov:getopt

Conversation

@evelikov

@evelikov evelikov commented Aug 2, 2026

Copy link
Copy Markdown
Collaborator

A small series that started off with "hey, let me add a test for modinfo --invalid" and ended up homogenising the getopt usage in-tree.

@codecov

codecov Bot commented Aug 2, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 29.26829% with 29 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
tools/static-nodes.c 0.00% 7 Missing ⚠️
tools/kmod.c 0.00% 5 Missing ⚠️
tools/insmod.c 0.00% 3 Missing ⚠️
tools/lsmod.c 0.00% 3 Missing ⚠️
tools/rmmod.c 0.00% 3 Missing ⚠️
testsuite/testsuite.c 60.00% 2 Missing ⚠️
tools/depmod.c 60.00% 2 Missing ⚠️
tools/modinfo.c 60.00% 2 Missing ⚠️
tools/modprobe.c 60.00% 2 Missing ⚠️
Files with missing lines Coverage Δ
testsuite/testsuite.c 56.12% <60.00%> (+0.83%) ⬆️
tools/depmod.c 57.06% <60.00%> (+0.31%) ⬆️
tools/modinfo.c 48.63% <60.00%> (-1.17%) ⬇️
tools/modprobe.c 27.93% <60.00%> (-0.31%) ⬇️
tools/insmod.c 0.00% <0.00%> (ø)
tools/lsmod.c 0.00% <0.00%> (ø)
tools/rmmod.c 0.00% <0.00%> (ø)
tools/kmod.c 14.28% <0.00%> (-0.53%) ⬇️
tools/static-nodes.c 0.00% <0.00%> (ø)

... and 10 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@evelikov
evelikov force-pushed the getopt branch 2 times, most recently from 11e9fe7 to af7853f Compare August 3, 2026 20:50
@evelikov

evelikov commented Aug 3, 2026

Copy link
Copy Markdown
Collaborator Author

v2:

  • clang-format tweaks and commit message polish in last commit

Comment thread tools/kmod.c Outdated
The struct option::flag is of type "int *", so we should be using NULL
instead of 0. In addition, the sentinel entry can be left completely
empty.

With those in place, we can drop most of the clang-format notations.

Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
Signed-off-by: Lucas De Marchi <ldemarchi@kernel.org>
Pull the unistd.h for optind and adjust the loop to follow the
in-documentation example.

In addition, we don't need the unused idx.

Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
Signed-off-by: Lucas De Marchi <ldemarchi@kernel.org>
Was meaning to add a negative test or two to modinfo - where a invalid
option is passed into the program - only to notice that the default will
print the path, alongside the program name.

While fixing that, I've decided to pimp-up the reporting to also show
the help screen.

Eg. from this:

/usr/bin/insmod: unrecognized option '--versoin'

... to this

insmod: ERROR: unrecognised option '--versoin'

Usage:
	insmod [options] filename [module options]
Options:
	-f, --force              DANGEROUS: forces a module load, may cause
	                         data corruption and crash your machine.
	                         implies --force-modversion and
	                         --force-vermagic
	    --force-modversion   Ignore module's version
	    --force-vermagic     Ignore module's version magic
	-s, --syslog             print to syslog, not stderr
	-v, --verbose            enables more messages
	-V, --version            show version
	-h, --help               show this help

Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
Signed-off-by: Lucas De Marchi <ldemarchi@kernel.org>
Lucas De Marchi added 2 commits August 5, 2026 09:07
Fix 47999f7 ("ci: Workaround alpine CI build")

Signed-off-by: Lucas De Marchi <ldemarchi@kernel.org>
lucasdemarchi pushed a commit that referenced this pull request Aug 5, 2026
The struct option::flag is of type "int *", so we should be using NULL
instead of 0. In addition, the sentinel entry can be left completely
empty.

With those in place, we can drop most of the clang-format notations.

Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
Link: #453
Signed-off-by: Lucas De Marchi <ldemarchi@kernel.org>
lucasdemarchi pushed a commit that referenced this pull request Aug 5, 2026
Pull the unistd.h for optind and adjust the loop to follow the
in-documentation example.

In addition, we don't need the unused idx.

Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
Link: #453
Signed-off-by: Lucas De Marchi <ldemarchi@kernel.org>
lucasdemarchi pushed a commit that referenced this pull request Aug 5, 2026
Was meaning to add a negative test or two to modinfo - where a invalid
option is passed into the program - only to notice that the default will
print the path, alongside the program name.

While fixing that, I've decided to pimp-up the reporting to also show
the help screen.

Eg. from this:

/usr/bin/insmod: unrecognized option '--versoin'

... to this

insmod: ERROR: unrecognised option '--versoin'

Usage:
	insmod [options] filename [module options]
Options:
	-f, --force              DANGEROUS: forces a module load, may cause
	                         data corruption and crash your machine.
	                         implies --force-modversion and
	                         --force-vermagic
	    --force-modversion   Ignore module's version
	    --force-vermagic     Ignore module's version magic
	-s, --syslog             print to syslog, not stderr
	-v, --verbose            enables more messages
	-V, --version            show version
	-h, --help               show this help

Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
Link: #453
Signed-off-by: Lucas De Marchi <ldemarchi@kernel.org>
@lucasdemarchi

Copy link
Copy Markdown
Contributor

Applied, thanks

@evelikov
evelikov deleted the getopt branch August 6, 2026 17:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants