421 Commits

Author SHA1 Message Date
Tobias Stoeckmann
2537c171bc modprobe: return error on timeout
If module cannot be removed in time, return with a failure, not success:

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
Link: https://github.com/kmod-project/kmod/pull/377
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
2025-07-07 10:20:33 -05:00
Lucas De Marchi
5eac1d728c tools/modprobe: --dry-run shouldn't need -v
Make sure it shows something when running in dry-run mode.

Before:
	kmod $ lsmod | grep i915
	kmod $ ./build/modprobe --dry-run i915
	kmod $ ./build/modprobe -v --dry-run i915
	insmod /lib/modules/6.14.11-1-MANJARO/kernel/drivers/char/agp/intel-gtt.ko.zst
	insmod /lib/modules/6.14.11-1-MANJARO/kernel/drivers/gpu/drm/i915/i915.ko.zst

After:
	kmod $ lsmod | grep i915
	kmod $ ./build/modprobe --dry-run i915
	insmod /lib/modules/6.14.11-1-MANJARO/kernel/drivers/char/agp/intel-gtt.ko.zst
	insmod /lib/modules/6.14.11-1-MANJARO/kernel/drivers/gpu/drm/i915/i915.ko.zst

Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
Link: https://github.com/kmod-project/kmod/pull/372
2025-06-16 07:36:44 -05:00
Lucas De Marchi
15edeed386 tools/modprobe: Fix odd --remove-holders behavior
--remove-holders was not implying --remove, which means that if the user
called `modprobe --remove-holders xe` it would actually try to insert
the xe module. Fix it and spell it out in the man page about one option
implying the other.

Considering i915 is not currently loaded:

Before:
	kmod $ ./build/modprobe -v --dry-run --remove-holders i915
	insmod /lib/modules/6.14.11-1-MANJARO/kernel/drivers/char/agp/intel-gtt.ko.zst
	insmod /lib/modules/6.14.11-1-MANJARO/kernel/drivers/gpu/drm/i915/i915.ko.zst
	kmod $

After:
	kmod $ ./build/modprobe -v --dry-run --remove-holders i915
	kmod $

Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
Link: https://github.com/kmod-project/kmod/pull/372
2025-06-16 07:36:44 -05:00
Emil Velikov
fc0edb4ac1 tools/modprobe: accept module name with --show-modversions
Use the newly introduced helper module_new_from_any(), so we accept both
files as well as modules. This means you can now do:
 - modprobe --show-modversions drm-vram-helper, alongside the existing
 - modprobe --show-modversions /full/path/to/the/module/drm_vram_helper.ko

Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
Link: https://github.com/kmod-project/kmod/pull/353
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
2025-06-13 13:52:41 -05:00
Emil Velikov
5dfa7c9a9b tools/modprobe: accept module name with --show-exports
Use the newly introduced helper module_new_from_any(), so we accept both
files as well as modules. This means you can now do:
 - modprobe --show-exports drm-vram-helper, alongside the existing
 - modprobe --show-exports /full/path/to/the/module/drm_vram_helper.ko

Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
Link: https://github.com/kmod-project/kmod/pull/353
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
2025-06-13 13:52:41 -05:00
Emil Velikov
5753d25231 tools/modprobe: factor out module_new_from_any()
Split the functionality into a helper function, which will be used with
later commits.

Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
Link: https://github.com/kmod-project/kmod/pull/353
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
2025-06-13 13:52:41 -05:00
Emil Velikov
200c7b32f3 tools/modprobe: standardize on --show-foo, deprecate the rest
Currently we have a range of options which show specific details,
although they vary in prefix or spelling:
 - prefix: dump vs resolve vs show
 - with and without dash after show

Converge on --show-foo and deprecate the rest. The old options are still
accepted but will throw a warning. Only the (new) consistent names are
listed in --help, while the manual page lists both but spells out that
the old ones will be removed.

To avoid any confusion with --show (aka --dry-run) the option is also
soft-deprecated.

Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
Link: https://github.com/kmod-project/kmod/pull/353
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
2025-06-13 13:52:41 -05:00
Emil Velikov
f9ecaf7e1f tools/modprobe: properly deprecate --remove-dependencies
The option was annotated as deprecated a while ago, although we never
flagged a warning when it is in use.

