platform/upstream/kmod.git
12 years agofix snprintf usage.
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.

12 years agoUse alias/symbol index_mm if it's open
Lucas De Marchi [Fri, 9 Dec 2011 18:11:42 +0000 (16:11 -0200)]
Use alias/symbol index_mm if it's open

12 years agoPass enum around instead of filename
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.

12 years agoUse index_mm if it's open for moddep search
Lucas De Marchi [Fri, 9 Dec 2011 17:47:23 +0000 (15:47 -0200)]
Use index_mm if it's open for moddep search

12 years agoDo not allocate path for known places an close resource asap
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.

12 years agoLoad and unload resources
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.

12 years agoindex: mm: Add flag to open call to populate buffer
Lucas De Marchi [Thu, 8 Dec 2011 17:10:55 +0000 (15:10 -0200)]
index: mm: Add flag to open call to populate buffer

12 years agoRefactor index file handling
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.

12 years agoremove useless look checking for duplicates
Gustavo Sverzut Barbieri [Thu, 8 Dec 2011 18:36:48 +0000 (16:36 -0200)]
remove useless look checking for duplicates

12 years agoindex: avoid strlen() whenever possible.
Gustavo Sverzut Barbieri [Thu, 8 Dec 2011 16:50:29 +0000 (14:50 -0200)]
index: avoid strlen() whenever possible.

12 years agoreduce calls to realloc() if size did not change.
Gustavo Sverzut Barbieri [Thu, 8 Dec 2011 18:35:08 +0000 (16:35 -0200)]
reduce calls to realloc() if size did not change.

12 years agoindex: improve buffer management and reduce mallocs.
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.

12 years agofix path handling at dependencies parsing.
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.

12 years agoNULL safety in public places, allows disable logging.
Gustavo Sverzut Barbieri [Thu, 8 Dec 2011 15:58:46 +0000 (13:58 -0200)]
NULL safety in public places, allows disable logging.

12 years agolog: give log function its data instead of kmod_ctx.
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.

12 years agomodname_normalize: fix const and buffer overflow.
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.

12 years agokmod_loaded: document exported function
Lucas De Marchi [Thu, 8 Dec 2011 14:50:40 +0000 (12:50 -0200)]
kmod_loaded: document exported function

12 years agokmod_list: document exported functions
Lucas De Marchi [Thu, 8 Dec 2011 14:25:36 +0000 (12:25 -0200)]
kmod_list: document exported functions

12 years agokmod_module: Remove const from path
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.

12 years agoadd kmod_module_get_filtered_blacklist()
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.

12 years agoOnly search path in moddep if it's not already set
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

12 years agoFix abs path helper function
Lucas De Marchi [Thu, 8 Dec 2011 12:37:56 +0000 (10:37 -0200)]
Fix abs path helper function

12 years agotest-insmod: show the path libkmod is using
Lucas De Marchi [Thu, 8 Dec 2011 12:57:50 +0000 (10:57 -0200)]
test-insmod: show the path libkmod is using

12 years agotest-insmod: print name to test modname_normalize().
Gustavo Sverzut Barbieri [Thu, 8 Dec 2011 06:13:44 +0000 (04:13 -0200)]
test-insmod: print name to test modname_normalize().

12 years agokmod_module: treat module creation by path with same names
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.

12 years agokmod_module: store absolute path when creating module from path
Lucas De Marchi [Wed, 7 Dec 2011 15:53:53 +0000 (13:53 -0200)]
kmod_module: store absolute path when creating module from path

12 years agoAdd helper path_make_absolute_cwd()
Lucas De Marchi [Wed, 7 Dec 2011 15:51:40 +0000 (13:51 -0200)]
Add helper path_make_absolute_cwd()

12 years agoAdd helper path_is_absolute()
Lucas De Marchi [Wed, 7 Dec 2011 15:50:52 +0000 (13:50 -0200)]
Add helper path_is_absolute()

12 years agokmod_config: parse install and remove commands
Lucas De Marchi [Wed, 7 Dec 2011 13:31:28 +0000 (11:31 -0200)]
kmod_config: parse install and remove commands

12 years agokmod_config: parse module options
Lucas De Marchi [Wed, 7 Dec 2011 05:18:57 +0000 (03:18 -0200)]
kmod_config: parse module options

12 years agoAdd helper strchr_replace()
Lucas De Marchi [Wed, 7 Dec 2011 12:59:17 +0000 (10:59 -0200)]
Add helper strchr_replace()

