1 /* SPDX-License-Identifier: GPL-2.0+ */
5 * Copyright © 2011 ProFUSION embedded systems
14 #include "module-util.h"
15 #include "string-util.h"
16 #include "udev-builtin.h"
18 static struct kmod_ctx
*ctx
= NULL
;
20 _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
) {
21 log_internalv(priority
, 0, file
, line
, fn
, format
, args
);
24 static int builtin_kmod(sd_device
*dev
, int argc
, char *argv
[], bool test
) {
30 if (argc
< 3 || !streq(argv
[1], "load"))
31 return log_error_errno(SYNTHETIC_ERRNO(EINVAL
),
32 "%s: expected: load <module>", argv
[0]);
34 for (i
= 2; argv
[i
]; i
++)
35 (void) module_load_and_warn(ctx
, argv
[i
], false);
40 /* called at udev startup and reload */
41 static int builtin_kmod_init(void) {
45 ctx
= kmod_new(NULL
, NULL
);
49 log_debug("Load module index");
50 kmod_set_log_fn(ctx
, udev_kmod_log
, NULL
);
51 kmod_load_resources(ctx
);
55 /* called on udev shutdown and reload request */
56 static void builtin_kmod_exit(void) {
57 log_debug("Unload module index");
58 ctx
= kmod_unref(ctx
);
61 /* called every couple of seconds during event activity; 'true' if config has changed */
62 static bool builtin_kmod_validate(void) {
63 log_debug("Validate module index");
66 return (kmod_validate_resources(ctx
) != KMOD_RESOURCES_OK
);
69 const UdevBuiltin udev_builtin_kmod
= {
72 .init
= builtin_kmod_init
,
73 .exit
= builtin_kmod_exit
,
74 .validate
= builtin_kmod_validate
,
75 .help
= "Kernel module loader",