List of commits:
Subject Hash Author Date (UTC)
cleanup 85905188203b776ac80b2e7b1addb95f5169888b Sylvain BERTRAND 2017-07-22 15:28:19
first extraction and cleanup 67a09ceb6fc5b3536801096e1002347e2f115ddc Sylvain BERTRAND 2017-07-22 02:00:46
Commit 85905188203b776ac80b2e7b1addb95f5169888b - cleanup
Author: Sylvain BERTRAND
Author date (UTC): 2017-07-22 15:28
Committer name: Sylvain BERTRAND
Committer date (UTC): 2017-07-22 15:28
Parent(s): 67a09ceb6fc5b3536801096e1002347e2f115ddc
Signing key:
Tree: 3ac0df1996b77e91f27f4a4cd7b4f7a380c17788
File Lines added Lines deleted
README 0 2
src/config.h 3 0
src/libkmod-config.c 33 35
src/libkmod-elf.c 15 14
src/libkmod-file.c 22 23
src/libkmod-index.c 16 17
src/libkmod-internal.h 30 19
src/libkmod-list.c 6 8
src/libkmod-module.c 72 91
src/libkmod-namespace.h 26 9
src/libkmod-signature.c 11 11
src/libkmod.c 41 47
src/libkmod.h 3 3
src/shared/array.c 3 4
src/shared/hash.c 11 6
src/shared/linux-syscalls.h 2 2
src/shared/scratchbuf.c 4 2
src/shared/strbuf.c 9 10
src/shared/util.c 14 13
src/tools/depmod.c 18 26
src/tools/insmod.c 8 5
src/tools/kmod.c 11 7
src/tools/kmod.h 2 2
src/tools/log.c 21 1
src/tools/lsmod.c 0 2
src/tools/modinfo.c 14 8
src/tools/modprobe.c 11 12
src/tools/rmmod.c 7 8
src/tools/static-nodes.c 5 10
File README changed (mode: 100644) (index f838b13..67770db)
... ... the SDK.... YEAY!
10 10
11 11 The "configuration" is set in stone, but this is only the first commit. The "configuration" is set in stone, but this is only the first commit.
12 12
13 The headers need some tightening though.
14
15 13 -- --
16 14 Sylvain BERTRAND Sylvain BERTRAND
17 15 sylvain.bertrand@gmail.com sylvain.bertrand@gmail.com
File src/config.h changed (mode: 100644) (index 590b7c7..c0d3302)
1 #ifndef CONFIG_H
2 #define CONFIG_H
1 3 /* Debug messages. */ /* Debug messages. */
2 4 /* #undef ENABLE_DEBUG */ /* #undef ENABLE_DEBUG */
3 5
 
18 20
19 21 /* Version number of package */ /* Version number of package */
20 22 #define VERSION "24" #define VERSION "24"
23 #endif
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-elf.c changed (mode: 100644) (index 5aec464..86e047f)
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 <elf.h>
22 #include <errno.h>
23 #include <stdlib.h>
20 #include <stdint.h>
24 21 #include <string.h> #include <string.h>
25 #include <limits.h>
22 #include <errno.h>
26 23 #include <stddef.h> #include <stddef.h>
24 #include <stdarg.h>
25 #include <limits.h>
26 #include <stdbool.h>
27 #include <unistd.h>
27 28 #include <stdio.h> #include <stdio.h>
29 #include <sys/types.h>
30 #include <sys/stat.h>
31 #include <stdlib.h>
28 32
29 #include "config.h"
33 #include <linux/elf.h>
30 34
31 35 #include "libkmod.h" #include "libkmod.h"
32 #include "libkmod-namespace.h"
33 36 #include "libkmod-paths.h" #include "libkmod-paths.h"
37 #include "libkmod-namespace.h"
38
39 #include "config.h"
40
34 41 #include "shared/macro.h" #include "shared/macro.h"
35 42 #include "shared/util.h" #include "shared/util.h"
43
36 44 #define LIBKMOD_ELF_C #define LIBKMOD_ELF_C
37 45 #include "libkmod-internal.h" #include "libkmod-internal.h"
38 46 #undef LIBKMOD_ELF_C #undef LIBKMOD_ELF_C
 