12 years agoUse streq() when possible
Lucas De Marchi [Wed, 7 Dec 2011 04:26:31 +0000 (02:26 -0200)]
Use streq() when possible

12 years agoSplit function so we don't call basename() unnecessarily
Lucas De Marchi [Tue, 6 Dec 2011 11:01:01 +0000 (09:01 -0200)]
Split function so we don't call basename() unnecessarily

12 years agotest: add test for modules' hash
Lucas De Marchi [Tue, 6 Dec 2011 05:49:30 +0000 (03:49 -0200)]
test: add test for modules' hash

12 years agoMaintain a pool of modules alive
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>

12 years agokmod_config: optimize config files handling
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()

12 years agokmod_list: remove nodes in order
Lucas De Marchi [Tue, 6 Dec 2011 04:20:46 +0000 (02:20 -0200)]
kmod_list: remove nodes in order

12 years agokmod_list: add helper function to merge two lists
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.

12 years agokmod_list: add helper kmod_list_insert_before()
Lucas De Marchi [Tue, 6 Dec 2011 01:53:56 +0000 (23:53 -0200)]
kmod_list: add helper kmod_list_insert_before()

12 years agokmod_list: add helper kmod_list_insert_after()
Lucas De Marchi [Tue, 6 Dec 2011 01:41:14 +0000 (23:41 -0200)]
kmod_list: add helper kmod_list_insert_after()

12 years agotest: add test to get dependencies of a module
Lucas De Marchi [Tue, 6 Dec 2011 04:40:38 +0000 (02:40 -0200)]
test: add test to get dependencies of a module

12 years agotest: add test to convert name to path
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.

12 years agokmod_module: normalize module name
Lucas De Marchi [Tue, 6 Dec 2011 04:46:22 +0000 (02:46 -0200)]
kmod_module: normalize module name

12 years agokmod_module: get path on demand
Lucas De Marchi [Mon, 5 Dec 2011 22:28:13 +0000 (20:28 -0200)]
kmod_module: get path on demand

12 years agokmod_module: parse dependencies on demand
Lucas De Marchi [Mon, 5 Dec 2011 22:23:05 +0000 (20:23 -0200)]
kmod_module: parse dependencies on demand

12 years agoSplit function to search moddep file
Lucas De Marchi [Mon, 5 Dec 2011 21:58:39 +0000 (19:58 -0200)]
Split function to search moddep file

12 years agokmod_module: return a new list and increase ref of dependencies
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().

12 years agoFix missing parenthesis in macro
Lucas De Marchi [Tue, 6 Dec 2011 03:44:08 +0000 (01:44 -0200)]
Fix missing parenthesis in macro

12 years agoAdd simple hash implementation
Gustavo Sverzut Barbieri [Mon, 5 Dec 2011 02:17:37 +0000 (00:17 -0200)]
Add simple hash implementation

12 years agokmod_module: inline name and make it always available
Lucas De Marchi [Mon, 5 Dec 2011 20:14:51 +0000 (18:14 -0200)]
kmod_module: inline name and make it always available

12 years agokmod_alias: reduce from 3 mallocs to a single one.
Gustavo Sverzut Barbieri [Sun, 4 Dec 2011 19:32:44 +0000 (17:32 -0200)]
kmod_alias: reduce from 3 mallocs to a single one.

12 years agoUse readdir_r in kmod_module_get_sections()
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.

12 years agoUse readdir_r in kmod_module_get_holders()
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.

12 years agoAdd padding to enum to make sure it's an int
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

12 years agoInline foreach macro for internal usage
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.

12 years agotests: release memory before error exits.
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.

12 years agono more kmod_loaded and kmod_loaded_module.
Gustavo Sverzut Barbieri [Sun, 4 Dec 2011 16:02:30 +0000 (14:02 -0200)]
no more kmod_loaded and kmod_loaded_module.

kmod_loaded_get_list() now returns a regular list of kmod_modules, use
kmod_module_get_module(), kmod_module_unref() and
kmod_module_unref_list() to operate on it.

12 years agokmod_module: extended information gathering.
Gustavo Sverzut Barbieri [Sun, 4 Dec 2011 14:40:00 +0000 (12:40 -0200)]
kmod_module: extended information gathering.

provide means to get:
 * refcount
 * initstate
 * holders
 * sections

this can be used to individually query properties from modules,
similar to /proc/modules (kmod_loaded / kmod_loaded_module).

12 years agokmod_module_get_module: safety against NULL pointers
Gustavo Sverzut Barbieri [Sun, 4 Dec 2011 15:14:11 +0000 (13:14 -0200)]
kmod_module_get_module: safety against NULL pointers

