Commit Graph

283 Commits

Author SHA1 Message Date
Luis Felipe Strano Moraes
a969376fb0 Removing warnings when compiling on i686 platform. 2011-12-20 13:15:32 -02:00
Gustavo Sverzut Barbieri
b55df2ee03 kmod_module_new_*: improve debugging. 2011-12-20 13:13:41 -02:00
Lucas De Marchi
16ca3666bf Fix check for opened indexes 2011-12-20 12:29:13 -02:00
Lucas De Marchi
76b8031bce elf: fix regression with empty strings
Commit "b20dc17 Remove unneeded reference to last string" reverted the
fix in "47a0ef6 elf: do not output empty strings." and empty strings are
appearing again in kmod-modinfo.

With this commit we do a bit different and instead of keeping the
reference to last string we skip the '\0' inside the loop.
2011-12-20 12:04:21 -02:00
Lucas De Marchi
51c409b449 Cache the offset of crc
This way we don't need to check every time in loop. Indeed compiler
could already optimize out that checks, but this ways is cleaner and
shorter.
2011-12-20 11:41:19 -02:00
Lucas De Marchi
58b7191c94 Make section size constant since it's always the same 2011-12-20 11:35:17 -02:00
Lucas De Marchi
f8fa525c7f Optimize kmod_elf_get_strings() by reducing calls to memcpy
Copy the entire string only once and then scan it, setting up the
pointers of the vector.
2011-12-20 03:34:28 -02:00
Lucas De Marchi
b20dc17068 Remove unneeded reference to last string 2011-12-20 03:27:51 -02:00
Lucas De Marchi
052656f5b3 Put blank lines where it's due
See CODING-STYLE for reference
2011-12-20 03:27:51 -02:00
Lucas De Marchi
3267026e0b Terminate strv with NULL 2011-12-20 03:27:50 -02:00
Lucas De Marchi
4f0f0e75e2 Reduce ident by continuing early 2011-12-20 03:27:50 -02:00
Gustavo Sverzut Barbieri
1c58590549 elf: skip leading symbol dot in modversion.
Mimics module-init-tools's dump_modversions() that calls skip_dot()
to skip leading dots. This is required for PPC64.
2011-12-19 21:55:27 -02:00
Gustavo Sverzut Barbieri
fc8e58ba4e elf: fix typo that resulted in invalid uint reads for big-endian platforms. 2011-12-19 21:55:22 -02:00
Gustavo Sverzut Barbieri
47a0ef601d elf: do not output empty strings. 2011-12-19 18:32:58 -02:00
Gustavo Sverzut Barbieri
fc27344ed9 elf: fix minimum file size calculation.
there is only a single file header, multiple sections.
2011-12-19 15:06:49 -02:00
Gustavo Sverzut Barbieri
708624a4eb ELF: initial support for modinfo and strip of modversions and vermagic.
Needs testing, but should work.
2011-12-19 15:06:49 -02:00
Lucas De Marchi
e5a7f6ac79 Fix debug message formatting 2011-12-19 15:06:49 -02:00
Lucas De Marchi
9dec24462d Fix wrong name len when converting path to modname 2011-12-18 15:12:57 -02:00
Gustavo Sverzut Barbieri
a6bf2495f6 compatibility: match commands using fnmatch() instead of strcmp().
module-init-tools modprobe.c use fnmatch() and not strcmp() to match
commands and softdeps, although the man page does not say so. Then use
the same function to provide compatibility.
2011-12-17 20:03:44 -02:00
Gustavo Sverzut Barbieri
d6b55b7d18 introduce kmod_list_foreach_reverse().
walks the list in the reverse order.
2011-12-17 20:03:43 -02:00
Lucas De Marchi
fecbad2f22 Use tab instead of spaces 2011-12-17 20:03:13 -02:00
Gustavo Sverzut Barbieri
d5ec60bc0c introduce kmod_list_last()
This gets the last element in the list, that is, the previous element
of the head.
2011-12-17 19:43:11 -02:00
Gustavo Sverzut Barbieri
2a70a5d4e0 fix kmod_list_prev().
kmod_list_prev() should return NULL if the current element is the
head, not if the previous element is the head. This was likely a copy
& paste error from kmod_list_next().
2011-12-17 19:43:11 -02:00
Gustavo Sverzut Barbieri
1c52260048 implement softdeps. 2011-12-17 19:43:11 -02:00
Gustavo Sverzut Barbieri
a5a92a613c fix error handling path. 2011-12-17 19:43:11 -02:00
Gustavo Sverzut Barbieri
3d8226edfe implement zlib module loading. 2011-12-17 19:43:11 -02:00
Lucas De Marchi
f4fc552368 Lookup for commands in kmod_module_new_from_lookup()
Install and remove commands are now properly treated on lookup. Example
config file:

$ ./test/test-lookup installme
libkmod version 1
Alias: 'installme'
Modules matching:
	installme
		install commands: 'echo "this is a install message"'

$ ./test/test-lookup removeme
libkmod version 1
Alias: 'removeme'
Modules matching:
	removeme
		remove commands: 'echo "this is a remove message"'
2011-12-17 19:41:35 -02:00
Lucas De Marchi
60f6760e73 kmod_module: do not find more than the first command
modprobe from module-init-tools does not use more than one
install/remove command, it just stops on the first one. Test
modprobe.conf:

install bla echo "this is a message"
install bla echo "this is a message"

$ modprobe bla
this is a message
$

Install and remove commands are already a legacy thing we need to carry,
but let's not extend it so people do not start doing crazy things.

With this patch we are breaking on the first element we find in the
configuration. May be we can add a warning later when parsing the config
that install commands are duplicated.
2011-12-17 19:41:35 -02:00
Cristian Rodríguez
8e3e5839a0 Open more file descriptors with O_CLOEXEC 2011-12-17 19:28:10 -02:00
Cristian Rodríguez
79e5ea91e0 Library must use O_CLOEXEC whenever it opens file descriptors 2011-12-16 04:16:09 -02:00
Ulisses Furquim
a955f71f60 trivial: fix typo causing an infinite loop 2011-12-15 21:36:12 +00:00
Lucas De Marchi
4084c176c1 Remove module from hash when it's gone
Module was never being removed from hash table. Therefore, if we create
a module, unref it and create it again we will access freed memory.
Commit "53385cf Improve test of double references" introduced a new test
in test-mod-double-ref.c that previously to this commit was crashing and
now it's working fine.
2011-12-15 13:49:13 -02:00
Lucas De Marchi
818f8e8ad5 Add safety NULL checks in exported functions 2011-12-15 13:49:13 -02:00
Lucas De Marchi
8bdeca11b1 Fix changing hash key after module is inserted in hash
The hash key is not copied so we can't change the string from:
	modname/modalias

	to:

	modname'\0'modalias

in order to setup mod->name and mod->alias.

Now what we do is:

1) if name is in the form 'modname/modalias', the final struct
   kmod_module will be:

   struct kmod_module {
           char *alias;------,
           char *name;-----, |
           char *hashkey;--|-|-,
   }                       | | |
   name <------------------' | |
   alias <-------------------' |
   hashkey <-------------------'

2) if name is in the simple form 'modname', then the final struct
   kmod_module will be:

   struct kmod_module {
           char *alias;------> NULL
           char *name;-----,
           char *hashkey;--|---,
   }                       |   |
   name <------------------*---'
2011-12-15 13:48:19 -02:00
Lucas De Marchi
91428ae1b8 Fix docs with wrong function names 2011-12-15 13:09:46 -02:00
Lucas De Marchi
5f3429cdad Add comment in public header about flags not implemented 2011-12-15 12:27:45 -02:00
Lucas De Marchi
128386a406 Rename symbol group 2011-12-15 12:26:15 -02:00
Lucas De Marchi
3e71947c1e Remove flags that likely will not be used 2011-12-15 12:18:00 -02:00
Lucas De Marchi
23c0d01279 Fix format of log message 2011-12-14 17:21:46 -02:00
Lucas De Marchi
1684e4402c kmod_config: parse kernel command line for options and blacklist 2011-12-14 17:19:19 -02:00
Lucas De Marchi
113c66a562 kmod_module: use 'modname/aliasname' as key for hash
1 alias may correspond to more than 1 module. This would cause a
conflict in the hash table when inserting a module there and bad things
could happen.

Now we use 'modname/aliasname' as key, '/aliasname' part being optional.
Internally kmod_module_new_from_alias() will setup a 'modname/aliasname'
string and pass to kmod_module_new_from_name() that will treat the case
with a '/' in the name.

