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 78281 Build 75164: arc lint + arc unit
Event Timeline
| sbin/kldinfo/kldinfo.c | ||
|---|---|---|
| 167 | This function would benefit from being broken up. You can start by moving everything from elf_begin() to elf_end() into a separate function. | |
| 186 | This line serves no purpose. | |
| 194 | What if argc > 1? | |
| 346 | Why else here and not continue as above? | |
| 347 | I would check print_ver first. | |
| 358 | Why is this going to stderr and not stdout? | |
| sbin/kldinfo/Makefile | ||
|---|---|---|
| 2–29 | There is nothing copyrightable in this file. | |
| sbin/kldinfo/Makefile | ||
|---|---|---|
| 2–29 | I think I just copied Makefile from some other tool (kldload), it has this copyright and license message. Ok, will remove it. | |
| sbin/kldinfo/kldinfo.c | ||
| 68 | Will do, where it is possible. Note that printf("%.*s") wants string size to be int. | |
| 73 | I hope you mean a lesser known "%.*s" feature of printf(3) ? Ok, will definitely use it. | |
| 169–175 | Ok. | |
| 178 | Did not know that. Ok, will use opt. | |
| 186 | Agreed. | |
| 194 | Will set limit to one (file) exactly. | |
| 197 | Ok, will also use warnx() for messages. | |
| 347 | Makes sense, yes. | |
| 358 | We might want to pass kldinfo output to some other command (sort?), this stat message will be a pain. | |
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 | ||
|---|---|---|
| 52–55 | none of these initializations are needed | |
| 107–108 | please use warnx() | |
| 111 | no cast is needed here | |
| 112–113 | please use warnx() | |
| 118–119 | please use warnx() | |
| 126 | size_t sorts after pointers | |
| 128 | structs go first | |
| 131 | you can avoid this if by normalizing the name upstream | |
| 132 | ...and you should check the return value | |
| 134 | ...and you should check the return value | |
| 162 | size_t sorts after pointers | |
| 326 | not really needed | |
| 345 | 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]. | |
| 350 | ||
| sbin/kldinfo/kldinfo.c | ||
|---|---|---|
| 52–55 | Agree. Will remove. | |
| 107–108 | Will do. I completely forgot about that. Sorry. | |
| 111 | Did not know that void* is compatible with any pointer in C. Thanks. | |
| 131 | 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. | |
| 326 | indeed. | |
| 345 | 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 | |