12 years agomodule refcount should start at 1.
Gustavo Sverzut Barbieri [Sun, 4 Dec 2011 14:34:02 +0000 (12:34 -0200)]
module refcount should start at 1.

the current way was having the referenced modules to be released given
the unref comparison checking for "> 0".

12 years agofix missing ")".
Gustavo Sverzut Barbieri [Sun, 4 Dec 2011 16:18:19 +0000 (14:18 -0200)]
fix missing ")".

12 years agoTODO: update file
Lucas De Marchi [Sat, 3 Dec 2011 22:51:01 +0000 (20:51 -0200)]
TODO: update file

12 years agoLicense library as LGPL
Lucas De Marchi [Sat, 3 Dec 2011 06:30:41 +0000 (04:30 -0200)]
License library as LGPL

The only part under GPL was the index, that is now re-licensed. Switch
back to LGPL.

12 years agoindex: change license to LGPL
Lucas De Marchi [Sat, 3 Dec 2011 06:28:49 +0000 (04:28 -0200)]
index: change license to LGPL

I've got an explicit permit from index author to re-license it as LGPL.

12 years agoindex: update copyrignt
Lucas De Marchi [Fri, 2 Dec 2011 20:25:44 +0000 (18:25 -0200)]
index: update copyrignt

mmap implementation

12 years agoindex: mmap: add support for seaching with wildcards
Lucas De Marchi [Fri, 2 Dec 2011 20:23:36 +0000 (18:23 -0200)]
index: mmap: add support for seaching with wildcards

Almost a clean copy & paste from the previous implementation.

12 years agoindex: mmap: add support for searching
Lucas De Marchi [Fri, 2 Dec 2011 19:49:03 +0000 (17:49 -0200)]
index: mmap: add support for searching

Almost a clean copy & paste from the previous implementation.

12 years agoindex: mmap: add support for searching node
Lucas De Marchi [Fri, 2 Dec 2011 19:45:01 +0000 (17:45 -0200)]
index: mmap: add support for searching node

Almost a clean copy & paste from the previous implementation.

12 years agoindex: mmap: read child node
Lucas De Marchi [Fri, 2 Dec 2011 19:41:46 +0000 (17:41 -0200)]
index: mmap: read child node

12 years agoindex: mmap: read root node
Lucas De Marchi [Fri, 2 Dec 2011 19:41:30 +0000 (17:41 -0200)]
index: mmap: read root node

12 years agoindex: mmap: create and destroy node
Lucas De Marchi [Fri, 2 Dec 2011 19:27:52 +0000 (17:27 -0200)]
index: mmap: create and destroy node

12 years agoAdd memdup() helper
Lucas De Marchi [Fri, 2 Dec 2011 19:21:18 +0000 (17:21 -0200)]
Add memdup() helper

12 years agoindex: mmap: open and close file
Lucas De Marchi [Fri, 2 Dec 2011 01:14:20 +0000 (23:14 -0200)]
index: mmap: open and close file

12 years agoindex: use idx instead of index due to name clash
Lucas De Marchi [Fri, 2 Dec 2011 19:48:14 +0000 (17:48 -0200)]
index: use idx instead of index due to name clash

12 years agoFix some coding style issues
Lucas De Marchi [Sat, 3 Dec 2011 06:05:22 +0000 (04:05 -0200)]
Fix some coding style issues

12 years agoimprove kmod_config api.
Gustavo Sverzut Barbieri [Fri, 2 Dec 2011 23:40:22 +0000 (21:40 -0200)]
improve kmod_config api.

make the function names reflect the structure they are operating on.

the structure is now allocated and remembers the context it was
created, then no need to give the context in every function call.

12 years agoreorder struct fields to avoid holes, improving packing
Gustavo Sverzut Barbieri [Fri, 2 Dec 2011 23:10:24 +0000 (21:10 -0200)]
reorder struct fields to avoid holes, improving packing

12 years agoREADME with purpose and initial overview.
Gustavo Sverzut Barbieri [Fri, 2 Dec 2011 23:05:38 +0000 (21:05 -0200)]
README with purpose and initial overview.

12 years agoFix extra attribute
Lucas De Marchi [Sat, 3 Dec 2011 05:53:10 +0000 (03:53 -0200)]
Fix extra attribute

linenum can be NULL in case we are not interested in the number of lines
parsed.

