Commit Graph

277 Commits

Author SHA1 Message Date
Philippe De Swert 2b2a503e4f insmod: do support -f
The -f switch is accepted by insmod, but silently ignored. This
causes the user to wonder why things don't work. As insmod is
most often used with "evil" modules, -f is almost default and
thus needs to work.

Signed-off-by: Philippe De Swert <philippe.deswert@jollamobile.com>
2015-10-25 13:57:17 -02:00
Laura Abbott f3f62f5ec3 depmod: Don't fall back to uname on bad version
Currently, if a value that doesn't match a kernel version
("%u.%u") is passed in, depmod silently falls back to
using uname. Rather than try and work around the caller passing
bad data, just exit out instead.
2015-09-30 15:17:05 -03:00
Laura Abbott 50f43ce2f6 depmod: Remove unprinted debug messages
In between the start of the program and the call to log_setup_kmod_log,
the only messages that will be printed are the ones at or above the
global default level. Debug messages in this range will never be printed
so remove them.
2015-09-30 15:17:03 -03:00
Laura Abbott 16d863c317 Change default log level
The default log level is currently LOG_ERR. Tools can override this
default but there is a non-trivial amount of setup that needs to
happen before the log level can be changed. Since tools may want to
use the warn level for things such as deprecated flags, change the
default to LOG_WARNING to ensure messages get printed.
2015-09-30 15:17:01 -03:00
Laura Abbott b87d01d6ef modprobe: Update error message when path is missing
Currently, modprobe fails with no output by default if the
search paths it tries are missing:

$ modprobe -S notakernel dm-crypt
$
$ modprobe -S notakernel lkjjweiojo
$

This is fairly cryptic and not at all obvious there is a problem
unless the error code is checked or verbose flags are used.
Update the error message to indicate a problem and print out the
directory that failed.
2015-09-30 15:16:59 -03:00
Lucas De Marchi 655de2751d tools: display features in --version
Reviewed-by: Andreas Mohr <andim2@users.sf.net>
2015-06-08 22:38:02 -03:00
Lucas De Marchi b1499094c6 tools: add PACKAGE definition in message
Reported-by: Andreas Mohr <andim2@users.sf.net>
2015-06-08 21:33:06 -03:00
Lucas De Marchi 013e855043 tools: Hide new commands behind experimental flag
Hide the commands behind a flag so we can continue doing releases while
the commands aren't ready.
2015-06-06 23:26:31 -03:00
Santiago Vila 7266ec4337 Fix spurious spaces in lsmod output
While using "localyesconfig" to build a custom kernel I noticed that
lsmod output now has trailing spaces when the list of "Used by" modules
is empty.

The following patch just delays the space to the point where we are sure
that there are more things to print.
2015-04-16 08:46:43 -03:00
Caio Marcelo de Oliveira Filho 037618816c tools: add basic versions of insert and remove 2015-03-07 12:09:51 -03:00
Lucas De Marchi 22df456760 depmod: add asserts to ensure positive return from ftell()
Also ignore some errors that will later be returned by ferror().
2015-02-28 14:57:00 -03:00
Lucas De Marchi e2719b32cc modprobe: stop checking initstate for builtin modules
builtin modules are handled in libkmod by looking at the modules.builtin
index. There's no need to check again for the module's initstate to
decide if it's builtin.
2015-02-28 14:18:54 -03:00
Lucas De Marchi a1bec0dfdb depmod: fix leak in case of malloc(0)
malloc(0) can return != NULL. We need to pass the pointer to free().
This happens if index__haschildren(node) returned true, but
child_count is set to 0.
2015-02-26 03:40:47 -03:00
Lucas De Marchi a07ea0329c depmod: use cleanup attribute to simplify free on exit
Reusing the root variable was a bad idea. Doing so we could call free()
on a variable that was not allocated. For example: "depmod -b / -h".
Since we would jump to cmdline_failed, root would not be duplicated.