... ... static inline uint64_t elf_get_uint(const struct kmod_elf *elf, uint64_t offset,
142 150 uint64_t ret = 0; uint64_t ret = 0;
143 151 size_t i; size_t i;
144 152
145 assert(size <= sizeof(uint64_t));
146 assert(offset + size <= elf->size);
147 153 if (offset + size > elf->size) { if (offset + size > elf->size) {
148 154 ELFDBG(elf, "out of bounds: %"PRIu64" + %"PRIu16" = %"PRIu64"> %"PRIu64" (ELF size)\n", ELFDBG(elf, "out of bounds: %"PRIu64" + %"PRIu16" = %"PRIu64"> %"PRIu64" (ELF size)\n",
149 155 offset, size, offset + size, elf->size); offset, size, offset + size, elf->size);
 
... ... static inline int elf_set_uint(struct kmod_elf *elf, uint64_t offset, uint64_t s
173 179 ELFDBG(elf, "size=%"PRIu16" offset=%"PRIu64" value=%"PRIu64" write memory=%p\n", ELFDBG(elf, "size=%"PRIu16" offset=%"PRIu64" value=%"PRIu64" write memory=%p\n",
174 180 size, offset, value, elf->changed); size, offset, value, elf->changed);
175 181
176 assert(size <= sizeof(uint64_t));
177 assert(offset + size <= elf->size);
178 182 if (offset + size > elf->size) { if (offset + size > elf->size) {
179 183 ELFDBG(elf, "out of bounds: %"PRIu64" + %"PRIu16" = %"PRIu64"> %"PRIu64" (ELF size)\n", ELFDBG(elf, "out of bounds: %"PRIu64" + %"PRIu16" = %"PRIu64"> %"PRIu64" (ELF size)\n",
180 184 offset, size, offset + size, elf->size); offset, size, offset + size, elf->size);
 
... ... static inline int elf_set_uint(struct kmod_elf *elf, uint64_t offset, uint64_t s
208 212
209 213 static inline const void *elf_get_mem(const struct kmod_elf *elf, uint64_t offset) static inline const void *elf_get_mem(const struct kmod_elf *elf, uint64_t offset)
210 214 { {
211 assert(offset < elf->size);
212 215 if (offset >= elf->size) { if (offset >= elf->size) {
213 216 ELFDBG(elf, "out-of-bounds: %"PRIu64" >= %"PRIu64" (ELF size)\n", ELFDBG(elf, "out-of-bounds: %"PRIu64" >= %"PRIu64" (ELF size)\n",
214 217 offset, elf->size); offset, elf->size);
 
... ... static inline const void *elf_get_mem(const struct kmod_elf *elf, uint64_t offse
219 222
220 223 static inline const void *elf_get_section_header(const struct kmod_elf *elf, uint16_t idx) static inline const void *elf_get_section_header(const struct kmod_elf *elf, uint16_t idx)
221 224 { {
222 assert(idx != SHN_UNDEF);
223 assert(idx < elf->header.section.count);
224 225 if (idx == SHN_UNDEF || idx >= elf->header.section.count) { if (idx == SHN_UNDEF || idx >= elf->header.section.count) {
225 226 ELFDBG(elf, "invalid section number: %"PRIu16", last=%"PRIu16"\n", ELFDBG(elf, "invalid section number: %"PRIu16", last=%"PRIu16"\n",
226 227 idx, elf->header.section.count); idx, elf->header.section.count);
File src/libkmod-file.c changed (mode: 100644) (index 39e8c99..b55c614)
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 <errno.h>
21 20 #include <stdbool.h> #include <stdbool.h>
22 #include <stdio.h>
23 #include <stdlib.h>
24 #include <string.h>
25 #include <limits.h>
26 21 #include <stddef.h> #include <stddef.h>
27 #include <syslog.h>
28 #include <sys/mman.h>
29 #include <sys/stat.h>
30 22 #include <sys/types.h> #include <sys/types.h>
23 #include <sys/stat.h>
24 #include <errno.h>
25 #include <sys/mman.h>
26 #include <stdlib.h>
27 #include <limits.h>
28 #include <stdio.h>
31 29 #include <unistd.h> #include <unistd.h>
30 #include <string.h>
31
32 #include "libkmod.h"
33 #include "libkmod-paths.h"
34 #include "libkmod-namespace.h"
35
36 #include "config.h"
32 37 #ifdef ENABLE_XZ #ifdef ENABLE_XZ
33 38 #include <lzma.h> #include <lzma.h>
34 39 #endif #endif
 
36 41 #include <zlib.h> #include <zlib.h>
37 42 #endif #endif
38 43
39 #include "config.h"
40
41 #include "libkmod.h"
42 #include "libkmod-namespace.h"
43 #include "libkmod-paths.h"
44
45 44 #include "shared/macro.h" #include "shared/macro.h"
46 45 #include "shared/util.h" #include "shared/util.h"
47 46
 
... ... static void xz_uncompress_belch(struct kmod_file *file, lzma_ret ret)
76 75 { {
77 76 switch (ret) { switch (ret) {
78 77 case LZMA_MEM_ERROR: case LZMA_MEM_ERROR:
79 ERR(file->ctx, "xz: %s\n", strerror(ENOMEM));
78 LIBKMOD_ERR(file->ctx, "xz: %s\n", strerror(ENOMEM));
80 79 break; break;
81 80 case LZMA_FORMAT_ERROR: case LZMA_FORMAT_ERROR:
82 ERR(file->ctx, "xz: File format not recognized\n");
81 LIBKMOD_ERR(file->ctx, "xz: File format not recognized\n");
83 82 break; break;
84 83 case LZMA_OPTIONS_ERROR: case LZMA_OPTIONS_ERROR:
85 ERR(file->ctx, "xz: Unsupported compression options\n");
84 LIBKMOD_ERR(file->ctx, "xz: Unsupported compression options\n");
86 85 break; break;
87 86 case LZMA_DATA_ERROR: case LZMA_DATA_ERROR:
88 ERR(file->ctx, "xz: File is corrupt\n");
87 LIBKMOD_ERR(file->ctx, "xz: File is corrupt\n");
89 88 break; break;
90 89 case LZMA_BUF_ERROR: case LZMA_BUF_ERROR:
91 ERR(file->ctx, "xz: Unexpected end of input\n");
90 LIBKMOD_ERR(file->ctx, "xz: Unexpected end of input\n");
92 91 break; break;
93 92 default: default:
94 ERR(file->ctx, "xz: Internal error (bug)\n");
93 LIBKMOD_ERR(file->ctx, "xz: Internal error (bug)\n");
95 94 break; break;
96 95 } }
97 96 } }
 
... ... static int load_xz(struct kmod_file *file)
159 158
160 159 lzret = lzma_stream_decoder(&strm, UINT64_MAX, LZMA_CONCATENATED); lzret = lzma_stream_decoder(&strm, UINT64_MAX, LZMA_CONCATENATED);
161 160 if (lzret == LZMA_MEM_ERROR) { if (lzret == LZMA_MEM_ERROR) {
162 ERR(file->ctx, "xz: %s\n", strerror(ENOMEM));
161 LIBKMOD_ERR(file->ctx, "xz: %s\n", strerror(ENOMEM));
163 162 return -ENOMEM; return -ENOMEM;
164 163 } else if (lzret != LZMA_OK) { } else if (lzret != LZMA_OK) {
165 ERR(file->ctx, "xz: Internal error (bug)\n");
164 LIBKMOD_ERR(file->ctx, "xz: Internal error (bug)\n");
166 165 return -EINVAL; return -EINVAL;
167 166 } }
168 167 ret = xz_uncompress(&strm, file); ret = xz_uncompress(&strm, file);
 
... ... static int load_zlib(struct kmod_file *file)
214 213 int gzerr; int gzerr;
215 214 const char *gz_errmsg = gzerror(file->gzf, &gzerr); const char *gz_errmsg = gzerror(file->gzf, &gzerr);
216 215
217 ERR(file->ctx, "gzip: %s\n", gz_errmsg);
216 LIBKMOD_ERR(file->ctx, "gzip: %s\n", gz_errmsg);
218 217
219 218 /* gzip might not set errno here */ /* gzip might not set errno here */
220 219 err = gzerr == Z_ERRNO ? -errno : -EINVAL; err = gzerr == Z_ERRNO ? -errno : -EINVAL;
File src/libkmod-index.c changed (mode: 100644) (index 7516e62..a8839e5)
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 <arpa/inet.h>
21 #include <assert.h>
22 #include <errno.h>
23 #include <fnmatch.h>
24 #include <inttypes.h>
25 #include <stdio.h>
26 20 #include <stdlib.h> #include <stdlib.h>
27 21 #include <string.h> #include <string.h>
22 #include <stdio.h>
23 #include <errno.h>
24 #include <arpa/inet.h>
28 25 #include <limits.h> #include <limits.h>
29 #include <syslog.h>
30 #include <sys/stat.h>
31
32 #include "config.h"
26 #include <fnmatch.h>
27 #include <syslog.h> /* XSI */
33 28
34 29 #include "libkmod.h" #include "libkmod.h"
35 #include "libkmod-namespace.h"
36 30 #include "libkmod-paths.h" #include "libkmod-paths.h"
31 #include "libkmod-namespace.h"
32
33 #include "config.h"
34
37 35 #include "shared/macro.h" #include "shared/macro.h"
38 36 #include "shared/strbuf.h" #include "shared/strbuf.h"
39 37 #include "shared/util.h" #include "shared/util.h"
38
40 39 #include "libkmod-internal.h" #include "libkmod-internal.h"
41 40 #define LIBKMOD_INDEX_C #define LIBKMOD_INDEX_C
42 41 #include "libkmod-index.h" #include "libkmod-index.h"
 
... ... struct index_mm *index_mm_open(struct kmod_ctx *ctx, const char *filename,
760 759 } hdr; } hdr;
761 760 void *p; void *p;
762 761
763 DBG(ctx, "file=%s\n", filename);
762 LIBKMOD_DBG(ctx, "file=%s\n", filename);
764 763
765 764 idx = malloc(sizeof(*idx)); idx = malloc(sizeof(*idx));
766 765 if (idx == NULL) { if (idx == NULL) {
767 ERR(ctx, "malloc: %m\n");
766 LIBKMOD_ERR(ctx, "malloc: %m\n");
768 767 return NULL; return NULL;
769 768 } }
770 769
771 770 if ((fd = open(filename, O_RDONLY|O_CLOEXEC)) < 0) { if ((fd = open(filename, O_RDONLY|O_CLOEXEC)) < 0) {
772 DBG(ctx, "open(%s, O_RDONLY|O_CLOEXEC): %m\n", filename);
771 LIBKMOD_DBG(ctx, "open(%s, O_RDONLY|O_CLOEXEC): %m\n", filename);
773 772 goto fail_open; goto fail_open;
774 773 } }
775 774
 
... ... struct index_mm *index_mm_open(struct kmod_ctx *ctx, const char *filename,
780 779
781 780 if ((idx->mm = mmap(NULL, st.st_size, PROT_READ, MAP_PRIVATE, fd, 0)) if ((idx->mm = mmap(NULL, st.st_size, PROT_READ, MAP_PRIVATE, fd, 0))
782 781 == MAP_FAILED) { == MAP_FAILED) {
783 ERR(ctx, "mmap(NULL, %"PRIu64", PROT_READ, %d, MAP_PRIVATE, 0): %m\n",
782 LIBKMOD_ERR(ctx, "mmap(NULL, %"PRIu64", PROT_READ, %d, MAP_PRIVATE, 0): %m\n",
784 783 st.st_size, fd); st.st_size, fd);
785 784 goto fail_nommap; goto fail_nommap;
786 785 } }
 
... ... struct index_mm *index_mm_open(struct kmod_ctx *ctx, const char *filename,
791 790 hdr.root_offset = read_long_mm(&p); hdr.root_offset = read_long_mm(&p);
792 791
793 792 if (hdr.magic != INDEX_MAGIC) { if (hdr.magic != INDEX_MAGIC) {
794 ERR(ctx, "magic check fail: %x instead of %x\n", hdr.magic,
793 LIBKMOD_ERR(ctx, "magic check fail: %x instead of %x\n", hdr.magic,
795 794 INDEX_MAGIC); INDEX_MAGIC);
796 795 goto fail; goto fail;
797 796 } }
798 797
799 798 if (hdr.version >> 16 != INDEX_VERSION_MAJOR) { if (hdr.version >> 16 != INDEX_VERSION_MAJOR) {
800 ERR(ctx, "major version check fail: %u instead of %u\n",
799 LIBKMOD_ERR(ctx, "major version check fail: %u instead of %u\n",
801 800 hdr.version >> 16, INDEX_VERSION_MAJOR); hdr.version >> 16, INDEX_VERSION_MAJOR);
802 801 goto fail; goto fail;
803 802 } }
File src/libkmod-internal.h changed (mode: 100644) (index 609bc29..7dc36e4)
1 1 #ifndef LIBKMOD_INTERNAL_H #ifndef LIBKMOD_INTERNAL_H
2 2 #define LIBKMOD_INTERNAL_H #define LIBKMOD_INTERNAL_H
3 3
4 /*
5 * this header file is supposed to be included right after the public libkmod.h
6 * in order to properly expose some libkmod internals.
7 */
8
9
10
11 /*---------------------------------------------------------------------------*/
12 #ifdef LIBKMOD_C
13 #define EXTERN
14 #else
15 #define EXTERN extern
16 #endif
4 17 _unused_ static void kmod_log_null(struct kmod_ctx *ctx, const char *format, ...) {} _unused_ static void kmod_log_null(struct kmod_ctx *ctx, const char *format, ...) {}
5 18
6 19 #define kmod_log_cond(ctx, prio, arg...) \ #define kmod_log_cond(ctx, prio, arg...) \
 
... ... _unused_ static void kmod_log_null(struct kmod_ctx *ctx, const char *format, ...
9 22 kmod_log(ctx, prio, __FILE__, __LINE__, __func__, ## arg);\ kmod_log(ctx, prio, __FILE__, __LINE__, __func__, ## arg);\
10 23 } while (0) } while (0)
11 24
25 /*
26 * we do prefixed the macros since some kmod tool functions may include this
27 * header in order to access some kmod internals (i.e. depmod function), and
28 * kmod tool functions usullay similar macro names.
29 */
30
12 31 #ifdef ENABLE_LOGGING #ifdef ENABLE_LOGGING
13 32 # ifdef ENABLE_DEBUG # ifdef ENABLE_DEBUG
14 # define DBG(ctx, arg...) kmod_log_cond(ctx, LOG_DEBUG, ## arg)
33 # define LIBKMOD_DBG(ctx, arg...) kmod_log_cond(ctx, LOG_DEBUG, ## arg)
15 34 # else # else
16 # define DBG(ctx, arg...) kmod_log_null(ctx, ## arg)
35 # define LIBKMOD_DBG(ctx, arg...) kmod_log_null(ctx, ## arg)
17 36 # endif # endif
18 # define INFO(ctx, arg...) kmod_log_cond(ctx, LOG_INFO, ## arg)
19 # define ERR(ctx, arg...) kmod_log_cond(ctx, LOG_ERR, ## arg)
37 # define LIBKMOD_INFO(ctx, arg...) kmod_log_cond(ctx, LOG_INFO, ## arg)
38 # define LIBKMOD_ERR(ctx, arg...) kmod_log_cond(ctx, LOG_ERR, ## arg)
20 39 #else #else
21 # define DBG(ctx, arg...) kmod_log_null(ctx, ## arg)
22 # define INFO(ctx, arg...) kmod_log_null(ctx, ## arg)
23 # define ERR(ctx, arg...) kmod_log_null(ctx, ## arg)
40 # define LIBKMOD_DBG(ctx, arg...) kmod_log_null(ctx, ## arg)
41 # define LIBKMOD_INFO(ctx, arg...) kmod_log_null(ctx, ## arg)
42 # define LIBKMOD_ERR(ctx, arg...) kmod_log_null(ctx, ## arg)
24 43 #endif #endif
25 44
26 45 #define KCMD_LINE_SIZE 4096 #define KCMD_LINE_SIZE 4096
27 46
28
29
30
31 /*---------------------------------------------------------------------------*/
32 #ifdef LIBKMOD_C
33 #define EXTERN
34 #else
35 #define EXTERN extern
36 #endif
37 47 EXTERN void kmod_log(const struct kmod_ctx *ctx, int priority, const char *file, int line, const char *fn, const char *format, ...); EXTERN void kmod_log(const struct kmod_ctx *ctx, int priority, const char *file, int line, const char *fn, const char *format, ...);
38 48 #undef EXTERN #undef EXTERN
39 49 /*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
 
... ... EXTERN void kmod_log(const struct kmod_ctx *ctx, int priority, const char *file,
47 57 #else #else
48 58 #define EXTERN extern #define EXTERN extern
49 59 #endif #endif
60
50 61 struct list_node { struct list_node {
51 62 struct list_node *next, *prev; struct list_node *next, *prev;
52 63 }; };
 
... ... struct kmod_list {
56 67 void *data; void *data;
57 68 }; };
58 69
59 /* this internal needs to be accessed by the kmod tools, it's exported */
70 /* those will be exported to be used by some kmod tool functions */
60 71 EXTERN struct kmod_list *__kmod_list_append(struct kmod_list *list, const void *data); EXTERN struct kmod_list *__kmod_list_append(struct kmod_list *list, const void *data);
61 EXTERN struct kmod_list *kmod_list_prepend(struct kmod_list *list, const void *data);
62 /* those internals need to be accessed by the kmod tools, they are exported */
63 72 EXTERN struct kmod_list *__kmod_list_remove(struct kmod_list *list); EXTERN struct kmod_list *__kmod_list_remove(struct kmod_list *list);
64 73 EXTERN struct kmod_list *__kmod_list_remove_data(struct kmod_list *list, const void *data); EXTERN struct kmod_list *__kmod_list_remove_data(struct kmod_list *list, const void *data);
74
75 EXTERN struct kmod_list *kmod_list_prepend(struct kmod_list *list, const void *data);
65 76 EXTERN struct kmod_list *kmod_list_remove_n_latest(struct kmod_list *list, unsigned int n); EXTERN struct kmod_list *kmod_list_remove_n_latest(struct kmod_list *list, unsigned int n);
66 77 EXTERN struct kmod_list *kmod_list_insert_after(struct kmod_list *list, const void *data); EXTERN struct kmod_list *kmod_list_insert_after(struct kmod_list *list, const void *data);
67 78 EXTERN struct kmod_list *kmod_list_insert_before(struct kmod_list *list, const void *data); EXTERN struct kmod_list *kmod_list_insert_before(struct kmod_list *list, const void *data);
File src/libkmod-list.c changed (mode: 100644) (index ec74edd..2477aac)
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 <stdlib.h>
21 20 #include <stddef.h> #include <stddef.h>
22 #include <limits.h>
23 #include <stdio.h>
24 #include <errno.h>
25
26 #include "config.h"
21 #include <stdlib.h>
27 22
28 23 #include "libkmod.h" #include "libkmod.h"
29 #include "libkmod-namespace.h"
30 24 #include "libkmod-paths.h" #include "libkmod-paths.h"
25 #include "libkmod-namespace.h"
26
27 #include "config.h"
28
31 29 #include "shared/macro.h" #include "shared/macro.h"
32 #include "shared/util.h"
30
33 31 #define LIBKMOD_LIST_C #define LIBKMOD_LIST_C
34 32 #include "libkmod-internal.h" #include "libkmod-internal.h"
35 33 #undef LIBKMOD_LIST_C #undef LIBKMOD_LIST_C
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-namespace.h changed (mode: 100644) (index 9eb2892..02dcee6)
27 27
28 28 /*----------------------------------------------------------------------------*/ /*----------------------------------------------------------------------------*/
29 29 /* strbuf */ /* strbuf */
30 #define strbuf_init libkmod_strbuf_init
31 #define strbuf_release libkmod_strbuf_release
32 #define strbuf_clear libkmod_strbuf_clear
33 #define strbuf_steal libkmod_strbuf_steal
34 #define strbuf_str libkmod_strbuf_str
35 #define strbuf_pushchar libkmod_strbuf_pushchar
36 #define strbuf_pushchars libkmod_strbuf_pushchars
37 #define strbuf_popchar libkmod_strbuf_popchar
38 #define strbuf_popchars libkmod_strbuf_popchars
30 #define strbuf_init libkmod_strbuf_init
31 #define strbuf_release libkmod_strbuf_release
32 #define strbuf_clear libkmod_strbuf_clear
33 #define strbuf_steal libkmod_strbuf_steal
34 #define strbuf_str libkmod_strbuf_str
35 #define strbuf_pushchar libkmod_strbuf_pushchar
36 #define strbuf_pushchars libkmod_strbuf_pushchars
37 #define strbuf_popchar libkmod_strbuf_popchar
38 #define strbuf_popchars libkmod_strbuf_popchars
39 /*----------------------------------------------------------------------------*/
40
41 /*----------------------------------------------------------------------------*/
42 /* libkmod-index */
43 #define index_file_open libkmod_index_file_open
44 #define index_file_close libkmod_index_file_close
45 #define index_search libkmod_index_search
46 #define index_dump libkmod_index_dump
47 #define index_searchwild libkmod_index_searchwild
48
49 #define index_values_free libkmod_index_values_free
50
51 #define index_mm_open libkmod_index_mm_open
52 #define index_mm_close libkmod_index_mm_close
53 #define index_mm_search libkmod_index_mm_search
54 #define index_mm_searchwild libkmod_index_mm_searchwild
55 #define index_mm_dump libkmod_index_mm_dump
39 56 /*----------------------------------------------------------------------------*/ /*----------------------------------------------------------------------------*/
40 57 #endif #endif
41 58 #endif #endif
File src/libkmod-signature.c changed (mode: 100644) (index 45fad29..c1f77e0)
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 <endian.h>
21 #include <inttypes.h>
22 #include <stdio.h>
23 #include <stdlib.h>
20 #include <stdint.h>
21 #include <stdbool.h>
22 #include <stddef.h>
24 23 #include <string.h> #include <string.h>
25 #include <limits.h>
26
27 #include "config.h"
24 #include <endian.h> /* BSD */
28 25
29 26 #include "libkmod.h" #include "libkmod.h"
30 #include "libkmod-namespace.h"
31 27 #include "libkmod-paths.h" #include "libkmod-paths.h"
28 #include "libkmod-namespace.h"
29
30 #include "config.h"
31
32 32 #include "shared/macro.h" #include "shared/macro.h"
33 #include "shared/util.h"
33
34 34 #define LIBKMOD_SIGNATURE_C #define LIBKMOD_SIGNATURE_C
35 35 #include "libkmod-internal.h" #include "libkmod-internal.h"
36 36 #undef LIBKMOD_SIGNATURE_C #undef LIBKMOD_SIGNATURE_C
 
... ... enum pkey_hash_algo {
62 62 PKEY_HASH__LAST PKEY_HASH__LAST
63 63 }; };
64 64
65 const char *const pkey_hash_algo[PKEY_HASH__LAST] = {
65 static const char *const pkey_hash_algo[PKEY_HASH__LAST] = {
66 66 [PKEY_HASH_MD4] = "md4", [PKEY_HASH_MD4] = "md4",
67 67 [PKEY_HASH_MD5] = "md5", [PKEY_HASH_MD5] = "md5",
68 68 [PKEY_HASH_SHA1] = "sha1", [PKEY_HASH_SHA1] = "sha1",
 
... ... enum pkey_id_type {
80 80 PKEY_ID_TYPE__LAST PKEY_ID_TYPE__LAST
81 81 }; };
82 82
83 const char *const pkey_id_type[PKEY_ID_TYPE__LAST] = {
83 static const char *const pkey_id_type[PKEY_ID_TYPE__LAST] = {
84 84 [PKEY_ID_PGP] = "PGP", [PKEY_ID_PGP] = "PGP",
85 85 [PKEY_ID_X509] = "X509", [PKEY_ID_X509] = "X509",
86 86 [PKEY_ID_PKCS7] = "PKCS#7", [PKEY_ID_PKCS7] = "PKCS#7",
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)
File src/libkmod.h changed (mode: 100644) (index ddf02dc..0499ebd)
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 #pragma once
21 #ifndef _LIBKMOD_H_
22 #define _LIBKMOD_H_
20 #ifndef LIBKMOD_H
21 #define LIBKMOD_H
23 22
24 23 #include <fcntl.h> #include <fcntl.h>
25 24 #include <stdarg.h> #include <stdarg.h>
 
... ... struct kmod_list *kmod_list_last(const struct kmod_list *list);
98 97 list_entry != NULL; \ list_entry != NULL; \
99 98 list_entry = kmod_list_prev(first_entry, list_entry)) list_entry = kmod_list_prev(first_entry, list_entry))
100 99
100
101 101 /* /*
102 102 * kmod_config_iter * kmod_config_iter
103 103 * *
File src/shared/array.c changed (mode: 100644) (index eb9b148..bd56446)
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 <errno.h>
20 #include <stddef.h>
22 21 #include <stdlib.h> #include <stdlib.h>
22 #include <errno.h>
23 23 #include <string.h> #include <string.h>
24 24
25 25 #include "config.h" #include "config.h"
26
26 27 #define SHARED_ARRAY_C #define SHARED_ARRAY_C
27 28 #include "shared/array.h" #include "shared/array.h"
28 29 #undef SHARED_ARRAY_C #undef SHARED_ARRAY_C
29 30
30 31 /* basic pointer array growing in steps */ /* basic pointer array growing in steps */
31 32
32
33 33 static int array_realloc(struct array *array, size_t new_total) static int array_realloc(struct array *array, size_t new_total)
34 34 { {
35 35 void *tmp = realloc(array->array, sizeof(void *) * new_total); void *tmp = realloc(array->array, sizeof(void *) * new_total);
 
... ... static int array_realloc(struct array *array, size_t new_total)
42 42
43 43 void array_init(struct array *array, size_t step) void array_init(struct array *array, size_t step)
44 44 { {
45 assert(step > 0);
46 45 array->array = NULL; array->array = NULL;
47 46 array->count = 0; array->count = 0;
48 47 array->total = 0; array->total = 0;
File src/shared/hash.c changed (mode: 100644) (index 8733a40..584f0b4)
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 <errno.h>
21 #include <inttypes.h>
22 #include <stdlib.h>
23 #include <string.h>
20 #include <stddef.h>
21 #include <stdarg.h>
24 22 #include <limits.h> #include <limits.h>
25 #include <stdio.h>
26 23 #include <stdbool.h> #include <stdbool.h>
24 #include <unistd.h>
25 #include <stdio.h>
26 #include <sys/types.h>
27 27 #include <sys/stat.h> #include <sys/stat.h>
28 #include <stdint.h>
29 #include <stdlib.h>
30 #include <string.h>
31 #include <errno.h>
28 32
29 33 #include "config.h" #include "config.h"
34
30 35 #include "shared/macro.h" #include "shared/macro.h"
36 #include "shared/util.h"
31 37 #define SHARED_HASH_C #define SHARED_HASH_C
32 38 #include "shared/hash.h" #include "shared/hash.h"
33 39 #undef SHARED_HASH_C #undef SHARED_HASH_C
34 #include "shared/util.h"
35 40
36 41 struct hash_entry { struct hash_entry {
37 42 const char *key; const char *key;
File src/shared/linux-syscalls.h changed (mode: 100644) (index 7e0dcbe..78b6873)
1 #ifndef LINUX_SYSCALLS_H
2 #define LINUX_SYSCALLS_H
1 #ifndef SHARED_LINUX_SYSCALLS_H
2 #define SHARED_LINUX_SYSCALLS_H
3 3 static inline int finit_module(int fd, const char *uargs, int flags) static inline int finit_module(int fd, const char *uargs, int flags)
4 4 { {
5 5 if (__NR_finit_module == -1) { if (__NR_finit_module == -1) {
File src/shared/scratchbuf.c changed (mode: 100644) (index 355ab60..f0c44fe)
16 16 * You should have received a copy of the GNU Lesser General Public * You should have received a copy of the GNU Lesser General Public
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 #include <errno.h>
20 #include <string.h>
19
20 #include <stddef.h>
21 21 #include <stdbool.h> #include <stdbool.h>
22 22 #include <stdlib.h> #include <stdlib.h>
23 #include <errno.h>
24 #include <string.h>
23 25
24 26 #include "config.h" #include "config.h"
25 27
File src/shared/strbuf.c changed (mode: 100644) (index 8198bfd..716d4ba)
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 <assert.h>
22 21 #include <stdbool.h> #include <stdbool.h>
23 #include <stdlib.h>
24 #include <string.h>
22 #include <stddef.h>
23 #include <stdarg.h>
25 24 #include <limits.h> #include <limits.h>
26 #include <stdint.h>
25 #include <unistd.h>
27 26 #include <stdio.h> #include <stdio.h>
27 #include <sys/types.h>
28 28 #include <sys/stat.h> #include <sys/stat.h>
29 #include <stdint.h>
30 #include <stdlib.h>
31 #include <string.h>
32
33 #include "libkmod-namespace.h"
29 34
30 35 #include "config.h" #include "config.h"
31 36
32 #include "libkmod-namespace.h"
33 37 #include "shared/macro.h" #include "shared/macro.h"
34 38 #include "shared/util.h" #include "shared/util.h"
35 39 #define SHARED_STRBUF_C #define SHARED_STRBUF_C
 
... ... unsigned strbuf_pushchars(struct strbuf *buf, const char *str)
105 109 { {
106 110 unsigned int len; unsigned int len;
107 111
108 assert(str != NULL);
109 assert(buf != NULL);
110
111 112 len = strlen(str); len = strlen(str);
112 113
113 114 if (!buf_grow(buf, buf->used + len)) if (!buf_grow(buf, buf->used + len))
 
... ... unsigned strbuf_pushchars(struct strbuf *buf, const char *str)
121 122
122 123 void strbuf_popchar(struct strbuf *buf) void strbuf_popchar(struct strbuf *buf)
123 124 { {
124 assert(buf->used > 0);
125 125 buf->used--; buf->used--;
126 126 } }
127 127
128 128 void strbuf_popchars(struct strbuf *buf, unsigned n) void strbuf_popchars(struct strbuf *buf, unsigned n)
129 129 { {
130 assert(buf->used >= n);
131 130 buf->used -= n; buf->used -= n;
132 131 } }
133 132
File src/shared/util.c changed (mode: 100644) (index 5cfb205..658fbd6)
19 19 * 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/>.
20 20 */ */
21 21
22 #include <assert.h>
23 #include <ctype.h>
24 #include <errno.h>
25 #include <stdarg.h>
26 22 #include <stddef.h> #include <stddef.h>
27 #include <stdio.h>
28 #include <stdlib.h>
29 #include <string.h>
30 #include <unistd.h>
23 #include <stdarg.h>
31 24 #include <limits.h> #include <limits.h>
32 #include <stdint.h>
33 25 #include <stdbool.h> #include <stdbool.h>
34 #include <libgen.h>
26 #include <unistd.h>
27 #include <stdio.h>
28 #include <sys/types.h>
35 29 #include <sys/stat.h> #include <sys/stat.h>
30 #include <stdint.h>
31 #include <stdlib.h>
32 #include <unistd.h>
33 #include <string.h>
34 #include <errno.h>
35 #include <ctype.h>
36 36
37 #include "config.h"
37 #include <libgen.h> /* POSIX basename selector */
38 38
39 39 #include "libkmod-namespace.h" #include "libkmod-namespace.h"
40
41 #include "config.h"
42
40 43 #include "shared/macro.h" #include "shared/macro.h"
41 44 #define SHARED_UTIL_C #define SHARED_UTIL_C
42 45 #include "shared/util.h" #include "shared/util.h"
 
... ... char *freadline_wrapped(FILE *fp, unsigned int *linenum)
415 418
416 419 bool path_is_absolute(const char *p) bool path_is_absolute(const char *p)
417 420 { {
418 assert(p != NULL);
419
420 421 return p[0] == '/'; return p[0] == '/';
421 422 } }
422 423
File src/tools/depmod.c changed (mode: 100644) (index fcfb327..806acc4)
17 17 * along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. 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 <getopt.h>
25 #include <limits.h>
26 #include <regex.h>
20 #include <syslog.h>
21 #include <stddef.h>
22 #include <getopt.h> /* GNU getopt */
27 23 #include <stdio.h> #include <stdio.h>
24 #include <stdarg.h>
28 25 #include <stdlib.h> #include <stdlib.h>
29 26 #include <string.h> #include <string.h>
30 #include <unistd.h>
31 #include <stddef.h>
32 #include <syslog.h>
33 #include <libgen.h>
27 #include <stdbool.h>
28 #include <limits.h>
34 29 #include <sys/stat.h> #include <sys/stat.h>
30 #include <stdint.h>
31 #include <errno.h>
32 #include <regex.h>
33 #include <dirent.h>
34 #include <unistd.h>
35 #include <ctype.h>
35 36 #include <sys/utsname.h> #include <sys/utsname.h>
36 37
37 #include "config.h"
38 #include <libgen.h> /* POSIX basename selector */
38 39
39 40 #include "libkmod.h" #include "libkmod.h"
40 41 #include "libkmod-paths.h" #include "libkmod-paths.h"
41 42
42 #include "shared/array.h"
43 #include "shared/hash.h"
43 #include "config.h"
44
44 45 #include "shared/macro.h" #include "shared/macro.h"
45 46 #include "shared/util.h" #include "shared/util.h"
47 #include "shared/array.h"
48 #include "shared/hash.h"
46 49 #include "shared/scratchbuf.h" #include "shared/scratchbuf.h"
47 50
48 #include "libkmod-internal.h"
51 #include "libkmod-internal.h" /* need to access libkmod list internals */
49 52
50 #undef ERR
51 #undef DBG
52 53 #define TOOLS_DEPMOD_C #define TOOLS_DEPMOD_C
53 54 #include "kmod.h" #include "kmod.h"
54 55 #undef TOOLS_DEPMOD_C #undef TOOLS_DEPMOD_C
 
... ... static void index_write(const struct index_node *node, FILE *out)
420 421
421 422 /* Second word is reserved for the offset of the root node */ /* Second word is reserved for the offset of the root node */
422 423 initial_offset = ftell(out); initial_offset = ftell(out);
423 assert(initial_offset >= 0);
424 424 u = 0; u = 0;
425 425 fwrite(&u, sizeof(uint32_t), 1, out); fwrite(&u, sizeof(uint32_t), 1, out);
426 426
 
... ... static void index_write(const struct index_node *node, FILE *out)
429 429
430 430 /* Update first word */ /* Update first word */
431 431 final_offset = ftell(out); final_offset = ftell(out);
432 assert(final_offset >= 0);
433 432 (void)fseek(out, initial_offset, SEEK_SET); (void)fseek(out, initial_offset, SEEK_SET);
434 433 fwrite(&u, sizeof(uint32_t), 1, out); fwrite(&u, sizeof(uint32_t), 1, out);
435 434 (void)fseek(out, final_offset, SEEK_SET); (void)fseek(out, final_offset, SEEK_SET);
 
... ... static int depmod_module_is_higher_priority(const struct depmod *depmod, const s
1027 1026 const char *oldpath = mod->path; const char *oldpath = mod->path;
1028 1027 int i, bprio = -1, oldprio = -1, newprio = -1; int i, bprio = -1, oldprio = -1, newprio = -1;
1029 1028
1030 assert(strncmp(newpath, cfg->dirname, cfg->dirnamelen) == 0);
1031 assert(strncmp(oldpath, cfg->dirname, cfg->dirnamelen) == 0);
1032
1033 1029 newpath += cfg->dirnamelen + 1; newpath += cfg->dirnamelen + 1;
1034 1030 newlen -= cfg->dirnamelen + 1; newlen -= cfg->dirnamelen + 1;
1035 1031 oldpath += cfg->dirnamelen + 1; oldpath += cfg->dirnamelen + 1;
 
... ... static int depmod_report_cycles_from_root(struct depmod *depmod,
1617 1613 ERR("No memory to report cycles\n"); ERR("No memory to report cycles\n");
1618 1614 return -ENOMEM; return -ENOMEM;
1619 1615 } }
1620 assert(is < stack_size);
1621 1616 stack[is++] = v; stack[is++] = v;
1622 1617
1623 1618 l = __kmod_list_append(free_list, v); l = __kmod_list_append(free_list, v);
 
... ... static int depmod_calculate_dependencies(struct depmod *depmod)
1714 1709
1715 1710 DBG("calculate dependencies and ordering (%hu modules)\n", n_mods); DBG("calculate dependencies and ordering (%hu modules)\n", n_mods);
1716 1711
1717 assert(depmod->modules.count < UINT16_MAX);
1718
1719 1712 /* populate modules users (how many modules uses it) */ /* populate modules users (how many modules uses it) */
1720 1713 itrm = (const struct mod **)depmod->modules.array; itrm = (const struct mod **)depmod->modules.array;
1721 1714 for (i = 0; i < n_mods; i++, itrm++) { for (i = 0; i < n_mods; i++, itrm++) {
 
... ... static int depmod_calculate_dependencies(struct depmod *depmod)
1743 1736 for (; itr_dst < itr_dst_end; itr_dst++) { for (; itr_dst < itr_dst_end; itr_dst++) {
1744 1737 const struct mod *dst = *itr_dst; const struct mod *dst = *itr_dst;
1745 1738 uint16_t dst_idx = dst->idx; uint16_t dst_idx = dst->idx;
1746 assert(users[dst_idx] > 0);
1747 1739 users[dst_idx]--; users[dst_idx]--;
1748 1740 if (users[dst_idx] == 0) { if (users[dst_idx] == 0) {
1749 1741 roots[n_roots] = dst_idx; roots[n_roots] = dst_idx;
File src/tools/insmod.c changed (mode: 100644) (index fb9e061..feb05c1)
17 17 * along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 18 */ */
19 19
20 #include <errno.h>
21 #include <getopt.h>
20 #include <getopt.h> /* GNU getopt */
21 #include <stddef.h>
22 22 #include <stdio.h> #include <stdio.h>
23 #include <stdlib.h>
23 #include <errno.h>
24 24 #include <string.h> #include <string.h>
25 #include <limits.h>
25 #include <stdlib.h>
26 26 #include <syslog.h> #include <syslog.h>
27 #include <limits.h>
28
29 #include "libkmod.h"
27 30
28 31 #include "config.h" #include "config.h"
29 32
30 #include "libkmod.h"
31 33 #include "shared/macro.h" #include "shared/macro.h"
32 34 #include "shared/util.h" #include "shared/util.h"
35
33 36 #define TOOLS_INSMOD_C #define TOOLS_INSMOD_C
34 37 #include "kmod.h" #include "kmod.h"
35 38 #undef TOOLS_INSMOD_C #undef TOOLS_INSMOD_C
File src/tools/kmod.c changed (mode: 100644) (index 388c78f..d5ee638)
17 17 * along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 18 */ */
19 19
20 #include <errno.h>
21 #include <getopt.h>
22 #include <stdio.h>
23 #include <stdlib.h>
20 #include <unistd.h>
21 #include <getopt.h> /* GNU getopt */
24 22 #include <string.h> #include <string.h>
23 #include <stdlib.h>
24 #include <stdio.h>
25 #include <errno.h>
25 26 #include <limits.h> #include <limits.h>
26 #include <libgen.h>
27 #include <stdbool.h>
28 #include <sys/stat.h>
29 #include <stdint.h>
30
31 #include <libgen.h> /* POSIX basename selector */
27 32
28 33 #include "config.h" #include "config.h"
29 34
30 #include "libkmod.h"
31 35 #include "shared/macro.h" #include "shared/macro.h"
32 36 #include "shared/util.h" #include "shared/util.h"
37
33 38 #define TOOLS_KMOD_C #define TOOLS_KMOD_C
34 39 #include "kmod.h" #include "kmod.h"
35 40 #undef TOOLS_KMOD_C #undef TOOLS_KMOD_C
36 #include "log.h"
37 41
38 42 static const char options_s[] = "+hV"; static const char options_s[] = "+hV";
39 43 static const struct option options[] = { static const struct option options[] = {
File src/tools/kmod.h changed (mode: 100644) (index adac9cf..6836bae)
1 #ifndef KMOD_H
2 #define KMOD_H
1 #ifndef TOOLS_KMOD_H
2 #define TOOLS_KMOD_H
3 3 /* /*
4 4 * kmod - one tool to rule them all * kmod - one tool to rule them all
5 5 * *
File src/tools/log.c changed (mode: 100644) (index ec6de54..b3c5a9b)
16 16 * You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
17 17 * along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 18 */ */
19
19 #if 0
20 20 #include <errno.h> #include <errno.h>
21 21 #include <stdio.h> #include <stdio.h>
22 22 #include <stdlib.h> #include <stdlib.h>
 
33 33 #define TOOLS_LOG_C #define TOOLS_LOG_C
34 34 #include "log.h" #include "log.h"
35 35 #undef TOOLS_LOG_C #undef TOOLS_LOG_C
36 #endif
37
38 #include <stdbool.h>
39 #include <syslog.h>
40 #include <stdio.h>
41 #include <stdarg.h>
42 #include <limits.h>
43 #include <sys/types.h>
44 #include <sys/stat.h>
45 #include <stdint.h>
46 #include <stdlib.h>
47
48 #include "libkmod.h"
49
50 #include "config.h"
51
52 #include "shared/macro.h"
53 #include "shared/util.h"
54
55 #include "kmod.h"
36 56
37 57 #define PRIO_MAX_SIZE 32 #define PRIO_MAX_SIZE 32
38 58
File src/tools/lsmod.c changed (mode: 100644) (index 5be23ba..c3d4dfc)
17 17 * along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 18 */ */
19 19
20 #include <errno.h>
21 20 #include <stddef.h> #include <stddef.h>
22 21 #include <stdio.h> #include <stdio.h>
23 22 #include <stdlib.h> #include <stdlib.h>
24 23 #include <string.h> #include <string.h>
25 #include <unistd.h>
26 24
27 25 #include "config.h" #include "config.h"
28 26
File src/tools/modinfo.c changed (mode: 100644) (index 925f2e6..2d601ee)
17 17 * along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 18 */ */
19 19
20 #include <errno.h>
21 #include <getopt.h>
22 #include <limits.h>
23 #include <stdbool.h>
24 #include <stdio.h>
25 #include <stdlib.h>
20 #include <stddef.h>
26 21 #include <string.h> #include <string.h>
27 #include <limits.h>
22 #include <stdbool.h>
28 23 #include <syslog.h> #include <syslog.h>
24 #include <stdarg.h>
25 #include <limits.h>
26 #include <unistd.h>
27 #include <stdio.h>
28 #include <sys/types.h>
29 29 #include <sys/stat.h> #include <sys/stat.h>
30 #include <stdint.h>
31 #include <errno.h>
32 #include <stdlib.h>
33 #include <getopt.h> /* GNU getopt */
30 34 #include <sys/utsname.h> #include <sys/utsname.h>
31 35
36 #include "libkmod.h"
37
32 38 #include "config.h" #include "config.h"
33 39
34 #include "libkmod.h"
35 40 #include "shared/macro.h" #include "shared/macro.h"
36 41 #include "shared/util.h" #include "shared/util.h"
42
37 43 #define TOOLS_MODINFO_C #define TOOLS_MODINFO_C
38 44 #include "kmod.h" #include "kmod.h"
39 45 #undef TOOLS_MODINFO_C #undef TOOLS_MODINFO_C
File src/tools/modprobe.c changed (mode: 100644) (index 34eae75..0a7d968)
17 17 * along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 18 */ */
19 19
20 #include <assert.h>
21 #include <errno.h>
22 #include <getopt.h>
23 #include <limits.h>
24 20 #include <stdbool.h> #include <stdbool.h>
21 #include <syslog.h>
22 #include <getopt.h> /* GNU getopt */
23 #include <stddef.h>
25 24 #include <stdio.h> #include <stdio.h>
26 #include <stdlib.h>
27 #include <string.h>
25 #include <stdarg.h>
28 26 #include <unistd.h> #include <unistd.h>
27 #include <string.h>
28 #include <errno.h>
29 #include <stdlib.h>
30 #include <stdarg.h>
29 31 #include <limits.h> #include <limits.h>
30 #include <syslog.h>
31 #include <sys/stat.h>
32 #include <sys/types.h>
33 32 #include <sys/utsname.h> #include <sys/utsname.h>
34 #include <sys/wait.h>
33
34 #include "libkmod.h"
35 35
36 36 #include "config.h" #include "config.h"
37 37
38 #include "libkmod.h"
39 #include "shared/array.h"
40 38 #include "shared/macro.h" #include "shared/macro.h"
41 39 #include "shared/util.h" #include "shared/util.h"
40
42 41 #define TOOLS_MODPROBE_C #define TOOLS_MODPROBE_C
43 42 #include "kmod.h" #include "kmod.h"
44 43 #undef TOOLS_MODPROBE_C #undef TOOLS_MODPROBE_C
File src/tools/rmmod.c changed (mode: 100644) (index 35e44e4..6944a2b)
17 17 * along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 18 */ */
19 19
20 #include <errno.h>
21 #include <getopt.h>
20 #include <syslog.h>
21 #include <getopt.h> /* GNU getopt */
22 #include <stddef.h>
22 23 #include <stdio.h> #include <stdio.h>
24 #include <errno.h>
23 25 #include <stdlib.h> #include <stdlib.h>
24 #include <string.h>
25 #include <unistd.h>
26 #include <syslog.h>
27 26 #include <sys/stat.h> #include <sys/stat.h>
28 #include <sys/types.h>
27 #include <string.h>
28
29 #include "libkmod.h"
29 30
30 31 #include "config.h" #include "config.h"
31 32
32 #include "libkmod.h"
33 #include "shared/macro.h"
34 33 #define TOOLS_RMMOD_C #define TOOLS_RMMOD_C
35 34 #include "kmod.h" #include "kmod.h"
36 35 #undef TOOLS_RMMOD_C #undef TOOLS_RMMOD_C
File src/tools/static-nodes.c changed (mode: 100644) (index e10fb40..b34719a)
19 19 * along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
20 20 */ */
21 21
22 #include <errno.h>
23 #include <getopt.h>
24 #include <limits.h>
25 #include <stddef.h>
26 22 #include <stdio.h> #include <stdio.h>
23 #include <getopt.h> /* GNU getopt */
27 24 #include <stdlib.h> #include <stdlib.h>
28 25 #include <string.h> #include <string.h>
29 #include <stddef.h>
30 #include <unistd.h>
26 #include <sys/utsname.h>
27 #include <limits.h>
31 28 #include <stdbool.h> #include <stdbool.h>
32 #include <stdint.h>
33 29 #include <sys/stat.h> #include <sys/stat.h>
34 #include <sys/types.h>
35 #include <sys/utsname.h>
30 #include <stdint.h>
31 #include <errno.h>
36 32
37 33 #include "config.h" #include "config.h"
38 34
 
42 38 #define TOOLS_STATIC_NODES_C #define TOOLS_STATIC_NODES_C
43 39 #include "kmod.h" #include "kmod.h"
44 40 #undef TOOLS_STATIC_NODES_C #undef TOOLS_STATIC_NODES_C
45 #include "log.h"
46 41
47 42 struct static_nodes_format { struct static_nodes_format {
48 43 const char *name; const char *name;
Hints:
Before first commit, do not forget to setup your git environment:
git config --global user.name "your_name_here"
git config --global user.email "your@email_here"

Clone this repository using HTTP(S):
git clone https://rocketgit.com/user/sylware/nyankmod

Clone this repository using ssh (do not forget to upload a key first):
git clone ssh://rocketgit@ssh.rocketgit.com/user/sylware/nyankmod

Clone this repository using git:
git clone git://git.rocketgit.com/user/sylware/nyankmod

You are allowed to anonymously push to this repository.
This means that your pushed commits will automatically be transformed into a merge request:
... clone the repository ...
... make some changes and some commits ...
git push origin main