Commit Graph

454 Commits

Author SHA1 Message Date
Lucas De Marchi
ecced7dd77 doc: fix out of tree build 2012-01-09 13:32:31 -02:00
Lucas De Marchi
6681951bbe doc: organize sections 2012-01-09 05:28:57 -02:00
Lucas De Marchi
646b83b841 doc: add gtk-doc to generate documentation
Current limitation is horrible no support to sections: we have to to
have separate header files or to maintain the libkmod-sections.txt file.
We are doing the latter.
2012-01-09 05:28:57 -02:00
Lucas De Marchi
db74ceec80 doc: fix broken links to other functions 2012-01-09 03:45:48 -02:00
Lucas De Marchi
e1daa4f54b doc: fix order of param descriptions 2012-01-09 03:30:10 -02:00
Lucas De Marchi
6a82921113 Match param names on header and source code
This is needed by gtk-doc (to be added later) to be able to properly
document the function.
2012-01-09 03:29:48 -02:00
Lucas De Marchi
f4cc6ea5eb doc: fix comments format 2012-01-09 03:29:29 -02:00
Lucas De Marchi
a66a6a999f Update copyright 2012-01-09 00:41:07 -02:00
Lucas De Marchi
6daceb2f1f Replace NAME_MAX with PATH_MAX for module aliases
Module aliases can be bigger than NAME_MAX. So, replace with PATH_MAX
that is bigger enough to hold them.

Technically in some places NAME_MAX would be sufficient (those using
module names only), but they use functions that can be called with
alias. So increase the buffers in these cases to PATH_MAX too.
2012-01-08 01:02:29 -02:00
Lucas De Marchi
dd1cf10fc4 config: check if opening /proc/cmdline succeeded 2012-01-06 19:22:41 -02:00
Dave Reisner
4f17bb0bd2 libkmod/hash: check for NULL before freeing hash 2012-01-04 22:34:36 -02:00
Lucas De Marchi
b5b4d8e8a5 Add missing doc for function argument 2012-01-04 21:07:59 -02:00
Dave Reisner
b787b5693d libkmod: Fix casing in error output 2012-01-04 10:59:49 -05:00
Lucas De Marchi
3f63505812 file: use log facilities
Don't clutter stderr with messages that might be useful in the log.
2012-01-04 08:49:23 -02:00
Lucas De Marchi
c68e92f731 file: take a weakref to ctx 2012-01-04 08:49:15 -02:00
Lucas De Marchi
29b69c0b98 config: take a weakref to ctx
Commit "b6a4dfb config: save list of config paths with their timestamps"
removed the weakref to ctx. Add it back.
2012-01-04 08:49:10 -02:00
Lucas De Marchi
7749bedbf7 Add missing static const 2012-01-04 08:00:45 -02:00
Gustavo Sverzut Barbieri
79b656faeb utils/array: add array_remove_at()
remove array element at given position, will be used by depmod.
2012-01-03 15:58:24 -02:00
Gustavo Sverzut Barbieri
599a032467 elf: zero *array when count is zero. 2012-01-03 14:53:15 -02:00
Gustavo Sverzut Barbieri
db5d14cf24 libkmod-file: refactor code to avoid ifdef mess.
Refactor code to use pointer to functions, avoiding the previous

Now comp_types defines a magic header to be checked (size and bytes),
with the associated load() and unload() operations. If a header
matches, their operations are used. Otherwise the regular file
operations (mmap/munmap) are used.

File descriptor close is managed by the common code if it's valid
(>=0). If some code steals the file descriptor (eg: gzopen), then they
must change file->fd to -1.

This way the code should be easier to extend and avoid bugs.
2012-01-03 14:25:49 -02:00
Gustavo Sverzut Barbieri
6717994157 utils/read_str_safe(): fix wrong behavior and bugs.
ouch, I did a mess in the original function, fix them:

 * on errors (read() < 0), continue reading after the done bytes, not
   at position 0.

 * read buflen - 1 bytes, so there is always room to store the
   trailing \0, as expected by user due behavior of snprintf(),
   fgets() and others.