User might call kmod_module_new_from_name() without any slashes, so the
key my not contain it.
2011-12-14 15:26:04 -02:00
Lucas De Marchi
788ef0f7e6 Use malloc + memset instead of calloc 2011-12-14 15:05:03 -02:00
Lucas De Marchi
2d7bab5c7d kmod_module: move function to the right section 2011-12-14 12:10:30 -02:00
Lucas De Marchi
63af0615d5 kmod_module: fix log message upon module removal 2011-12-14 12:10:30 -02:00
Lucas De Marchi
7afc98a1f6 kmod_module: add missing documentation 2011-12-14 12:10:30 -02:00
Lucas De Marchi
6de8f6e966 Simplify kmod_load_resources()
We have a static vector of indexes. There's no need to check if they
have a suffix or if they are absolute, we just already know in advance
and there are no plans to change it.
2011-12-14 10:53:10 -02:00
Lucas De Marchi
3e67676617 Log and break early if index is already open 2011-12-14 10:53:10 -02:00
Lucas De Marchi
be5a6deaea Update documentation 2011-12-14 10:53:10 -02:00
Lucas De Marchi
25c0543ff6 Remove function kmod_resolve_alias_options()
Remove function kmod_resolve_alias_options since it's not needed
anymore. Test is using the following configuration file:

alias blablabla ac
options ac test=1
options blablabla test=2

Lookup test by module name:
	$ ./test/test-lookup ac
	libkmod version 1
	Alias: 'ac'
	Modules matching:
		ac
			options: 'test=1'

Lookup test by alias:
	$ ./test/test-lookup blablabla
	libkmod version 1
	Alias: 'blablabla'
	Modules matching:
		ac
			options: 'test=1 test=2'
2011-12-13 14:28:16 -02:00
Lucas De Marchi
07b8c823ed kmod_module: make get_options() search for alias names too 2011-12-13 14:21:24 -02:00
Lucas De Marchi
ee3b3ff292 Create module by alias name where appropriate 2011-12-13 14:20:48 -02:00
Lucas De Marchi
6ad5f26362 Add private function kmod_module_new_from_alias()
This function will create a new kmod_module() by calling
kmod_module_new_from_name(), but instead of given the module name, it
gives the alias. This way, the modules' hash will contain the alias
instead of the name. If module was created successfully, then it swap
the alias with the actual name.

The downside is that the structure is not shared anymore if we create a
kmod_module by alias and after by name. However, in modprobe's
configuration it's possible to have different options for different
aliases. In future we might want to create a way to share the common
part of the structure (then having only one instance as we had before).
2011-12-13 14:12:50 -02:00
Lucas De Marchi
219f9c38bb kmod_module: use pointer instead of vector for its name
We still have name allocated just after the struct kmod_module, but
now we use a pointer instead of putting name as a vector in the end of
the structure.

The previous way has some problems, the worst is:
	- it's not possible to swap the name with another value: this is
	  the real problem that this patch is solving. Later patches
	  will make name be swappable with alias, which is not possible
	  if name is a vector.
2011-12-13 13:15:49 -02:00
Lucas De Marchi
ecd6bcd204 Return early on lookup error
There's no reason to keep looking for options if alias didn't match.
2011-12-13 10:52:00 -02:00
Lucas De Marchi
d470db10a3 Use alias_normalize() instead of modname_normalize()
When normalizing alias names (or if we don't know if it's an alias or
modname), use alias_normalize() instead of modname_normalize(). The
difference is that alias names can contain dashes withing brackets, and
those should not be changed to underscores.

