Commit Graph

599 Commits

Author SHA1 Message Date
Andy Grover 1e688f86a7 python: Add support for listing loaded modules, modprobe, rmmod
And other misc. cleanups and changes.
2014-03-25 00:34:14 -03:00
Andy Grover d2042ca0c7 python: use c99 init for struct init
move casts of pyobject -> kmodobject to the functions from the struct
init.
2014-03-25 00:34:14 -03:00
Andy Grover a942131e7b python: a skeleton that compiles 2014-03-25 00:34:14 -03:00
Andy Grover cc688e6722 python: initial checkin 2014-03-25 00:34:14 -03:00
Lucas De Marchi f87dc57a71 libkmod: Fix unaligned access
From Jan Engelhardt:

	Program received signal SIGBUS, Bus error.
	[Switching to process 11100]
	0x00035278 in kmod_module_signature_info (file=0x4eeb8, sig_info=0xffffc254)
	    at libkmod/libkmod-signature.c:124
	124             sig_len = be32toh(modsig->sig_len);
	(gdb) p modsig
	$1 = (const struct module_signature *) 0xf7dfe143

modsig->sig_len can be unaligned if modsig is unaligned, so the padding
in the struct has no effect since we are mapping it to the mem buffer.
2014-03-24 23:47:31 -03:00
Lucas De Marchi fea655dcb3 libkmod-elf: Fix check by class in get_modversions()
Commit 51c409b ("Cache the offset of crc") unintentinally changed the
comparison "if (elf->class & KMOD_ELF_32)" to
"if (elf->class == KMOD_ELF_32)".

This has been reported by Serge Voilokov <serge0x76@gmail.com>:

	On Raspberry PI elf->class equals KMOD_ELF_32|KMOD_ELF_LSB so
	valid condition should be (elf->class & KMOD_ELF_32) instead of
	(elf->class == KMOD_ELF_32).