Do that, remove it from the --help screen and add an explicit "will be
removed" notice in the manual page.

Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
Link: https://github.com/kmod-project/kmod/pull/353
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
2025-06-13 13:52:41 -05:00
Emil Velikov
077323d034 tools/static-nodes: don't use %m on mkdir_parents() failure
The function returns the error code itself, so we should be using
strerror(-err) instead.

Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
Link: https://github.com/kmod-project/kmod/pull/368
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
2025-06-11 08:03:26 -05:00
Emil Velikov
994da3b8d2 tools/depmod: don't use %m on kmod_new() failure
The KMOD API returns NULL on error and getting the exact means why it
failed is undefined. In practise the errno is set in _some_ of the error
paths, but not all.

Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
Link: https://github.com/kmod-project/kmod/pull/368
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
2025-06-11 08:03:26 -05:00
Emil Velikov
5c226b6fa0 tools/depmod: don't use %m on mkdir_p() failure
The function returns the error code itself, so we should be using
strerror(-err) instead.

Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
Link: https://github.com/kmod-project/kmod/pull/368
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
2025-06-11 08:03:26 -05:00
Emil Velikov
137e47880f tools/depmod: explicitly return ENOMEM on hash_new() failure
The function will always set errno of ENOMEM, so we might as well use
that. Making the code more consistent and removing a few bytes/LoC.

Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
Link: https://github.com/kmod-project/kmod/pull/368
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
2025-06-11 08:03:26 -05:00
Emil Velikov
d44eb2ffa4 Use explicit ENOMEM when {m,re}alloc fails
Currently our codebase has a mix of explicitly using ENOMEM and
propagating the errno... The latter of which is guaranteed to be ENOMEM
as documented in the manual pages.

Consolidate on ENOMEM, both for consistency sake and to remove a few
bytes off our binaries ;-)

Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
Link: https://github.com/kmod-project/kmod/pull/368
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
2025-06-11 08:03:26 -05:00
Emil Velikov
0c4ebd45bd Remove unused errno.h include
Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
Link: https://github.com/kmod-project/kmod/pull/368
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
2025-06-11 08:03:26 -05:00
Emil Velikov
d2ee70eac8 shared/util: remove unused t0 in get_backoff_delta_msec()
The argument was unused ever since the function was introduced - remove
it.

Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
Link: https://github.com/kmod-project/kmod/pull/361
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
2025-06-11 07:54:40 -05:00
Emil Velikov
2f5b9f1e2c tools/static-nodes: silence unused parameter warning
The function signature for our printers is uniform, even though in one
of the instances a parameter is unused. There is not much we can do
here, just silence the compiler warning.

Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
Link: https://github.com/kmod-project/kmod/pull/361
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
2025-06-11 07:54:40 -05:00
Emil Velikov
72dfead09b tools/modprobe: initialize msec variables as needed
Remove the initialization for interval_msec and tend_msec. They are set
on the first iteration... Assuming the user has set non-zero wait time.

Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
Link: https://github.com/kmod-project/kmod/pull/361
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
2025-06-11 07:54:40 -05:00
Emil Velikov
affec6677a tools/kmod: silence unused parameter warnings
kmod_help() does not use neither argc nor argv although due to the
dispatch mechanism they are part of the function signature.

