1 /* SPDX-License-Identifier: GPL-2.0+ */
5 * Copyright © 2011 ProFUSION embedded systems
15 #include "module-util.h"
16 #include "string-util.h"
19 static struct kmod_ctx
*ctx
= NULL
;
21 _printf_(6,0) static void udev_kmod_log(void *data
, int priority
, const char *file
, int line
, const char *fn
, const char *format
, va_list args
) {
22 log_internalv(priority
, 0, file
, line
, fn
, format
, args
);
25 static int builtin_kmod(struct udev_device
*dev
, int argc
, char *argv
[], bool test
) {
31 if (argc
< 3 || !streq(argv
[1], "load")) {
32 log_error("%s: expected: load <module>", argv
[0]);
36 for (i
= 2; argv
[i
]; i
++)
37 (void) module_load_and_warn(ctx
, argv
[i
], false);
42 /* called at udev startup and reload */
43 static int builtin_kmod_init(struct udev
*udev
) {
47 ctx
= kmod_new(NULL
, NULL
);
51 log_debug("Load module index");
52 kmod_set_log_fn(ctx
, udev_kmod_log
, udev
);
53 kmod_load_resources(ctx
);
57 /* called on udev shutdown and reload request */
58 static void builtin_kmod_exit(struct udev
*udev
) {
59 log_debug("Unload module index");
60 ctx
= kmod_unref(ctx
);
63 /* called every couple of seconds during event activity; 'true' if config has changed */
64 static bool builtin_kmod_validate(struct udev
*udev
) {
65 log_debug("Validate module index");
68 return (kmod_validate_resources(ctx
) != KMOD_RESOURCES_OK
);
71 const struct udev_builtin udev_builtin_kmod
= {
74 .init
= builtin_kmod_init
,
75 .exit
= builtin_kmod_exit
,
76 .validate
= builtin_kmod_validate
,
77 .help
= "Kernel module loader",