Most of the places using underscores() function might be converted to
alias_normalize(), but this is not done now.
2011-12-13 10:41:18 -02:00
Lucas De Marchi
b148b8606a Add helper alias_normalize() 2011-12-13 10:41:18 -02:00
Lucas De Marchi
4308b176e9 Fix check for NULL variable 2011-12-13 10:41:18 -02:00
Lucas De Marchi
7d51d8bfe2 Fix "Dereference of null pointer" as reported by llvm 2011-12-12 18:43:04 -02:00
Lucas De Marchi
1c250ec150 Fix "Dead assignments" as reported by llvm 2011-12-12 18:36:27 -02:00
Gustavo Sverzut Barbieri
973c80ba7c handle case where modname was not detected. 2011-12-12 18:28:52 -02:00
Lucas De Marchi
cb451f35d9 Change licenses
libkmod is under LGPL 2.1 or later
tools/* are under GPL
2011-12-12 18:24:35 -02:00
Lucas De Marchi
45f2778174 Remove warnings: ‘err’ may be used uninitialized in this function 2011-12-12 17:23:04 -02:00
Lucas De Marchi
cb48c9b2e6 Rename project from libkmod to kmod 2011-12-12 16:54:18 -02:00
Lucas De Marchi
8f767e2dfa Use true/false for bool return 2011-12-12 15:27:57 -02:00
Lucas De Marchi
98c80f44c9 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.
2011-12-12 15:26:59 -02:00
Lucas De Marchi
4782396cc4 Do not stat() dir twice 2011-12-12 15:00:51 -02:00
Lucas De Marchi
016d619cd9 Fix leak of DIR 2011-12-12 14:39:35 -02:00
Lucas De Marchi
970ba8be9d Remove leftover comment
mod->path is always absolute: remove comment from previous behavior.
2011-12-12 14:01:39 -02:00
Lucas De Marchi
49ce6d0741 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.
2011-12-12 13:56:47 -02:00
Lucas De Marchi
a102e262e6 Rename kmod_loaded_get_list() to kmod_module_new_from_loaded()
Be consistent with other similar functions already present and improve
documentation.
2011-12-12 13:50:19 -02:00
Lucas De Marchi
28c175edd1 coding style: be consistent with blank lines 2011-12-12 11:52:59 -02:00
Lucas De Marchi
c35347f15c 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
2011-12-12 10:54:19 -02:00
Gustavo Sverzut Barbieri
cb8d4d3e99 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.
2011-12-11 20:58:22 -02:00
Gustavo Sverzut Barbieri
d01c67e383 add missing newline to log messages. 2011-12-11 20:58:22 -02:00
Gustavo Sverzut Barbieri
926f67a6d6 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
2011-12-11 20:58:22 -02:00
Gustavo Sverzut Barbieri
3a721bbcf0 insmod: allows providing option to module. 2011-12-11 20:58:22 -02:00
Gustavo Sverzut Barbieri
d917f2743e always normalize user-given alias. 2011-12-11 20:58:22 -02:00
Gustavo Sverzut Barbieri
bd3f553526 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.
2011-12-11 20:58:21 -02:00
Gustavo Sverzut Barbieri
b6a534f72c 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
2011-12-11 20:58:21 -02:00
Gustavo Sverzut Barbieri
bf8cf1483f fix string replace.
configure files with this would fail:

options wl x=1

were being handled as " =1".
2011-12-11 20:58:21 -02:00
Lucas De Marchi
54ba8b3416 kmod: Add documentation and format comments 2011-12-11 20:55:09 -02:00
Gustavo Sverzut Barbieri
27fdf63153 index: fix memleak for non-matchin aliases. 2011-12-10 13:28:18 -02:00
Gustavo Sverzut Barbieri
d091546448 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".
2011-12-10 13:04:43 -02:00
Gustavo Sverzut Barbieri
148226ed92 index: cleanup header, move as much as possible to libkmod-index.c 2011-12-10 11:53:51 -02:00
Gustavo Sverzut Barbieri
15c1c143f2 index-mm: no need to allocate prefix. 2011-12-10 11:44:31 -02:00
Gustavo Sverzut Barbieri
fc2d835df5 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.
2011-12-10 11:36:35 -02:00
Gustavo Sverzut Barbieri
79d57fcb29 kmod_load_resources: use proper full path to binary files to be mmaped. 2011-12-10 10:27:27 -02:00
Gustavo Sverzut Barbieri
3e245be100 kmod_lookup_alias_from_alias_bin: debug message for mmap case. 2011-12-10 09:28:42 -02:00
Gustavo Sverzut Barbieri
85132101e4 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.
2011-12-10 09:26:27 -02:00
Gustavo Sverzut Barbieri
3b2099595b fix snprintf usage.
snprintf() takes the full buffer size, including \0 and guarantees it
will be there.
2011-12-10 09:21:03 -02:00
Lucas De Marchi
65a84f5591 Use alias/symbol index_mm if it's open 2011-12-09 16:11:42 -02:00
Lucas De Marchi
810803dbe8 Pass enum around instead of filename
This will allow us to later use the index to search these indexes.
2011-12-09 16:07:33 -02:00
Lucas De Marchi
d65d71ceff Use index_mm if it's open for moddep search 2011-12-09 15:55:30 -02:00
Lucas De Marchi
4272d08780 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.
2011-12-09 15:45:55 -02:00
Lucas De Marchi
33bb69b943 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.
2011-12-08 19:51:06 -02:00
Lucas De Marchi
5109f2b422 index: mm: Add flag to open call to populate buffer 2011-12-08 19:51:06 -02:00
Lucas De Marchi
a4a750297d 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.
2011-12-08 19:51:06 -02:00
Gustavo Sverzut Barbieri
558b020704 remove useless look checking for duplicates 2011-12-08 16:36:48 -02:00
Gustavo Sverzut Barbieri
1433ba9ef5 index: avoid strlen() whenever possible. 2011-12-08 16:35:36 -02:00
Gustavo Sverzut Barbieri
435ad788e2 reduce calls to realloc() if size did not change. 2011-12-08 16:35:36 -02:00