LCOV - code coverage report
Current view: top level - udev - udev-builtin-kmod.c (source / functions) Hit Total Coverage
Test: main_coverage.info Lines: 0 30 0.0 %
Date: 2019-08-22 15:41:25 Functions: 0 5 0.0 %

          Line data    Source code
       1             : /* SPDX-License-Identifier: GPL-2.0+ */
       2             : /*
       3             :  * load kernel modules
       4             :  *
       5             :  * Copyright © 2011 ProFUSION embedded systems
       6             :  */
       7             : 
       8             : #include <errno.h>
       9             : #include <libkmod.h>
      10             : #include <stdarg.h>
      11             : #include <stdio.h>
      12             : #include <stdlib.h>
      13             : 
      14             : #include "module-util.h"
      15             : #include "string-util.h"
      16             : #include "udev-builtin.h"
      17             : 
      18             : static struct kmod_ctx *ctx = NULL;
      19             : 
      20           0 : _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           0 :         log_internalv(priority, 0, file, line, fn, format, args);
      22           0 : }
      23             : 
      24           0 : static int builtin_kmod(sd_device *dev, int argc, char *argv[], bool test) {
      25             :         int i;
      26             : 
      27           0 :         if (!ctx)
      28           0 :                 return 0;
      29             : 
      30           0 :         if (argc < 3 || !streq(argv[1], "load"))
      31           0 :                 return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
      32             :                                        "%s: expected: load <module>", argv[0]);
      33             : 
      34           0 :         for (i = 2; argv[i]; i++)
      35           0 :                 (void) module_load_and_warn(ctx, argv[i], false);
      36             : 
      37           0 :         return 0;
      38             : }
      39             : 
      40             : /* called at udev startup and reload */
      41           0 : static int builtin_kmod_init(void) {
      42           0 :         if (ctx)
      43           0 :                 return 0;
      44             : 
      45           0 :         ctx = kmod_new(NULL, NULL);
      46           0 :         if (!ctx)
      47           0 :                 return -ENOMEM;
      48             : 
      49           0 :         log_debug("Load module index");
      50           0 :         kmod_set_log_fn(ctx, udev_kmod_log, NULL);
      51           0 :         kmod_load_resources(ctx);
      52           0 :         return 0;
      53             : }
      54             : 
      55             : /* called on udev shutdown and reload request */
      56           0 : static void builtin_kmod_exit(void) {
      57           0 :         log_debug("Unload module index");
      58           0 :         ctx = kmod_unref(ctx);
      59           0 : }
      60             : 
      61             : /* called every couple of seconds during event activity; 'true' if config has changed */
      62           0 : static bool builtin_kmod_validate(void) {
      63           0 :         log_debug("Validate module index");
      64           0 :         if (!ctx)
      65           0 :                 return false;
      66           0 :         return (kmod_validate_resources(ctx) != KMOD_RESOURCES_OK);
      67             : }
      68             : 
      69             : const UdevBuiltin udev_builtin_kmod = {
      70             :         .name = "kmod",
      71             :         .cmd = builtin_kmod,
      72             :         .init = builtin_kmod_init,
      73             :         .exit = builtin_kmod_exit,
      74             :         .validate = builtin_kmod_validate,
      75             :         .help = "Kernel module loader",
      76             :         .run_once = false,
      77             : };

Generated by: LCOV version 1.14