Commit Graph

1356 Commits

Author SHA1 Message Date
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 e17cc3afcc Add address of mailing list 2011-12-16 04:11:25 -02:00
Lucas De Marchi 8122985dbb tools: fix kmod-modprobe -R trying to insert module 2011-12-16 02:58:48 -02:00
Lucas De Marchi 5e690c5cbd TODO: add new tasks and notes to future development 2011-12-16 02:20:44 -02:00
Ulisses Furquim a955f71f60 trivial: fix typo causing an infinite loop 2011-12-15 21:36:12 +00:00
Lucas De Marchi 89eba7cb77 kmod 1 2011-12-15 15:43:58 -02:00
Lucas De Marchi e269a84cab Add libkmod files to EXTRA_DIST 2011-12-15 15:40:22 -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 22907a188c Improve test of double references 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 c4b4ac9e5b TODO: rephrase some tasks 2011-12-15 12:14:43 -02:00
Lucas De Marchi 836e455155 Add file with details regarding coding style 2011-12-15 00:43:54 -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
Luis Felipe Strano Moraes fe8bf3b009 Do not depend on AM_SILENT_RULES if it is not available. 2011-12-14 16:19:03 -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 d68ea2aede TODO: update tasks 2011-12-14 14:39:26 -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 953653ab93 build-sys: enable debug by default in autogen.sh 2011-12-12 17:26:47 -02:00
Lucas De Marchi 927760641a build-sys: Set CFLAGS to "-O2 -Werror" in autogen.sh 2011-12-12 17:23:19 -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 0283d6b666 build-sys: add version map file to build dependencies
Based on original patch from Jan Engelhardt <jengelh@medozas.de> to
libabc.
2011-12-12 17:06:15 -02:00
Lucas De Marchi cb48c9b2e6 Rename project from libkmod to kmod 2011-12-12 16:54:18 -02:00