2012-01-03 14:22:05 -02:00
Lucas De Marchi
c4dc3ca8a2 Add call to check if resources are valid 2012-01-01 06:18:16 -02:00
Lucas De Marchi
9fd58f30bf index: save timestamp of each loaded index 2012-01-01 06:18:16 -02:00
Lucas De Marchi
b6a4dfb1b4 config: save list of config paths with their timestamps
Save a list of config paths with their timestamps so they can be checked
later.
2012-01-01 06:18:01 -02:00
Lucas De Marchi
0b29ef6f59 util: add helper function to compare timestamps 2012-01-01 06:17:54 -02:00
Dave Reisner
9070b117ec libkmod-config: remove warning for skipped config files
conf_files_filter_out() already skips these files, but writes to the log
to warn that they'll be ignored in the future.
2011-12-31 19:30:26 -02:00
Lucas De Marchi
2f76fda259 Use last enum value instead of ARRAY_SIZE 2011-12-31 19:30:09 -02:00
Lucas De Marchi
4926cb501d Do not call exported function for mod->name
Name is always available and we don't neet to call a exported function
to get it.
2011-12-31 11:21:52 -02:00
Lucas De Marchi
0d46743ca5 Move function to the right place 2011-12-31 11:15:52 -02:00
Lucas De Marchi
e47c604525 Ignore "already loaded" error in module_probe_insert_module()
It also fixes a leak in the error path.
2011-12-30 14:16:15 -02:00
Lucas De Marchi
bbf59327e3 Use errno instead of return value of init_module()
Return -errno instead of the value returned by init_module(). We need to
differentiate between the several errors that might occur, e.g. "module
already loaded", access denied, etc.
2011-12-30 14:13:33 -02:00
Leandro Pereira
1698456259 libkmod-util: getline_wrapped: return NULL when buffer allocation fails 2011-12-28 15:55:45 -02:00
Leandro Pereira
40ee8dadca Do not forget parenthesis around if (streq(A, B)). 2011-12-28 15:54:38 -02:00
Lucas De Marchi
0c010fae10 Move libkmod-util.c to convenience util lib
Share more code between tools and libkmod. underscores() in kmod-depmod
can not use the same function as in the lib, so rename it.
2011-12-28 13:33:26 -02:00
Lucas De Marchi
6670c63344 Move array implementation from depmode to libkmod-util 2011-12-28 12:58:47 -02:00
Lucas De Marchi
a4848e249f Move util functions to libkmod-util.c
These allow them to be later shared with tools.
2011-12-27 18:11:58 -02:00
Lucas De Marchi
8d1278d03f hash: add iterator 2011-12-27 18:11:58 -02:00
Lucas De Marchi
529148ea70 build-sys: create libkmod-util.la convenience lib
Util functions can be shared betweeing libkmod and tools. Start with the
hash implementation.
2011-12-27 18:11:58 -02:00
Lucas De Marchi
d707380744 Copy missing hash functions from kmod-depmod to libkmod 2011-12-27 18:11:58 -02:00
Lucas De Marchi
822913d74c Remove kmod_ prefix from hash implementation
In a future commit, hash implementation will be shared between libkmod
and depmod. kmod_hash is not exported, so remove the namespace.
2011-12-27 18:11:58 -02:00
Lucas De Marchi
ebaa7beb0a Log paths if kmod_module_new_from_path() failed 2011-12-27 18:11:12 -02:00
Lucas De Marchi
ddbda02286 Add implementation of modprobe's insertion
Treat module insertion as modprobe does: look for (soft-)dependencies, run
install commands, apply blacklist.

The difference with the blacklist is that it's applied to all modules,
including the dependencies. If you want to apply a blacklist only on the
module it's better to call the filter function by yourself.