Not much we can do here - silence the compiler warnings.

Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
Link: https://github.com/kmod-project/kmod/pull/361
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
2025-06-11 07:54:40 -05:00
Emil Velikov
d13b0567b9 tools/depmod: remove unused parameter struct depmod
In a handful of functions we don't need the depmod struct. Remove it,
making the compiler happy and shaving a few bytes off the resulting
binary.

Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
Link: https://github.com/kmod-project/kmod/pull/361
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
2025-06-11 07:54:40 -05:00
Emil Velikov
2497950466 tools/depmod: use nsec granularity when checking timestamps
Current code uses the POSIX.1-2001 stat::st_mtime which has one second
granularity. Considering the depmod execution time may be smaller, we
should be using the POSIX.1-2008 stat::st_mtim which has nano-second
granularity instead.

Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
Link: https://github.com/kmod-project/kmod/pull/359
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
2025-05-30 09:04:02 -05:00
Tobias Stoeckmann
dcd652b57c check strtol/strtoul/strtoull results
The strto* family of functions may fail if the input string contains
a number which is too large for the designated data type. In such
cases, errno is set to ERANGE. Check for this error condition and if
subsequent casts would truncate the value.

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/357
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
2025-05-29 22:57:51 -05:00
Emil Velikov
13b646a73f Remove default initializer for static variables
The spec dictates that static variables are initialized to 0/NULL.
Remove the unnecessary explicit initialization - on older compilers this
sheds a few bytes off the data section of respective binaries.

Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
Link: https://github.com/kmod-project/kmod/pull/358
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
2025-05-29 21:16:00 -05:00
Emil Velikov
219be963e9 tools: move a few more symbols to data.rel.ro
Annotate the arrays (not the data) as constant, so the compiler can
store it in the RO segment.

Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
Link: https://github.com/kmod-project/kmod/pull/358
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
2025-05-29 21:16:00 -05:00
Emil Velikov
5f55a879ef tools/depmod: remove set but unused timeval
No longer needed since the introduction of tmpfile-util.

Fixes: aae48bc9 ("depmod: add tmpfile-util to generate temporary file")
Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
Link: https://github.com/kmod-project/kmod/pull/358
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
2025-05-29 21:16:00 -05:00
Emil Velikov
0b116d8a6e tools: use strlen() for string literals
Older compilers had struggles expanding strlen(string-literal) to a
constant compile time expression. Thus our code-base used sizeof() - 1
instead.

This has been resolved for years, so let's use the correct function.

Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
Link: https://github.com/kmod-project/kmod/pull/354
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
2025-05-29 17:10:16 -05:00
Emil Velikov
e32eff22fa libkmod: reuse streq/strstartswith() whenever possible
Use our handy macro(s) for clarity and consistency sake.

Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
Link: https://github.com/kmod-project/kmod/pull/354
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
2025-05-29 17:10:16 -05:00
Emil Velikov
e45e624e05 tools/modinfo: return the errno from add_param()
The single caller of add_param() does not need the struct param*, so we
might as well return the error code directly. As a result we don't
manually overwrite errno.

Reference: https://github.com/kmod-project/kmod/issues/244
Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
Link: https://github.com/kmod-project/kmod/pull/346
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
2025-05-19 21:51:43 -05:00
Emil Velikov
fb0e59a12c Use %m over strerror(errno) where possible
The manual page of strerror() outlines a number of caveats wrt its usage.
Swap for the GNU specific %m printf modifier (also supported on musl and
bionic), which side-steps the issues as much as possible.

Co-authored-by: Cristian Rodríguez <cristian@rodriguez.im>
[emil: split from larger patch, convert more instances to %m]
Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
Link: https://github.com/kmod-project/kmod/pull/346
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
2025-05-19 21:51:43 -05:00
Emil Velikov
0fd84a53ab Use sizeof() over PATH_MAX in snprintf() contexts
Bunch of our codebase uses sizeof() while the rest hard-coded length for
the destination buffer. Converge on the former since it makes for more
obvious and less error prone code.

Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
Link: https://github.com/kmod-project/kmod/pull/345
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
2025-05-09 13:52:46 -05:00
Rong Tao
c494150668 insmod: Support --force-{vermagic,modversion} arguments
Supports --force-{vermagic,modversion} parameter like modprobe.

Link: https://github.com/kmod-project/kmod/pull/340
Signed-off-by: Rong Tao <rongtao@cestc.cn>
Reviewed-by: Emil Velikov <emil.l.velikov@gmail.com>
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
2025-05-09 09:07:14 -05:00
Rong Tao
3149b29086 modprobe: Fix typo
Argument --force-modversions should be --force-modversion

Link: https://github.com/kmod-project/kmod/pull/339
Signed-off-by: Rong Tao <rongtao@cestc.cn>
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
2025-05-05 16:05:39 -05:00
Lucas De Marchi
818851c770 depmod: Fix possible 0 return on error
errno may be long overwritten at this point and doesn't mean much on a
return from the cb(). Just replace with the same error we are output on
the log.

Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
Reviewed-by: Tobias Stoeckmann <tobias@stoeckmann.org>
Link: https://github.com/kmod-project/kmod/pull/337
2025-04-06 22:36:31 -05:00
Wang, Wenjie2
aae48bc9f7 depmod: add tmpfile-util to generate temporary file
* we use `mkstemp` to create the temporary file since it's a general
  function in linux system and O_TMPFILE is not supported on all linux
  system.