Instead of fighting the order in the options, just used the cleanup
attribute and remove the calls to free() on "config_paths" and "root".
2015-02-25 12:06:44 -03:00
Colin Walters 0b3aef23b8 depmod: Fix crash in previous commit if root is not set
[This fixes http://build.gnome.org/continuous/buildmaster/builds/2015/02/25/31/build/output.txt ]

The variable we're reading here is "root", not "optarg" which is only
valid inside the getopt call.
2015-02-25 11:27:05 -03:00
Lucas De Marchi e90f0704ea depmod: fix leaking root on exit 2015-02-25 00:50:37 -03:00
Lucas De Marchi 5b0436a759 tools: prefer the use of streq() 2015-01-14 14:32:09 -02:00
Lucas De Marchi 7db094c050 tools: kmod: use streq 2015-01-14 12:35:04 -02:00
Caio Marcelo de Oliveira Filho ace71985fc tools: kmod: break iteration once a command is executed 2015-01-14 12:24:31 -02:00
Lucas De Marchi f357866d97 Fix includes after change to build-sys
Make the includes be libkmod/libkmod.h for code outside of library. This
fixes the broken build after 1315123 ('build-sys: Don't add libkmod
subdirectory to include path').
2015-01-02 12:41:01 -02:00
Lucas De Marchi 778395e4e8 depmod: point to documentation in libkmod
Instead of repeating all documentation, point to the documentation
available in libkmod-index.c

This also removes INDEX_PRIORITY_MIN that was not being used.
2014-11-15 11:18:46 -02:00
Tom Gundersen 27eceb2e4e static-nodes: indicate that creation of static nodes should only happen at boot
udev will only manage static nodes that exist at the time udev is started, so
creating static nodes later on will likely not behave as expected. In
particular, recreating the static nodes at run-time will reset any permissions
udev may have applied to the nodes at boot.

See <https://bugzilla.redhat.com/show_bug.cgi?id=1147248> and the discussion
following <http://permalink.gmane.org/gmane.comp.sysutils.systemd.devel/23795>.

Note that this requires (the yet to be released) systemd v217 or a backport
of systemd patch 8c94052ee543c3598a3c7b0c46688150aa2c6168.
2014-10-28 16:49:46 -02:00
Lucas De Marchi f4e8c16291 Move remaining functions from libkmod-util to shared 2014-10-09 01:26:39 -03:00
Lucas De Marchi 3753ae16f5 depmod: use alias_normalize() from shared
Remove underscores2() function which is essentially the same as
alias_normalize() and the latter, which is now in shared/.
2014-10-09 01:26:39 -03:00
Lucas De Marchi 66bf1a7ff9 Do not rely on prio_to_str() being always inline
This function was declared as always-inline so there was not really a
problem in returning prioname, that could possibly point to the local
buf[] variable.

However static analysis tools are often confused about this and being
always-inline was just a workaround to make it work.

So, let's move the buffer to the caller. We have only 2 callers so it
doesn't matter much. This always reduce the size of log.o, since now the
function is not inlined anymore. Below is the size for "-g -O2" with
gcc:

before:
   text    data     bss     dec     hex filename
   1325       4       1    1330     532 tools/log.o

after:
   text    data     bss     dec     hex filename
   1171       4       1    1176     498 tools/log.o
2014-10-09 01:26:39 -03:00
Lucas De Marchi b95506ff61 Do not export array of kmod extensions
The only user outside of libkmod-util is depmod, which really only needs
to get the string for the extension of uncompressed modules. It doesn't
need to access the array itself.
2014-10-09 01:26:39 -03:00
Lucas De Marchi 1a07559af3 Clarify what licences apply where
This doesn't change any license, just clarifies what's licensed under
LGPL and what's under GPL.
2014-10-09 01:26:34 -03:00
Lucas De Marchi aafd38359a Rename getline_wrapped() to freadline_wrapped() 2014-10-03 03:25:06 -03:00
Lucas De Marchi c2e4286bb9 Reorder and reorganize header files
Let the includes in the following order:

< system headers >
< libkmod >
< tool >
< local headers >
2014-10-03 01:43:15 -03:00
Lucas De Marchi 0db718edcf Move hash implementation to shared directory 2014-10-03 00:40:11 -03:00
Lucas De Marchi 74d1df6682 Move array implementation to shared directory 2014-10-03 00:33:25 -03:00
Lucas De Marchi 96573a0220 Move generic util functions to shared directory 2014-10-03 00:33:25 -03:00
Lucas De Marchi 576dd4393d Move macro.h to shared directory
It's not really related to libkmod, so move it to a directory in which
we keep common stuff.
2014-10-02 22:03:19 -03:00
Lucas De Marchi c89d219884 depmod: Add better error messages when facing loops
Since now depmod fails when there are module loops, let's at least give
better error messages, printing the loops we found. Since we may have
more than 1 loop, just printing the modules that are in loop is not
very clear.

Assuming as an example 2 independent loops, this is how the new messages
compare to the old ones:

Before:
	depmod: ERROR: Found 5 modules in dependency cycles!
	depmod: ERROR: /tmp/test-kmod//lib/modules/3.14.4-1-ARCH/kernel/moduleE.ko in dependency cycle!
	depmod: ERROR: /tmp/test-kmod//lib/modules/3.14.4-1-ARCH/kernel/moduleB.ko in dependency cycle!
	depmod: ERROR: /tmp/test-kmod//lib/modules/3.14.4-1-ARCH/kernel/moduleC.ko in dependency cycle!
	depmod: ERROR: /tmp/test-kmod//lib/modules/3.14.4-1-ARCH/kernel/moduleD.ko in dependency cycle!
	depmod: ERROR: /tmp/test-kmod//lib/modules/3.14.4-1-ARCH/kernel/moduleA.ko in dependency cycle!

After:
	depmod: ERROR: Found 5 modules in dependency cycles!
	depmod: ERROR: Cycle detected: moduleE -> moduleD -> moduleE
	depmod: ERROR: Cycle detected: moduleB -> moduleC -> moduleA -> moduleB
2014-05-30 09:43:30 -03:00
Lucas De Marchi a873f2350f depmod: Rename variable to clarify its meaning
In mod->modnamelen we were actually including the '\0', i.e.
strlen(modname) + 1. So rename it to modnamesz and add a comment in
depmod_module_is_higher_priority() to notice why it's correct since the
new one is really using strlen(modname).
2014-05-30 09:03:33 -03:00
Lucas De Marchi c48b269d64 depmod: Make dependency loops be fatal
Since the beginning depmod just warned about dependency loops and upon
creation of modules.dep{,.bin} it skipped the modules that were part of
a loop. However just skipping the modules may come as a surprise to
kernel module developers: they will need to try to load the module (or
to pay attention to the log messages) to notice thavt the module has not
been put in the index. Also, differently from module-init-tools we were
not skipping modules that depend on modules with dependency loops,
leading to a segfault in depmod.

So this is a summary of the change in behavior with this patch:

Loop 1)
    A -> B -> C -
    ^           |
    '------------

    Before:
        depmod: WARNING: found 3 modules in dependency cycles!
        depmod: WARNING: /tmp/test-kmod/lib/modules/3.14.2-1-ARCH/kernel/moduleB.ko in dependency cycle!
        depmod: WARNING: /tmp/test-kmod/lib/modules/3.14.2-1-ARCH/kernel/moduleC.ko in dependency cycle!
        depmod: WARNING: /tmp/test-kmod/lib/modules/3.14.2-1-ARCH/kernel/moduleA.ko in dependency cycle!

        return code: 0

    After:
        depmod: ERROR: Found 3 modules in dependency cycles!
        depmod: ERROR: /tmp/test-kmod/lib/modules/3.14.2-1-ARCH/kernel/moduleB.ko in dependency cycle!
        depmod: ERROR: /tmp/test-kmod/lib/modules/3.14.2-1-ARCH/kernel/moduleC.ko in dependency cycle!
        depmod: ERROR: /tmp/test-kmod/lib/modules/3.14.2-1-ARCH/kernel/moduleA.ko in dependency cycle!

        return code: 2

Loop 2)
    A -> B -> C -
         ^      |
         '-------

    Before:
        depmod: WARNING: found 2 modules in dependency cycles!
        depmod: WARNING: /tmp/test-kmod//lib/modules/3.14.2-1-ARCH/kernel/moduleB.ko in dependency cycle!
        depmod: WARNING: /tmp/test-kmod//lib/modules/3.14.2-1-ARCH/kernel/moduleC.ko in dependency cycle!
        Segmentation fault (core dumped)

    After:
        depmod: ERROR: Found 2 modules in dependency cycles!
        depmod: ERROR: /tmp/test-kmod/lib/modules/3.14.2-1-ARCH/kernel/moduleB.ko in dependency cycle!
        depmod: ERROR: /tmp/test-kmod/lib/modules/3.14.2-1-ARCH/kernel/moduleC.ko in dependency cycle!

        return code: 2