This fixes "modprobe --dump-modversions" failing on 32b systems.
2014-03-07 01:24:39 -03:00
Lucas De Marchi 06eb29e117 build-sys: add small redirecting Makefiles
These redirecting makefiles simplifies compiling from some editors and
when CWD is not the root of the source tree. This is similar to what was
introduced in systemd in 340d89e ("build-sys: add small redirecting
Makefiles to simplify compilation from within emacs")
2014-03-06 01:59:58 -03:00
Michal Marek aa878540e6 libkmod-config: Only match dot before '=' in /proc/cmdline
Otherwise, we also parse strings like

  BOOT_IMAGE=/boot/vmlinuz-3.12.12-57.g5f654cf-default

In practice, this is not a problem, because there is no module named
BOOT_IMAGE=/boot/vmlinuz-3. It just disturbs in modprobe -c output.
2014-03-05 12:30:52 -03:00
Michal Marek 519d27de5a libkmod-config,depmod: Accept special files as configuration files, too
If we can open it and read it, it's good enough for us. Otherwise, we
cannot use -C /dev/null to skip the system configuration for instance:

$ ./tools/modprobe -C /dev/null -c
libkmod: ERROR libkmod/libkmod-config.c:821 conf_files_list: unsupported
file mode /dev/null: 0x21b6
...
2014-03-05 12:27:24 -03:00
Michal Marek c2f4d85a9a libkmod-module: Simplify kmod_module_insert_module()
Store the file and elf pointer in the kmod_module structure and have it
freed together with the module.
2014-03-05 12:22:37 -03:00
Lucas De Marchi 366e2ed791 Remove duplicate includes
Found by
https://raw.github.com/karelzak/util-linux/master/tools/checkincludes.pl
2014-01-21 14:03:02 -02:00
Lucas De Marchi d96ca9c429 Use C11's noreturn
Also define noreturn w/o <stdnoreturn.h> and move it to macro.h instead
of in the testsuite.

Based on similar commit on systemd by Shawn Landden
<shawn@churchofgit.com>.
2013-12-17 19:10:16 -02:00
Lucas De Marchi 9f02561d84 module: use _cleanup_free and remove useless call to free() 2013-11-18 11:56:57 -02:00
Lucas De Marchi d3c16c7946 file: use _cleanup_free_ 2013-11-18 11:43:10 -02:00
Lucas De Marchi cacbcc4215 array: avoid duplicate code to reallocate 2013-11-18 11:29:11 -02:00
Lucas De Marchi 9c306bad2e util: Be OOM-safe and use _cleanup_free_ 2013-11-18 11:01:16 -02:00
Lucas De Marchi b93d800640 util: use _cleanup_free_ on path_make_absolute_cwd() 2013-11-18 05:22:33 -02:00
Lucas De Marchi 342e9cea26 config: Use _cleanup_free_ 2013-11-18 04:35:04 -02:00
Lucas De Marchi d7aa6e23fc util: Add cleanup attribute 2013-11-18 04:35:04 -02:00
Lucas De Marchi 7ab8804448 libkmod: always pass O_NONBLOCK to kernel
Not passsing O_NONBLOCK to delete_module() is deprecated since kmod 11
and is being removed from the kernel. Force this flag in libkmod.
2013-09-20 01:37:24 -05:00
Lucas De Marchi 82fc7d986c libkmod-hash: always align n_buckets to power of 2
By aligning n_buckets to power of 2 we can turn the "bucket = hashval %
n_buckets" into a less expensive bucket = hashval & (n_buckets - 1).
This removes the DIV instruction as shown below.

Before:
	xor    %edx,%edx
	divl   0x8(%rbx)
	mov    %edx,%eax
	add    $0x1,%rax
	shl    $0x4,%rax
	add    %rbx,%rax

After:
	lea    -0x1(%rdi),%edx
	and    %edx,%eax
	add    $0x1,%rax
	shl    $0x4,%rax
	add    %rbx,%rax

With a microbenchmark, measuring the time to locate the bucket (i.e.
time_to_calculate_hashval + time_to_calculate_bucket_position) we have
the results below (time in clock cycles):

	keylen      before   after
	2-10          79.0    61.9 (-21.65%)
	11-17         81.0    64.4 (-20.48%)
	18-25         90.0    73.2 (-18.69%)
	26-32        104.7    87.0 (-16.82%)
	33-40        108.4    89.6 (-17.37%)
	41-48        111.2    91.9 (-17.38%)
	49-55        120.1   102.1 (-15.04%)
	56-63        134.4   115.7 (-13.91%)

As expected the gain is constant, regardless of the key length.
The time to clculate the hashval varies with the key length, which
explains the bigger gains for short keys.
2013-09-20 01:10:37 -05:00
Lucas De Marchi 3ba7f59e84 util: Add ALIGN_POWER2
Add static inline function to align a value to it's next power of 2.
This is commonly done by a SWAR like the one in:

http://aggregate.org/MAGIC/#Next Largest Power of 2

However a microbench shows that the implementation herer is a faster.
It doesn't really impact the possible user of this function, but it's
interesting nonetheless.

Using a x86_64 i7 Ivy Bridge it shows a ~4% advantage by using clz
instead instead of the OR and SHL chain. And this is by using a BSR
since Ivy Bridge doesn't have LZCNT. New Haswell processors have the
LZCNT instruction which can make this even better. ARM also has a CLZ
instruction so it should be better, too.

Code used to test:

	...
	v = val[i];
	t1 = get_cycles(0);
	a = ALIGN_POWER2(v);
	t1 = get_cycles(t1);

	t2 = get_cycles(0);
	v = nlpo2(v);
	t2 = get_cycles(t2);

	printf("%u\t%llu\t%llu\t%d\n", v, t1, t2, v == a);
	...

In which val is an array of 20 random unsigned int, nlop2 is the SWAR
implementation and get_cycles uses RDTSC to measure the performance.

Averages:
	ALIGN_POWER2: 	30 cycles
	nlop2:		31.4 cycles
2013-09-20 01:08:46 -05:00
Lucas De Marchi 4c2dc16a2e build: remove check for typeof
It's used in so many places without checking, that's really pointless to
check for it in macro.h.

Also remove AC_C_TYPEOF from configure.ac since we don't use -ansi.
2013-09-06 11:31:35 -03:00
Thomas Petazzoni dc8ed09f8f Add configure check for _Static_assert()
Commit 8efede20ef ("Use _Static_assert") introduced the usage of
_Static_assert(). However, _Static_assert() is a fairly new thing,
since it was introduced only in gcc 4.6. In order to support older
compilers, this patch adds a configure.in test that checks whether
_Static_assert() is usable or not, and adjust the behavior of the
assert_cc() macro accordingly.
2013-09-06 11:06:19 -03:00
Lucas De Marchi 7e0385c47a Fix usage of readdir_r()
With readdir_r() we should be providing enough space to store the dir
name. This could be accomplished by define an union like systemd does:

	union dirent_storage {
		struct dirent de;
		uint8_t storage[offsetof(struct dirent, d_name) +
				((NAME_MAX + 1 + sizeof(long)) & ~(sizeof(long) - 1))];
	};

However in all places that we use readdir_r() we have no concerns about
reentrance nor we have problems with threads. Thus use the simpler
readdir() instead.

We also remove the error logging here (that could be added back by
checking errno), but it was not adding much value so it's gone.
2013-08-29 01:33:51 -03:00
Lucas De Marchi 493dc650d6 libkmod: Fix getting param with no value from kcmdline 2013-08-13 22:04:46 -03:00
Jan Engelhardt c1170883b4 depmod: add missing "else" clause
It occurred to an openSUSE user that our mkinitrd would throw a
warning when used with kmod:

libkmod: conf_files_list: unsupported file mode /dev/null: 0x21b6

Grepping for the error message revealed that there might be a missing
"else" keyword here, since it is unusual to put an "if" directly after
closing brace.
2013-08-09 12:01:10 -03:00
Lucas De Marchi cd923111c6 README: Move items from TODO
Put the differences between kmod and module-init-tools in the README
file so it's more visible.
2013-07-17 02:31:27 -03:00
Lucas De Marchi fa6fc9f0b8 util: Add mkdir_parents()
Like mkdir_p, but discards the leaf, creating the parent directories.
2013-07-15 12:45:35 -03:00
Lucas De Marchi c493b93750 util: Add len arg to mkdir_p() 2013-07-15 12:44:33 -03:00
Lucas De Marchi 85d02ebea3 util: Add mkdir_p implementation from testsuite 2013-07-15 12:44:33 -03:00
Lucas De Marchi 83b855a6ed Use "-internal" suffix instead of "-private" 2013-07-04 16:13:11 -03:00
Jan Luebbe 5eac795b8b libkmod: Avoid calling syscall() with -1
At least in qemu 1.4.1 for vexpress/arm-cortexa9, this resulted in an
illegal instruction error. Solve that by returning an error when
__NR_finit_module is -1.
2013-05-11 00:54:15 -03:00
Lucas De Marchi 03f7dfb868 Revert "missing: Don't call syscall() with syscallno == -1"
This reverts commit 38829712e5.  It fixes
the problem, but it breaks the testsuite for those who don't have
__NR_finit_module. The testsuite would have to make the same check.

Instead, I'm reverting this change and I'm going to apply another patch
from Jan Luebbe who got this right from the beginning.
2013-05-11 00:50:32 -03:00
Chengwei Yang d7152f6282 Add document for exported enums
There are several exported enums by libkmod without document, this patch
mainly added documentation for below enums like the way kmod_resources
be documented in.
* kmod_index
* kmod_remove
* kmod_insert
* kmod_probe
* kmod_filter
* kmod_module_initstate

This is not the best way to document these exported enums, however, it's
the simple way due to gtkdoc limits. It doesn't support export plain
enum like below: see https://bugzilla.gnome.org/show_bug.cgi?id=657444
---------8<-------head.h--------------8<-----------
...
enum foo {
    ...
};
...
---------8<-------end of head.h-------8<-----------
---------8<-------source.c------------8<-----------
...
/**
 * document for foo here
 */
...
typedef enum foo foo;
...
---------8<-------end of source.c-----8<----------
2013-05-04 18:57:43 -03:00
Chengwei Yang 491c490204 Several minor fixes for documentation 2013-05-04 10:42:56 -03:00
Lucas De Marchi 38829712e5 missing: Don't call syscall() with syscallno == -1
Reported-by: Jean-Francis Roy <jeanfrancis@funtoo.org>
Reported-by: Jan Luebbe <jlu@pengutronix.de>
2013-05-02 17:02:52 -03:00
Lucas De Marchi 1114e781ad Fix coding style
Either with space or without, not a mix of both.
2013-04-30 12:37:43 -03:00
Lucas De Marchi 681bf89afd libkmod-index: Return early if readroot failed 2013-04-23 21:26:09 -03:00
Lucas De Marchi b9a7da3910 libkmod-module: Don't pass NULL ctx to kmod_log 2013-04-23 21:26:08 -03:00
Lucas De Marchi 818af4f6fa libkmod-module: Don't pass NULL pointer to memcpy
When passing n=0, don't pass a NULL pointer, but instead pass anything
else (like the pointer to the start of the string).
2013-04-23 21:26:08 -03:00
Lucas De Marchi 1958af88a2 Add format attribute and fix issues
Add __attribute__((format)) to log_filep() and _show() functions, fixing
the bugs they found in the source code.

For functions that receive va_list instead of being variadic functions
we put 0 in the last argument, so at least the string is checked and we
get warnings of -Wformat-nonliteral type. So, it's better than adding a
pragma here to shut up the warning.
2013-04-21 16:17:12 -03:00
Lucas De Marchi a20a37c351 Use static assertions for sizeof checks 2013-04-15 14:14:07 -03:00
Lucas De Marchi 8efede20ef Use _Static_assert
Both GCC and clang already supports C11's _Static_assert, so use it
instead of defining our own macro.
2013-04-15 14:09:05 -03:00
Lucas De Marchi 55112d19f7 libkmod: Move finit_module() definition to missing.h
Check for finit_module() and don't use our own static inline function if
there's such function in libc (or another lib).

In testsuite we need to unconditionally define HAVE_FINIT_MODULE because
we want to override this function, and never use the static inline one
in missing.h
2013-04-09 04:38:27 -03:00
Lucas De Marchi 1407064e73 libkmod: Add missing definitions
Depending on kernel header and simply not passing the flags in
finit_module() if this header is not found is not good.

Add a missing.h header in which stuff like this should be added.
2013-04-09 04:05:09 -03:00
Cristian Rodríguez 41a51c2af9 libkmod: Use secure_getenv if available
"The secure_getenv() function is intended for use in general-purpose
libraries to avoid vulnerabilities that could occur if set-user-ID or
set-group-ID programs accidentally trusted the environment."
2013-04-04 15:58:29 -03:00
Lucas De Marchi b66381385a libkmod-util: Add missing include file
Fix compilation issue with musl-libc:

  CC       libkmod/libkmod-list.lo
In file included from libkmod/libkmod-private.h:183:0,
                 from libkmod/libkmod-list.c:24:
libkmod/libkmod-util.h:33:45: warning: 'struct stat' declared inside parameter list [enabled by default]
libkmod/libkmod-util.h:33:45: warning: its scope is only this definition or declaration, which is probably not what you want [enabled by default]
2013-03-19 17:52:30 -03:00
Kees Cook c3e8d26946 libkmod: fix address argument to mmap calls
The first argument to mmap should be "NULL" instead of "0".
2013-02-19 19:19:51 -03:00
Kees Cook 144d1826f1 libkmod: add finit_module logic
When a module is being loaded directly from disk (no compression, etc),
pass the file descriptor to the new finit_module() syscall. If the
finit_module syscall is exported by the kernel syscall headers, use it.
Additionally, if the kernel's module.h file is available, map kmod flags
to finit_module flags.
2013-02-19 19:19:51 -03:00
Michal Marek 8fe1681c52 libkmod: Return module signature information in kmod_module_get_info()
If the module is built with CONFIG_MODULE_SIG, add the the signer's
name, hexadecimal key id and hash algorithm to the list returned in
kmod_module_get_info(). The modinfo output then looks like this:

filename:       /home/mmarek/kmod/testsuite/rootfs-pristine/test-modinfo/ext4-x86_64-sha256.ko
license:        GPL
description:    Fourth Extended Filesystem
author:         Remy Card, Stephen Tweedie, Andrew Morton, Andreas Dilger, Theodore Ts'o and others
alias:          ext3
alias:          ext2
depends:        mbcache,jbd2
intree:         Y
vermagic:       3.7.0 SMP mod_unload
signer:         Magrathea: Glacier signing key
sig_key:        E3:C8:FC:A7:3F:B3:1D:DE:84:81:EF:38:E3:4C:DE:4B:0C:FD:1B:F9
sig_hashalgo:   sha256

The signature algorithm (RSA) and key identifier type (X509) are not
displayed, because they are constant information for every signed
module. But it would be trivial to add this. Note: No attempt is made at
verifying the signature, I don't think that modinfo is the right tool
for this.
2013-01-17 23:48:43 -02:00
Michal Marek 6333934e27 libkmod-module: Do not free the list in kmod_module_info_append
In error case, just return NULL and let the caller free the list.
2013-01-17 23:48:43 -02:00
Lucas De Marchi e6b0e49b4e Update copyright notices 2013-01-16 11:27:45 -02:00
Michal Marek f64458cab5 libkmod-module: Add helper for building the module info list 2013-01-16 09:53:46 -02:00
Lucas De Marchi 5d352563bd Use bool instead of int
Also change the last field initializer in array to be empty.
2012-11-28 14:25:50 -02:00
Aleksey Makarov 6f02b6fa7a fix is_module_filename()
modinfo fails if there is a ".ko" substring in the path to the module
2012-11-28 11:22:00 -02:00
Lucas De Marchi a4578669ca libkmod-module: mangle the section header, not the section
When we are told to remove the "__versions" section we were mangling
that section instead of tweaking the SHF_ALLOC flag in its header.
2012-11-21 20:23:02 -02:00
Lucas De Marchi d196b8d99f libkmod-module: Remove key+value vermagic from .modinfo section
When told to force load a module, we were removing only the value of
vermagic instead of the complete entry.

Philippe De Swert (philippe.deswert@jollamobile.com) sent a patch that
was additionally mangling also the last two chars of the key
("vermagic="). Instead of creating an invalid entry in .modinfo section
like this, this patch removes the complete entry, key + value, by
zeroing the entire string.

Much thanks to Philippe who found the issue and pointed to the fix.
2012-11-21 20:22:56 -02:00
Lucas De Marchi 1eff942e37 libkmod: cache open file for later access
If we are accessing several times the modules and reading some sections
by sucessive calls to the functions below, we are incurring in a penalty
of having to open, parse the header and close the file. For each
function.

	- kmod_module_get_info()
	- kmod_module_get_versions()
	- kmod_module_get_symbols()
	- kmod_module_get_dependency_symbols()

These functions are particularly important to depmod. It calls all of
them, for each module. Moreover there's a huge bottleneck in the open
operation if we are using compression. Every time we open the module we
need to uncompress the file and after getting the information we need we
discard the result. This is clearly shown by profiling depmod with perf
(record + report), using compressed modules:

 64.07%  depmod  libz.so.1.2.7       [.] 0x00000000000074b8                                            ◆
 18.18%  depmod  libz.so.1.2.7       [.] crc32                                                         ▒
  2.42%  depmod  libz.so.1.2.7       [.] inflate                                                       ▒
  1.17%  depmod  libc-2.16.so        [.] __memcpy_ssse3_back                                           ▒
  0.96%  depmod  [kernel.kallsyms]   [k] copy_user_generic_string                                      ▒
  0.89%  depmod  libc-2.16.so        [.] __strcmp_sse42                                                ▒
  0.82%  depmod  [kernel.kallsyms]   [k] hrtimer_interrupt                                             ▒
  0.77%  depmod  libc-2.16.so        [.] _int_malloc                                                   ▒
  0.44%  depmod  kmod-nolib          [.] kmod_elf_get_strings                                          ▒
  0.41%  depmod  kmod-nolib          [.] kmod_elf_get_dependency_symbols                               ▒
  0.37%  depmod  kmod-nolib          [.] kmod_elf_get_section                                          ▒
  0.36%  depmod  kmod-nolib          [.] kmod_elf_get_symbols
  ...

Average of running depmod 5 times, dropping caches between them, in a
slow spinning disk:

Before:   12.25 +- 0.20
After:     8.20 +- 0.21
m-i-t:     9.62 +- 0.27

So this patch leads to an improvement of ~33% over unpatched version,
ending up with 15% speedup over module-init-tools.
2012-10-18 02:09:55 -03:00
Leandro Pereira 1faec2c134 libkmod-hash: Plug possible memory leak when free_value is defined
Although the hash table implementation allows passing a callback function
to free a value when it is removed from the hash table, hash_del() wasn't
freeing it if it was provided. Now it does.

As a bonus, it now checks if the callback is set in hash_add() as well.
2012-10-12 12:34:27 -03:00
Lucas De Marchi 66f3228d17 libkmod: Add support for '.' in module parameter on kcmdline
Otherwise we fail to parse arguments in kernel command line like
testmodule.testparam=1.5G

Suggested-by: Selim T. Erdogan <selim@alumni.cs.utexas.edu>
2012-10-09 09:56:50 -03:00
Dave Reisner c5b37dba89 build-sys: Remove --with-rootprefix option
This is a broken option that only leads to misery and incompatabilities
with other systems. Kbuild doesn't come close to supporting directories
other than /lib/modules with several targets simply failing without
hacky fixes. Simply remove the option and all traces of it, as it
doesn't make sense in today's world.
2012-10-02 00:27:31 -03:00
Lucas De Marchi 6882017f80 libkmod-module: Add KMOD_PROBE_APPLY_BLACKLIST_ALIAS_ONLY flag
With this flag kmod_module_probe_insert_module() check if module is
blacklisted only if it's also an alias. This is needed in order to allow
blacklisting a module by name and effectively blacklisting all its
aliases as module-init-tools was doing.

Before this patch we could load pcspkr module as follows:

	/etc/modprobe.d/test.conf:
		alias yay pcspkr
		blacklist pcspkr

	$ modprobe yay

Now libkmod has support to blacklist "yay" because "pcspkr" is blacklisted.
2012-08-17 09:42:15 -03:00
Lucas De Marchi e8fd8fec23 Use #pragma once instead of #ifndef
Only the public header maintains #ifndef in the header, together with
pragma. The other ones contain only pragma.

As reported by Shawn Landden on systemd mailing list this is compatible
with all major compilers and gcc has this since version 3.3.
2012-07-18 10:31:50 -03:00
Dave Reisner 486f901392 module: support reading coresize from /sys if supported
Linux 3.3 introduced the coresize attribute in /sys/module/*. When
available, use this instead of parsing some portion of /proc/modules.
2012-06-29 13:04:41 -04:00
Lucas De Marchi e7fc2c868e libkmod-config: refactor functions to get config
It makes more sense to have libkmod-config.c deal with the configuration
directly and the others get the config from ctx. As a bonus point we get
a smaller binary. Following numbers are for x86-64, libkmod + kmod:

Before:
   text	   data	    bss	    dec	    hex	filename
 128840	   1496	    104	 130440	  1fd88	tools/modprobe

After:
   text	   data	    bss	    dec	    hex	filename
 128392	   1496	    104	 129992	  1fbc8	tools/modprobe
2012-06-12 01:43:46 -03:00
Lucas De Marchi 5b05c32725 libkmod-index: protect ourselves from corrupted indexes
If index is shorter than 12 bytes, we couldn't even read its header. Go
to error handling in this case.
2012-06-06 09:36:29 -03:00
Lucas De Marchi 535c541e60 libkmod-util: split function for usec conversion 2012-06-06 01:08:56 -03:00
Lucas De Marchi e46bca009d libkmod-util: add missing stdbool.h include 2012-06-05 00:54:47 -03:00
Lucas De Marchi 9e2eadb1d7 Silence clang warnings with __unused__ attribute
I hate this kind of READV and WRITEV macros that Gustavo seems to love.
clang-analyzer hates them as well.

I'm not motivated enough to refactor this, but I want a clean clang
report, so just shut it up.
2012-05-23 20:31:18 -03:00
Lucas De Marchi a70c1e774e Don't use __ for attribute defines
System headers use __, don't mess with them.
2012-05-23 20:27:23 -03:00
Lucas De Marchi 5bbec8cdcb libkmod-index: use generic function for unaligned access 2012-05-23 19:32:58 -03:00
Lucas De Marchi af9080d9f9 libkmod-hash: use generic function for unaligned access 2012-05-21 20:43:39 -03:00
Lucas De Marchi a6b67f90c3 libkmod-util: copy macros for unaligned access from BlueZ 2012-05-21 20:22:12 -03:00
Mike Frysinger d30319e433 libkmod: move function to the only file using it
If we don't have --gc-sections support, linking kmod fails:
libkmod/.libs/libkmod-util.a(libkmod-util.o): In function 'underscores':
libkmod/libkmod-util.c:117: undefined reference to 'kmod_log'

This is because libkmod-util.la uses kmod_log(), that is in libkmod.la.
Move the function so we don't have a dependency loop while building the
libraries and it works with compilers with no support for --gc-sections.
2012-05-15 19:30:05 -03:00
Lucas De Marchi 96253751ae build: remove private symbol from linker script
There's no reason kmod_log should be exported, remove it from linker
script. This doesn't break the API/ABI because we are luck: since the
function had visibility=hidden it was not getting exported as a global
symbol.
2012-05-10 21:11:27 -03:00
Lucas De Marchi 719282889a Revert "libkmod: make sure to export kmod_log"
This reverts commit 88a170dbd6.

There's no reason for users of the API to call this method, it's just
wrong to export it.

The bug that this patch fixed needs to be fixed another way, not
exporting this function.
2012-05-10 20:58:46 -03:00
Dave Reisner c7d5a60d3d libkmod-file: gracefully handle errors from zlib
zlib won't necessarily set the system errno, and this is particularly
evident on corrupted data (which results in a double free). Use zlib's
gzerror to detect the failure, returning a generic EINVAL when zlib
doesn't provide us with an errno.
2012-05-08 10:22:13 -03:00
Lucas De Marchi 4321590770 Remove dead increment 2012-04-26 11:42:27 -03:00
Mike Frysinger 88a170dbd6 libkmod: make sure to export kmod_log
If we don't have --gc-sections support, linking kmod fails:
libkmod/.libs/libkmod-util.a(libkmod-util.o): In function 'underscores':
libkmod/libkmod-util.c:117: undefined reference to 'kmod_log'

This is because kmod_log is missing the export define, even though it's
already listed in the exported symbol list.
2012-04-23 10:40:04 -03:00
Lucas De Marchi 883d8c42c7 doc: remove links to NULL going nowhere 2012-04-19 11:08:24 -03:00
Kay Sievers 471a7d0089 doc: silent man page generation and fix gtk-doc warnings 2012-04-15 18:10:10 -03:00
Lucas De Marchi 436da1e96e config: use order /etc, /run, /lib
This matches the change in systemd and udev. Log message on udev's
change by Kay Sievers:

	After long consideration we came to the conclusion that user
	configuration in /etc should always override the (generally
	computer generated) configuration in /run. User configuration
	should always be what matters over anything else. Hence rearrange
	the search orders accordingly. In general this should change
	very little as overriding like this is seldomn done so far,
	and the order between /etc and /usr stays the same.
2012-03-15 09:19:34 -03:00
Lucas De Marchi 49c6489d74 Use upper case after Deprecated in doc 2012-03-02 22:28:38 -03:00
Lucas De Marchi 6204d5b123 Add kmod_module_apply_filter() to doc-sections file 2012-03-02 22:18:33 -03:00
Lucas De Marchi bfcd31def9 Fix wrong printf format string
This fixes build in 32 bits machines.
2012-03-02 21:28:11 -03:00
Lucas De Marchi 2e2e252bd4 libkmod-index: do not pre-populate mmap
If we tell mmap to populate all the indexes and they are big, this will
impact load time. Let them be mapped as they are used.
2012-03-02 20:33:26 -03:00
Lucas De Marchi 9c5f057c7c Downgrade log message: refcnt file may not exist
If kernel doesn't have support to unload modules,
/sys/module/<modname>/refcnt will not exist and that's ok.

Reported by: Sven Anders <anders@anduras.de>
2012-03-01 14:04:29 -03:00
Lucas De Marchi 817f4e33de libkmod-index: free node when we have only partial match 2012-02-27 19:54:33 -03:00
Lucas De Marchi ee1d188f70 libkmod-module: fill builtin's name
modules.builtin don't have any realname->value -- it follows the same
format of modules.dep, not the aliases ones.
2012-02-27 18:48:02 -03:00
Dave Reisner bdda7e14d8 find builtins by property, not initstate 2012-02-24 23:02:09 -05:00
Dave Reisner d80b103c63 libkmod/module: add kmod_module_apply_filter method
This is a more generic method of applying filters to module lists. This
deprecates kmod_module_get_filtered_blacklist() which now simply returns
a call to _apply_filter with the extra filter enum arg.
2012-02-24 10:53:42 -05:00
Lucas De Marchi 7cd664fbae libkmod-module: don't treat "coming" as in-kernel
Running two instances of modprobe with the same module should both
succeed or both fail:

modprobe foo&; modprobe foo;

Previously if foo failed to be inserted by the first call, the second one
could return 0 because it may have occurred while the first one was being
processed by kernel (thus marked as "coming").

Now we simply don't check by "coming" in order to decide if we need to
call init_module(). module-init-tools used to spin calling
usleep(100000), but calls to init_module() are already synchronous.
Therefore let kernel synchronize the calls.
2012-02-23 16:47:33 -02:00
Lucas De Marchi abd5557bd1 libkmod-module: probe: check if module exists for install cmds
Mimic what module-init-tools was doing before running install commands:
check if a module with the same name is already loaded in kerne, and if
it is, bail out.

This fixes the issue with some install commands used in Debian with
alsa-base package:

install snd /sbin/modprobe --ignore-install snd && { /sbin/modprobe --quiet snd-ioctl32 ; /sbin/modprobe --quiet snd-seq ; }
install snd_rawmidi /sbin/modprobe --ignore-install snd-rawmidi && { /sbin/modprobe --quiet snd-seq-midi ; : ; }
install snd_emu10k1 /sbin/modprobe --ignore-install snd-emu10k1 && { /sbin/modprobe --quiet snd-emu10k1-synth ; : ; }
install snd_pcm modprobe --ignore-install snd-pcm $CMDLINE_OPTS && { modprobe --quiet snd-pcm-oss ; : ; }
install snd_mixer modprobe --ignore-install snd-mixer $CMDLINE_OPTS && { modprobe --quiet snd-mixer-oss ; : ; }
install snd_seq modprobe --ignore-install snd-seq $CMDLINE_OPTS && { modprobe --quiet snd-seq-midi ; modprobe --quiet snd-seq-oss ; : ; }
2012-02-22 13:06:56 -02:00
Lucas De Marchi 050db08c57 Add missing newlines
Checked with following semantic patch for the library:

// smpl
@a@
identifier virtual.func;
expression E1;
expression fmt;
position p1;
@@

func(E1, fmt@p1, ...)

@script:python b@
fmt << a.fmt;
p1 << a.p1;
@@

s = str(fmt)
if s.find("\\n") < 0:
	print p1[0].file + ":" + p1[0].line

// smpl

For tools, just remove E1
2012-02-18 03:56:21 -02:00
Lucas De Marchi adca3cd203 Downgrade log level when modules.dep{,.bin} don't exist 2012-02-17 05:00:09 -02:00
Lucas De Marchi 3805274bf5 kmod-module: lookup: search modules.builtin file too
Search modules.builtin file before saying the module was not found.
Note: these "modules" should not appear as dependencies of other modules
(in modules.dep) even if they appear in modinfo. This fixes the return
code of modprobe with builtin modules.

Also fixes a small coding style issue in module_is_inkernel().
2012-02-16 21:18:00 -02:00
Lucas De Marchi 73298175ea libkmod-index: don't print an error if index doesn't exist
It's ok not to have the index files, so just print a DBG message instead
of an ERR.
2012-02-13 21:58:36 -02:00
Lucas De Marchi 8cd0f9e4f9 libkmod-module: probe: fix infinite loop with softdeps
If a softdep depends on a module in the dependency list of the module
being inserted, we would enter and infinite loop.

Move the "mod->visited = true" assignment to the proper place, hoping it
didn't break other use cases. This is a bug that comes and goes every
now and then. Since we have a testsuite now, a test for this should be
written.
2012-02-11 19:50:00 -02:00
Lucas De Marchi 269de2e0bf libkmod-module: probe: Fix ignore-loaded flag not being applied 2012-02-07 09:48:59 -02:00
Lucas De Marchi 08600ee579 libkmod-module: probe: return -EEXIST if told to do so
Commit "af9572c lib/module: check initstate before inserting module"
removed the check for "we should return -EEXIST" and moved it back to
the start of the function. The problem with this is the following
scenario:

- We check if module is in kernel -> no
- We insert the dependencies
					<-- External program loads
					the module
- We check if module is in kernel -> yes
- We return 0, when we should return -EEXIST
2012-02-06 12:54:42 -02:00
Lucas De Marchi 814a57babf libkmod-module: probe: rename flag to be more meaningful 2012-02-06 12:46:39 -02:00
Dan McGee 9a252c218a Fix simple grammar issue 2012-02-05 02:15:15 -02:00
Ambroz Bizjak a2c7d3e8b0 Fix unaligned memory access in hash function
Use a function to properly get an unsigned short from memory that is
possibly unaligned.

Note that it implicitly fixes a small bug in the hash function that
was introduced when modifying the eina code: the line "hash ^= key[2]
<< 18;" is supposed to be accessing the 3rd byte of the remainder of
the input, but when 'it' was introduced, 'key' ('data' in eina code)
was no longer incremented, so this ended up accessing the 3rd byte of
the input from the beginning. This is fixed by iterating over 'key',
like the eina code does.

Before this patch depmod was failing on ARMv5 and possibly others that
don't have unaligned access. They do not calculate correctly the
dependencies as shown below:

[root@alarm ~]# modinfo bridge
filename: /lib/modules/2.6.39.4/kernel/net/bridge/bridge.ko
version: 2.3
license: GPL
srcversion: 6B583530AE2B39C7E2317BF
depends: stp,llc
vermagic: 2.6.39.4 preempt mod_unload ARMv5
[root@alarm ~]# depmod
[root@alarm ~]# cat /lib/modules/2.6.39.4/modules.dep |grep bridge
kernel/net/bridge/bridge.ko:
[root@alarm ~]#

See how modinfo properly lists the dependencies, but modules.dep which
depmod generates does not contain them. As a result, most kernel
modules fail to load because their dependencies are not loaded by
modprobe.
2012-02-03 18:15:01 -02:00
Dave Reisner af9572c6d7 lib/module: check initstate before inserting module
This applies to both the high level probe_insert_module() and the
underlying insert_module() functions. By checking module initstate prior
to inserting a module, we can avoid a lot of needless work just to find
out that the init_module call fails with EEXIST.

This implements a helper function, module_is_inkernel, to return a
boolean value describing if a module is live, coming, or builtin.
2012-02-03 09:10:13 -05:00
Dave Reisner 7bede7b6a8 whitespace fix -- no logical code changes 2012-02-02 19:52:37 -02:00
Gustavo Sverzut Barbieri dfa96f1545 improve logging to mention context.
Just printing the errno string such as "%m\n" is not enough to help
debug or users understand the problem.

Change to provide more context on the failing operation.
2012-01-31 22:01:00 -02:00
Gustavo Sverzut Barbieri e3cb0900dd improve log when debugging.
Some messages may happen more than once in the same function and
discovering the line is hard. Now we print the actual log priority
that exposed the message as well as filename and line.

NOTE: We should consider printing the log priority in the non-debug
version as well.
2012-01-31 22:01:00 -02:00
Lucas De Marchi 9226ddad2c libkmod: organize public header 2012-01-31 17:23:35 -02:00
Lucas De Marchi 4bc1895674 Prepare for API bump 2012-01-31 16:05:02 -02:00
Lucas De Marchi 7aed46088e libkmod-module: probe: remove useless KMOD_PROBE_STOP_ON_COMMAND 2012-01-31 14:08:57 -02:00
Lucas De Marchi 3bc92e8949 libkmod-module: probe: return -EEXIST if told to stop on already loaded 2012-01-31 14:08:57 -02:00
Lucas De Marchi 4c1ffb75d4 libkmod-module: probe: add flag to dry-run 2012-01-31 14:08:57 -02:00
Lucas De Marchi 7c10c69c72 libkmod-module: probe: add flag to ignore loaded modules
We need a way to tell libkmod to ignore loaded modules, so modprobe can
tell it to dry-run and show dependencies. However there's a conflict
with two flags. KMOD_PROBE_STOP_ON_ALREADY_LOADED prevails if passed
together with KMOD_PROBE_IGNORE_LOADED.
2012-01-31 14:08:57 -02:00
Lucas De Marchi 6bd0713deb libkmod-module: probe: add print_action callback
This allows to implement dry-run in modprobe without exporting
kmod_module_get_probe_list().
2012-01-31 14:08:57 -02:00
Lucas De Marchi d851e9a144 libkmod-module: probe: add room in flags for future extension
Breaking flags is one of the reasons next version will need to bump ABI.
In future we don't want to bump it just because of this.
2012-01-30 20:05:34 -02:00
Lucas De Marchi 48b10305cb libkmod-module: probe: ignore-command flag can't be used in return 2012-01-30 20:05:34 -02:00
Lucas De Marchi 79d6c7d764 libkmod-module: probe: remove useless flag to stop on failure
We always want to stop if module failed to loaded due to unknown reason.
2012-01-30 20:05:34 -02:00
Lucas De Marchi 5f3514731e libkmod-module: probe: add flag to stop loading on already loaded
It's not as simple as tell user to check if the module is loaded before
calling this function. Due to race conditions, module might not be
loaded before the function call, but fail later because another process
inserted it.
2012-01-30 20:05:34 -02:00
Lucas De Marchi 9c7f3ad0a4 libkmod-module: split creation of new modules to share code
Share code of module creation among the several new functions. With this
we let the alias/modname/path parsing to the separate functions, and the
rest with the common one.

This fixes the issue of alias names not being able to contain dots.
2012-01-30 20:05:34 -02:00
Lucas De Marchi 9901cfe242 Partially fix parsing of alias with dots
Alias names may contain dots. However since kmod_module_from_alias()
still calls kmod_module_new_from_name(), the bug is not entirely fixed,
and will be completely corrected in a later patch.
2012-01-30 20:05:33 -02:00
Lucas De Marchi 89e92487bc libkmod-module: probe: add flag to ignore commands 2012-01-30 20:05:33 -02:00
Lucas De Marchi b1a51256a9 libkmod-module: probe: change insertion to cover more use cases
Split kmod_module_probe_insert_module() in 2:
	1) Get list of modules to be loaded
	2) Iterate the list, loading the module

With this in future we will be able to cover use cases of modprobe,
that has a logic a bit more complicated.

With this we also change the logic to detect dependency loops: instead
of checking the recursion every STEP times, we now keep a field in
kmod_module, marking it as visited. We simply ignore already visited
modules and thus we break loops.
2012-01-30 20:05:33 -02:00
Lucas De Marchi ece09aac7f libkmod-module: add visited field
This field can be used to iterate the modules, controlling whether we
are revisiting a certain module. A function to clear the values in all
modules is needed since when we are iterating, we don't know if the
module is created anew or if it's picked from the pool. Therefore we
can't know if the field is true because of a previous iteration or if
the module was indeed already visited.
2012-01-30 13:52:22 -02:00
Pedro Pedruzzi 647200fb5a libkmod: Fix handling of square brackets expressions in function alias_normalize 2012-01-28 12:19:25 -02:00
Lucas De Marchi ea17e2b043 elf: privately export kmod_elf_get_section()
This function is used to find a certain section in ELF file. It will be
used to get the modname from an ELF file.
2012-01-26 16:05:05 -02:00
Lucas De Marchi 434f32ca8d libkmod-list: allow to append an empty list 2012-01-17 21:16:23 -02:00
Thierry Vignaud eff917c0d2 WEXITSTATUS is defined in sys/wait.h
Fix compiling with dietlibc:

../libkmod/libkmod-module.c:858:2: warning: implicit declaration of function 'WEXITSTATUS' [-Wimplicit-function-declaration]
../libkmod/libkmod-module.c:858:2: warning: nested extern declaration of 'WEXITSTATUS' [-Wnested-externs]
(...)
kmod-modprobe.c:(.text.command_do+0x157): undefined reference to `WEXITSTATUS'
2012-01-17 17:33:07 -02:00
Lucas De Marchi 6068aaaea8 Check if struct stat has mtim member
Not all libc's have a mtim member in struct stat (dietlibc doesn't).
Change ts_usec() to receive a struct stat as parameter and implement it
accordingly for both cases.
2012-01-17 12:22:55 -02:00
Lucas De Marchi 09e9ae58b6 modprobe: flush stdout before dumping indexes
Index dump doesn't use stdio.h function and instead call write()
directly on STDOUT_FILENO file descriptor. Therefore we need to flush
stdio buffers before calling it, to be sure the configuration dump will
appear before index's.
2012-01-17 10:11:03 -02:00
Lucas De Marchi 0224482e62 Add doc to kmod_dump_index 2012-01-16 16:44:25 -02:00
Lucas De Marchi 758428a75f libkmod: dump index files
Provide a function to dump the index files to a certain fd. It could be
more optimized (particularly the functions to dump the index that were
copied and pasted from m-i-t), but it seems like the only user of it is
'modprobe -c', used for debugging purposes. So, keep it as is.
2012-01-16 16:05:46 -02:00
Lucas De Marchi f1cbf3cfe2 libkmod-util: add helper function to write to fd 2012-01-16 16:05:46 -02:00
Lucas De Marchi 7a973b0cb0 libkmod-util: adhere to coding style 2012-01-16 16:05:46 -02:00
Lucas De Marchi b08314f7b7 libkmod: export enum kmod_index and rename members 2012-01-16 16:05:36 -02:00
Lucas De Marchi 63be91cbd5 libkmod: store prefix of each index
Prefix is useful when dumping the index (to be added later).
2012-01-16 16:04:32 -02:00
Lucas De Marchi 2f47c7fae9 Update documentation with recent changes 2012-01-14 12:16:48 -02:00
Lucas De Marchi 2e092e19a7 kmod_new(): deal with relative paths for dirname 2012-01-14 02:32:25 -02:00
Lucas De Marchi 6b04ef324a config: let softdeps dump their data 2012-01-13 11:12:41 -02:00
Lucas De Marchi 0017862911 config: add exported iterator functions
Config iterators are useful to get each configuration list, remember its
type and how to get their key/value pair.

softdeps don't have the value yet, because they are stored as string
vectors.
2012-01-13 11:12:41 -02:00
Lucas De Marchi 8b5ee61872 libkmod-private: allow to get aliases from config 2012-01-13 11:12:41 -02:00
Lucas De Marchi e3ebcff7a4 build-sys: fix clean rule removing tracked files 2012-01-12 14:21:22 -02:00
Lucas De Marchi 0ad5dd0837 config: deprecate 'include' and 'config' commands 2012-01-11 00:29:34 -02:00
Lucas De Marchi ba998b9c9e Fix error code returned on module removal 2012-01-11 00:08:14 -02:00
Lucas De Marchi 83121fdea6 config: be reliable againt syntax errors in configs 2012-01-10 15:00:07 -02:00
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