12 years agoimprove compiler warnings and checks for internal functions.
Gustavo Sverzut Barbieri [Fri, 2 Dec 2011 22:34:58 +0000 (20:34 -0200)]
improve compiler warnings and checks for internal functions.

12 years agoimprove "const" keyword usage.
Gustavo Sverzut Barbieri [Fri, 2 Dec 2011 22:24:07 +0000 (20:24 -0200)]
improve "const" keyword usage.

functions that do not modify their parameters get them as const pointers.

special cases:
 * kmod_get_userdata/kmod_set_userdata: return as void* for user convenience.
 * kmod_list_append/kmod_list_prepend: take const void* for user convenience.

12 years agoautogen: use "$@" and exec last program
Jan Engelhardt [Sat, 3 Dec 2011 04:31:01 +0000 (02:31 -0200)]
autogen: use "$@" and exec last program

12 years agoDo not ship autogen.sh in the tarball
Lucas De Marchi [Fri, 2 Dec 2011 19:53:54 +0000 (17:53 -0200)]
Do not ship autogen.sh in the tarball

Copied from libabc.

12 years agoDrop configurations from /usr/local
Lucas De Marchi [Fri, 2 Dec 2011 17:02:50 +0000 (15:02 -0200)]
Drop configurations from /usr/local

12 years agoTODO: update tasks
Lucas De Marchi [Fri, 2 Dec 2011 16:49:57 +0000 (14:49 -0200)]
TODO: update tasks

12 years agoindex: follow libkmod coding style
Lucas De Marchi [Fri, 2 Dec 2011 12:27:15 +0000 (10:27 -0200)]
index: follow libkmod coding style

12 years agoRemove redundant comments
Lucas De Marchi [Fri, 2 Dec 2011 12:23:02 +0000 (10:23 -0200)]
Remove redundant comments

12 years agoindex: remove unused functions
Lucas De Marchi [Fri, 2 Dec 2011 12:21:42 +0000 (10:21 -0200)]
index: remove unused functions

12 years agoindex: re-order functions so prototypes are not needed
Lucas De Marchi [Fri, 2 Dec 2011 12:15:00 +0000 (10:15 -0200)]
index: re-order functions so prototypes are not needed

12 years agoRemove trailing whitespace
Lucas De Marchi [Fri, 2 Dec 2011 12:08:52 +0000 (10:08 -0200)]
Remove trailing whitespace

12 years agoFix 'redundant redeclaration' warnings
Lucas De Marchi [Fri, 2 Dec 2011 12:07:25 +0000 (10:07 -0200)]
Fix 'redundant redeclaration' warnings

12 years agoFix 'old style declaration' warnings
Lucas De Marchi [Fri, 2 Dec 2011 12:05:31 +0000 (10:05 -0200)]
Fix 'old style declaration' warnings

12 years agoFix missing return
Lucas De Marchi [Fri, 2 Dec 2011 12:03:34 +0000 (10:03 -0200)]
Fix missing return

12 years agoClean 'unused variable' warnings
Lucas De Marchi [Fri, 2 Dec 2011 12:02:05 +0000 (10:02 -0200)]
Clean 'unused variable' warnings

12 years agoClean 'shadowed declaration' warnings
Lucas De Marchi [Fri, 2 Dec 2011 12:00:03 +0000 (10:00 -0200)]
Clean 'shadowed declaration' warnings

12 years agoClean 'shadowed declaration' warnings
Lucas De Marchi [Fri, 2 Dec 2011 11:56:22 +0000 (09:56 -0200)]
Clean 'shadowed declaration' warnings

index is a function in string.h, so replace index with idx all over the
source code.

12 years agoClean 'no previous prototype' warning
Lucas De Marchi [Fri, 2 Dec 2011 11:53:31 +0000 (09:53 -0200)]
Clean 'no previous prototype' warning

12 years agoUse fstat() instead of stat() when possible
Lucas De Marchi [Fri, 2 Dec 2011 01:13:27 +0000 (23:13 -0200)]
Use fstat() instead of stat() when possible

12 years agoAdd fucntion to API to get dependencies
Lucas De Marchi [Thu, 1 Dec 2011 22:06:08 +0000 (20:06 -0200)]
Add fucntion to API to get dependencies

12 years agoUse strtok_r insteat of strtok
Lucas De Marchi [Thu, 1 Dec 2011 20:59:54 +0000 (18:59 -0200)]
Use strtok_r insteat of strtok

strtok is not thread-safe because it uses a static pointer to keep track
of position in the string. Using strtok_r solves the problem.