The segfault above could be fixed, but let's just fail everything
because dependency cycles should be fixed in the modules rather than
just be skipped in the index.
2014-05-14 20:05:12 -03:00
Tom Gundersen 8240333b25 config: also parse softdeps from modules
This information can be found in /lib/modules/`uname -r`/modules.softdep, and
has only recently been exported by the kernel.

Also remove the advice about copying modules.softdep to /lib/modules as it is
not clear how to do this correctly with several kernels installed with
potentially conflicting soft dependencies.
2014-04-01 08:13:54 -03:00
Anssi Hannula 49b33c1f21 depmod: do not allow partial matches with "search" directive
Currently e.g. "search foo foobar built-in" will cause unpredictable
results if baz.ko is in both foo/ and foobar/, since "foo" in search may
match both of those directories and the preferred module therefore
depends on processing order.

Fix the code to ensure that the match is performed on full pathname
components only.
2014-03-19 09:18:39 -03:00
Anssi Hannula 27881f6fbc depmod: fix debug print parameter order 2014-03-19 07:04:24 -03:00
Lucas De Marchi 06eb29e117 build-sys: add small redirecting Makefiles
These redirecting makefiles simplifies compiling from some editors and
when CWD is not the root of the source tree. This is similar to what was
introduced in systemd in 340d89e ("build-sys: add small redirecting
Makefiles to simplify compilation from within emacs")
2014-03-06 01:59:58 -03:00
Michal Marek 519d27de5a libkmod-config,depmod: Accept special files as configuration files, too
If we can open it and read it, it's good enough for us. Otherwise, we
cannot use -C /dev/null to skip the system configuration for instance:

$ ./tools/modprobe -C /dev/null -c
libkmod: ERROR libkmod/libkmod-config.c:821 conf_files_list: unsupported
file mode /dev/null: 0x21b6
...
2014-03-05 12:27:24 -03:00
Stephen Kitt a4bd1441e5 Remove "rmmod -w" documentation and getopt entry
This patch removes the cmdopts declaration and the documentation. They
were leftover from the -w removal.
2014-01-26 18:00:23 -02:00
Lucas De Marchi 017893f244 rmmod: remove --wait option
Let libkmod enforce KMOD_REMOVE_NOWAIT.
2013-09-20 01:42:04 -05:00
Tom Gundersen 6506ddf5a3 depmod: warn on invalid devname specification
During the last merge window (3.12) a couple of modules gained devname
aliases, but without the necessary major and minor information. These were
then silently ignored when generating modules.devname.

Complain loudly to avoid such errors sneaking in undetected in the future:

    depmod: ERROR: Module 'zram' has devname (zram) but lacks major and minor information. Ignoring.
    depmod: ERROR: Module 'uhid' has devname (uhid) but lacks major and minor information. Ignoring.

Cc: Kay Sievers <kay@vrfy.org>
Cc: Lucas De Marchi <lucas.demarchi@profusion.mobi>
2013-09-10 00:49:41 -03:00
Lucas De Marchi 7e0385c47a Fix usage of readdir_r()
With readdir_r() we should be providing enough space to store the dir
name. This could be accomplished by define an union like systemd does:

	union dirent_storage {
		struct dirent de;
		uint8_t storage[offsetof(struct dirent, d_name) +
				((NAME_MAX + 1 + sizeof(long)) & ~(sizeof(long) - 1))];
	};

However in all places that we use readdir_r() we have no concerns about
reentrance nor we have problems with threads. Thus use the simpler
readdir() instead.

We also remove the error logging here (that could be added back by
checking errno), but it was not adding much value so it's gone.
2013-08-29 01:33:51 -03:00
Jan Engelhardt c1170883b4 depmod: add missing "else" clause
It occurred to an openSUSE user that our mkinitrd would throw a
warning when used with kmod:

libkmod: conf_files_list: unsupported file mode /dev/null: 0x21b6

Grepping for the error message revealed that there might be a missing
"else" keyword here, since it is unusual to put an "if" directly after
closing brace.
2013-08-09 12:01:10 -03:00
Tom Gundersen 232bf4d863 static-nodes: create parent directories of output file
Allows us to drop call to "mkdir -p" from the systemd service file.
2013-07-15 12:46:12 -03:00
Tom Gundersen ae17710117 static-nodes: don't fail if modules.devname not found
In containers/VM's/initrd one might not have installed any modules and
accompanying modules.devname Don't fail if this is the case, just warn.

When used in systemd this means we don't get a failing unit on booting
containers.
2013-07-15 12:44:33 -03:00
Lucas De Marchi 9de9e07da6 tools: Use test/kmod instead of kmod-nolib
The reason to have a kmod-nolib binary is that we need to call kmod on
test cases (or a symlink to it) and for testing things in tree. Since
we are using libtool if we are dinamically linking to libkmod what we
end up having is a shell script that (depending on the version *)
changes argv[0] to contain an "lt-" prefix. Since this screws with our
compat stuff, we had a kmod-nolib that links statically.

This all workaround works fine iff we are using one of the compat
commands, i.e. we are using the symlinks insmod, rmmod, modprobe, etc.
However if we are actually trying the kmod binary, this doesn't work
because we can't create a kmod symlink since there's already a kmod
binary.

So, completely give up on libtool fixing their mess. Now we create a
tool/test/ directory and the symlinks and kmod is put there.

* http://lists.gnu.org/archive/html/bug-libtool/2011-12/msg00023.html
2013-07-02 21:15:54 -03:00
Lucas De Marchi a5cbde4bce static-nodes: Better -f option description 2013-07-01 23:02:08 -03:00
Johannes Berg c010f02030 modprobe: don't check refcount with remove command
The modprobe.d (5) documentation for the "install" command
states that you could specify

install fred /sbin/modprobe barney; /sbin/modprobe --ignore-install fred

This makes some sense, but then the loading of "barney" is
hidden from the user who did only "modprobe fred". Thus,
it seems it should be possible to be able to unload the
"fred" module with "modprobe -r fred" by configuring the
"barney" module to also be removed:

remove fred /sbin/rmmod barney fred

(or similar.)

Make this possible by not checking the refcount when an
unload command was configured.

Reported-by: David Spinadel <david.spinadel@intel.com>
2013-05-02 23:30:44 -03:00
Lucas De Marchi 1958af88a2 Add format attribute and fix issues
Add __attribute__((format)) to log_filep() and _show() functions, fixing
the bugs they found in the source code.

For functions that receive va_list instead of being variadic functions
we put 0 in the last argument, so at least the string is checked and we
get warnings of -Wformat-nonliteral type. So, it's better than adding a
pragma here to shut up the warning.
2013-04-21 16:17:12 -03:00
Lucas De Marchi 19ac5bd8a0 static-nodes: Fix indentation
kmod uses tab instead of spaces and tries to honour 80chr limit, when
that doesn't worsen the readability.
2013-04-19 19:28:46 -03:00
Tom Gundersen 4905769de7 static-nodes: tmpfiles - also create parents directories of device nodes
Before:

c /dev/cpu/microcode 0600 - - - 10:184
c /dev/fuse 0600 - - - 10:229
c /dev/btrfs-control 0600 - - - 10:234
c /dev/loop-control 0600 - - - 10:237
c /dev/snd/timer 0600 - - - 116:33

After:

d /dev/cpu 0755 - - -
c /dev/cpu/microcode 0600 - - - 10:184
c /dev/fuse 0600 - - - 10:229
c /dev/btrfs-control 0600 - - - 10:234
c /dev/loop-control 0600 - - - 10:237
d /dev/snd 0755 - - -
c /dev/snd/timer 0600 - - - 116:33
2013-04-19 19:03:03 -03:00
Lucas De Marchi 279b177de6 kmod: It's an error not to have modules.devname
This file is created by depmod even if there's no node. In this case it
will be empty.

Previously 'kmod static-nodes' was segfaulting due to passing in==NULL
to fgets.

Also show the error message with %m.
2013-04-17 00:57:11 -03:00
Tom Gundersen db6f2fc7e1 tools: add static-nodes tool
This tool reads modules.devname from the current kernel directory and outputs
the information. By default in a human-readable format, and optionally in
machine-readable formats.

For now only the tmpfiles.d(5) format is supported, but more could easily be
added in the future if there is a need.

This means nothing but kmod needs to reads the private files under
/lib/modules/. In particular systemd-udevd can stop reading modules.devname.

Tools that used to read /lib/modules/`uname -r`/modules.devname directly, can
now move to reading 'kmod static-nodes devname'.
2013-04-16 23:10:36 -03:00
Lucas De Marchi ace742fa9a modprobe: Fix assertion on --show-depends with bogus config file
Putting something like "alias psmouse deadbeef" is a hackish way to
blacklist a module. While I don't encourage doing so, let's not explode
if we fiund such config files.

A small difference from the behavior of module-init-tools: we exit with
0 instead of 1.
2013-03-21 02:33:25 -03:00
Josh Boyer d53abca3be rmmod: Teach rmmod about builtin modules
Currently modprobe -r will fail if a module is built in and report that it
is built in.  rmmod calls the same function to determine state but doesn't
handle the KMOD_MODULE_BUILTIN return code.  This leads to confusing errors
like this:

	libkmod: kmod_module_get_holders: could not open '/sys/module/loop/holders': No such file or directory
	Error: Module loop is in use

Fix this so that it actually reports the correct problem to the user.
2013-03-18 11:16:50 -03:00
Lucas De Marchi e6b0e49b4e Update copyright notices 2013-01-16 11:27:45 -02:00
Andrey Mazo 572a2711e7 depmod: fix builtin symbols resolution when the prefix symbol is set
When the prefix symbol is set, take it into account while adding symbols
from System.map file by skipping it before "__ksymtab_" comparison.

Also, prevent inserted fake symbols (like "__this_module") from being
wrongly truncated from beginning.
2012-12-31 18:23:30 -02:00
Andrey Mazo c02a8e6f9b depmod: --symbol-prefix actually requires an argument
-P requires and uses an argument but its long counterpart --symbol-prefix does not:
depmod: option '--symbol-prefix' doesn't allow an argument
2012-12-13 15:52:42 -02:00
Lucas De Marchi 650f89cd25 depmod: fix checking file extension
In depfile_up_to_date_dir() we need to check if name has a kmod
extension. "path" variable there will be the directory name, which
doesn't contain an extension.

Without this, "depmod -A" returns that the modules.dep is up to date,
even if it isn't.

In depmod_modules_search_file() it's pointless to compare the basename,
so pass only the name to be checked.
2012-11-28 14:26:23 -02:00
Aleksey Makarov 6f02b6fa7a fix is_module_filename()
modinfo fails if there is a ".ko" substring in the path to the module
2012-11-28 11:22:00 -02:00
Lucas De Marchi 02c64df3c2 depmod: fix asserting mod->kmod == NULL
If we are replacing a lower priority module (due to its location), we
already created a kmod_module, but didn't open the file for reading its
symbols. This means mod->kmod won't be NULL, and this is just ok. Since
all the functions freeing stuff below the previous assert already takes
NULL into consideration, it's safe to just unref mod->kmod and let the
right thing happens.
2012-11-16 12:05:42 -02:00
Lucas De Marchi 06294621a9 depmod: fix hash lookup by relpath instead of uncrelpath
We index modules in depmod by it's uncompressed relative path, not
relative path. We didn't notice this bug before since this function is
only triggered if we release a module to be replaced by one of higher
priority.

Also fix a leftover log message referring to relpath instead of
uncrelpath.
2012-11-16 11:39:41 -02:00
Lucas De Marchi 7c04aeee40 tools: use program_invocation_short_name provided by libc
Thanks to Dave Reisner for pointing this out.
2012-11-06 19:30:16 -02:00
Lucas De Marchi c841273721 tools: staticize functions that are now only used in log.c 2012-11-06 19:06:11 -02:00
Lucas De Marchi fcb0ce9475 tools: share function for logging 2012-11-06 19:02:23 -02:00
Lucas De Marchi 52a50fe2e5 tools: share setting up libkmod log
This also fixes a bug in "e6996c5 rmmod: route all messages to syslog if
told to" in which "+ verbose" was removed. Instead of letting verbose
add to kmod_get_log_priority(), let it be similar to the other programs
instead.
2012-11-06 18:52:09 -02:00
Lucas De Marchi 92aad74925 tools: use a single function for logging libkmod output 2012-11-06 18:35:17 -02:00
Lucas De Marchi 34e06bfb54 tools: make usage() messages go to stdout rather than stderr
When user supplied --help/-h, program should output to stdout the usage,
not to stderr. It's the expected behavior, what the user asked for,
not something to log or an error.
2012-11-06 17:32:41 -02:00
Lucas De Marchi 84341fbe01 tools: share function to convert prio to string
No change is expected in the final binary since right now only an inline
function is shared. Later we expect to share more code.
2012-11-06 17:10:57 -02:00
Lucas De Marchi 4a2e20dfb3 tools: share getting program name from argv for all tools 2012-11-06 16:55:00 -02:00
Lucas De Marchi e6996c5c30 rmmod: route all messages to syslog if told to 2012-11-05 18:32:05 -02:00
Lucas De Marchi 04c26d28be rmmod: prefer ERR over plain fprintf 2012-11-05 18:31:19 -02:00
Lucas De Marchi 9382dbf7aa modinfo: prefer ERR over plain fprintf 2012-11-05 18:31:19 -02:00
Lucas De Marchi e2f9478faf insmod: prefer ERR over plain fprintf 2012-11-05 17:59:23 -02:00
Lucas De Marchi 96b50d3623 depmod: add depmod prefix to log messages 2012-11-05 02:08:16 -02:00
Lucas De Marchi a3f16ff704 depmod: remove inline from _log 2012-11-05 02:08:16 -02:00
Lucas De Marchi 61c48db360 depmod: prefer ERR and WRN over plain fprintf 2012-11-05 02:01:06 -02:00
Lucas De Marchi d9a2e15504 modprobe: use ERR() instead of fprintf(stderr, ...) 2012-11-01 13:03:02 -02:00
Lucas De Marchi d96ae03bd9 modprobe: prefix log messages to stderr with modprobe 2012-11-01 12:46:12 -02:00
Lucas De Marchi 07df56eb24 modprobe: move log function 2012-11-01 12:46:12 -02:00
Lucas De Marchi 86cc1f2328 modprobe: prefix libkmod messages to stderr with modprobe:
When we are logging to stderr we are previously relying on libkmod
sending it to the default location in case we are not asked to log to
syslog. The problem is that modprobe may be used in scripts that don't
want to log to syslog (since they are not daemons, like scripts to
generate initrd) and then it's difficult to know where the message comes
from.

This patch treats only the messages coming from libkmod.
2012-11-01 12:46:03 -02:00
Lucas De Marchi 1e947e3c87 modprobe: use prio_to_str() helper 2012-10-31 22:00:40 -02:00
Lucas De Marchi 4434d8ba36 modprobe: exit in one place 2012-10-31 21:29:54 -02:00
Lucas De Marchi e4a7352ad3 depmod: unref kmod_module once we don't need it anymore
Once we read all we need from a module, unref it so any resource taken
by it (including the mmap to access the file in libkmod) will be
dropped. This drastically reduces the number of open file descriptors
and also the memory needed, with no performance penalties. Rather,
there's a small speedup of ~2.6%.

Running depmod in a laptop with 2973 modules and comparing the number of
open file descriptors for kmod-10, before and after the last patches to
depmod (caaf438cb6 and HEAD) we have:

	Before:		2980 simultaneously open fds
	After:		7    simultaneously open fds
	kmod-10:	7    simultaneously open fds

So now we have the speedup of caching the file in kmod_module without
the drawback of increasing the number of open file descriptors.
2012-10-30 04:56:59 -02:00
Lucas De Marchi 447eed8c48 depmod: use our copy of modname instead of calling libkmod
In depmod_module_add() we already called kmod_module_get_name() and
copied the string to our struct. Use it instead of calling again and
again the libkmod function.
2012-10-30 04:11:24 -02:00
Lucas De Marchi ec587f298c depmod: cache dependency_symbol list in struct mod
The overall goal is to coalesce the accesses to a file that is the
backend of a module. This commit addresses the calls to
kmod_module_get_get_dependency_symbols(). Calling it earlier, while we
are iterating the modules allows us to free the struct kmod of each
module much sooner. We are still not freeing it since there are other
places that must be refactored first.

There's a performance penalty of ~2.5% from previous commit.
2012-10-30 04:05:53 -02:00
Lucas De Marchi 7062eca38b depmod: cache info_list in struct mod
The overall goal is to coalesce the accesses to a file that is the
backend of a module. This commit addresses the calls to
kmod_module_get_info(). Calling it earlier, while we are iterating the
modules allows us to free the struct kmod of each module much sooner. We
are still not freeing it since there are other places that must be
refactored first.

A nice side effect is that this commit reduces in ~33% the calls to
malloc(), giving a speedup of ~6% for cold caches (reproduced on only 1
laptop).
2012-10-30 03:24:25 -02:00
Lucas De Marchi b51ac407c2 depmod: do not create a hole in struct depmod 2012-10-30 02:33:14 -02:00
Lucas De Marchi cc833644b2 rmmod: Deprecate --wait option
Remove --wait from usage() and give a message + sleep(10) if user is in
fact using it.
2012-10-17 18:43:17 -03:00
Lucas De Marchi 88c247f7f1 depmod: fix parsing of modules.order with compressed modules
We now index the modules by uncompressed-relative-path instead of
relative-path. This is because the file modules.order, coming from
kernel, always comes with uncompressed paths. This fixes the issue of
not sorting the aliases correctly due to paths not matching when using
compressed modules.
2012-10-03 16:29:36 -03:00
Dave Reisner c5b37dba89 build-sys: Remove --with-rootprefix option
This is a broken option that only leads to misery and incompatabilities
with other systems. Kbuild doesn't come close to supporting directories
other than /lib/modules with several targets simply failing without
hacky fixes. Simply remove the option and all traces of it, as it
doesn't make sense in today's world.
2012-10-02 00:27:31 -03:00
Lucas De Marchi 36ddee6562 modprobe: Unconditionally use KMOD_PROBE_APPLY_BLACKLIST_ALIAS_ONLY
This fixes a change in behavior regarding kmod and module-init-tools:
when trying to load a module by alias, we should check if it's
blacklisted, regardless of the command line arguments passed.

This was reported by "Dmitry V. Levin <ldv@altlinux.org>".
2012-08-17 09:42:47 -03:00
Lucas De Marchi e8fd8fec23 Use #pragma once instead of #ifndef
Only the public header maintains #ifndef in the header, together with
pragma. The other ones contain only pragma.

As reported by Shawn Landden on systemd mailing list this is compatible
with all major compilers and gcc has this since version 3.3.
2012-07-18 10:31:50 -03:00
Lucas De Marchi 3f376cd877 depmod: use ferror and fclose to check for error
Thanks to hpa for point this out.
2012-06-15 22:14:00 -03:00
Lucas De Marchi a4fb97a71e depmod: return error when index is truncated due to ENOSPC
Before:
=======
[lucas@vader kmod]$ sudo depmod
[lucas@vader kmod]$ echo $?
0
[lucas@vader kmod]$ ls -l /lib/modules/$(uname -r)
total 12
drwxr-xr-x 8 root root   160 Jun 13 11:05 kernel
-rw-r--r-- 1 root root 12288 Jun 15 21:29 modules.alias
-rw-r--r-- 1 root root     0 Jun 15 21:29 modules.alias.bin
-rw-r--r-- 1 root root     0 Jun 15 21:29 modules.dep
-rw-r--r-- 1 root root     0 Jun 15 21:29 modules.dep.bin
-rw-r--r-- 1 root root     0 Jun 15 21:29 modules.devname
-rw-r--r-- 1 root root     0 Jun 15 21:29 modules.softdep
-rw-r--r-- 1 root root     0 Jun 15 21:29 modules.symbols
-rw-r--r-- 1 root root     0 Jun 15 21:29 modules.symbols.bin

Note that modules.alias is truncated and the other have size == 0

After:
======

[lucas@vader kmod]$ sudo ./tools/depmod
WARNING: could not open /lib/modules/3.5.0-rc2-demarchi-00028-g94fa83c/modules.order: No such file or directory
ERROR: Could not create index: output truncated: No space left on device
[lucas@vader kmod]$ echo $?
1
2012-06-15 21:31:05 -03:00
Lucas De Marchi 015946da0c depmod: fix coding-style issue in array declaration 2012-06-15 03:04:28 -03:00
Lucas De Marchi 80e49ad988 depmod: fail if any index could not be created 2012-06-15 02:42:39 -03:00