* add `struct tmpfile` to keep the `dirfd`, temp file `fd` and the
  filename.

Co-developed-by: Wenjie Wang <wenjie2.wang@intel.com>
Signed-off-by: Wenjie Wang <wenjie2.wang@intel.com>
Co-developed-by: Gongjun Song <gongjun.song@intel.com>
Signed-off-by: Gongjun Song <gongjun.song@intel.com>
Signed-off-by: Dan He <dan.h.he@intel.com>
Signed-off-by: Qingqing Li <qingqing.li@intel.com>
Signed-off-by: Yuchi Chen <yuchi.chen@intel.com>
Link: https://github.com/kmod-project/kmod/pull/305
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
2025-04-02 23:23:28 -05:00
Lucas De Marchi
9078a01c0e Drop leftover makefiles
I don't think this was used before (at least I always build from the git
rootdir), and now that autotools is removed, they are wrong.

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/334
2025-04-01 12:27:12 -05:00
Emil Velikov
4d330bae4b modprobe: s|<MSEC>|MSEC|
Drop the brackets to stay consistent with quoting of other arguments -
see --config and friends further down.

Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
Link: https://github.com/kmod-project/kmod/pull/332
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
2025-04-01 12:15:45 -05:00
Yannick Le Pennec
da2654b78c tools/rmmod: fix garbled error message
a6f9cd0 ("tools/rmmod: consistently use ERR logging facility") fixed
the split between syslog and stderr of various error message substrings
by calling the ERR macro instead of writing directly to stderr, but in
doing so also completely mangled the output because the ERR macro
decorates its arguments:

    $ rmmod iwlwifi
    rmmod: ERROR: Module iwlwifi is in use by:rmmod: ERROR:  iwlmvmrmmod: ERROR:

And in syslog:

    $ rmmod -s iwlwifi
    2025-03-24T17:22:34.878318+01:00 mangolassi rmmod: ERROR: Module iwlwifi is in use by:
    2025-03-24T17:22:34.889145+01:00 mangolassi rmmod: ERROR:  iwlmvm
    2025-03-24T17:22:34.889224+01:00 mangolassi rmmod: ERROR:

This commit fixes that by building the holder names list with a strbuf
and then passes the whole thing at once to ERR.

Fixes: a6f9cd0 ("tools/rmmod: consistently use ERR logging facility")
Signed-off-by: Yannick Le Pennec <yannick.lepennec@live.fr>
Link: https://lore.kernel.org/r/VI1PR02MB48291E3BDB7E764ED67154949BA42@VI1PR02MB4829.eurprd02.prod.outlook.com
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
Link: https://github.com/kmod-project/kmod/pull/328
2025-03-28 10:30:07 -05:00
Emil Velikov
0e5b3b7910 tools: use space for long opts
The getopt_long() API handles both space and = separated long options
just fine. On the other hand, supporting both in the shell completions
means that we'll have to quadruple them in terms of size/complexity.

So let's try to keep things simple and consistent, by recommending only
the space variant.

Make sure to update both the tools' --help and the respective man pages.

Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
Link: https://github.com/kmod-project/kmod/pull/313
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
2025-03-25 14:08:08 -05:00
Tobias Stoeckmann
3b9f13937c depmod: remove strbuf_reserve_extra call
The strbuf_reserve_extra call is only left for a possible '/' addition,
which only occurs before depmod_modules_search_dir recursively calls
itself.

By adding the slash at the start, it also simplifies
depmod_modules_search_path which does not have to do this before calling
depmod_modules_search_dir on its own.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
Link: https://github.com/kmod-project/kmod/pull/296
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
2025-03-06 22:57:37 -06:00
Tobias Stoeckmann
72029c4293 depmod: refactor depmod_modules_search_dir
The function depmod_modules_search_dir is supposed to ignore all errors
encountered during directory entry iteration. This was not true for
out of memory conditions, which could also lead to wrong output.

