If realloc fails, do not override the still valid pointer with NULL.
Otherwise freeing the iterator won't free the previously allocated
buffer.
Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org> Reviewed-by: Emil Velikov <emil.l.velikov@gmail.com> Link: https://github.com/kmod-project/kmod/pull/82 Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
shared: use proper data types in freadline_wrapped
Do not use signed data types if unsigned arithmetic is expected,
i.e. use size_t if processing sizes and unsigned int for line numbers
due to given API of freadline_wrapped.
This fixes a possible signed integer overflow on 64 bit systems.
Signed-off-by: dependabot[bot] <support@github.com> Reviewed-by: Emil Velikov <emil.l.velikov@gmail.com> Link: https://github.com/kmod-project/kmod/pull/80 Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
Calling free(NULL) is valid. No need for previous if-check.
Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org> Reviewed-by: Emil Velikov <emil.l.velikov@gmail.com> Link: https://github.com/kmod-project/kmod/pull/79 Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
If a relative path is supplied, the conversion to an absolute path can
fail, e.g. if current working directory does not exist anymore.
Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org> Reviewed-by: Emil Velikov <emil.l.velikov@gmail.com> Link: https://github.com/kmod-project/kmod/pull/79 Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
Lucas De Marchi [Fri, 16 Aug 2024 19:01:22 +0000 (14:01 -0500)]
build: Set AM_DISTCHECK_CONFIGURE_FLAGS
Follow the usual approach for flags in autotools: Set the AM_ variant
so the user may set the non-AM variant that is appended. This is needed
to pass additional flags from the configure to the configure call done
while creating the dist tarball if something doesn't match the default.
Lucas De Marchi [Fri, 16 Aug 2024 13:41:11 +0000 (08:41 -0500)]
build: Add mod-weakdep.ko to cache
A long forgotten feature of the build system: we commit the built
modules from playground so distros can build without linux-headers
available.
Cc: Marco d'Itri <md@linux.it> Closes: https://lore.kernel.org/linux-modules/Zr3A96SfR21UjdL1@bongo.bofh.it Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com> Reviewed-by: Emil Velikov <emil.l.velikov@gmail.com> Link: https://github.com/kmod-project/kmod/pull/78
Emil Velikov [Fri, 16 Aug 2024 15:19:38 +0000 (16:19 +0100)]
ci: use hash-pinned workflow actions, update checkout
The tags are mutable and groups like Google Open Source Security Team
(GOSST) are suggesting use of hash-pinned (alongside the tag as comment)
actions.
The dependabot just introduced, can handle the format automatically.
Ref: https://github.com/libarchive/libarchive/issues/1959 Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com> Link: https://github.com/kmod-project/kmod/pull/76 Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
Emil Velikov [Fri, 16 Aug 2024 13:48:35 +0000 (14:48 +0100)]
ci: add dependabot.yml
It's a scheduled action, which checks if any of the actions used are out
of date. If so, it will open a PR with a summary of the changes in the
new version.
Emil Velikov [Fri, 16 Aug 2024 13:39:57 +0000 (14:39 +0100)]
.editorconfig: add initial config file
Most editors support the config format out of the box and with some
upcoming new yml files, I think it's great to have something in-tree to
avoid miss-matched style.
Copy-pasted from Mesa, with minor changes - tab for indent (C), remove
irrelevant sections. Keep the meson section - meson patches will be
comings shortly.
Lucas De Marchi [Fri, 16 Aug 2024 04:17:11 +0000 (23:17 -0500)]
testsuite: Rename test-user
First version of the patches implementing weakdep called them "user
dep", hence the name of the test. That doesn't make sense anymore after
the rename. Rename the test accordingly.
An error during array_realloc is always ignored if the idea
was to save memory by trimming an array.
Move two occurrences of same code into a single function for
easier reviewing.
Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org> Reviewed-by: Emil Velikov <emil.l.velikov@gmail.com> Link: https://github.com/kmod-project/kmod/pull/68 Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
- Make sure that SIZE_MAX boundaries are never crossed
- Clear pointer address in struct during array_free_array
- Do nothing if array_pop is called with empty array
Also added test case for pop behavior and extended tests with
more checks.
Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org> Reviewed-by: Emil Velikov <emil.l.velikov@gmail.com> Link: https://github.com/kmod-project/kmod/pull/68 Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
The position in array_remove_at could be theoretically larger
than unsigned int. Switch to size_t to stay in sync with all
other such arguments in array context.
Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org> Reviewed-by: Emil Velikov <emil.l.velikov@gmail.com> Link: https://github.com/kmod-project/kmod/pull/68 Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
If array operations fail, forward the error instead of silently
ignoring it and continuing the operation.
Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org> Reviewed-by: Emil Velikov <emil.l.velikov@gmail.com> Link: https://github.com/kmod-project/kmod/pull/68 Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
The command line option P takes one argument, which is supposed to
contain exactly one character. The current check performs an out
of boundary read if an empty string is supplied.
If a root path is specified which is PATH_MAX - 1 characters long
and option -A is specified, then depfile_up_to_date_dir triggers
an out of boundary write during slash addition.
Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org> Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
Christian Hesse [Wed, 14 Aug 2024 07:58:16 +0000 (09:58 +0200)]
testsuite: fix path for test-user
... as this just does not find its paths.
Closes: https://github.com/kmod-project/kmod/issues/69 Fixes: 9d1fb31 ("libkmod, depmod, modprobe: Make directory for kernel modules configurable") Signed-off-by: Christian Hesse <mail@eworm.de> Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
Reviewed-by: Emil Velikov <emil.l.velikov@gmail.com> Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org> Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
libkmod: avoid undefined behaviour in libkmod-builtin.c:get_string
Static analysis has reported a potential UB:
kmod-31/libkmod/libkmod-builtin.c:125: use_invalid: Using "nullp", which points to an out-of-scope variable "buf".
# 123| size_t linesz = 0;
# 124|
# 125|-> while (!nullp) {
# 126| char buf[BUFSIZ];
# 127| ssize_t sz;
It seems to be indeed an UB, as nullp is getting assined an address
inside object buf, which has a lifetime of the while loop body,
and is not available outside of it (specifically, in the while
condition, where nullp is checked for NULL). Fix it by putting
buf definition in the outer block.
Emil Velikov [Sat, 10 Aug 2024 12:25:16 +0000 (13:25 +0100)]
m4: remove verbose license exception clause
It is already encoded in the SPDX license identifier.
Cc: Lucas De Marchi <lucas.de.marchi@gmail.com> Fixes: b5a2cd0 ("Use SPDX header for license") Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com> Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
Emil Velikov [Sat, 10 Aug 2024 12:25:15 +0000 (13:25 +0100)]
m4: reinstate CC_CHECK_FLAG_APPEND summary
Earlier commit was reducing the license boilerplate to SPDX license
identifiers and erroneously dropped the function summary section.
Cc: Lucas De Marchi <lucas.de.marchi@gmail.com> Fixes: b5a2cd0 ("Use SPDX header for license") Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com> Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
Lucas De Marchi [Tue, 23 Jul 2024 18:59:21 +0000 (13:59 -0500)]
depmod: Remove license/copyright from the middle
The top license is enough as it's the same. Just move the copyright to
the top and remove notice about code that was copied and modified: that
comment doesn't age well as source is updated.
Lucas De Marchi [Tue, 23 Jul 2024 18:59:19 +0000 (13:59 -0500)]
Use SPDX header for license
Drop the lengthy license from each file and just use SPDX like most
projects nowadays. This doesn't have any change to license, just how
they are recorded in each file.
This follows the kernel approach: header files use '/*' for comments
while .c files use '//'. For .m4, use "#".
Emil Velikov [Fri, 19 Jul 2024 16:12:43 +0000 (17:12 +0100)]
libkmod: move new weak API to separate section
Add the new weak API, to a separate section in the version script. These
will be exposed with the upcoming v33 release and not with v5 as the
symbol tag implies.
Cc: Jose Ignacio Tornos Martinez <jtornosm@redhat.com> Fixes: 05828b4 ("libkmod: add weak dependecies") Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com> Reviewed-by: Lucas De Marchi <lucas.demarchi@intel.com> Link: https://lore.kernel.org/r/20240719-abi-fixes-v1-3-1e6d99a2846b@gmail.com
Emil Velikov [Fri, 19 Jul 2024 16:12:42 +0000 (17:12 +0100)]
libkmod: correctly tag kmod_module_new_from_name_lookup
The symbol was introduced with v30, yet was erroneously added in the v5
section. Move it to the correct place.
In theory this might cause an issue - severity depends on how the
runtime linker is setup. From a harmless warning (on stderr/stdout) to
failure to load the library.
In practise this shouldn't be a problem, since there are seemingly no
external users of the API.
Emil Velikov [Fri, 19 Jul 2024 16:12:41 +0000 (17:12 +0100)]
libkmod: document KMOD_INDEX_MODULES_BUILTIN_ALIAS in kmod_dump_index()
The extra enum was introduced a few years ago, although the (only)
function using it did not have it's documentation updated.
The commit itself has caused an ABI break with kmod v27, since the
KMOD_INDEX_MODULES_BUILTIN value has changed.
A search through Google, Github and Arch packages have shown one user of
kmod_dump_index() - the only API that uses the enum.
In that case and all others, no projects referencing the changed enum
were found. Although since recent and/or supported distros use kmod v27
or later we've decided to only update the documentation.
Cc: Alexey Gladkov <gladkov.alexey@gmail.com> Fixes: b866b21 ("Lookup aliases in the modules.builtin.modinfo") Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com> Reviewed-by: Lucas De Marchi <lucas.demarchi@intel.com> Link: https://lore.kernel.org/r/20240719-abi-fixes-v1-1-1e6d99a2846b@gmail.com
Emil Velikov [Wed, 17 Jul 2024 17:26:45 +0000 (18:26 +0100)]
kmod: remove .alias config files for modprobe.d
The use of .alias (alongside .conf) was added for compatibility with the
original module-init-tools project and has been living in kmod ever
since.
In practise, all the linux distributions that I can see are using .conf
files alone, as instructed by modprobe.d(5) and the only instance of an
.alias file is the modules.alias as shipped in the kernel.
The latter is already handled by other parts of the kmod project, so
let's enforce what our documentation says.
Lucas De Marchi [Fri, 12 Jul 2024 18:12:10 +0000 (13:12 -0500)]
ci: Add Fedora
Add an action to setup latest Fedora and use it for the initial setup.
Add hack on /usr/lib/modules so /usr/lib/modules/*/build can still be
used in the rest of the workflow as the KDIR.
Lucas De Marchi [Fri, 12 Jul 2024 17:06:42 +0000 (12:06 -0500)]
ci: Add Archlinux
Add an action to setup Archlinux and use it for the initial setup.
The rest of the workflow can stay the same.
Currently the Arch container in docker hub is not very up-to-date with
some expired keys and other keys not yet in the package. Workaround
that by wiping the current db and reinstalling the keyring. As requested
by Emil, add a comment in this part of the github-action about why
that is done.
Lucas De Marchi [Fri, 12 Jul 2024 16:06:07 +0000 (11:06 -0500)]
ci: Use a container and expand versions
Use containers to build/test so it's not restricted to the OS versions
supported by Github runners. A few changes are needed to the workflow to
support using containers:
1) No need for sudo, so remove it
2) Explicitly install missing zlib
3) Explicitly pass KDIR= while building kernel modules, since it
won't match `uname -r`. This assumes the container has just
one kernel installed and so /usr/lib/modules/*/build can be
used as the single symlink to the kernel headers. This should
be common to other distros to be added, too.
Lucas De Marchi [Fri, 12 Jul 2024 13:24:49 +0000 (08:24 -0500)]
README: update to a decade+ later
- State support for clang and other libc's
- Fix typos
- Reword the compatibility with module-init-tools section,
removing most of the specific examples as we didn't keep
track of all of them, and they are not important anymore
in year 2024
q66 [Mon, 17 Jun 2024 23:22:06 +0000 (01:22 +0200)]
libkmod: improve realloc behavior for zstd outbuffer
The allocator in glibc has a particular quirk that successive
reallocs on the same pointer are cheap, at the cost of excess
memory fragmentation. Other allocators generally do not do this,
so excessive reallocs become relatively expensive.
Reducing the number of reallocations by using a more agressive
strategy for buffer size increase makes performance better on
those setups, e.g. musl libc, or generally any other allocator;
on my Chimera Linux setup with Scudo allocator (LLVM) it doubles
to triples the performance of running e.g. depmod.
Signed-off-by: q66 <q66@chimera-linux.org> Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
Lucas De Marchi [Tue, 9 Jul 2024 04:47:57 +0000 (23:47 -0500)]
build: Add mod-weakdep.c to EXTRA_DIST
Fix distcheck failure:
make[5]: *** No rule to make target
'/home/runner/work/kmod/kmod/build/kmod-32/_build/sub/testsuite/module-playground/mod-weakdep.o',
needed by
'/home/runner/work/kmod/kmod/build/kmod-32/_build/sub/testsuite/module-playground/'.
Stop.
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
Emil Velikov [Mon, 8 Jul 2024 13:43:25 +0000 (14:43 +0100)]
man: list options one per line
Somewhat inspired by my selfish use of VIM as man pager. Namely, when
there are multiple options on the same line, only the first one gets
properly rendered.
A good bonus point is that very long instances, like modinfo's legacy
"--author, --description ..." look a bit neater now.
With this is also more consistently handle short/long options which take
an argument.
Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com> Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
Emil Velikov [Tue, 11 Jun 2024 15:05:03 +0000 (16:05 +0100)]
man: build the scdoc based man pages
Note that scdoc does not handle natively handle the dummy
modules.dep.bin.5 entry, so we need to create one manually.
Not a big deal, since it's single static line anyway.
Also: pkg-config --variable=scdoc scdoc, produces the full executable
and path, although for now we stick with the AC_PATH_PROG approach.
Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
[ Do not add the stub man page (modules.dep.bin.5) to CLEANFILES
to avoid removing a file that is tracked by git. Also fix a typo
s/AM_V_SCDOR_/AM_V_SCDOC_/ to make silent rules to work ] Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
The following tests to verify weak dependencies have been implemented:
1) modprobe test to check that related weakdep modules are not loaded
due to being a weakdep.
2) depmod test to check weakdep output.
3) user test to check that configuration files with weakdep are parsed
correctly and related weakdep modules can be read correctly from user
applications.
Signed-off-by: Jose Ignacio Tornos Martinez <jtornosm@redhat.com> Link: https://lore.kernel.org/r/20240530070836.9438-1-jtornosm@redhat.com
[ Minor whitespace issues and define MODULE_WEAKDEP if it's not defined
already ] Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
Lucas De Marchi [Tue, 11 Jun 2024 13:02:26 +0000 (08:02 -0500)]
depmod: Fix warning with -D_TIME_BITS=64
Printing time_t, suseconds_t, useconds_t in 32bits with -D_TIME_BITS=64
leads to the following warning:
../tools/depmod.c:2641:61: warning: format ‘%li’ expects argument of type ‘long int’, but argument 6 has type ‘__suseconds64_t’ {aka ‘long long int’} [-Wformat=]
2641 | snprintf(tmp, sizeof(tmp), "%s.%i.%li.%li", itr->name, getpid(),
| ~~^
| |
| long int
| %lli
2642 | tv.tv_usec, tv.tv_sec);
| ~~~~~~~~~~
Paper it over by casting the argument to 64 bits and switching to long long.
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
Khem Raj [Sun, 10 Dec 2023 01:35:59 +0000 (17:35 -0800)]
Use portable implementation for basename API
musl has removed the non-prototype declaration of basename from
string.h [1] which now results in build errors with clang-17+ compiler
Implement GNU basename behavior using strchr which is portable across libcs
Fixes
../git/tools/kmod.c:71:19: error: call to undeclared function 'basename'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration]
71 | "Commands:\n", basename(argv[0]));
| ^
Suggested-by: Rich Felker Signed-off-by: Khem Raj <raj.khem@gmail.com>
[ Implement a basename() function in missing.h and ensure we always use
the right include rather than having a separate gnu_basename() ] Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
It has been seen that for some network mac drivers (i.e. lan78xx) the
related module for the phy is loaded dynamically depending on the current
hardware. In this case, the associated phy is read using mdio bus and then
the associated phy module is loaded during runtime (kernel function
phy_request_driver_module). However, no software dependency is defined, so
the user tools will no be able to get this dependency. For example, if
dracut is used and the hardware is present, lan78xx will be included but no
phy module will be added, and in the next restart the device will not work
from boot because no related phy will be found during initramfs stage.
In order to solve this, we could define a normal 'pre' software dependency
in lan78xx module with all the possible phy modules (there may be some),
but proceeding in that way, all the possible phy modules would be loaded
while only one is necessary.
The idea is to create a new type of dependency, that we are going to call
'weak' to be used only by the user tools that need to detect this situation.
In that way, for example, dracut could check the 'weak' dependency of the
modules involved in order to install these dependencies in initramfs too.
That is, for the commented lan78xx module, defining the 'weak' dependency
with the possible phy modules list, only the necessary phy would be loaded
on demand keeping the same behavior, but all the possible phy modules would
be available from initramfs.
A new function 'kmod_module_get_weakdeps' in libkmod will be added for
this to avoid breaking the API and maintain backward compatibility. This
general procedure could be useful for other similar cases (not only for
dynamic phy loading).
Emil Velikov [Mon, 12 Feb 2024 17:23:13 +0000 (17:23 +0000)]
libkmod: keep KMOD_FILE_COMPRESSION_NONE/load_reg in comp_types
It's cleaner to handle all compression types and load functions in the
same style.
Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com> Reviewed-by: Lucas De Marchi <lucas.demarchi@intel.com> Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
Emil Velikov [Mon, 12 Feb 2024 17:23:12 +0000 (17:23 +0000)]
libkmod: move load_reg() further up
We're about to reference it in comp_types with next commit.
Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com> Reviewed-by: Lucas De Marchi <lucas.demarchi@intel.com> Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
Emil Velikov [Mon, 12 Feb 2024 17:23:11 +0000 (17:23 +0000)]
libkmod: tidy-up kmod_file_open()
This commit cleans up the indentation and the error path of the
function. It bears no functional changes.
Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
[ Move assert to avoid warning with -Wdeclaration-after-statement ] Reviewed-by: Lucas De Marchi <lucas.demarchi@intel.com> Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
Emil Velikov [Mon, 12 Feb 2024 17:23:10 +0000 (17:23 +0000)]
libkmod: swap alloca usage for a few assert_cc
Since all the compression magic is always available now, we don't need
to loop at runtime nor use alloca - latter of which comes with a handful
of caveats.
Simply throw in a few assert_cc(), which will trigger at build-time.
Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com> Reviewed-by: Lucas De Marchi <lucas.demarchi@intel.com> Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
Emil Velikov [Mon, 12 Feb 2024 17:23:09 +0000 (17:23 +0000)]
libkmod: always detect the module compression
Currently, when built w/o given compression we'll incorrectly report a
"compression_none".
As we reach do_finit_module(), we'll naively assume that the kernel can
handle the compressed module, yet omit the MODULE_INIT_COMPRESSED_FILE
flag.
As result the kernel will barf at us, do_finit_module will fail with non
-ENOSYS and we won't end in the do_init_module codepath (which will also
fail).
In other words: with this change, you can build kmod without zstd, xz
and zlib support and the kernel will load the modules, assuming it
supports the format \o/
Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com> Reviewed-by: Lucas De Marchi <lucas.demarchi@intel.com> Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
Emil Velikov [Mon, 12 Feb 2024 17:23:08 +0000 (17:23 +0000)]
libkmod: move kmod_file_load_contents as applicable
When dealing with an elf, we don't know or care about loading the file.
The kmod_elf subsystem/API will deal with the required parts itself.
Which in this case, already calls kmod_file_load_contents() as
applicable.
Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com> Reviewed-by: Lucas De Marchi <lucas.demarchi@intel.com> Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
Emil Velikov [Mon, 12 Feb 2024 17:23:07 +0000 (17:23 +0000)]
libkmod: propagate {zstd,xz,zlib}_load errors
Propagate any errors during decompression further up the call stack.
Without this we could easily pass NULL as mem to init_module(2).
Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com> Reviewed-by: Lucas De Marchi <lucas.demarchi@intel.com> Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
Emil Velikov [Mon, 12 Feb 2024 17:23:06 +0000 (17:23 +0000)]
libkmod: nuke struct file_ops
With the previous commits, we removed the need for a distinct unload
callback.
So nuke the struct all together and only use/keep the load one around.
Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com> Reviewed-by: Lucas De Marchi <lucas.demarchi@intel.com> Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
Emil Velikov [Mon, 12 Feb 2024 17:23:05 +0000 (17:23 +0000)]
libkmod: clear file->memory if map fails
On mmap failure file->memory is set to -1, which we'll happily pass down
to munmap later on.
More importantly, since we do a NULL check in kmod_file_load_contents()
we will exit the function without (re)attempting the load again.
Since we ignore the return code for the load function(s), one can end up
calling kmod_elf_get_memory() and feed that -1 into init_module.
Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com> Reviewed-by: Lucas De Marchi <lucas.demarchi@intel.com> Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
Emil Velikov [Mon, 12 Feb 2024 17:23:04 +0000 (17:23 +0000)]
libkmod: remove kmod_file::{zstd,xz}_used flags
These are used to protect a free(file->memory), within their respective
unload functions. Where the sole caller of the unload function already
does a NULL check prior.
Even so, free(NULL) is guaranteed to be safe by the standard.
Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com> Reviewed-by: Lucas De Marchi <lucas.demarchi@intel.com> Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
Emil Velikov [Mon, 12 Feb 2024 17:23:03 +0000 (17:23 +0000)]
libkmod: keep gzFile gzf local to load_zlib()
There is no need to keep the root gzFile context open for the whole
duration. Once we've copied the decompressed module to file->memory we
can close the handle.
Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com> Reviewed-by: Lucas De Marchi <lucas.demarchi@intel.com> Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
Emil Velikov [Mon, 12 Feb 2024 17:23:02 +0000 (17:23 +0000)]
libkmod: use a dup()'d fd for zlib
The gzdopen() API used, takes ownership of the fd. To make that more
explicit we clear it (-1) as applicable.
Yet again, kmod has explicit API to return the fd to the user - which
currently is used solely when uncompressed, so we're safe.
Regardless - simply duplicate the fd locally and use that with zlib.
Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com> Reviewed-by: Lucas De Marchi <lucas.demarchi@intel.com> Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
Lucas De Marchi [Wed, 6 Mar 2024 14:58:04 +0000 (08:58 -0600)]
build: Allow to install over dirty dir
Before commit e98cef6f3f8c ("make: install/uninstall tools symlinks to
kmod") it was possible to call `make install DESTDIR=<dir>` multiple
times. Use `ln -sf` so the symlink is always re-created.
It would be preferred to remove install in an empty dir, but there's
not a bad consequence of re-using the same, so let the user decide.
Fixes the following errors while installing for the second time:
ln: failed to create symbolic link '/tmp/inst/usr/bin/insmod': File exists
ln: failed to create symbolic link '/tmp/inst/usr/bin/lsmod': File exists
ln: failed to create symbolic link '/tmp/inst/usr/bin/rmmod': File exists
ln: failed to create symbolic link '/tmp/inst/usr/bin/depmod': File exists
ln: failed to create symbolic link '/tmp/inst/usr/bin/modprobe': File exists
ln: failed to create symbolic link '/tmp/inst/usr/bin/modinfo': File exists
make[3]: *** [Makefile:2679: install-exec-hook] Error 1
make[2]: *** [Makefile:2553: install-exec-am] Error 2
make[1]: *** [Makefile:2439: install-am] Error 2
make: *** [Makefile:1848: install-recursive] Error 1
Emil Velikov [Sat, 17 Feb 2024 16:01:26 +0000 (16:01 +0000)]
man: silence autoconf warnings
Currently we have a pattern rule, which effective states that two output
files are produced - %.5 and %.8. Although that's not the case in
practise, since each input xml will be generated to a single manual
page.
Add the manpage section as part of the xml filename and tweak the
pattern (match) rule, accordingly.
Emil Velikov [Fri, 26 Jan 2024 14:43:51 +0000 (14:43 +0000)]
make: install/uninstall tools symlinks to kmod
Currently we create symlinks like modprobe (pointing to kmod), during
the normal `make` build. Although those were never installed.
Add a few lines in the install-exec-hook, to ensure they're present at
`make install` time. Thus one can actually use those without additional
changes. As an added bonus, distributions can drop the similar hunk from
their packaging.
Signed-off-by: Emil Velikov <emil.velikov@collabora.com>
[ Use a relative symlink ] Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>