This implementation detects loops caused by poorly written
soft-dependencies and fail gracefully, printing the loop to the log.
2011-12-27 11:55:22 -02:00
Lucas De Marchi
2bd7cbf644 Do not cache softdeps list
This might include a circular dependency which would screw up the
refcounting because there's an internal reference.
2011-12-27 10:40:51 -02:00
Lucas De Marchi
b72f74b5dd Allow to internally get dependencies without copying list 2011-12-27 10:40:51 -02:00
Lucas De Marchi
c1c9c44628 Add functions to get ctx blacklists 2011-12-27 02:49:46 -02:00
Lucas De Marchi
eb4ae531f7 Fix kmod_list_remove_n_latest()
It only worked because n was always 1. kmod_list_remove returns a
pointer to the next element, relative to the removed one. Therefore we
need to always get a pointer to the last.
2011-12-27 02:48:36 -02:00
Lucas De Marchi
b94a737935 Reverse order of dependency list
Dependency list in modules.dep is kept in reverse order. Prepend to
list so all the other places treat it in the right order.
2011-12-26 20:15:10 -02:00
Cristian Rodríguez
4088b27e21 index_file_open: fix another fd leak on error path. 2011-12-26 09:55:15 -02:00
Lucas De Marchi
ef4a349aaa Merge branch 'master' of git://dev.medozas.de/libkmod 2011-12-24 17:51:27 -02:00
Lucas De Marchi
7adfd2c36d Merge branch 'master' of git://dev.medozas.de/libkmod 2011-12-24 17:39:44 -02:00
Jan Engelhardt
c362171286 libkmod: remove external cflags from .pc file
Since the public header files of libkmod do not include header files
of liblzma or zlib, the flags need not be present.
2011-12-24 20:28:11 +01:00
Jan Engelhardt
b182f8fb5e Support for loading Xz-compressed modules 2011-12-24 20:26:22 +01:00
Jan Engelhardt
7b3a74fc67 build: use pkgconfig to detect zlib
build: explicitly call PKG_PROG_PKG_CONFIG

Per the manual page, PKG_PROG_PKG_CONFIG needs to be invoked
explicitly if PKG_CHECK_MODULES might not happen (it is indeed stowed
in an AS_IF in kmod). Without this, funny failures can occur.
(As it did.)
2011-12-24 20:25:21 +01:00
Lucas De Marchi
3af4f558da Fix version script with v3 symbols 2011-12-24 02:40:30 -02:00
Gustavo Sverzut Barbieri
674f8590e3 elf: implement kmod_module_get_dependency_symbols()
Uses kmod_elf_get_dependency_symbols() that looks into ".symtab" for
UNDEF symbols and matches the name from ".strtab" to "__versions" to
get crc.

Likely the public API should unify the symbol information getters and
list release, they are almost the same.
2011-12-24 01:44:31 -02:00
Gustavo Sverzut Barbieri
4b55befd37 elf: add bind type to kmod_modversion.
will be used to share this structure with get_dependency_symbols()
2011-12-24 01:44:31 -02:00
Gustavo Sverzut Barbieri
45e6db9c01 elf: add get_symbols()
Similar to module-init-tools load_symbols(), it will try .symtab and
.strtab for symbols starting with __crc_, if they are found their crc
is read from ELF's Elf_Sym::st_value.

If not found, then it will fallback to __ksymtab_strings.
2011-12-24 01:44:31 -02:00
Gustavo Sverzut Barbieri
9bbb72df05 elf: minimum size is enough. 2011-12-24 01:24:55 -02:00
Gustavo Sverzut Barbieri
bb417099e4 file: speed up loading non-gzipped modules when zlib is enabled.
Just now realized that my distro (Gentoo) enables support for gzip but
does not compress modules by default.

