Commit Graph

111 Commits

Author SHA1 Message Date
Lucas De Marchi f7f2851024 libkmod: export new kmod_get_dirname() function
Make sure it gets exported and add documentation.
2015-09-30 15:28:24 -03:00
Harish Jenny K N fd44a98ae2 Fix race while loading modules
usecase: two sd cards are being mounted in parallel at same time on
dual core. example modules which are getting loaded is nls_cp437.
While one module is being loaded , it starts creating sysfs files.
meanwhile on other core, modprobe might return saying the module
is KMOD_MODULE_BUILTIN, which might result in not mounting sd card.

Experiments done to prove the issue in kmod.
Added sleep in kernel module.c at the place of creation of sysfs files.
Then tried `modprobe nls_cp437` from two different shells.
While the first was still waiting for its completion ,
the second one returned saying the module is built-in.

[ Lucas:

  The problem is that the creation of /sys/module/<name> and
  /sys/module/<name>/initstate are not atomic. There's a small window in
  which the directory exists but the initstate file was still not
  created.

  Built-in modules can be handled by searching the modules.builtin file.
  We actually lose some "modules" that create entries in /sys/modules
  (e.g. vt) and are not in modules.builtin file: only those that can be
  compiled as module are present in this file.

  We enforce mod->builtin to always be up-to-date when
  kmod_module_get_initstate() is called. This way if the directory
  exists but the initstate doesn't, we can be sure this is because the
  module is in the "coming" state, i.e. kernel didn't create the file
  yet, but since builtin modules were already handled by checking our
  index the only reason for that to happen is that we hit the race
  condition.

  I also added some tweaks to the patch, so we don't repeat the code for builtin
  lookup.  ]
2015-02-28 14:15:22 -03:00
Lucas De Marchi dea2dfee9b Remove FSF mailing address
It has changed in the past, and these days, anyone can get a copy of the
LGPL via the web rather than by post.

Like 657a122 (Remove FSF mailing address) in libabc by Josh Tripplet,
but let the FSF website in which the license can be found.
2014-12-25 23:41:34 -02:00
Lucas De Marchi c2e4286bb9 Reorder and reorganize header files
Let the includes in the following order:

< system headers >
< libkmod >
< tool >
< local headers >
2014-10-03 01:43:15 -03:00
Lucas De Marchi 0db718edcf Move hash implementation to shared directory 2014-10-03 00:40:11 -03:00
Lucas De Marchi 96573a0220 Move generic util functions to shared directory 2014-10-03 00:33:25 -03:00
Leandro Pereira e84d912bd7 Free realnames if kmod_lookup_alias_from_alias_bin() fails 2014-05-14 20:19:52 -03:00
Michal Marek 450bd1b429 libkmod: Ignore errors from softdeps
Before we had softdeps, the usual idiom was

install foo /sbin/modprobe bar; /sbin/modprobe --ignore-install foo

ignoring errors from the first modprobe invocation. This also matches
the behavior of module-init-tools' implementation of softdep.
2014-04-01 07:40:37 -03:00
Lucas De Marchi 83b855a6ed Use "-internal" suffix instead of "-private" 2013-07-04 16:13:11 -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 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
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 e6b0e49b4e Update copyright notices 2013-01-16 11:27:45 -02: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 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 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
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 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 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 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
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
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 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
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 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 8b5ee61872 libkmod-private: allow to get aliases from config 2012-01-13 11:12:41 -02:00
Lucas De Marchi e1daa4f54b doc: fix order of param descriptions 2012-01-09 03:30:10 -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 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 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 2f76fda259 Use last enum value instead of ARRAY_SIZE 2011-12-31 19:30:09 -02:00
Lucas De Marchi 0d46743ca5 Move function to the right place 2011-12-31 11:15:52 -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 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 c1c9c44628 Add functions to get ctx blacklists 2011-12-27 02:49:46 -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 16ca3666bf Fix check for opened indexes 2011-12-20 12:29:13 -02:00
Gustavo Sverzut Barbieri 1c52260048 implement softdeps. 2011-12-17 19:43:11 -02:00