kldinfo utility parses ELF header of a given KLD module file, then searches for
available Kernel Loadable objects and shows their dependency and version
information. If path to file is given the utility tries to open it directly.
It quits if open fails. Otherwise, it searches for .ko in directories set by
kern.module_path sysctl variable. Can be used to show builtin modules in kernel.
Details
Diff Detail
- Repository
- rG FreeBSD src repository
- Lint
Lint Skipped - Unit
Tests Skipped - Build Status
Buildable 79355 Build 76238: arc lint + arc unit
Event Timeline
More coding style rework
- Order variables
- Use err(3) for errors and warnx(3) for messages
- Eliminate use of strncat(3) in favour of printf("%.*s)
- Remove unnecessary copyright message from Makefile
- Rename some vars, use temp var for base address
- Accept only one file in args
- Misc.
Even more code style rework, add support for arbitrary num of files
- Reorder local vars by occupied amount of mem.
- Add support for arbitrary files, reflect feature in man page.
- Split main(), move all processing logic to process_module_file().
- Fix usage().
| sbin/kldinfo/kldinfo.c | ||
|---|---|---|
| 53–56 | none of these initializations are needed | |
| 108–109 | please use warnx() | |
| 112 | no cast is needed here | |
| 113–114 | please use warnx() | |
| 119–120 | please use warnx() | |
| 127 | size_t sorts after pointers | |
| 129 | structs go first | |
| 132 | you can avoid this if by normalizing the name upstream | |
| 133 | ...and you should check the return value | |
| 135 | ...and you should check the return value | |
| 163 | size_t sorts after pointers | |
| 327 | not really needed | |
| 346 | this is a nit but if you are treating argv here as an iterator rather than an array, then *argv is more appropriate than argv[0]. | |
| 351 | ||
| sbin/kldinfo/kldinfo.c | ||
|---|---|---|
| 53–56 | Agree. Will remove. | |
| 108–109 | Will do. I completely forgot about that. Sorry. | |
| 112 | Did not know that void* is compatible with any pointer in C. Thanks. | |
| 132 | Normalizing name upstream will make it impossible to use arbitrary file as input, i.e. /boot/kernel/kernel. I'll take that "if" out and put before the loop, so it will be called once. | |
| 327 | indeed. | |
| 346 | Ok, will use *argv. | |
Yet some more code style rework
- Remove unnecessary initialization.
- Eliminate progname global var as it's used only once.
- Use err(3) to fail in find_module_file().
- Reorder variables (size_t after pointer).
- Take strstr() out of the loop.
- Use *argv instead of argv[0].
- Return with exit(EX_OK) on success.
- The -r option does not appear to work.
- The output format could use some work, perhaps something in key=value form would be better. Try to think of how a shell script running kldinfo on a single file would ingest the output. Consider adding libxo support in a future revision.
| sbin/kldinfo/kldinfo.8 | ||
|---|---|---|
| 6 | this has no legal value | |
| sbin/kldinfo/kldinfo.c | ||
| 6 | this has no legal value | |
| 53 | this should be a static local variable in find_module() | |
| 125–126 | better yet, use asprintf(3) instead. | |
| 125–126 | sorry, I meant to drop this before hitting submit on my review, using a static buffer is fine. | |
| 279 | the assignment serves no purpose | |
| 282 | the assignment serves no purpose | |
Thank you for finding time to get back to this diff!
Erm.. what makes you think so ? :) Here below are two examples of using -r
rz@butterfly:~/FreeBSD-src/kldinfo % ./kldinfo amdgpio MODULE: amdgpio_acpi DEPENDS: kernel VERSION: 1501000 1501000 1501000 MODULE: amdgpio DEPENDS: acpi VERSION: 1 1 1 MODULE: amdgpio DEPENDS: gpiobus VERSION: 1 1 1 kldinfo: found 3 dependencies in /boot/kernel/amdgpio.ko rz@butterfly:~/FreeBSD-src/kldinfo % ./kldinfo -r amdgpio MODULE: amdgpio_acpi DEPENDS: kernel VERSION: 1501000 1501000 1501000 MODULE: amdgpio DEPENDS: acpi VERSION: 1 1 1 MODULE: amdgpio DEPENDS: gpiobus VERSION: 1 1 1 OBJECT: amdgpio VERSION: 1 kldinfo: found 3 dependencies in /boot/kernel/amdgpio.ko
rz@butterfly:~/FreeBSD-src/kldinfo % ./kldinfo /boot/kernel/kernel | wc -l
kldinfo: found 926 dependencies in /boot/kernel/kernel
926
rz@butterfly:~/FreeBSD-src/kldinfo % ./kldinfo -r /boot/kernel/kernel | wc -l
kldinfo: found 926 dependencies in /boot/kernel/kernel
1121
- The output format could use some work, perhaps something in key=value form would be better. Try to think of how a shell script running kldinfo on a single file would ingest the output.
I fully agree. My initial idea was to produce human readable output which also could be easily parsable using grep, awk and others, it has some drawbacks of course. Proper solution would be to produce machine readable output as per your following suggestion:
Consider adding libxo support in a future revision.
I like the idea of libxo, but I never used it before. I looked through the man page, I think I'll rewrite kldinfo utility using xo API in next revision. Currently I would prefer it to go this "classical" way, if possible. :) I'm working on adding PNP and firmware list to the output, as suggested by imp@. That's a bit more tricky and more interesting. ;-)
| sbin/kldinfo/kldinfo.c | ||
|---|---|---|
| 53 | Good point. Will fix it. | |
| 282 | Yup. Will remove useless assignments. | |
Code polishing
- Remove useless assignments.
- Make static buffer mod_file local to find_module_file().
- Remove "All rightis reserved" string from copyright.
| sbin/kldinfo/kldinfo.8 | ||
|---|---|---|
| 27 | additionally, we updated the preferred license template for new files. the linux foundation has been campaigning for several years to make it acceptable to only use the SPDX short form, and we have adopted that along with many other projects. Take a look: | |
| 33–34 | the spec for Nd is "one line about what it does". This is too long. This field is for listing in search results and also makes up the search keywords for whatis. When I'm doing these, I like to check what has been said about the utilities around it, so that the system looks cohesively designed. Maybe: show kld file dependency and version | |
| 38 | Consider something like this, or alternatively something like this: .Sh SYNOPSIS .Nm .Op Fl rv .Ar filename.ko .Nm .Op Fl rv .Ar modname .Nm .Op Fl rv .Ar kernel .Sh DESCRIPTION My goal is that synopsis should show there are (iiuc) three possible things to give this: a module name, a module path, and the kernel itself. | |
| 50 | ||
| 67 | I would prefer for this section to be worked into DESCRIPTION | |
| 79 | ||
| 80 | imho this sentence should not go here. it should be worked into the sentence on line 52. | |
| 86–104 |
| |
| sbin/kldinfo/kldinfo.c | ||
| 27 | Ditto | |
I have had some spare time tonight, so I decided to take a closer look on libxo. The result is in the update. ;)
Dude, adding libxo is totally awesome!
| sbin/kldinfo/kldinfo.8 | ||
|---|---|---|
| 15 | (I think, you'll have to double check other libxo utilities) | |
| 33–34 | This one is still not done. Please try the command apropos kld to see how this is done so far for everything else in this problem space. | |
| 41 | ||
| 62 | We use a table style for FILES. Please keep it alphabetically sorted. Also, try marking up paths with Pa, the path macro. It adds them them to the search database. Sorry I'm on phone so I can't highlight the whole section, so I just did the suggestion accordingly. | |
Polish man page
- Add missing --libxo flag to SYNOPSYS
- Rephrase .Nd text
- Restyle FILES section
I leave logic implementation details to senior src colleagues, but the manpage looks great to me.