In this case it's better to have a special case that uses mmap()
instead of a loop of realloc() + gzread().
2011-12-24 01:15:25 -02:00
Cristian Rodríguez
67d94ad388 Fix leak on error path 2011-12-23 03:08:57 -02:00
Lucas De Marchi
759214fad0 Initialize line number with 0 2011-12-22 01:30:40 -02:00
Gustavo Sverzut Barbieri
c6824b62f2 Fix unaligned memory access
Bug found on sparc64. Thanks to "Jan Engelhardt <jengelh@medozas.de>"
for providing access to such a machine.
2011-12-21 18:37:46 -02:00
Lucas De Marchi
f304afe153 Change error message to reflect reality 2011-12-20 23:48:27 -02:00
Lucas De Marchi
142db570bf Update doc to reflect function behavior 2011-12-20 23:39:30 -02:00
Luis Felipe Strano Moraes
9efaf2f627 Testing for return of alias_normalize. 2011-12-20 23:23:55 -02:00
Lucas De Marchi
f39dc70e4b Removing comments saying flags are not implemented
Both removal and insertion flags are already implemented.
2011-12-20 19:31:14 -02:00
Lucas De Marchi
5e50464548 Move symbols introduced in libkmod2 to the right place 2011-12-20 17:16:24 -02:00
Kay Sievers
a308abec37 introduce --with-rootprefix=DIR
Configure the location of the rootfs directories and use it
to find (/usr)/lib/modules and (/usr)/lib/modprobe.d.
2011-12-20 16:22:07 -02:00
Lucas De Marchi
7fe5f7abce Use sorted configuration files in precedence order
We need to keep config files sorted and use them taking the precedence
order into account.

The following message was taken from module-init-tools commit doing a
similar thing:

	Configuration files are parsed in alphabetic order, regardles of
	what directory they reside in. Furthermore, if several files by
	the same name exist in different directories only the one in the
	directory with highest precedence is loaded.

	The order of precedence is /run, /etc, /usr/lib, /lib.

The sad thing is that we are not using openat() anymore since each file
is in different directories. In future we might change the
implementation to open all DIRs and keep a reference
to them instead of the path. However we'd have to keep a separate list
with all the opened dirs so we can close them later (when all configs
are parsed).
2011-12-20 16:08:18 -02:00
Jan Engelhardt
87beacc99f libkmod: use C99 __func__ over GNU-specific __FUNCTION__ 2011-12-20 13:48:44 -02:00
Lucas De Marchi
135bffd652 kmod_config: fix kcmd line parser with dots after =
Check if '=' appeared before the dot. In this case, it's not a valid
module option in kernel command line.

The command line that was failing is:

"root=/dev/sda3 ro pcie_aspm=force init=/sbin/bootchartd
	initrd=../initramfs-linux.img BOOT_IMAGE=../vmlinuz-linux"
2011-12-20 13:25:24 -02:00
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
Gustavo Sverzut Barbieri
405f614af9 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.
2011-12-08 14:38:22 -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
e5c60f1c28 NULL safety in public places, allows disable logging. 2011-12-08 14:07:13 -02:00
Gustavo Sverzut Barbieri
1bdd951ee2 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.
2011-12-08 14:06:50 -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
Lucas De Marchi
8fc83fe1de kmod_loaded: document exported function 2011-12-08 12:59:16 -02:00
Lucas De Marchi
7e1b3ae2b9 kmod_list: document exported functions 2011-12-08 12:25:36 -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
Gustavo Sverzut Barbieri
1487a64ffa 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.
2011-12-08 11:17:16 -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
4eb2c0fca1 Fix abs path helper function 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
06363cc126 Add helper path_make_absolute_cwd() 2011-12-07 13:51:40 -02:00
Lucas De Marchi
3a468809b8 Add helper path_is_absolute() 2011-12-07 13:50:52 -02:00
Lucas De Marchi
a5cce6d6ef kmod_config: parse install and remove commands 2011-12-07 11:31:28 -02:00
Lucas De Marchi
615c42be5c kmod_config: parse module options 2011-12-07 10:59:44 -02:00
Lucas De Marchi
afca78015b Add helper strchr_replace() 2011-12-07 10:59:44 -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
b7b7ac298f 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()
2011-12-06 03:34:51 -02:00
Lucas De Marchi
e16e27f4a4 kmod_list: remove nodes in order 2011-12-06 03:34:51 -02:00
Lucas De Marchi
1965029cb0 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.
2011-12-06 03:34:51 -02:00
Lucas De Marchi
b91a1c6d3d kmod_list: add helper kmod_list_insert_before() 2011-12-06 03:34:51 -02:00
Lucas De Marchi
86e8788572 kmod_list: add helper kmod_list_insert_after() 2011-12-06 03:34:51 -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