Commit Graph

74 Commits

Author SHA1 Message Date
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
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
1c52260048 implement softdeps. 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
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
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
07b8c823ed kmod_module: make get_options() search for alias names too 2011-12-13 14:21:24 -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
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
4308b176e9 Fix check for NULL variable 2011-12-13 10:41:18 -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
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
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
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
e18ad35c64 fix path handling at dependencies parsing.
paths come relative to dirname, make them absolute to avoid confusion
later.
2011-12-08 14:12:39 -02:00
Gustavo Sverzut Barbieri
e1a6b30dc4 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.
2011-12-08 13:33:25 -02:00
Gustavo Sverzut Barbieri
f1fb6f8525 kmod_module: Remove const from path
It's an ugly hack. This is an internal variable, we know we shouldn't
change it everywhere.
2011-12-08 11:37:03 -02:00
Lucas De Marchi
e005facdb9 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
2011-12-08 11:15:24 -02:00
Lucas De Marchi
6bd0b8d01d 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.
2011-12-07 14:15:49 -02:00
Lucas De Marchi
71e975cd4d kmod_module: store absolute path when creating module from path 2011-12-07 13:53:53 -02:00
Lucas De Marchi
877e80cd93 Use streq() when possible 2011-12-07 02:32:28 -02:00
Lucas De Marchi
6c343b1aee Split function so we don't call basename() unnecessarily 2011-12-06 09:02:13 -02:00
Lucas De Marchi
fd186ae996 Maintain a pool of modules alive
Based on previous implementation by
	Gustavo Sverzut Barbieri <barbieri@profusion.mobi>
2011-12-06 03:49:07 -02:00
Lucas De Marchi
4f2bb7cdd4 kmod_module: normalize module name 2011-12-06 03:34:51 -02:00
Lucas De Marchi
c5e7b1f7ef kmod_module: get path on demand 2011-12-06 02:48:04 -02:00
Lucas De Marchi
671d489424 kmod_module: parse dependencies on demand 2011-12-06 02:48:04 -02:00
Lucas De Marchi
f1cd799fb0 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().
2011-12-06 02:48:03 -02:00
Lucas De Marchi
d753b8ca35 kmod_module: inline name and make it always available 2011-12-05 18:14:51 -02:00