Commit Graph

1116 Commits

Author SHA1 Message Date
Lucas De Marchi
52c9c99056 Log error on failed underscores(), moving it to shared/
Move underscores() to shared/. It's the same as alias_normalize(), but
it rather operates in place, with the same string being passed.

The difference now that it's in shared/ is that it's a non-logging
function.

This makes us a little bit more verbose: we don't accept partially
correct module and aliases names in kcmdline and in configuration files.
We log an error instead.
2014-10-09 11:00:21 -03:00
Lucas De Marchi
2c5bc218be build-sys: rename libkmod-util convenience library
Now that all source code from libkmod-util has been moved to shared/
directory, rename also the convenience library to libshared.
2014-10-09 01:26:39 -03: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
2b0104fe3c Move alias_normalize() to 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
fdafa6b655 testsuite: add tests for array implementation 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
b18979b770 Prefer inttypes.h over stdint.h 2014-10-03 02:03:55 -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
8eded79c50 build-sys: normalize line breaks
Break lines earlier, as it's already done in some places and use only 1
tab to avoid reaching the column limit.
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
8b7189bc25 Move missing.h to shared directory 2014-10-03 00:31:10 -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
Randy MacLeod
9b34db1ae6 Add back-up implementation of be32toh()
Older systems may not have the be32toh function defined. Check for this
and fall back to checking the endianness and calling bswap_32 directly
if needed.  This works on both old and new systems.

[Thomas De Schampheleire <thomas.de.schampheleire@gmail.com>:
address comments raised by Lucas De Marchi [1], update commit message]
[1] http://www.spinics.net/lists/linux-modules/msg01129.html
2014-09-29 17:13:26 -03:00
Lucas De Marchi
419b7003af Update TODO 2014-09-23 00:21:53 -03:00
Marco d'Itri
66f4f6804c Add the man page for kmod(8) 2014-09-22 08:52:47 -03:00
Marco d'Itri
fde693c94f Document depmod --show in depmod(8) 2014-09-20 11:23:56 -03:00
Holger Obermaier
1a4aa7e2cb libkmod-index.c: Fix error message 2014-09-04 16:29:47 -03:00
Cristian Rodríguez
74c26943f1 Add missing O_CLOEXEC in kmod_module_get_size() 2014-06-19 18:01:37 -03:00
Lucas De Marchi
ae58de0fcb kmod 18 2014-06-14 12:46:38 -03:00
Lucas De Marchi
a5a41f8dbb testsuite: Fix macro missing format string 2014-06-14 11:14:58 -03:00
Lucas De Marchi
5963c36da3 testsuite: Add basic tests for hash implementation
Far from complete, but already covers all internal APIs.
2014-06-06 02:24:39 -03:00
Lucas De Marchi
30471c80a4 testsuite: Add assert_return
Add assert_return to use in testcases instead of assert. The issues
with assert are:
	1) It's disabled when NDEBUG is defined
	2) Even if it's well supported by testsuite (the parent will
	   report the child died) it can't output any meaningful
	   error message
2014-06-06 02:19:28 -03:00
Lucas De Marchi
f988e25c68 testsuite: separate testcases on log 2014-06-05 17:54:41 -03:00
Lucas De Marchi
7a2d0e6187 testsuite: check for correct error message in detect-loop 2014-05-30 10:26:17 -03:00
Lucas De Marchi
d7293a1628 testsuite: Fix expected_fail parsing
If a test has expected_fail=true, it means the return code must be
different from 0 *and* the outputs must match. This way it's possible to
check if the error messages are printed as they should.
2014-05-30 10:23:05 -03:00
Lucas De Marchi
f429113a47 testsuite: Add braces 2014-05-30 10:20: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
8183cfa9da testsuite: add test to fail depmod on module loops 2014-05-30 09:36:56 -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
Lukas Anzinger
86e19e9acd Fix use-after-free in hash implementation.
If a value is added to the hash under a key that already exists the new value
replaces the old value for that key. Since key can be a pointer to data that
is part of value and freed by hash->free_value(), the key must be also
replaced and not only the value. Otherwise key potentially points to freed data.
2014-05-18 16:04:50 -03:00
Leandro Pereira
30bfd48aef Close /sys/module/$NAME directory if opening /proc/module fails. 2014-05-14 20:24:19 -03:00
Leandro Pereira
c1bc88c98e Free abspath if kmod_module_new_from_path() fails. 2014-05-14 20:21:20 -03:00
Leandro Pereira
e84d912bd7 Free realnames if kmod_lookup_alias_from_alias_bin() fails 2014-05-14 20:19:52 -03:00
Leandro Pereira
b6d985c61a Ensure read_long() reads the correct number of bytes from the index 2014-05-14 20:18:00 -03:00
Leandro Pereira
d36c886aed Bail out of index_mm_open() if fstat() fails 2014-05-14 20:17:30 -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
Joe Lawrence
445e51c57d man: fixup spacing/parens in modprobe.d(5) 2014-05-13 14:45:15 -03:00
Lucas De Marchi
b8b990f47d Add gitignore to module playground 2014-05-09 08:43:32 -03:00
Marco d'Itri
1008a2d5ba Remove references to systemd from the bash completion file
And restore the original LGPL disclaimer text.
2014-05-05 01:52:04 -03:00
Lucas De Marchi
3f8dd30a76 testsuite: Add module playground dir 2014-05-02 12:57:17 -03:00
Lucas De Marchi
f5cdd574a5 Make sure there's NUL byte at the end of strndupa
Since strcpy() doesn't ensure we have a NUL byte in the resulting
string, use alloca() + memcpy(). Also make sure we don't evaluate "s"
twice.
2014-04-07 12:30:04 -03:00
Lucas De Marchi
04c0956e20 Add strndupa to missing.h 2014-04-07 11:00:24 -03:00
Lucas De Marchi
29bc329f55 Update .travis.yml
- Add cython to the dependencies, so it can compile the python bindings
 - Remove unecessary -Wno-error since now we don't use -Werror anymore.
2014-04-07 10:55:47 -03:00
Lucas De Marchi
49d8e0b590 kmod 17 2014-04-06 17:52:44 -03:00