Commit Graph

230 Commits

Author SHA1 Message Date
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