File src/libkmod-config.c changed (mode: 100644) (index d4f53d6..601065c) |
18 |
18 |
* License along with this library; if not, see <http://www.gnu.org/licenses/>. |
* License along with this library; if not, see <http://www.gnu.org/licenses/>. |
19 |
19 |
*/ |
*/ |
20 |
20 |
|
|
21 |
|
#include <ctype.h> |
|
22 |
|
#include <dirent.h> |
|
23 |
|
#include <errno.h> |
|
24 |
|
#include <stdarg.h> |
|
25 |
21 |
#include <stddef.h> |
#include <stddef.h> |
26 |
|
#include <stdio.h> |
|
27 |
|
#include <stdlib.h> |
|
28 |
22 |
#include <string.h> |
#include <string.h> |
29 |
|
#include <unistd.h> |
|
30 |
|
#include <inttypes.h> |
|
|
23 |
|
#include <errno.h> |
|
24 |
|
#include <stdlib.h> |
31 |
25 |
#include <limits.h> |
#include <limits.h> |
32 |
|
#include <stdbool.h> |
|
33 |
|
#include <syslog.h> |
|
|
26 |
|
#include <stdio.h> |
|
27 |
|
#include <ctype.h> |
|
28 |
|
#include <unistd.h> |
|
29 |
|
#include <dirent.h> |
34 |
30 |
#include <sys/stat.h> |
#include <sys/stat.h> |
35 |
|
#include <sys/types.h> |
|
|
31 |
|
#include <syslog.h> /* XSI */ |
36 |
32 |
|
|
37 |
|
#include <libgen.h> |
|
38 |
|
|
|
39 |
|
#include "config.h" |
|
|
33 |
|
#include <libgen.h> /* POSIX basename selector */ |
40 |
34 |
|
|
41 |
35 |
#include "libkmod.h" |
#include "libkmod.h" |
42 |
|
#include "libkmod-namespace.h" |
|
43 |
36 |
#include "libkmod-paths.h" |
#include "libkmod-paths.h" |
|
37 |
|
#include "libkmod-namespace.h" |
|
38 |
|
|
|
39 |
|
#include "config.h" |
|
40 |
|
|
44 |
41 |
#include "shared/macro.h" |
#include "shared/macro.h" |
45 |
42 |
#include "shared/util.h" |
#include "shared/util.h" |
|
43 |
|
|
46 |
44 |
#define LIBKMOD_CONFIG_C |
#define LIBKMOD_CONFIG_C |
47 |
45 |
#include "libkmod-internal.h" |
#include "libkmod-internal.h" |
48 |
46 |
#undef LIBKMOD_CONFIG_C |
#undef LIBKMOD_CONFIG_C |
|
... |
... |
static int kmod_config_add_command(struct kmod_config *config, |
133 |
131 |
size_t modnamelen = strlen(modname) + 1; |
size_t modnamelen = strlen(modname) + 1; |
134 |
132 |
size_t commandlen = strlen(command) + 1; |
size_t commandlen = strlen(command) + 1; |
135 |
133 |
|
|
136 |
|
DBG(config->ctx, "modname='%s' cmd='%s %s'\n", modname, command_name, |
|
|
134 |
|
LIBKMOD_DBG(config->ctx, "modname='%s' cmd='%s %s'\n", modname, command_name, |
137 |
135 |
command); |
command); |
138 |
136 |
|
|
139 |
137 |
cmd = malloc(sizeof(*cmd) + modnamelen + commandlen); |
cmd = malloc(sizeof(*cmd) + modnamelen + commandlen); |
|
... |
... |
static int kmod_config_add_options(struct kmod_config *config, |
173 |
171 |
size_t modnamelen = strlen(modname) + 1; |
size_t modnamelen = strlen(modname) + 1; |
174 |
172 |
size_t optionslen = strlen(options) + 1; |
size_t optionslen = strlen(options) + 1; |
175 |
173 |
|
|
176 |
|
DBG(config->ctx, "modname='%s' options='%s'\n", modname, options); |
|
|
174 |
|
LIBKMOD_DBG(config->ctx, "modname='%s' options='%s'\n", modname, options); |
177 |
175 |
|
|
178 |
176 |
opt = malloc(sizeof(*opt) + modnamelen + optionslen); |
opt = malloc(sizeof(*opt) + modnamelen + optionslen); |
179 |
177 |
if (!opt) |
if (!opt) |
|
... |
... |
static int kmod_config_add_alias(struct kmod_config *config, |
211 |
209 |
struct kmod_list *list; |
struct kmod_list *list; |
212 |
210 |
size_t namelen = strlen(name) + 1, modnamelen = strlen(modname) + 1; |
size_t namelen = strlen(name) + 1, modnamelen = strlen(modname) + 1; |
213 |
211 |
|
|
214 |
|
DBG(config->ctx, "name=%s modname=%s\n", name, modname); |
|
|
212 |
|
LIBKMOD_DBG(config->ctx, "name=%s modname=%s\n", name, modname); |
215 |
213 |
|
|
216 |
214 |
alias = malloc(sizeof(*alias) + namelen + modnamelen); |
alias = malloc(sizeof(*alias) + namelen + modnamelen); |
217 |
215 |
if (!alias) |
if (!alias) |
|
... |
... |
static int kmod_config_add_blacklist(struct kmod_config *config, |
249 |
247 |
char *p = NULL; |
char *p = NULL; |
250 |
248 |
struct kmod_list *list; |
struct kmod_list *list; |
251 |
249 |
|
|
252 |
|
DBG(config->ctx, "modname=%s\n", modname); |
|
|
250 |
|
LIBKMOD_DBG(config->ctx, "modname=%s\n", modname); |
253 |
251 |
|
|
254 |
252 |
p = strdup(modname); |
p = strdup(modname); |
255 |
253 |
if (!p) |
if (!p) |
|
... |
... |
static int kmod_config_add_softdep(struct kmod_config *config, |
287 |
285 |
bool was_space = false; |
bool was_space = false; |
288 |
286 |
enum { S_NONE, S_PRE, S_POST } mode = S_NONE; |
enum { S_NONE, S_PRE, S_POST } mode = S_NONE; |
289 |
287 |
|
|
290 |
|
DBG(config->ctx, "modname=%s\n", modname); |
|
|
288 |
|
LIBKMOD_DBG(config->ctx, "modname=%s\n", modname); |
291 |
289 |
|
|
292 |
290 |
/* analyze and count */ |
/* analyze and count */ |
293 |
291 |
for (p = s = line; ; s++) { |
for (p = s = line; ; s++) { |
|
... |
... |
static int kmod_config_add_softdep(struct kmod_config *config, |
330 |
328 |
break; |
break; |
331 |
329 |
} |
} |
332 |
330 |
|
|
333 |
|
DBG(config->ctx, "%u pre, %u post\n", n_pre, n_post); |
|
|
331 |
|
LIBKMOD_DBG(config->ctx, "%u pre, %u post\n", n_pre, n_post); |
334 |
332 |
|
|
335 |
333 |
dep = malloc(sizeof(struct kmod_softdep) + modnamelen + |
dep = malloc(sizeof(struct kmod_softdep) + modnamelen + |
336 |
334 |
n_pre * sizeof(const char *) + |
n_pre * sizeof(const char *) + |
337 |
335 |
n_post * sizeof(const char *) + |
n_post * sizeof(const char *) + |
338 |
336 |
buflen); |
buflen); |
339 |
337 |
if (dep == NULL) { |
if (dep == NULL) { |
340 |
|
ERR(config->ctx, "out-of-memory modname=%s\n", modname); |
|
|
338 |
|
LIBKMOD_ERR(config->ctx, "out-of-memory modname=%s\n", modname); |
341 |
339 |
return -ENOMEM; |
return -ENOMEM; |
342 |
340 |
} |
} |
343 |
341 |
dep->n_pre = n_pre; |
dep->n_pre = n_pre; |
|
... |
... |
static void kcmdline_parse_result(struct kmod_config *config, char *modname, |
491 |
489 |
if (modname == NULL || param == NULL) |
if (modname == NULL || param == NULL) |
492 |
490 |
return; |
return; |
493 |
491 |
|
|
494 |
|
DBG(config->ctx, "%s %s\n", modname, param); |
|
|
492 |
|
LIBKMOD_DBG(config->ctx, "%s %s\n", modname, param); |
495 |
493 |
|
|
496 |
494 |
if (streq(modname, "modprobe") && !strncmp(param, "blacklist=", 10)) { |
if (streq(modname, "modprobe") && !strncmp(param, "blacklist=", 10)) { |
497 |
495 |
for (;;) { |
for (;;) { |
|
... |
... |
static void kcmdline_parse_result(struct kmod_config *config, char *modname, |
503 |
501 |
} |
} |
504 |
502 |
} else { |
} else { |
505 |
503 |
if (underscores(modname) < 0) { |
if (underscores(modname) < 0) { |
506 |
|
ERR(config->ctx, "Ignoring bad option on kernel command line while parsing module name: '%s'\n", |
|
|
504 |
|
LIBKMOD_ERR(config->ctx, "Ignoring bad option on kernel command line while parsing module name: '%s'\n", |
507 |
505 |
modname); |
modname); |
508 |
506 |
} |
} |
509 |
507 |
kmod_config_add_options(config, modname, param); |
kmod_config_add_options(config, modname, param); |
|
... |
... |
static int kmod_config_parse_kcmdline(struct kmod_config *config) |
520 |
518 |
fd = open("/proc/cmdline", O_RDONLY|O_CLOEXEC); |
fd = open("/proc/cmdline", O_RDONLY|O_CLOEXEC); |
521 |
519 |
if (fd < 0) { |
if (fd < 0) { |
522 |
520 |
err = -errno; |
err = -errno; |
523 |
|
DBG(config->ctx, "could not open '/proc/cmdline' for reading: %m\n"); |
|
|
521 |
|
LIBKMOD_DBG(config->ctx, "could not open '/proc/cmdline' for reading: %m\n"); |
524 |
522 |
return err; |
return err; |
525 |
523 |
} |
} |
526 |
524 |
|
|
527 |
525 |
err = read_str_safe(fd, buf, sizeof(buf)); |
err = read_str_safe(fd, buf, sizeof(buf)); |
528 |
526 |
close(fd); |
close(fd); |
529 |
527 |
if (err < 0) { |
if (err < 0) { |
530 |
|
ERR(config->ctx, "could not read from '/proc/cmdline': %s\n", |
|
|
528 |
|
LIBKMOD_ERR(config->ctx, "could not read from '/proc/cmdline': %s\n", |
531 |
529 |
strerror(-err)); |
strerror(-err)); |
532 |
530 |
return err; |
return err; |
533 |
531 |
} |
} |
|
... |
... |
static int kmod_config_parse(struct kmod_config *config, int fd, |
600 |
598 |
fp = fdopen(fd, "r"); |
fp = fdopen(fd, "r"); |
601 |
599 |
if (fp == NULL) { |
if (fp == NULL) { |
602 |
600 |
err = -errno; |
err = -errno; |
603 |
|
ERR(config->ctx, "fd %d: %m\n", fd); |
|
|
601 |
|
LIBKMOD_ERR(config->ctx, "fd %d: %m\n", fd); |
604 |
602 |
close(fd); |
close(fd); |
605 |
603 |
return err; |
return err; |
606 |
604 |
} |
} |
|
... |
... |
static int kmod_config_parse(struct kmod_config *config, int fd, |
666 |
664 |
kmod_config_add_softdep(config, modname, softdeps); |
kmod_config_add_softdep(config, modname, softdeps); |
667 |
665 |
} else if (streq(cmd, "include") |
} else if (streq(cmd, "include") |
668 |
666 |
|| streq(cmd, "config")) { |
|| streq(cmd, "config")) { |
669 |
|
ERR(ctx, "%s: command %s is deprecated and not parsed anymore\n", |
|
|
667 |
|
LIBKMOD_ERR(ctx, "%s: command %s is deprecated and not parsed anymore\n", |
670 |
668 |
filename, cmd); |
filename, cmd); |
671 |
669 |
} else { |
} else { |
672 |
670 |
syntax_error: |
syntax_error: |
673 |
|
ERR(ctx, "%s line %u: ignoring bad line starting with '%s'\n", |
|
|
671 |
|
LIBKMOD_ERR(ctx, "%s line %u: ignoring bad line starting with '%s'\n", |
674 |
672 |
filename, linenum, cmd); |
filename, linenum, cmd); |
675 |
673 |
} |
} |
676 |
674 |
|
|
|
... |
... |
static bool conf_files_filter_out(struct kmod_ctx *ctx, DIR *d, |
730 |
728 |
fstatat(dirfd(d), fn, &st, 0); |
fstatat(dirfd(d), fn, &st, 0); |
731 |
729 |
|
|
732 |
730 |
if (S_ISDIR(st.st_mode)) { |
if (S_ISDIR(st.st_mode)) { |
733 |
|
ERR(ctx, "Directories inside directories are not supported: " |
|
|
731 |
|
LIBKMOD_ERR(ctx, "Directories inside directories are not supported: " |
734 |
732 |
"%s/%s\n", path, fn); |
"%s/%s\n", path, fn); |
735 |
733 |
return true; |
return true; |
736 |
734 |
} |
} |
|
... |
... |
static int conf_files_insert_sorted(struct kmod_ctx *ctx, |
771 |
769 |
} |
} |
772 |
770 |
|
|
773 |
771 |
if (cmp == 0) { |
if (cmp == 0) { |
774 |
|
DBG(ctx, "Ignoring duplicate config file: %s/%s\n", path, |
|
|
772 |
|
LIBKMOD_DBG(ctx, "Ignoring duplicate config file: %s/%s\n", path, |
775 |
773 |
name); |
name); |
776 |
774 |
free(path_cpy); |
free(path_cpy); |
777 |
775 |
return -EEXIST; |
return -EEXIST; |
|
... |
... |
static int conf_files_list(struct kmod_ctx *ctx, struct kmod_list **list, |
821 |
819 |
|
|
822 |
820 |
if (stat(path, &st) != 0) { |
if (stat(path, &st) != 0) { |
823 |
821 |
err = -errno; |
err = -errno; |
824 |
|
DBG(ctx, "could not stat '%s': %m\n", path); |
|
|
822 |
|
LIBKMOD_DBG(ctx, "could not stat '%s': %m\n", path); |
825 |
823 |
return err; |
return err; |
826 |
824 |
} |
} |
827 |
825 |
|
|
|
... |
... |
static int conf_files_list(struct kmod_ctx *ctx, struct kmod_list **list, |
834 |
832 |
|
|
835 |
833 |
d = opendir(path); |
d = opendir(path); |
836 |
834 |
if (d == NULL) { |
if (d == NULL) { |
837 |
|
ERR(ctx, "opendir(%s): %m\n", path); |
|
|
835 |
|
LIBKMOD_ERR(ctx, "opendir(%s): %m\n", path); |
838 |
836 |
return -EINVAL; |
return -EINVAL; |
839 |
837 |
} |
} |
840 |
838 |
|
|
|
... |
... |
int kmod_config_new(struct kmod_ctx *ctx, struct kmod_config **p_config, |
900 |
898 |
fn = cf->path; |
fn = cf->path; |
901 |
899 |
} else if (snprintf(buf, sizeof(buf), "%s/%s", |
} else if (snprintf(buf, sizeof(buf), "%s/%s", |
902 |
900 |
cf->path, cf->name) >= (int)sizeof(buf)) { |
cf->path, cf->name) >= (int)sizeof(buf)) { |
903 |
|
ERR(ctx, "Error parsing %s/%s: path too long\n", |
|
|
901 |
|
LIBKMOD_ERR(ctx, "Error parsing %s/%s: path too long\n", |
904 |
902 |
cf->path, cf->name); |
cf->path, cf->name); |
905 |
903 |
free(cf); |
free(cf); |
906 |
904 |
continue; |
continue; |
907 |
905 |
} |
} |
908 |
906 |
|
|
909 |
907 |
fd = open(fn, O_RDONLY|O_CLOEXEC); |
fd = open(fn, O_RDONLY|O_CLOEXEC); |
910 |
|
DBG(ctx, "parsing file '%s' fd=%d\n", fn, fd); |
|
|
908 |
|
LIBKMOD_DBG(ctx, "parsing file '%s' fd=%d\n", fn, fd); |
911 |
909 |
|
|
912 |
910 |
if (fd >= 0) |
if (fd >= 0) |
913 |
911 |
kmod_config_parse(config, fd, fn); |
kmod_config_parse(config, fd, fn); |
File src/libkmod-module.c changed (mode: 100644) (index a632059..6efab46) |
17 |
17 |
* License along with this library; if not, see <http://www.gnu.org/licenses/>. |
* License along with this library; if not, see <http://www.gnu.org/licenses/>. |
18 |
18 |
*/ |
*/ |
19 |
19 |
|
|
20 |
|
#include <assert.h> |
|
21 |
|
#include <ctype.h> |
|
22 |
|
#include <dirent.h> |
|
23 |
|
#include <errno.h> |
|
24 |
|
#include <fnmatch.h> |
|
25 |
|
#include <inttypes.h> |
|
26 |
|
#include <limits.h> |
|
27 |
|
#include <stdarg.h> |
|
|
20 |
|
#include <stdbool.h> |
28 |
21 |
#include <stddef.h> |
#include <stddef.h> |
29 |
|
#include <stdio.h> |
|
30 |
|
#include <stdlib.h> |
|
|
22 |
|
#include <limits.h> |
31 |
23 |
#include <string.h> |
#include <string.h> |
|
24 |
|
#include <syslog.h> /* XSI */ |
|
25 |
|
#include <errno.h> |
32 |
26 |
#include <unistd.h> |
#include <unistd.h> |
33 |
|
#include <syslog.h> |
|
34 |
|
#include <sys/mman.h> |
|
|
27 |
|
#include <stdio.h> |
35 |
28 |
#include <sys/stat.h> |
#include <sys/stat.h> |
|
29 |
|
#include <stdlib.h> |
|
30 |
|
#include <fnmatch.h> |
|
31 |
|
#include <dirent.h> |
|
32 |
|
|
36 |
33 |
#include <sys/syscall.h> |
#include <sys/syscall.h> |
37 |
|
#include <sys/types.h> |
|
38 |
|
#include <sys/wait.h> |
|
39 |
34 |
#include <linux/module.h> |
#include <linux/module.h> |
40 |
35 |
|
|
41 |
|
#include "config.h" |
|
42 |
|
|
|
43 |
36 |
#include "libkmod.h" |
#include "libkmod.h" |
44 |
|
#include "libkmod-namespace.h" |
|
45 |
37 |
#include "libkmod-paths.h" |
#include "libkmod-paths.h" |
46 |
|
#include "shared/linux-syscalls.h" |
|
|
38 |
|
#include "libkmod-namespace.h" |
|
39 |
|
|
|
40 |
|
#include "config.h" |
|
41 |
|
|
47 |
42 |
#include "shared/macro.h" |
#include "shared/macro.h" |
48 |
43 |
#include "shared/util.h" |
#include "shared/util.h" |
|
44 |
|
#include "shared/linux-syscalls.h" |
|
45 |
|
|
49 |
46 |
#define LIBKMOD_MODULE_C |
#define LIBKMOD_MODULE_C |
50 |
47 |
#include "libkmod-internal.h" |
#include "libkmod-internal.h" |
51 |
48 |
#undef LIBKMOD_MODULE_C |
#undef LIBKMOD_MODULE_C |
52 |
49 |
|
|
|
50 |
|
|
53 |
51 |
/** |
/** |
54 |
52 |
* SECTION:libkmod-module |
* SECTION:libkmod-module |
55 |
53 |
* @short_description: operate on kernel modules |
* @short_description: operate on kernel modules |
|
... |
... |
int kmod_module_parse_depline(struct kmod_module *mod, char *line) |
152 |
150 |
|
|
153 |
151 |
if (mod->init.dep) |
if (mod->init.dep) |
154 |
152 |
return mod->n_dep; |
return mod->n_dep; |
155 |
|
assert(mod->dep == NULL); |
|
156 |
153 |
mod->init.dep = true; |
mod->init.dep = true; |
157 |
154 |
|
|
158 |
155 |
p = strchr(line, ':'); |
p = strchr(line, ':'); |
|
... |
... |
int kmod_module_parse_depline(struct kmod_module *mod, char *line) |
187 |
184 |
|
|
188 |
185 |
path = path_join(p, dirnamelen, buf); |
path = path_join(p, dirnamelen, buf); |
189 |
186 |
if (path == NULL) { |
if (path == NULL) { |
190 |
|
ERR(ctx, "could not join path '%s' and '%s'.\n", |
|
|
187 |
|
LIBKMOD_ERR(ctx, "could not join path '%s' and '%s'.\n", |
191 |
188 |
dirname, p); |
dirname, p); |
192 |
189 |
goto fail; |
goto fail; |
193 |
190 |
} |
} |
194 |
191 |
|
|
195 |
192 |
err = kmod_module_new_from_path(ctx, path, &depmod); |
err = kmod_module_new_from_path(ctx, path, &depmod); |
196 |
193 |
if (err < 0) { |
if (err < 0) { |
197 |
|
ERR(ctx, "ctx=%p path=%s error=%s\n", |
|
|
194 |
|
LIBKMOD_ERR(ctx, "ctx=%p path=%s error=%s\n", |
198 |
195 |
ctx, path, strerror(-err)); |
ctx, path, strerror(-err)); |
199 |
196 |
goto fail; |
goto fail; |
200 |
197 |
} |
} |
201 |
198 |
|
|
202 |
|
DBG(ctx, "add dep: %s\n", path); |
|
|
199 |
|
LIBKMOD_DBG(ctx, "add dep: %s\n", path); |
203 |
200 |
|
|
204 |
201 |
list = kmod_list_prepend(list, depmod); |
list = kmod_list_prepend(list, depmod); |
205 |
202 |
n++; |
n++; |
206 |
203 |
} |
} |
207 |
204 |
|
|
208 |
|
DBG(ctx, "%d dependencies for %s\n", n, mod->name); |
|
|
205 |
|
LIBKMOD_DBG(ctx, "%d dependencies for %s\n", n, mod->name); |
209 |
206 |
|
|
210 |
207 |
mod->dep = list; |
mod->dep = list; |
211 |
208 |
mod->n_dep = n; |
mod->n_dep = n; |
|
... |
... |
int kmod_module_new_from_path(struct kmod_ctx *ctx, |
406 |
403 |
|
|
407 |
404 |
abspath = path_make_absolute_cwd(path); |
abspath = path_make_absolute_cwd(path); |
408 |
405 |
if (abspath == NULL) { |
if (abspath == NULL) { |
409 |
|
DBG(ctx, "no absolute path for %s\n", path); |
|
|
406 |
|
LIBKMOD_DBG(ctx, "no absolute path for %s\n", path); |
410 |
407 |
return -ENOMEM; |
return -ENOMEM; |
411 |
408 |
} |
} |
412 |
409 |
|
|
413 |
410 |
err = stat(abspath, &st); |
err = stat(abspath, &st); |
414 |
411 |
if (err < 0) { |
if (err < 0) { |
415 |
412 |
err = -errno; |
err = -errno; |
416 |
|
DBG(ctx, "stat %s: %s\n", path, strerror(errno)); |
|
|
413 |
|
LIBKMOD_DBG(ctx, "stat %s: %s\n", path, strerror(errno)); |
417 |
414 |
free(abspath); |
free(abspath); |
418 |
415 |
return err; |
return err; |
419 |
416 |
} |
} |
420 |
417 |
|
|
421 |
418 |
if (path_to_modname(path, name, &namelen) == NULL) { |
if (path_to_modname(path, name, &namelen) == NULL) { |
422 |
|
DBG(ctx, "could not get modname from path %s\n", path); |
|
|
419 |
|
LIBKMOD_DBG(ctx, "could not get modname from path %s\n", path); |
423 |
420 |
free(abspath); |
free(abspath); |
424 |
421 |
return -ENOENT; |
return -ENOENT; |
425 |
422 |
} |
} |
|
... |
... |
int kmod_module_new_from_path(struct kmod_ctx *ctx, |
431 |
428 |
else if (streq(m->path, abspath)) |
else if (streq(m->path, abspath)) |
432 |
429 |
free(abspath); |
free(abspath); |
433 |
430 |
else { |
else { |
434 |
|
ERR(ctx, "kmod_module '%s' already exists with different path: new-path='%s' old-path='%s'\n", |
|
|
431 |
|
LIBKMOD_ERR(ctx, "kmod_module '%s' already exists with different path: new-path='%s' old-path='%s'\n", |
435 |
432 |
name, abspath, m->path); |
name, abspath, m->path); |
436 |
433 |
free(abspath); |
free(abspath); |
437 |
434 |
return -EEXIST; |
return -EEXIST; |
|
... |
... |
struct kmod_module *kmod_module_unref(struct kmod_module *mod) |
471 |
468 |
if (--mod->refcount > 0) |
if (--mod->refcount > 0) |
472 |
469 |
return mod; |
return mod; |
473 |
470 |
|
|
474 |
|
DBG(mod->ctx, "kmod_module %p released\n", mod); |
|
|
471 |
|
LIBKMOD_DBG(mod->ctx, "kmod_module %p released\n", mod); |
475 |
472 |
|
|
476 |
473 |
kmod_pool_del_module(mod->ctx, mod, mod->hashkey); |
kmod_pool_del_module(mod->ctx, mod, mod->hashkey); |
477 |
474 |
kmod_module_unref_list(mod->dep); |
kmod_module_unref_list(mod->dep); |
|
... |
... |
int kmod_module_new_from_lookup(struct kmod_ctx *ctx, |
550 |
547 |
return -ENOENT; |
return -ENOENT; |
551 |
548 |
|
|
552 |
549 |
if (list == NULL || *list != NULL) { |
if (list == NULL || *list != NULL) { |
553 |
|
ERR(ctx, "An empty list is needed to create lookup\n"); |
|
|
550 |
|
LIBKMOD_ERR(ctx, "An empty list is needed to create lookup\n"); |
554 |
551 |
return -ENOSYS; |
return -ENOSYS; |
555 |
552 |
} |
} |
556 |
553 |
|
|
557 |
554 |
if (alias_normalize(given_alias, alias, NULL) < 0) { |
if (alias_normalize(given_alias, alias, NULL) < 0) { |
558 |
|
DBG(ctx, "invalid alias: %s\n", given_alias); |
|
|
555 |
|
LIBKMOD_DBG(ctx, "invalid alias: %s\n", given_alias); |
559 |
556 |
return -EINVAL; |
return -EINVAL; |
560 |
557 |
} |
} |
561 |
558 |
|
|
562 |
|
DBG(ctx, "input alias=%s, normalized=%s\n", given_alias, alias); |
|
|
559 |
|
LIBKMOD_DBG(ctx, "input alias=%s, normalized=%s\n", given_alias, alias); |
563 |
560 |
|
|
564 |
561 |
/* Aliases from config file override all the others */ |
/* Aliases from config file override all the others */ |
565 |
562 |
err = kmod_lookup_alias_from_config(ctx, alias, list); |
err = kmod_lookup_alias_from_config(ctx, alias, list); |
566 |
563 |
CHECK_ERR_AND_FINISH(err, fail, list, finish); |
CHECK_ERR_AND_FINISH(err, fail, list, finish); |
567 |
564 |
|
|
568 |
|
DBG(ctx, "lookup modules.dep %s\n", alias); |
|
|
565 |
|
LIBKMOD_DBG(ctx, "lookup modules.dep %s\n", alias); |
569 |
566 |
err = kmod_lookup_alias_from_moddep_file(ctx, alias, list); |
err = kmod_lookup_alias_from_moddep_file(ctx, alias, list); |
570 |
567 |
CHECK_ERR_AND_FINISH(err, fail, list, finish); |
CHECK_ERR_AND_FINISH(err, fail, list, finish); |
571 |
568 |
|
|
572 |
|
DBG(ctx, "lookup modules.symbols %s\n", alias); |
|
|
569 |
|
LIBKMOD_DBG(ctx, "lookup modules.symbols %s\n", alias); |
573 |
570 |
err = kmod_lookup_alias_from_symbols_file(ctx, alias, list); |
err = kmod_lookup_alias_from_symbols_file(ctx, alias, list); |
574 |
571 |
CHECK_ERR_AND_FINISH(err, fail, list, finish); |
CHECK_ERR_AND_FINISH(err, fail, list, finish); |
575 |
572 |
|
|
576 |
|
DBG(ctx, "lookup install and remove commands %s\n", alias); |
|
|
573 |
|
LIBKMOD_DBG(ctx, "lookup install and remove commands %s\n", alias); |
577 |
574 |
err = kmod_lookup_alias_from_commands(ctx, alias, list); |
err = kmod_lookup_alias_from_commands(ctx, alias, list); |
578 |
575 |
CHECK_ERR_AND_FINISH(err, fail, list, finish); |
CHECK_ERR_AND_FINISH(err, fail, list, finish); |
579 |
576 |
|
|
580 |
|
DBG(ctx, "lookup modules.aliases %s\n", alias); |
|
|
577 |
|
LIBKMOD_DBG(ctx, "lookup modules.aliases %s\n", alias); |
581 |
578 |
err = kmod_lookup_alias_from_aliases_file(ctx, alias, list); |
err = kmod_lookup_alias_from_aliases_file(ctx, alias, list); |
582 |
579 |
CHECK_ERR_AND_FINISH(err, fail, list, finish); |
CHECK_ERR_AND_FINISH(err, fail, list, finish); |
583 |
580 |
|
|
584 |
|
DBG(ctx, "lookup modules.builtin %s\n", alias); |
|
|
581 |
|
LIBKMOD_DBG(ctx, "lookup modules.builtin %s\n", alias); |
585 |
582 |
err = kmod_lookup_alias_from_builtin_file(ctx, alias, list); |
err = kmod_lookup_alias_from_builtin_file(ctx, alias, list); |
586 |
583 |
CHECK_ERR_AND_FINISH(err, fail, list, finish); |
CHECK_ERR_AND_FINISH(err, fail, list, finish); |
587 |
584 |
|
|
588 |
585 |
finish: |
finish: |
589 |
|
DBG(ctx, "lookup %s=%d, list=%p\n", alias, err, *list); |
|
|
586 |
|
LIBKMOD_DBG(ctx, "lookup %s=%d, list=%p\n", alias, err, *list); |
590 |
587 |
return err; |
return err; |
591 |
588 |
fail: |
fail: |
592 |
|
DBG(ctx, "Failed to lookup %s\n", alias); |
|
|
589 |
|
LIBKMOD_DBG(ctx, "Failed to lookup %s\n", alias); |
593 |
590 |
kmod_module_unref_list(*list); |
kmod_module_unref_list(*list); |
594 |
591 |
*list = NULL; |
*list = NULL; |
595 |
592 |
return err; |
return err; |
|
... |
... |
struct kmod_list *kmod_module_get_dependencies(const struct kmod_module *mod) |
686 |
683 |
return list_new; |
return list_new; |
687 |
684 |
|
|
688 |
685 |
fail: |
fail: |
689 |
|
ERR(mod->ctx, "out of memory\n"); |
|
|
686 |
|
LIBKMOD_ERR(mod->ctx, "out of memory\n"); |
690 |
687 |
kmod_module_unref_list(list_new); |
kmod_module_unref_list(list_new); |
691 |
688 |
return NULL; |
return NULL; |
692 |
689 |
} |
} |
|
... |
... |
const char *kmod_module_get_path(const struct kmod_module *mod) |
747 |
744 |
if (mod == NULL) |
if (mod == NULL) |
748 |
745 |
return NULL; |
return NULL; |
749 |
746 |
|
|
750 |
|
DBG(mod->ctx, "name='%s' path='%s'\n", mod->name, mod->path); |
|
|
747 |
|
LIBKMOD_DBG(mod->ctx, "name='%s' path='%s'\n", mod->name, mod->path); |
751 |
748 |
|
|
752 |
749 |
if (mod->path != NULL) |
if (mod->path != NULL) |
753 |
750 |
return mod->path; |
return mod->path; |
|
... |
... |
int kmod_module_remove_module(struct kmod_module *mod, |
796 |
793 |
err = delete_module(mod->name, flags); |
err = delete_module(mod->name, flags); |
797 |
794 |
if (err != 0) { |
if (err != 0) { |
798 |
795 |
err = -errno; |
err = -errno; |
799 |
|
ERR(mod->ctx, "could not remove '%s': %m\n", mod->name); |
|
|
796 |
|
LIBKMOD_ERR(mod->ctx, "could not remove '%s': %m\n", mod->name); |
800 |
797 |
} |
} |
801 |
798 |
|
|
802 |
799 |
return err; |
return err; |
|
... |
... |
int kmod_module_insert_module(struct kmod_module *mod, |
835 |
832 |
|
|
836 |
833 |
path = kmod_module_get_path(mod); |
path = kmod_module_get_path(mod); |
837 |
834 |
if (path == NULL) { |
if (path == NULL) { |
838 |
|
ERR(mod->ctx, "could not find module by name='%s'\n", mod->name); |
|
|
835 |
|
LIBKMOD_ERR(mod->ctx, "could not find module by name='%s'\n", mod->name); |
839 |
836 |
return -ENOENT; |
return -ENOENT; |
840 |
837 |
} |
} |
841 |
838 |
|
|
|
... |
... |
int kmod_module_insert_module(struct kmod_module *mod, |
870 |
867 |
if (flags & KMOD_INSERT_FORCE_MODVERSION) { |
if (flags & KMOD_INSERT_FORCE_MODVERSION) { |
871 |
868 |
err = kmod_elf_strip_section(elf, "__versions"); |
err = kmod_elf_strip_section(elf, "__versions"); |
872 |
869 |
if (err < 0) |
if (err < 0) |
873 |
|
INFO(mod->ctx, "Failed to strip modversion: %s\n", strerror(-err)); |
|
|
870 |
|
LIBKMOD_INFO(mod->ctx, "Failed to strip modversion: %s\n", strerror(-err)); |
874 |
871 |
} |
} |
875 |
872 |
|
|
876 |
873 |
if (flags & KMOD_INSERT_FORCE_VERMAGIC) { |
if (flags & KMOD_INSERT_FORCE_VERMAGIC) { |
877 |
874 |
err = kmod_elf_strip_vermagic(elf); |
err = kmod_elf_strip_vermagic(elf); |
878 |
875 |
if (err < 0) |
if (err < 0) |
879 |
|
INFO(mod->ctx, "Failed to strip vermagic: %s\n", strerror(-err)); |
|
|
876 |
|
LIBKMOD_INFO(mod->ctx, "Failed to strip vermagic: %s\n", strerror(-err)); |
880 |
877 |
} |
} |
881 |
878 |
|
|
882 |
879 |
mem = kmod_elf_get_memory(elf); |
mem = kmod_elf_get_memory(elf); |
|
... |
... |
int kmod_module_insert_module(struct kmod_module *mod, |
889 |
886 |
init_finished: |
init_finished: |
890 |
887 |
if (err < 0) { |
if (err < 0) { |
891 |
888 |
err = -errno; |
err = -errno; |
892 |
|
INFO(mod->ctx, "Failed to insert module '%s': %m\n", path); |
|
|
889 |
|
LIBKMOD_INFO(mod->ctx, "Failed to insert module '%s': %m\n", path); |
893 |
890 |
} |
} |
894 |
891 |
return err; |
return err; |
895 |
892 |
} |
} |
|
... |
... |
static int command_do(struct kmod_module *mod, const char *type, |
974 |
971 |
const char *modname = kmod_module_get_name(mod); |
const char *modname = kmod_module_get_name(mod); |
975 |
972 |
int err; |
int err; |
976 |
973 |
|
|
977 |
|
DBG(mod->ctx, "%s %s\n", type, cmd); |
|
|
974 |
|
LIBKMOD_DBG(mod->ctx, "%s %s\n", type, cmd); |
978 |
975 |
|
|
979 |
976 |
setenv("MODPROBE_MODULE", modname, 1); |
setenv("MODPROBE_MODULE", modname, 1); |
980 |
977 |
err = system(cmd); |
err = system(cmd); |
981 |
978 |
unsetenv("MODPROBE_MODULE"); |
unsetenv("MODPROBE_MODULE"); |
982 |
979 |
|
|
983 |
980 |
if (err == -1 || WEXITSTATUS(err)) { |
if (err == -1 || WEXITSTATUS(err)) { |
984 |
|
ERR(mod->ctx, "Error running %s command for %s\n", |
|
|
981 |
|
LIBKMOD_ERR(mod->ctx, "Error running %s command for %s\n", |
985 |
982 |
type, modname); |
type, modname); |
986 |
983 |
if (err != -1) |
if (err != -1) |
987 |
984 |
err = -WEXITSTATUS(err); |
err = -WEXITSTATUS(err); |
|
... |
... |
static int module_do_install_commands(struct kmod_module *mod, |
1005 |
1002 |
int err; |
int err; |
1006 |
1003 |
size_t cmdlen, options_len, varlen; |
size_t cmdlen, options_len, varlen; |
1007 |
1004 |
|
|
1008 |
|
assert(command); |
|
1009 |
|
|
|
1010 |
1005 |
if (options == NULL) |
if (options == NULL) |
1011 |
1006 |
options = ""; |
options = ""; |
1012 |
1007 |
|
|
|
... |
... |
static int __kmod_module_fill_softdep(struct kmod_module *mod, |
1087 |
1082 |
|
|
1088 |
1083 |
err = kmod_module_get_softdeps(mod, &pre, &post); |
err = kmod_module_get_softdeps(mod, &pre, &post); |
1089 |
1084 |
if (err < 0) { |
if (err < 0) { |
1090 |
|
ERR(mod->ctx, "could not get softdep: %s\n", |
|
|
1085 |
|
LIBKMOD_ERR(mod->ctx, "could not get softdep: %s\n", |
1091 |
1086 |
strerror(-err)); |
strerror(-err)); |
1092 |
1087 |
goto fail; |
goto fail; |
1093 |
1088 |
} |
} |
|
... |
... |
static int __kmod_module_get_probe_list(struct kmod_module *mod, |
1132 |
1127 |
int err = 0; |
int err = 0; |
1133 |
1128 |
|
|
1134 |
1129 |
if (mod->visited) { |
if (mod->visited) { |
1135 |
|
DBG(mod->ctx, "Ignore module '%s': already visited\n", |
|
|
1130 |
|
LIBKMOD_DBG(mod->ctx, "Ignore module '%s': already visited\n", |
1136 |
1131 |
mod->name); |
mod->name); |
1137 |
1132 |
return 0; |
return 0; |
1138 |
1133 |
} |
} |
|
... |
... |
static int kmod_module_get_probe_list(struct kmod_module *mod, |
1182 |
1177 |
{ |
{ |
1183 |
1178 |
int err; |
int err; |
1184 |
1179 |
|
|
1185 |
|
assert(mod != NULL); |
|
1186 |
|
assert(list != NULL && *list == NULL); |
|
1187 |
|
|
|
1188 |
1180 |
/* |
/* |
1189 |
1181 |
* Make sure we don't get screwed by previous calls to this function |
* Make sure we don't get screwed by previous calls to this function |
1190 |
1182 |
*/ |
*/ |
|
... |
... |
int kmod_module_probe_insert_module(struct kmod_module *mod, |
1310 |
1302 |
|
|
1311 |
1303 |
if (!(flags & KMOD_PROBE_IGNORE_LOADED) |
if (!(flags & KMOD_PROBE_IGNORE_LOADED) |
1312 |
1304 |
&& module_is_inkernel(m)) { |
&& module_is_inkernel(m)) { |
1313 |
|
DBG(mod->ctx, "Ignoring module '%s': already loaded\n", |
|
|
1305 |
|
LIBKMOD_DBG(mod->ctx, "Ignoring module '%s': already loaded\n", |
1314 |
1306 |
m->name); |
m->name); |
1315 |
1307 |
err = -EEXIST; |
err = -EEXIST; |
1316 |
1308 |
goto finish_module; |
goto finish_module; |
|
... |
... |
const char *kmod_module_get_options(const struct kmod_module *mod) |
1398 |
1390 |
size_t len; |
size_t len; |
1399 |
1391 |
void *tmp; |
void *tmp; |
1400 |
1392 |
|
|
1401 |
|
DBG(mod->ctx, "modname=%s mod->name=%s mod->alias=%s\n", modname, mod->name, mod->alias); |
|
|
1393 |
|
LIBKMOD_DBG(mod->ctx, "modname=%s mod->name=%s mod->alias=%s\n", modname, mod->name, mod->alias); |
1402 |
1394 |
if (!(streq(modname, mod->name) || (mod->alias != NULL && |
if (!(streq(modname, mod->name) || (mod->alias != NULL && |
1403 |
1395 |
streq(modname, mod->alias)))) |
streq(modname, mod->alias)))) |
1404 |
1396 |
continue; |
continue; |
1405 |
1397 |
|
|
1406 |
|
DBG(mod->ctx, "passed = modname=%s mod->name=%s mod->alias=%s\n", modname, mod->name, mod->alias); |
|
|
1398 |
|
LIBKMOD_DBG(mod->ctx, "passed = modname=%s mod->name=%s mod->alias=%s\n", modname, mod->name, mod->alias); |
1407 |
1399 |
str = kmod_option_get_options(l); |
str = kmod_option_get_options(l); |
1408 |
1400 |
len = strlen(str); |
len = strlen(str); |
1409 |
1401 |
if (len < 1) |
if (len < 1) |
|
... |
... |
const char *kmod_module_get_options(const struct kmod_module *mod) |
1434 |
1426 |
return mod->options; |
return mod->options; |
1435 |
1427 |
|
|
1436 |
1428 |
failed: |
failed: |
1437 |
|
ERR(mod->ctx, "out of memory\n"); |
|
|
1429 |
|
LIBKMOD_ERR(mod->ctx, "out of memory\n"); |
1438 |
1430 |
return NULL; |
return NULL; |
1439 |
1431 |
} |
} |
1440 |
1432 |
|
|
|
... |
... |
static struct kmod_list *lookup_softdep(struct kmod_ctx *ctx, const char * const |
1504 |
1496 |
|
|
1505 |
1497 |
err = kmod_module_new_from_lookup(ctx, depname, &lst); |
err = kmod_module_new_from_lookup(ctx, depname, &lst); |
1506 |
1498 |
if (err < 0) { |
if (err < 0) { |
1507 |
|
ERR(ctx, "failed to lookup soft dependency '%s', continuing anyway.\n", depname); |
|
|
1499 |
|
LIBKMOD_ERR(ctx, "failed to lookup soft dependency '%s', continuing anyway.\n", depname); |
1508 |
1500 |
continue; |
continue; |
1509 |
1501 |
} else if (lst != NULL) |
} else if (lst != NULL) |
1510 |
1502 |
ret = kmod_list_append_list(ret, lst); |
ret = kmod_list_append_list(ret, lst); |
|
... |
... |
int kmod_module_get_softdeps(const struct kmod_module *mod, |
1539 |
1531 |
if (mod == NULL || pre == NULL || post == NULL) |
if (mod == NULL || pre == NULL || post == NULL) |
1540 |
1532 |
return -ENOENT; |
return -ENOENT; |
1541 |
1533 |
|
|
1542 |
|
assert(*pre == NULL); |
|
1543 |
|
assert(*post == NULL); |
|
1544 |
|
|
|
1545 |
1534 |
config = kmod_get_config(mod->ctx); |
config = kmod_get_config(mod->ctx); |
1546 |
1535 |
|
|
1547 |
1536 |
kmod_list_foreach(l, config->softdeps) { |
kmod_list_foreach(l, config->softdeps) { |
|
... |
... |
int kmod_module_new_from_loaded(struct kmod_ctx *ctx, |
1662 |
1651 |
fp = fopen("/proc/modules", "re"); |
fp = fopen("/proc/modules", "re"); |
1663 |
1652 |
if (fp == NULL) { |
if (fp == NULL) { |
1664 |
1653 |
int err = -errno; |
int err = -errno; |
1665 |
|
ERR(ctx, "could not open /proc/modules: %s\n", strerror(errno)); |
|
|
1654 |
|
LIBKMOD_ERR(ctx, "could not open /proc/modules: %s\n", strerror(errno)); |
1666 |
1655 |
return err; |
return err; |
1667 |
1656 |
} |
} |
1668 |
1657 |
|
|
|
... |
... |
int kmod_module_new_from_loaded(struct kmod_ctx *ctx, |
1675 |
1664 |
|
|
1676 |
1665 |
err = kmod_module_new_from_name(ctx, name, &m); |
err = kmod_module_new_from_name(ctx, name, &m); |
1677 |
1666 |
if (err < 0) { |
if (err < 0) { |
1678 |
|
ERR(ctx, "could not get module from name '%s': %s\n", |
|
|
1667 |
|
LIBKMOD_ERR(ctx, "could not get module from name '%s': %s\n", |
1679 |
1668 |
name, strerror(-err)); |
name, strerror(-err)); |
1680 |
1669 |
goto eat_line; |
goto eat_line; |
1681 |
1670 |
} |
} |
|
... |
... |
int kmod_module_new_from_loaded(struct kmod_ctx *ctx, |
1684 |
1673 |
if (node) |
if (node) |
1685 |
1674 |
l = node; |
l = node; |
1686 |
1675 |
else { |
else { |
1687 |
|
ERR(ctx, "out of memory\n"); |
|
|
1676 |
|
LIBKMOD_ERR(ctx, "out of memory\n"); |
1688 |
1677 |
kmod_module_unref(m); |
kmod_module_unref(m); |
1689 |
1678 |
} |
} |
1690 |
1679 |
eat_line: |
eat_line: |
|
... |
... |
int kmod_module_get_initstate(const struct kmod_module *mod) |
1754 |
1743 |
if (fd < 0) { |
if (fd < 0) { |
1755 |
1744 |
err = -errno; |
err = -errno; |
1756 |
1745 |
|
|
1757 |
|
DBG(mod->ctx, "could not open '%s': %s\n", |
|
|
1746 |
|
LIBKMOD_DBG(mod->ctx, "could not open '%s': %s\n", |
1758 |
1747 |
path, strerror(-err)); |
path, strerror(-err)); |
1759 |
1748 |
|
|
1760 |
1749 |
if (pathlen > (int)sizeof("/initstate") - 1) { |
if (pathlen > (int)sizeof("/initstate") - 1) { |
|
... |
... |
int kmod_module_get_initstate(const struct kmod_module *mod) |
1764 |
1753 |
return KMOD_MODULE_COMING; |
return KMOD_MODULE_COMING; |
1765 |
1754 |
} |
} |
1766 |
1755 |
|
|
1767 |
|
DBG(mod->ctx, "could not open '%s': %s\n", |
|
|
1756 |
|
LIBKMOD_DBG(mod->ctx, "could not open '%s': %s\n", |
1768 |
1757 |
path, strerror(-err)); |
path, strerror(-err)); |
1769 |
1758 |
return err; |
return err; |
1770 |
1759 |
} |
} |
|
... |
... |
int kmod_module_get_initstate(const struct kmod_module *mod) |
1772 |
1761 |
err = read_str_safe(fd, buf, sizeof(buf)); |
err = read_str_safe(fd, buf, sizeof(buf)); |
1773 |
1762 |
close(fd); |
close(fd); |
1774 |
1763 |
if (err < 0) { |
if (err < 0) { |
1775 |
|
ERR(mod->ctx, "could not read from '%s': %s\n", |
|
|
1764 |
|
LIBKMOD_ERR(mod->ctx, "could not read from '%s': %s\n", |
1776 |
1765 |
path, strerror(-err)); |
path, strerror(-err)); |
1777 |
1766 |
return err; |
return err; |
1778 |
1767 |
} |
} |
|
... |
... |
int kmod_module_get_initstate(const struct kmod_module *mod) |
1784 |
1773 |
else if (streq(buf, "going\n")) |
else if (streq(buf, "going\n")) |
1785 |
1774 |
return KMOD_MODULE_GOING; |
return KMOD_MODULE_GOING; |
1786 |
1775 |
|
|
1787 |
|
ERR(mod->ctx, "unknown %s: '%s'\n", path, buf); |
|
|
1776 |
|
LIBKMOD_ERR(mod->ctx, "unknown %s: '%s'\n", path, buf); |
1788 |
1777 |
return -EINVAL; |
return -EINVAL; |
1789 |
1778 |
} |
} |
1790 |
1779 |
|
|
|
... |
... |
long kmod_module_get_size(const struct kmod_module *mod) |
1823 |
1812 |
cfd = openat(dfd, "coresize", O_RDONLY|O_CLOEXEC); |
cfd = openat(dfd, "coresize", O_RDONLY|O_CLOEXEC); |
1824 |
1813 |
if (cfd >= 0) { |
if (cfd >= 0) { |
1825 |
1814 |
if (read_str_long(cfd, &size, 10) < 0) |
if (read_str_long(cfd, &size, 10) < 0) |
1826 |
|
ERR(mod->ctx, "failed to read coresize from %s\n", line); |
|
|
1815 |
|
LIBKMOD_ERR(mod->ctx, "failed to read coresize from %s\n", line); |
1827 |
1816 |
close(cfd); |
close(cfd); |
1828 |
1817 |
goto done; |
goto done; |
1829 |
1818 |
} |
} |
|
... |
... |
long kmod_module_get_size(const struct kmod_module *mod) |
1832 |
1821 |
fp = fopen("/proc/modules", "re"); |
fp = fopen("/proc/modules", "re"); |
1833 |
1822 |
if (fp == NULL) { |
if (fp == NULL) { |
1834 |
1823 |
int err = -errno; |
int err = -errno; |
1835 |
|
ERR(mod->ctx, |
|
|
1824 |
|
LIBKMOD_ERR(mod->ctx, |
1836 |
1825 |
"could not open /proc/modules: %s\n", strerror(errno)); |
"could not open /proc/modules: %s\n", strerror(errno)); |
1837 |
1826 |
close(dfd); |
close(dfd); |
1838 |
1827 |
return err; |
return err; |
|
... |
... |
long kmod_module_get_size(const struct kmod_module *mod) |
1849 |
1838 |
|
|
1850 |
1839 |
tok = strtok_r(NULL, " \t", &saveptr); |
tok = strtok_r(NULL, " \t", &saveptr); |
1851 |
1840 |
if (tok == NULL) { |
if (tok == NULL) { |
1852 |
|
ERR(mod->ctx, |
|
|
1841 |
|
LIBKMOD_ERR(mod->ctx, |
1853 |
1842 |
"invalid line format at /proc/modules:%d\n", lineno); |
"invalid line format at /proc/modules:%d\n", lineno); |
1854 |
1843 |
break; |
break; |
1855 |
1844 |
} |
} |
1856 |
1845 |
|
|
1857 |
1846 |
value = strtol(tok, &endptr, 10); |
value = strtol(tok, &endptr, 10); |
1858 |
1847 |
if (endptr == tok || *endptr != '\0') { |
if (endptr == tok || *endptr != '\0') { |
1859 |
|
ERR(mod->ctx, |
|
|
1848 |
|
LIBKMOD_ERR(mod->ctx, |
1860 |
1849 |
"invalid line format at /proc/modules:%d\n", lineno); |
"invalid line format at /proc/modules:%d\n", lineno); |
1861 |
1850 |
break; |
break; |
1862 |
1851 |
} |
} |
|
... |
... |
int kmod_module_get_refcnt(const struct kmod_module *mod) |
1896 |
1885 |
fd = open(path, O_RDONLY|O_CLOEXEC); |
fd = open(path, O_RDONLY|O_CLOEXEC); |
1897 |
1886 |
if (fd < 0) { |
if (fd < 0) { |
1898 |
1887 |
err = -errno; |
err = -errno; |
1899 |
|
DBG(mod->ctx, "could not open '%s': %s\n", |
|
|
1888 |
|
LIBKMOD_DBG(mod->ctx, "could not open '%s': %s\n", |
1900 |
1889 |
path, strerror(errno)); |
path, strerror(errno)); |
1901 |
1890 |
return err; |
return err; |
1902 |
1891 |
} |
} |
|
... |
... |
int kmod_module_get_refcnt(const struct kmod_module *mod) |
1904 |
1893 |
err = read_str_long(fd, &refcnt, 10); |
err = read_str_long(fd, &refcnt, 10); |
1905 |
1894 |
close(fd); |
close(fd); |
1906 |
1895 |
if (err < 0) { |
if (err < 0) { |
1907 |
|
ERR(mod->ctx, "could not read integer from '%s': '%s'\n", |
|
|
1896 |
|
LIBKMOD_ERR(mod->ctx, "could not read integer from '%s': '%s'\n", |
1908 |
1897 |
path, strerror(-err)); |
path, strerror(-err)); |
1909 |
1898 |
return err; |
return err; |
1910 |
1899 |
} |
} |
|
... |
... |
struct kmod_list *kmod_module_get_holders(const struct kmod_module *mod) |
1935 |
1924 |
|
|
1936 |
1925 |
d = opendir(dname); |
d = opendir(dname); |
1937 |
1926 |
if (d == NULL) { |
if (d == NULL) { |
1938 |
|
ERR(mod->ctx, "could not open '%s': %s\n", |
|
|
1927 |
|
LIBKMOD_ERR(mod->ctx, "could not open '%s': %s\n", |
1939 |
1928 |
dname, strerror(errno)); |
dname, strerror(errno)); |
1940 |
1929 |
return NULL; |
return NULL; |
1941 |
1930 |
} |
} |
|
... |
... |
struct kmod_list *kmod_module_get_holders(const struct kmod_module *mod) |
1954 |
1943 |
err = kmod_module_new_from_name(mod->ctx, dent->d_name, |
err = kmod_module_new_from_name(mod->ctx, dent->d_name, |
1955 |
1944 |
&holder); |
&holder); |
1956 |
1945 |
if (err < 0) { |
if (err < 0) { |
1957 |
|
ERR(mod->ctx, "could not create module for '%s': %s\n", |
|
|
1946 |
|
LIBKMOD_ERR(mod->ctx, "could not create module for '%s': %s\n", |
1958 |
1947 |
dent->d_name, strerror(-err)); |
dent->d_name, strerror(-err)); |
1959 |
1948 |
goto fail; |
goto fail; |
1960 |
1949 |
} |
} |
|
... |
... |
struct kmod_list *kmod_module_get_holders(const struct kmod_module *mod) |
1963 |
1952 |
if (l != NULL) { |
if (l != NULL) { |
1964 |
1953 |
list = l; |
list = l; |
1965 |
1954 |
} else { |
} else { |
1966 |
|
ERR(mod->ctx, "out of memory\n"); |
|
|
1955 |
|
LIBKMOD_ERR(mod->ctx, "out of memory\n"); |
1967 |
1956 |
kmod_module_unref(holder); |
kmod_module_unref(holder); |
1968 |
1957 |
goto fail; |
goto fail; |
1969 |
1958 |
} |
} |
|
... |
... |
struct kmod_list *kmod_module_get_sections(const struct kmod_module *mod) |
2016 |
2005 |
|
|
2017 |
2006 |
d = opendir(dname); |
d = opendir(dname); |
2018 |
2007 |
if (d == NULL) { |
if (d == NULL) { |
2019 |
|
ERR(mod->ctx, "could not open '%s': %s\n", |
|
|
2008 |
|
LIBKMOD_ERR(mod->ctx, "could not open '%s': %s\n", |
2020 |
2009 |
dname, strerror(errno)); |
dname, strerror(errno)); |
2021 |
2010 |
return NULL; |
return NULL; |
2022 |
2011 |
} |
} |
|
... |
... |
struct kmod_list *kmod_module_get_sections(const struct kmod_module *mod) |
2038 |
2027 |
|
|
2039 |
2028 |
fd = openat(dfd, dent->d_name, O_RDONLY|O_CLOEXEC); |
fd = openat(dfd, dent->d_name, O_RDONLY|O_CLOEXEC); |
2040 |
2029 |
if (fd < 0) { |
if (fd < 0) { |
2041 |
|
ERR(mod->ctx, "could not open '%s/%s': %m\n", |
|
|
2030 |
|
LIBKMOD_ERR(mod->ctx, "could not open '%s/%s': %m\n", |
2042 |
2031 |
dname, dent->d_name); |
dname, dent->d_name); |
2043 |
2032 |
goto fail; |
goto fail; |
2044 |
2033 |
} |
} |
|
... |
... |
struct kmod_list *kmod_module_get_sections(const struct kmod_module *mod) |
2046 |
2035 |
err = read_str_ulong(fd, &address, 16); |
err = read_str_ulong(fd, &address, 16); |
2047 |
2036 |
close(fd); |
close(fd); |
2048 |
2037 |
if (err < 0) { |
if (err < 0) { |
2049 |
|
ERR(mod->ctx, "could not read long from '%s/%s': %m\n", |
|
|
2038 |
|
LIBKMOD_ERR(mod->ctx, "could not read long from '%s/%s': %m\n", |
2050 |
2039 |
dname, dent->d_name); |
dname, dent->d_name); |
2051 |
2040 |
goto fail; |
goto fail; |
2052 |
2041 |
} |
} |
|
... |
... |
struct kmod_list *kmod_module_get_sections(const struct kmod_module *mod) |
2055 |
2044 |
section = malloc(sizeof(*section) + namesz); |
section = malloc(sizeof(*section) + namesz); |
2056 |
2045 |
|
|
2057 |
2046 |
if (section == NULL) { |
if (section == NULL) { |
2058 |
|
ERR(mod->ctx, "out of memory\n"); |
|
|
2047 |
|
LIBKMOD_ERR(mod->ctx, "out of memory\n"); |
2059 |
2048 |
goto fail; |
goto fail; |
2060 |
2049 |
} |
} |
2061 |
2050 |
|
|
|
... |
... |
struct kmod_list *kmod_module_get_sections(const struct kmod_module *mod) |
2066 |
2055 |
if (l != NULL) { |
if (l != NULL) { |
2067 |
2056 |
list = l; |
list = l; |
2068 |
2057 |
} else { |
} else { |
2069 |
|
ERR(mod->ctx, "out of memory\n"); |
|
|
2058 |
|
LIBKMOD_ERR(mod->ctx, "out of memory\n"); |
2070 |
2059 |
free(section); |
free(section); |
2071 |
2060 |
goto fail; |
goto fail; |
2072 |
2061 |
} |
} |
|
... |
... |
int kmod_module_get_info(const struct kmod_module *mod, struct kmod_list **list) |
2229 |
2218 |
if (mod == NULL || list == NULL) |
if (mod == NULL || list == NULL) |
2230 |
2219 |
return -ENOENT; |
return -ENOENT; |
2231 |
2220 |
|
|
2232 |
|
assert(*list == NULL); |
|
2233 |
|
|
|
2234 |
2221 |
elf = kmod_module_get_elf(mod); |
elf = kmod_module_get_elf(mod); |
2235 |
2222 |
if (elf == NULL) |
if (elf == NULL) |
2236 |
2223 |
return -errno; |
return -errno; |
|
... |
... |
int kmod_module_get_versions(const struct kmod_module *mod, struct kmod_list **l |
2426 |
2413 |
if (mod == NULL || list == NULL) |
if (mod == NULL || list == NULL) |
2427 |
2414 |
return -ENOENT; |
return -ENOENT; |
2428 |
2415 |
|
|
2429 |
|
assert(*list == NULL); |
|
2430 |
|
|
|
2431 |
2416 |
elf = kmod_module_get_elf(mod); |
elf = kmod_module_get_elf(mod); |
2432 |
2417 |
if (elf == NULL) |
if (elf == NULL) |
2433 |
2418 |
return -errno; |
return -errno; |
|
... |
... |
int kmod_module_get_symbols(const struct kmod_module *mod, struct kmod_list **li |
2567 |
2552 |
if (mod == NULL || list == NULL) |
if (mod == NULL || list == NULL) |
2568 |
2553 |
return -ENOENT; |
return -ENOENT; |
2569 |
2554 |
|
|
2570 |
|
assert(*list == NULL); |
|
2571 |
|
|
|
2572 |
2555 |
elf = kmod_module_get_elf(mod); |
elf = kmod_module_get_elf(mod); |
2573 |
2556 |
if (elf == NULL) |
if (elf == NULL) |
2574 |
2557 |
return -errno; |
return -errno; |
|
... |
... |
int kmod_module_get_dependency_symbols(const struct kmod_module *mod, struct kmo |
2711 |
2694 |
if (mod == NULL || list == NULL) |
if (mod == NULL || list == NULL) |
2712 |
2695 |
return -ENOENT; |
return -ENOENT; |
2713 |
2696 |
|
|
2714 |
|
assert(*list == NULL); |
|
2715 |
|
|
|
2716 |
2697 |
elf = kmod_module_get_elf(mod); |
elf = kmod_module_get_elf(mod); |
2717 |
2698 |
if (elf == NULL) |
if (elf == NULL) |
2718 |
2699 |
return -errno; |
return -errno; |
File src/libkmod.c changed (mode: 100644) (index 5134e7b..19ab1a3) |
17 |
17 |
* License along with this library; if not, see <http://www.gnu.org/licenses/>. |
* License along with this library; if not, see <http://www.gnu.org/licenses/>. |
18 |
18 |
*/ |
*/ |
19 |
19 |
|
|
20 |
|
#include <assert.h> |
|
21 |
|
#include <ctype.h> |
|
22 |
|
#include <errno.h> |
|
23 |
|
#include <fnmatch.h> |
|
24 |
|
#include <limits.h> |
|
25 |
|
#include <stdarg.h> |
|
26 |
20 |
#include <stddef.h> |
#include <stddef.h> |
27 |
21 |
#include <stdio.h> |
#include <stdio.h> |
28 |
22 |
#include <stdlib.h> |
#include <stdlib.h> |
|
23 |
|
#include <ctype.h> |
29 |
24 |
#include <string.h> |
#include <string.h> |
30 |
|
#include <unistd.h> |
|
31 |
|
#include <stdbool.h> |
|
32 |
|
#include <stdint.h> |
|
33 |
|
#include <syslog.h> |
|
34 |
|
#include <sys/stat.h> |
|
|
25 |
|
#include <syslog.h> /* XSI */ |
35 |
26 |
#include <sys/utsname.h> |
#include <sys/utsname.h> |
36 |
|
|
|
37 |
|
#include "config.h" |
|
|
27 |
|
#include <limits.h> |
|
28 |
|
#include <errno.h> |
|
29 |
|
#include <fnmatch.h> |
|
30 |
|
#include <sys/stat.h> |
38 |
31 |
|
|
39 |
32 |
#include "libkmod.h" |
#include "libkmod.h" |
40 |
|
|
|
41 |
|
#include "libkmod-namespace.h" |
|
42 |
33 |
#include "libkmod-paths.h" |
#include "libkmod-paths.h" |
|
34 |
|
#include "libkmod-namespace.h" |
|
35 |
|
|
|
36 |
|
#include "config.h" |
|
37 |
|
|
43 |
38 |
#include "shared/macro.h" |
#include "shared/macro.h" |
44 |
|
#include "shared/hash.h" |
|
45 |
39 |
#include "shared/util.h" |
#include "shared/util.h" |
|
40 |
|
#include "shared/hash.h" |
|
41 |
|
|
46 |
42 |
#define LIBKMOD_C |
#define LIBKMOD_C |
47 |
43 |
#include "libkmod-internal.h" |
#include "libkmod-internal.h" |
48 |
44 |
#undef LIBKMOD_C |
#undef LIBKMOD_C |
|
... |
... |
static void log_filep(void *data, |
139 |
135 |
priname = "NOTICE"; |
priname = "NOTICE"; |
140 |
136 |
break; |
break; |
141 |
137 |
case LOG_INFO: |
case LOG_INFO: |
142 |
|
priname = "INFO"; |
|
|
138 |
|
priname = "LIBKMOD_INFO"; |
143 |
139 |
break; |
break; |
144 |
140 |
case LOG_DEBUG: |
case LOG_DEBUG: |
145 |
141 |
priname = "DEBUG"; |
priname = "DEBUG"; |
|
... |
... |
struct kmod_ctx *kmod_new(const char *dirname, |
282 |
278 |
config_paths = default_config_paths; |
config_paths = default_config_paths; |
283 |
279 |
err = kmod_config_new(ctx, &ctx->config, config_paths); |
err = kmod_config_new(ctx, &ctx->config, config_paths); |
284 |
280 |
if (err < 0) { |
if (err < 0) { |
285 |
|
ERR(ctx, "could not create config\n"); |
|
|
281 |
|
LIBKMOD_ERR(ctx, "could not create config\n"); |
286 |
282 |
goto fail; |
goto fail; |
287 |
283 |
} |
} |
288 |
284 |
|
|
289 |
285 |
ctx->modules_by_name = hash_new(KMOD_HASH_SIZE, NULL); |
ctx->modules_by_name = hash_new(KMOD_HASH_SIZE, NULL); |
290 |
286 |
if (ctx->modules_by_name == NULL) { |
if (ctx->modules_by_name == NULL) { |
291 |
|
ERR(ctx, "could not create by-name hash\n"); |
|
|
287 |
|
LIBKMOD_ERR(ctx, "could not create by-name hash\n"); |
292 |
288 |
goto fail; |
goto fail; |
293 |
289 |
} |
} |
294 |
290 |
|
|
295 |
|
INFO(ctx, "ctx %p created\n", ctx); |
|
296 |
|
DBG(ctx, "log_priority=%d\n", ctx->log_priority); |
|
|
291 |
|
LIBKMOD_INFO(ctx, "ctx %p created\n", ctx); |
|
292 |
|
LIBKMOD_DBG(ctx, "log_priority=%d\n", ctx->log_priority); |
297 |
293 |
|
|
298 |
294 |
return ctx; |
return ctx; |
299 |
295 |
|
|
|
... |
... |
struct kmod_ctx *kmod_unref(struct kmod_ctx *ctx) |
337 |
333 |
if (--ctx->refcount > 0) |
if (--ctx->refcount > 0) |
338 |
334 |
return ctx; |
return ctx; |
339 |
335 |
|
|
340 |
|
INFO(ctx, "context %p released\n", ctx); |
|
|
336 |
|
LIBKMOD_INFO(ctx, "context %p released\n", ctx); |
341 |
337 |
|
|
342 |
338 |
kmod_unload_resources(ctx); |
kmod_unload_resources(ctx); |
343 |
339 |
hash_free(ctx->modules_by_name); |
hash_free(ctx->modules_by_name); |
|
... |
... |
void kmod_set_log_fn(struct kmod_ctx *ctx, |
370 |
366 |
return; |
return; |
371 |
367 |
ctx->log_fn = log_fn; |
ctx->log_fn = log_fn; |
372 |
368 |
ctx->log_data = (void *)data; |
ctx->log_data = (void *)data; |
373 |
|
INFO(ctx, "custom logging function %p registered\n", log_fn); |
|
|
369 |
|
LIBKMOD_INFO(ctx, "custom logging function %p registered\n", log_fn); |
374 |
370 |
} |
} |
375 |
371 |
|
|
376 |
372 |
/** |
/** |
|
... |
... |
struct kmod_module *kmod_pool_get_module(struct kmod_ctx *ctx, |
408 |
404 |
|
|
409 |
405 |
mod = hash_find(ctx->modules_by_name, key); |
mod = hash_find(ctx->modules_by_name, key); |
410 |
406 |
|
|
411 |
|
DBG(ctx, "get module name='%s' found=%p\n", key, mod); |
|
|
407 |
|
LIBKMOD_DBG(ctx, "get module name='%s' found=%p\n", key, mod); |
412 |
408 |
|
|
413 |
409 |
return mod; |
return mod; |
414 |
410 |
} |
} |
|
... |
... |
struct kmod_module *kmod_pool_get_module(struct kmod_ctx *ctx, |
416 |
412 |
void kmod_pool_add_module(struct kmod_ctx *ctx, struct kmod_module *mod, |
void kmod_pool_add_module(struct kmod_ctx *ctx, struct kmod_module *mod, |
417 |
413 |
const char *key) |
const char *key) |
418 |
414 |
{ |
{ |
419 |
|
DBG(ctx, "add %p key='%s'\n", mod, key); |
|
|
415 |
|
LIBKMOD_DBG(ctx, "add %p key='%s'\n", mod, key); |
420 |
416 |
|
|
421 |
417 |
hash_add(ctx->modules_by_name, key, mod); |
hash_add(ctx->modules_by_name, key, mod); |
422 |
418 |
} |
} |
|
... |
... |
void kmod_pool_add_module(struct kmod_ctx *ctx, struct kmod_module *mod, |
424 |
420 |
void kmod_pool_del_module(struct kmod_ctx *ctx, struct kmod_module *mod, |
void kmod_pool_del_module(struct kmod_ctx *ctx, struct kmod_module *mod, |
425 |
421 |
const char *key) |
const char *key) |
426 |
422 |
{ |
{ |
427 |
|
DBG(ctx, "del %p key='%s'\n", mod, key); |
|
|
423 |
|
LIBKMOD_DBG(ctx, "del %p key='%s'\n", mod, key); |
428 |
424 |
|
|
429 |
425 |
hash_del(ctx->modules_by_name, key); |
hash_del(ctx->modules_by_name, key); |
430 |
426 |
} |
} |
|
... |
... |
static int kmod_lookup_alias_from_alias_bin(struct kmod_ctx *ctx, |
439 |
435 |
struct index_value *realnames, *realname; |
struct index_value *realnames, *realname; |
440 |
436 |
|
|
441 |
437 |
if (ctx->indexes[index_number] != NULL) { |
if (ctx->indexes[index_number] != NULL) { |
442 |
|
DBG(ctx, "use mmaped index '%s' for name=%s\n", |
|
|
438 |
|
LIBKMOD_DBG(ctx, "use mmaped index '%s' for name=%s\n", |
443 |
439 |
index_files[index_number].fn, name); |
index_files[index_number].fn, name); |
444 |
440 |
realnames = index_mm_searchwild(ctx->indexes[index_number], |
realnames = index_mm_searchwild(ctx->indexes[index_number], |
445 |
441 |
name); |
name); |
|
... |
... |
static int kmod_lookup_alias_from_alias_bin(struct kmod_ctx *ctx, |
449 |
445 |
snprintf(fn, sizeof(fn), "%s/%s.bin", ctx->dirname, |
snprintf(fn, sizeof(fn), "%s/%s.bin", ctx->dirname, |
450 |
446 |
index_files[index_number].fn); |
index_files[index_number].fn); |
451 |
447 |
|
|
452 |
|
DBG(ctx, "file=%s name=%s\n", fn, name); |
|
|
448 |
|
LIBKMOD_DBG(ctx, "file=%s name=%s\n", fn, name); |
453 |
449 |
|
|
454 |
450 |
idx = index_file_open(fn); |
idx = index_file_open(fn); |
455 |
451 |
if (idx == NULL) |
if (idx == NULL) |
|
... |
... |
static int kmod_lookup_alias_from_alias_bin(struct kmod_ctx *ctx, |
464 |
460 |
|
|
465 |
461 |
err = kmod_module_new_from_alias(ctx, name, realname->value, &mod); |
err = kmod_module_new_from_alias(ctx, name, realname->value, &mod); |
466 |
462 |
if (err < 0) { |
if (err < 0) { |
467 |
|
ERR(ctx, "Could not create module for alias=%s realname=%s: %s\n", |
|
|
463 |
|
LIBKMOD_ERR(ctx, "Could not create module for alias=%s realname=%s: %s\n", |
468 |
464 |
name, realname->value, strerror(-err)); |
name, realname->value, strerror(-err)); |
469 |
465 |
goto fail; |
goto fail; |
470 |
466 |
} |
} |
|
... |
... |
static char *lookup_builtin_file(struct kmod_ctx *ctx, const char *name) |
505 |
501 |
char *line; |
char *line; |
506 |
502 |
|
|
507 |
503 |
if (ctx->indexes[KMOD_INDEX_MODULES_BUILTIN]) { |
if (ctx->indexes[KMOD_INDEX_MODULES_BUILTIN]) { |
508 |
|
DBG(ctx, "use mmaped index '%s' modname=%s\n", |
|
|
504 |
|
LIBKMOD_DBG(ctx, "use mmaped index '%s' modname=%s\n", |
509 |
505 |
index_files[KMOD_INDEX_MODULES_BUILTIN].fn, |
index_files[KMOD_INDEX_MODULES_BUILTIN].fn, |
510 |
506 |
name); |
name); |
511 |
507 |
line = index_mm_search(ctx->indexes[KMOD_INDEX_MODULES_BUILTIN], |
line = index_mm_search(ctx->indexes[KMOD_INDEX_MODULES_BUILTIN], |
|
... |
... |
static char *lookup_builtin_file(struct kmod_ctx *ctx, const char *name) |
516 |
512 |
|
|
517 |
513 |
snprintf(fn, sizeof(fn), "%s/%s.bin", ctx->dirname, |
snprintf(fn, sizeof(fn), "%s/%s.bin", ctx->dirname, |
518 |
514 |
index_files[KMOD_INDEX_MODULES_BUILTIN].fn); |
index_files[KMOD_INDEX_MODULES_BUILTIN].fn); |
519 |
|
DBG(ctx, "file=%s modname=%s\n", fn, name); |
|
|
515 |
|
LIBKMOD_DBG(ctx, "file=%s modname=%s\n", fn, name); |
520 |
516 |
|
|
521 |
517 |
idx = index_file_open(fn); |
idx = index_file_open(fn); |
522 |
518 |
if (idx == NULL) { |
if (idx == NULL) { |
523 |
|
DBG(ctx, "could not open builtin file '%s'\n", fn); |
|
|
519 |
|
LIBKMOD_DBG(ctx, "could not open builtin file '%s'\n", fn); |
524 |
520 |
return NULL; |
return NULL; |
525 |
521 |
} |
} |
526 |
522 |
|
|
|
... |
... |
int kmod_lookup_alias_from_builtin_file(struct kmod_ctx *ctx, const char *name, |
537 |
533 |
char *line; |
char *line; |
538 |
534 |
int err = 0; |
int err = 0; |
539 |
535 |
|
|
540 |
|
assert(*list == NULL); |
|
541 |
|
|
|
542 |
536 |
line = lookup_builtin_file(ctx, name); |
line = lookup_builtin_file(ctx, name); |
543 |
537 |
if (line != NULL) { |
if (line != NULL) { |
544 |
538 |
struct kmod_module *mod; |
struct kmod_module *mod; |
545 |
539 |
|
|
546 |
540 |
err = kmod_module_new_from_name(ctx, name, &mod); |
err = kmod_module_new_from_name(ctx, name, &mod); |
547 |
541 |
if (err < 0) { |
if (err < 0) { |
548 |
|
ERR(ctx, "Could not create module from name %s: %s\n", |
|
|
542 |
|
LIBKMOD_ERR(ctx, "Could not create module from name %s: %s\n", |
549 |
543 |
name, strerror(-err)); |
name, strerror(-err)); |
550 |
544 |
goto finish; |
goto finish; |
551 |
545 |
} |
} |
|
... |
... |
char *kmod_search_moddep(struct kmod_ctx *ctx, const char *name) |
582 |
576 |
char *line; |
char *line; |
583 |
577 |
|
|
584 |
578 |
if (ctx->indexes[KMOD_INDEX_MODULES_DEP]) { |
if (ctx->indexes[KMOD_INDEX_MODULES_DEP]) { |
585 |
|
DBG(ctx, "use mmaped index '%s' modname=%s\n", |
|
|
579 |
|
LIBKMOD_DBG(ctx, "use mmaped index '%s' modname=%s\n", |
586 |
580 |
index_files[KMOD_INDEX_MODULES_DEP].fn, name); |
index_files[KMOD_INDEX_MODULES_DEP].fn, name); |
587 |
581 |
return index_mm_search(ctx->indexes[KMOD_INDEX_MODULES_DEP], |
return index_mm_search(ctx->indexes[KMOD_INDEX_MODULES_DEP], |
588 |
582 |
name); |
name); |
|
... |
... |
char *kmod_search_moddep(struct kmod_ctx *ctx, const char *name) |
591 |
585 |
snprintf(fn, sizeof(fn), "%s/%s.bin", ctx->dirname, |
snprintf(fn, sizeof(fn), "%s/%s.bin", ctx->dirname, |
592 |
586 |
index_files[KMOD_INDEX_MODULES_DEP].fn); |
index_files[KMOD_INDEX_MODULES_DEP].fn); |
593 |
587 |
|
|
594 |
|
DBG(ctx, "file=%s modname=%s\n", fn, name); |
|
|
588 |
|
LIBKMOD_DBG(ctx, "file=%s modname=%s\n", fn, name); |
595 |
589 |
|
|
596 |
590 |
idx = index_file_open(fn); |
idx = index_file_open(fn); |
597 |
591 |
if (idx == NULL) { |
if (idx == NULL) { |
598 |
|
DBG(ctx, "could not open moddep file '%s'\n", fn); |
|
|
592 |
|
LIBKMOD_DBG(ctx, "could not open moddep file '%s'\n", fn); |
599 |
593 |
return NULL; |
return NULL; |
600 |
594 |
} |
} |
601 |
595 |
|
|
|
... |
... |
int kmod_lookup_alias_from_moddep_file(struct kmod_ctx *ctx, const char *name, |
624 |
618 |
|
|
625 |
619 |
n = kmod_module_new_from_name(ctx, name, &mod); |
n = kmod_module_new_from_name(ctx, name, &mod); |
626 |
620 |
if (n < 0) { |
if (n < 0) { |
627 |
|
ERR(ctx, "Could not create module from name %s: %s\n", |
|
|
621 |
|
LIBKMOD_ERR(ctx, "Could not create module from name %s: %s\n", |
628 |
622 |
name, strerror(-n)); |
name, strerror(-n)); |
629 |
623 |
goto finish; |
goto finish; |
630 |
624 |
} |
} |
|
... |
... |
int kmod_lookup_alias_from_config(struct kmod_ctx *ctx, const char *name, |
656 |
650 |
err = kmod_module_new_from_alias(ctx, aliasname, |
err = kmod_module_new_from_alias(ctx, aliasname, |
657 |
651 |
modname, &mod); |
modname, &mod); |
658 |
652 |
if (err < 0) { |
if (err < 0) { |
659 |
|
ERR(ctx, "Could not create module for alias=%s modname=%s: %s\n", |
|
|
653 |
|
LIBKMOD_ERR(ctx, "Could not create module for alias=%s modname=%s: %s\n", |
660 |
654 |
name, modname, strerror(-err)); |
name, modname, strerror(-err)); |
661 |
655 |
goto fail; |
goto fail; |
662 |
656 |
} |
} |
|
... |
... |
int kmod_lookup_alias_from_commands(struct kmod_ctx *ctx, const char *name, |
689 |
683 |
|
|
690 |
684 |
err = kmod_module_new_from_name(ctx, modname, &mod); |
err = kmod_module_new_from_name(ctx, modname, &mod); |
691 |
685 |
if (err < 0) { |
if (err < 0) { |
692 |
|
ERR(ctx, "Could not create module from name %s: %s\n", |
|
|
686 |
|
LIBKMOD_ERR(ctx, "Could not create module from name %s: %s\n", |
693 |
687 |
modname, strerror(-err)); |
modname, strerror(-err)); |
694 |
688 |
return err; |
return err; |
695 |
689 |
} |
} |
696 |
690 |
|
|
697 |
691 |
node = __kmod_list_append(*list, mod); |
node = __kmod_list_append(*list, mod); |
698 |
692 |
if (node == NULL) { |
if (node == NULL) { |
699 |
|
ERR(ctx, "out of memory\n"); |
|
|
693 |
|
LIBKMOD_ERR(ctx, "out of memory\n"); |
700 |
694 |
return -ENOMEM; |
return -ENOMEM; |
701 |
695 |
} |
} |
702 |
696 |
|
|
|
... |
... |
int kmod_lookup_alias_from_commands(struct kmod_ctx *ctx, const char *name, |
725 |
719 |
|
|
726 |
720 |
err = kmod_module_new_from_name(ctx, modname, &mod); |
err = kmod_module_new_from_name(ctx, modname, &mod); |
727 |
721 |
if (err < 0) { |
if (err < 0) { |
728 |
|
ERR(ctx, "Could not create module from name %s: %s\n", |
|
|
722 |
|
LIBKMOD_ERR(ctx, "Could not create module from name %s: %s\n", |
729 |
723 |
modname, strerror(-err)); |
modname, strerror(-err)); |
730 |
724 |
return err; |
return err; |
731 |
725 |
} |
} |
732 |
726 |
|
|
733 |
727 |
node = __kmod_list_append(*list, mod); |
node = __kmod_list_append(*list, mod); |
734 |
728 |
if (node == NULL) { |
if (node == NULL) { |
735 |
|
ERR(ctx, "out of memory\n"); |
|
|
729 |
|
LIBKMOD_ERR(ctx, "out of memory\n"); |
736 |
730 |
return -ENOMEM; |
return -ENOMEM; |
737 |
731 |
} |
} |
738 |
732 |
|
|
|
... |
... |
int kmod_load_resources(struct kmod_ctx *ctx) |
854 |
848 |
char path[PATH_MAX]; |
char path[PATH_MAX]; |
855 |
849 |
|
|
856 |
850 |
if (ctx->indexes[i] != NULL) { |
if (ctx->indexes[i] != NULL) { |
857 |
|
INFO(ctx, "Index %s already loaded\n", |
|
|
851 |
|
LIBKMOD_INFO(ctx, "Index %s already loaded\n", |
858 |
852 |
index_files[i].fn); |
index_files[i].fn); |
859 |
853 |
continue; |
continue; |
860 |
854 |
} |
} |
|
... |
... |
int kmod_dump_index(struct kmod_ctx *ctx, enum kmod_index type, |
931 |
925 |
return -ENOENT; |
return -ENOENT; |
932 |
926 |
|
|
933 |
927 |
if (ctx->indexes[type] != NULL) { |
if (ctx->indexes[type] != NULL) { |
934 |
|
DBG(ctx, "use mmaped index '%s'\n", index_files[type].fn); |
|
|
928 |
|
LIBKMOD_DBG(ctx, "use mmaped index '%s'\n", index_files[type].fn); |
935 |
929 |
index_mm_dump(ctx->indexes[type], fd, |
index_mm_dump(ctx->indexes[type], fd, |
936 |
930 |
index_files[type].prefix); |
index_files[type].prefix); |
937 |
931 |
} else { |
} else { |
|
... |
... |
int kmod_dump_index(struct kmod_ctx *ctx, enum kmod_index type, |
941 |
935 |
snprintf(fn, sizeof(fn), "%s/%s.bin", ctx->dirname, |
snprintf(fn, sizeof(fn), "%s/%s.bin", ctx->dirname, |
942 |
936 |
index_files[type].fn); |
index_files[type].fn); |
943 |
937 |
|
|
944 |
|
DBG(ctx, "file=%s\n", fn); |
|
|
938 |
|
LIBKMOD_DBG(ctx, "file=%s\n", fn); |
945 |
939 |
|
|
946 |
940 |
idx = index_file_open(fn); |
idx = index_file_open(fn); |
947 |
941 |
if (idx == NULL) |
if (idx == NULL) |