Clarify this fact by turning it void and adjust callers accordingly.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
Link: https://github.com/kmod-project/kmod/pull/296
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
2025-03-06 22:57:37 -06:00
Tobias Stoeckmann
2b47598178 shared: let strbuf_str never fail
The strbuf functionality is always used to create C strings, so already
reserve an extra byte for NUL whenever size allocations occur.

Together with the fact that strbuf_str already returns a const char *,
an empty strbuf may return an unmodifiable empty string.

This renders all strbuf_str return value checks obsolete.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
Link: https://github.com/kmod-project/kmod/pull/296
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
2025-03-06 22:57:37 -06:00
Tobias Stoeckmann
5350ef9901 depmod: use stack strbuf where possible
The deps bin output uses a strbuf. A size of 2048 covers all cases
on current Arch Linux (max used size is 1548) and removes heap
allocations.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
Link: https://github.com/kmod-project/kmod/pull/296
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
2025-03-06 22:57:37 -06:00
Tobias Stoeckmann
45a0b46535 modinfo: reduce amount of continue statements
Clarify that the code does not perform error checks, for which we
regularly use checks and continue at the start, but merely checks
how to print/filter the data.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
Link: https://github.com/kmod-project/kmod/pull/290
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
2025-03-06 22:47:50 -06:00
Tobias Stoeckmann
3e33ca0881 kmod: use program_invocation_short_name more often
Remove the explicit basename(argv[0]) calls because we already
rely on program_invocation_short_name even before reaching
these lines. Unifies code and slightly reduces binary size.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
Link: https://github.com/kmod-project/kmod/pull/284
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
2025-02-21 13:59:03 -06:00
Tobias Stoeckmann
51ba885d5b static-nodes: unify return statements
The write_* functions have different return statement handling. Unify
them by removing "else" if the if-block itself returns and also unify
the error handling by checking for the error case, leaving the success
return statement at the end of the function.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
Link: https://github.com/kmod-project/kmod/pull/285
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
2025-02-21 13:51:08 -06:00
Tobias Stoeckmann
94131a4a34 modprobe: unify help output
Add = to modprobe help output for --wait to comply with all other long
option descriptions.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
Link: https://github.com/kmod-project/kmod/pull/287
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
2025-02-21 13:49:01 -06:00
Tobias Stoeckmann
1ae5179d48 static-nodes: do not open /dev/stdout explicitly
If no -o option is given, use stdout directly without opening
/dev/stdout manually. In a chroot environment, this could lead
to /dev/stdout creation as a regular file.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
Link: https://github.com/kmod-project/kmod/pull/283
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
2025-02-18 15:57:37 -06:00
Tobias Stoeckmann
359ed91b75 log: fix style
Add a missing newline between two functions.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
Link: https://github.com/kmod-project/kmod/pull/282
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
2025-02-18 15:42:17 -06:00
Tobias Stoeckmann
816eb8ab72 modprobe: reduce visibility of use_syslog
The use_syslog variable is only used within main function, so reduce
its visibility.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
Link: https://github.com/kmod-project/kmod/pull/282
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
2025-02-18 15:42:17 -06:00
Tobias Stoeckmann
378fd27803 tools: use bool instead of int for log_open
Since log_open takes a booln as argument, turn use_syslog into a
bool instead of using an int. Shrinks binary size with GCC and from
C point of view, this makes the code cleaner.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
Link: https://github.com/kmod-project/kmod/pull/282
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
2025-02-18 15:42:17 -06:00
Grayson Nocera
47bc9145fc tools: specify buffer to be size PATH_MAX
Using a CodeQL query, I discovered that the destination of a `sscanf` call could overflow.
Thus, we bound the buffer size to be PATH_MAX, to ensure that it is
not larger than `modname` or `devname`.

Signed-off-by: Grayson Nocera <gnocera@purdue.edu>
Suggested-by: Tobias Stoeckmann <tobias@stoeckmann.org>
Link: https://github.com/kmod-project/kmod/pull/260
Reviewed-by: Emil Velikov <emil.l.velikov@gmail.com>
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
2025-01-02 18:20:49 -06:00