Gustavo Sverzut Barbieri [Mon, 12 Dec 2011 20:28:52 +0000 (18:28 -0200)]
handle case where modname was not detected.
Lucas De Marchi [Mon, 12 Dec 2011 20:24:35 +0000 (18:24 -0200)]
Change licenses
libkmod is under LGPL 2.1 or later
tools/* are under GPL
Lucas De Marchi [Mon, 12 Dec 2011 19:26:47 +0000 (17:26 -0200)]
build-sys: enable debug by default in autogen.sh
Lucas De Marchi [Mon, 12 Dec 2011 19:23:19 +0000 (17:23 -0200)]
build-sys: Set CFLAGS to "-O2 -Werror" in autogen.sh
Lucas De Marchi [Mon, 12 Dec 2011 19:23:04 +0000 (17:23 -0200)]
Remove warnings: ‘err’ may be used uninitialized in this function
Lucas De Marchi [Mon, 12 Dec 2011 19:05:23 +0000 (17:05 -0200)]
build-sys: add version map file to build dependencies
Based on original patch from Jan Engelhardt <jengelh@medozas.de> to
libabc.
Lucas De Marchi [Mon, 12 Dec 2011 18:41:38 +0000 (16:41 -0200)]
Rename project from libkmod to kmod
Lucas De Marchi [Mon, 12 Dec 2011 17:41:02 +0000 (15:41 -0200)]
Do not use config if it's not needed/wanted
Lucas De Marchi [Mon, 12 Dec 2011 17:27:57 +0000 (15:27 -0200)]
Use true/false for bool return
Lucas De Marchi [Mon, 12 Dec 2011 17:23:03 +0000 (15:23 -0200)]
Directories inside config directories are not supported
This was failing silent, both in libkmod and module-init-tools. Give a
warning if we created a dir inside config directories.
Lucas De Marchi [Mon, 12 Dec 2011 17:00:51 +0000 (15:00 -0200)]
Do not stat() dir twice
Lucas De Marchi [Mon, 12 Dec 2011 16:26:45 +0000 (14:26 -0200)]
Fix leak of DIR
Lucas De Marchi [Mon, 12 Dec 2011 16:01:25 +0000 (14:01 -0200)]
Remove leftover comment
mod->path is always absolute: remove comment from previous behavior.
Lucas De Marchi [Mon, 12 Dec 2011 15:56:47 +0000 (13:56 -0200)]
Remove libkmod-loaded.c and re-order functions in libkmod-module.c
It's not possible to move functions related to "live" modules to
libkmod-loaded.c because they depend on the definition of kmod_module.
Putting this structure in the private header is not a good idea, so let
all functions related to "live" information in the end of
libkmod-module.c, and move the sole function from libkmod-loaded.c to
this place. This way all functions get the right documentation
about their sections.
Lucas De Marchi [Mon, 12 Dec 2011 15:49:27 +0000 (13:49 -0200)]
Rename kmod_loaded_get_list() to kmod_module_new_from_loaded()
Be consistent with other similar functions already present and improve
documentation.
Lucas De Marchi [Mon, 12 Dec 2011 15:39:07 +0000 (13:39 -0200)]
build-sys: replace spaces with tabs
Lucas De Marchi [Mon, 12 Dec 2011 15:37:13 +0000 (13:37 -0200)]
build-sys: move remaining warning flags to configure
Lucas De Marchi [Mon, 12 Dec 2011 15:26:34 +0000 (13:26 -0200)]
build-sys: remove duplicated warning flags
"822ce23 beef compile flags" added warning flags to configure, but some
of them were already present in autogen.sh. Remove the flags from
autogen.sh.
Lucas De Marchi [Mon, 12 Dec 2011 13:52:59 +0000 (11:52 -0200)]
coding style: be consistent with blank lines
Lucas De Marchi [Mon, 12 Dec 2011 12:48:02 +0000 (10:48 -0200)]
coding style: fix lines over 80 chars
Lines should not go over 80 chars with a few exceptions:
- headers
- function definitions with only 1 argument
- long strings, otherwise we break grep
This should go later in a coding-style file
Lucas De Marchi [Mon, 12 Dec 2011 12:30:01 +0000 (10:30 -0200)]
Merge branch 'use-mmap'
Conflicts:
libkmod/libkmod.c
Gustavo Sverzut Barbieri [Sun, 11 Dec 2011 22:37:01 +0000 (20:37 -0200)]
API-BREAK: kmod_new() takes a second parameter for configuration directory.
This is required by modprobe and also to help doing unit tests in future.
Gustavo Sverzut Barbieri [Sun, 11 Dec 2011 21:36:18 +0000 (19:36 -0200)]
tools: add modprobe
try to mimic original module-init-tools' modprobe as much as possible,
but this exposed some missing features in libkmod, these are now
listed in TODO.
Gustavo Sverzut Barbieri [Sun, 11 Dec 2011 00:19:41 +0000 (22:19 -0200)]
add lsmod, insmod and rmmod tools.
these tools are compatible with module-init-tools (except insmod does
not take data from stdin).
Gustavo Sverzut Barbieri [Sun, 11 Dec 2011 21:42:02 +0000 (19:42 -0200)]
add missing newline to log messages.
Gustavo Sverzut Barbieri [Sun, 11 Dec 2011 21:33:03 +0000 (19:33 -0200)]
be less verbose on initstate for unexistent modules.
the module may be unloaded, in this case -NOENT is returned but it
should not present an error message
Gustavo Sverzut Barbieri [Sun, 11 Dec 2011 00:26:40 +0000 (22:26 -0200)]
beef compile flags.
Beef the compile flags by using the same set recommended by systemd,
it uses attribute.m4 from the xine project to check supported flags.
Gustavo Sverzut Barbieri [Sat, 10 Dec 2011 23:02:39 +0000 (21:02 -0200)]
insmod: allows providing option to module.
Gustavo Sverzut Barbieri [Sat, 10 Dec 2011 23:00:19 +0000 (21:00 -0200)]
always normalize user-given alias.
Gustavo Sverzut Barbieri [Sat, 10 Dec 2011 22:47:01 +0000 (20:47 -0200)]
export module's options and commands.
This will be required to implement modprobe later. The implementation
follows "man modprobe.conf" and allows options to be specified for
alias as well, thus the need for kmod_resolve_alias_options().
Example mod-a.conf:
options mod-a a=1 b=2
options mod-a c=3
alias mymod-a mod-a
options mymod-a d=4
Results in:
options mod-a a=1 b=2 c=3
options mymod-a a=1 b=2 c=3 d=4
Install commands are being concatenated with ";", but manpage is not
clean about this behavior.
Gustavo Sverzut Barbieri [Sat, 10 Dec 2011 22:36:22 +0000 (20:36 -0200)]
parse_depline may be called from libkmod.c
allow parse_depline to be called when already initialized as it may be
called from libkmod.c and at that point there is no way to check
mod->init.dep
Gustavo Sverzut Barbieri [Sat, 10 Dec 2011 21:45:37 +0000 (19:45 -0200)]
fix string replace.
configure files with this would fail:
options wl x=1
were being handled as " =1".
Lucas De Marchi [Fri, 9 Dec 2011 18:42:14 +0000 (16:42 -0200)]
kmod: Add documentation and format comments
Gustavo Sverzut Barbieri [Sat, 10 Dec 2011 15:32:27 +0000 (13:32 -0200)]
update TODO
Gustavo Sverzut Barbieri [Sat, 10 Dec 2011 15:28:18 +0000 (13:28 -0200)]
index: fix memleak for non-matchin aliases.
Gustavo Sverzut Barbieri [Sat, 10 Dec 2011 15:04:43 +0000 (13:04 -0200)]
index-mm: allocate values inline into node, strings points to mmap.
For mmap mode, we can avoid allocating and copying strings from the
mmap'ed memory.
With that we have fixed length "struct index_mm_value" that can be
allocated inline with "struct index_mm_node".
Gustavo Sverzut Barbieri [Sat, 10 Dec 2011 13:53:51 +0000 (11:53 -0200)]
index: cleanup header, move as much as possible to libkmod-index.c
Gustavo Sverzut Barbieri [Sat, 10 Dec 2011 13:44:31 +0000 (11:44 -0200)]
index-mm: no need to allocate prefix.
Gustavo Sverzut Barbieri [Sat, 10 Dec 2011 13:36:35 +0000 (11:36 -0200)]
index-mm: fix memory access.
uint32_t reads must be aligned, they're not then use memcpy().
read_alloc_chars_mm() and read_chars_mm() were wrong, normalize all
address calculation using single byte pointer "addr" that is
incremented by the amount read, this will avoid further errors.
Gustavo Sverzut Barbieri [Sat, 10 Dec 2011 12:28:11 +0000 (10:28 -0200)]
test-lookup: allow loading resources for testing.
Gustavo Sverzut Barbieri [Sat, 10 Dec 2011 12:27:27 +0000 (10:27 -0200)]
kmod_load_resources: use proper full path to binary files to be mmaped.
Gustavo Sverzut Barbieri [Sat, 10 Dec 2011 11:28:42 +0000 (09:28 -0200)]
kmod_lookup_alias_from_alias_bin: debug message for mmap case.
Gustavo Sverzut Barbieri [Sat, 10 Dec 2011 11:26:27 +0000 (09:26 -0200)]
kmod_search_moddep: reorder to avoid creating path when not required.
if we're using mmap'ed index, say so and avoid creating the path as it
won't be used.
Gustavo Sverzut Barbieri [Sat, 10 Dec 2011 11:21:03 +0000 (09:21 -0200)]
fix snprintf usage.
snprintf() takes the full buffer size, including \0 and guarantees it
will be there.
Lucas De Marchi [Fri, 9 Dec 2011 18:42:14 +0000 (16:42 -0200)]
kmod: Add documentation and format comments
Lucas De Marchi [Fri, 9 Dec 2011 18:11:42 +0000 (16:11 -0200)]
Use alias/symbol index_mm if it's open
Lucas De Marchi [Fri, 9 Dec 2011 18:06:04 +0000 (16:06 -0200)]
Pass enum around instead of filename
This will allow us to later use the index to search these indexes.
Lucas De Marchi [Fri, 9 Dec 2011 17:47:23 +0000 (15:47 -0200)]
Use index_mm if it's open for moddep search
Lucas De Marchi [Fri, 9 Dec 2011 17:33:37 +0000 (15:33 -0200)]
Do not allocate path for known places an close resource asap
This place is not supposed to exceed PATH_MAX. So, use snprintf instead
of asprintf.
Close the index before iterating the values.
Lucas De Marchi [Thu, 8 Dec 2011 16:59:51 +0000 (14:59 -0200)]
Load and unload resources
This call will mmap all the index files and in future some of the work
done in ctx creation can be put here.
Lucas De Marchi [Thu, 8 Dec 2011 17:10:55 +0000 (15:10 -0200)]
index: mm: Add flag to open call to populate buffer
Lucas De Marchi [Thu, 8 Dec 2011 16:56:48 +0000 (14:56 -0200)]
Refactor index file handling
Put all names in a static vector and declare a enum containing the
number of indexes. This way it's easier to create vectors inside ctx
that depend on these files.
Gustavo Sverzut Barbieri [Thu, 8 Dec 2011 18:36:48 +0000 (16:36 -0200)]
remove useless look checking for duplicates
Gustavo Sverzut Barbieri [Thu, 8 Dec 2011 16:50:29 +0000 (14:50 -0200)]
index: avoid strlen() whenever possible.
Gustavo Sverzut Barbieri [Thu, 8 Dec 2011 18:35:08 +0000 (16:35 -0200)]
reduce calls to realloc() if size did not change.
Gustavo Sverzut Barbieri [Thu, 8 Dec 2011 16:36:30 +0000 (14:36 -0200)]
index: improve buffer management and reduce mallocs.
Grow buffer based on a step, avoiding hitting the system over and over
again.
Do not allocate the 'struct buffer' as in all cases the lifetime is
known and the pattern was allocate then free in every call site.
Gustavo Sverzut Barbieri [Thu, 8 Dec 2011 06:44:03 +0000 (04:44 -0200)]
fix path handling at dependencies parsing.
paths come relative to dirname, make them absolute to avoid confusion
later.
Gustavo Sverzut Barbieri [Thu, 8 Dec 2011 15:58:46 +0000 (13:58 -0200)]
NULL safety in public places, allows disable logging.
Gustavo Sverzut Barbieri [Thu, 8 Dec 2011 15:47:55 +0000 (13:47 -0200)]
log: give log function its data instead of kmod_ctx.
This will be the most common use case for logging, also changed
log_stderr() to log_filep() with data being stderr to test it.
Gustavo Sverzut Barbieri [Thu, 8 Dec 2011 06:10:49 +0000 (04:10 -0200)]
modname_normalize: fix const and buffer overflow.
"buf[NAME_MAX] = value" is invalid since it would access the byte
right after the array.
Also fix the const of modname, do not mess with it to avoid mistakes.
Lucas De Marchi [Thu, 8 Dec 2011 14:50:40 +0000 (12:50 -0200)]
kmod_loaded: document exported function
Lucas De Marchi [Thu, 8 Dec 2011 14:25:36 +0000 (12:25 -0200)]
kmod_list: document exported functions
Gustavo Sverzut Barbieri [Thu, 8 Dec 2011 06:44:03 +0000 (04:44 -0200)]
kmod_module: Remove const from path
It's an ugly hack. This is an internal variable, we know we shouldn't
change it everywhere.
Gustavo Sverzut Barbieri [Thu, 8 Dec 2011 07:17:43 +0000 (05:17 -0200)]
add kmod_module_get_filtered_blacklist()
This function will filter the given list against the known blacklist,
returning a new list with remaining modules with the reference
incremented.
Lucas De Marchi [Thu, 8 Dec 2011 12:42:34 +0000 (10:42 -0200)]
Only search path in moddep if it's not already set
rmmod/insmod should be able to operate directly on files, not relying on
indexes and configuration.
The following test was not working and now it is:
$ # go to a dir != mod->dirname
$ cd /lib/modules/$(uname -r)/kernel
$ # try to insert module giving a relative path
$ insmod drivers/acpi/ac.ko
Lucas De Marchi [Thu, 8 Dec 2011 12:37:56 +0000 (10:37 -0200)]
Fix abs path helper function
Lucas De Marchi [Thu, 8 Dec 2011 12:57:50 +0000 (10:57 -0200)]
test-insmod: show the path libkmod is using
Gustavo Sverzut Barbieri [Thu, 8 Dec 2011 06:13:44 +0000 (04:13 -0200)]
test-insmod: print name to test modname_normalize().
Lucas De Marchi [Wed, 7 Dec 2011 16:08:01 +0000 (14:08 -0200)]
kmod_module: treat module creation by path with same names
If a module with the same name already exists, try to reference it if
paths are the same. Otherwise fail.
Lucas De Marchi [Wed, 7 Dec 2011 15:53:53 +0000 (13:53 -0200)]
kmod_module: store absolute path when creating module from path
Lucas De Marchi [Wed, 7 Dec 2011 15:51:40 +0000 (13:51 -0200)]
Add helper path_make_absolute_cwd()
Lucas De Marchi [Wed, 7 Dec 2011 15:50:52 +0000 (13:50 -0200)]
Add helper path_is_absolute()
Lucas De Marchi [Wed, 7 Dec 2011 13:31:28 +0000 (11:31 -0200)]
kmod_config: parse install and remove commands
Lucas De Marchi [Wed, 7 Dec 2011 05:18:57 +0000 (03:18 -0200)]
kmod_config: parse module options
Lucas De Marchi [Wed, 7 Dec 2011 12:59:17 +0000 (10:59 -0200)]
Add helper strchr_replace()
Lucas De Marchi [Wed, 7 Dec 2011 04:26:31 +0000 (02:26 -0200)]
Use streq() when possible
Lucas De Marchi [Tue, 6 Dec 2011 11:01:01 +0000 (09:01 -0200)]
Split function so we don't call basename() unnecessarily
Lucas De Marchi [Tue, 6 Dec 2011 05:49:30 +0000 (03:49 -0200)]
test: add test for modules' hash
Lucas De Marchi [Tue, 6 Dec 2011 05:38:37 +0000 (03:38 -0200)]
Maintain a pool of modules alive
Based on previous implementation by
Gustavo Sverzut Barbieri <barbieri@profusion.mobi>
Lucas De Marchi [Tue, 6 Dec 2011 04:26:22 +0000 (02:26 -0200)]
kmod_config: optimize config files handling
1) Allocate less by not sorting the result with qsort. Instead,
insert the nodes in the correct order;
2) Do not maintain the whole path in memory, but rely on openat()
Lucas De Marchi [Tue, 6 Dec 2011 04:20:46 +0000 (02:20 -0200)]
kmod_list: remove nodes in order
Lucas De Marchi [Tue, 6 Dec 2011 02:47:06 +0000 (00:47 -0200)]
kmod_list: add helper function to merge two lists
This helper function will append the second list in the first one, so
they become one single list.
Lucas De Marchi [Tue, 6 Dec 2011 01:53:56 +0000 (23:53 -0200)]
kmod_list: add helper kmod_list_insert_before()
Lucas De Marchi [Tue, 6 Dec 2011 01:41:14 +0000 (23:41 -0200)]
kmod_list: add helper kmod_list_insert_after()
Lucas De Marchi [Tue, 6 Dec 2011 04:40:38 +0000 (02:40 -0200)]
test: add test to get dependencies of a module
Lucas De Marchi [Tue, 6 Dec 2011 01:17:29 +0000 (23:17 -0200)]
test: add test to convert name to path
If we create a kmod_module from a name, the path returned is relative to
the module dirname, as passed during kmod_ctx creation. Note that if
kmod_ctx is created with kmod_new(NULL), the dir used is the one
returned by uname.
Lucas De Marchi [Tue, 6 Dec 2011 04:46:22 +0000 (02:46 -0200)]
kmod_module: normalize module name
Lucas De Marchi [Mon, 5 Dec 2011 22:28:13 +0000 (20:28 -0200)]
kmod_module: get path on demand
Lucas De Marchi [Mon, 5 Dec 2011 22:23:05 +0000 (20:23 -0200)]
kmod_module: parse dependencies on demand
Lucas De Marchi [Mon, 5 Dec 2011 21:58:39 +0000 (19:58 -0200)]
Split function to search moddep file
Lucas De Marchi [Mon, 5 Dec 2011 21:40:45 +0000 (19:40 -0200)]
kmod_module: return a new list and increase ref of dependencies
kmod_module_get_dependency is renamed to kmod_module_get_dependencies
since it's returning a list. To match other APIs, now it returns a new
list that user must free with kmod_module_unref_list().
Lucas De Marchi [Tue, 6 Dec 2011 03:44:08 +0000 (01:44 -0200)]
Fix missing parenthesis in macro
Gustavo Sverzut Barbieri [Mon, 5 Dec 2011 02:17:37 +0000 (00:17 -0200)]
Add simple hash implementation
Lucas De Marchi [Mon, 5 Dec 2011 20:14:51 +0000 (18:14 -0200)]
kmod_module: inline name and make it always available
Gustavo Sverzut Barbieri [Sun, 4 Dec 2011 19:32:44 +0000 (17:32 -0200)]
kmod_alias: reduce from 3 mallocs to a single one.
Lucas De Marchi [Mon, 5 Dec 2011 15:40:16 +0000 (13:40 -0200)]
Use readdir_r in kmod_module_get_sections()
readdir() is not thread-safe. Use readdir_r instead.
Lucas De Marchi [Mon, 5 Dec 2011 15:24:23 +0000 (13:24 -0200)]
Use readdir_r in kmod_module_get_holders()
readdir() is not thread-safe. Use readdir_r instead.
Lucas De Marchi [Mon, 5 Dec 2011 13:42:12 +0000 (11:42 -0200)]
Add padding to enum to make sure it's an int
Lucas De Marchi [Mon, 5 Dec 2011 13:33:15 +0000 (11:33 -0200)]
Inline foreach macro for internal usage
Avoid calling _next() function because it's an exported function and
linker can not optimize it.
Thanks to "Gustavo Sverzut Barbieri <barbieri@profusion.mobi>" for
suggestion.
Gustavo Sverzut Barbieri [Sun, 4 Dec 2011 23:18:21 +0000 (21:18 -0200)]
tests: release memory before error exits.
this makes it easier to valgrind the error cases as well.