insmod.c 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. /* vi: set sw=4 ts=4: */
  2. /*
  3. * Mini insmod implementation for busybox
  4. *
  5. * Copyright (C) 2008 Timo Teras <timo.teras@iki.fi>
  6. *
  7. * Licensed under GPLv2 or later, see file LICENSE in this source tree.
  8. */
  9. //config:config INSMOD
  10. //config: bool "insmod (22 kb)"
  11. //config: default y
  12. //config: help
  13. //config: insmod is used to load specified modules in the running kernel.
  14. //applet:IF_INSMOD(IF_NOT_MODPROBE_SMALL(APPLET_NOEXEC(insmod, insmod, BB_DIR_SBIN, BB_SUID_DROP, insmod)))
  15. //kbuild:ifneq ($(CONFIG_MODPROBE_SMALL),y)
  16. //kbuild:lib-$(CONFIG_INSMOD) += insmod.o modutils.o
  17. //kbuild:endif
  18. #include "libbb.h"
  19. #include "modutils.h"
  20. /* 2.6 style insmod has no options and required filename
  21. * (not module name - .ko can't be omitted) */
  22. //usage:#if !ENABLE_MODPROBE_SMALL
  23. //usage:#define insmod_trivial_usage
  24. //usage: IF_FEATURE_2_4_MODULES("[-fkvqLx] MODULE")
  25. //usage: IF_NOT_FEATURE_2_4_MODULES("FILE")
  26. //usage: IF_FEATURE_CMDLINE_MODULE_OPTIONS(" [SYMBOL=VALUE]...")
  27. //usage:#define insmod_full_usage "\n\n"
  28. //usage: "Load kernel module"
  29. //usage: IF_FEATURE_2_4_MODULES( "\n"
  30. //usage: "\n -f Force module to load into the wrong kernel version"
  31. //usage: "\n -k Make module autoclean-able"
  32. //usage: "\n -v Verbose"
  33. //usage: "\n -q Quiet"
  34. //usage: "\n -L Lock: prevent simultaneous loads"
  35. //usage: IF_FEATURE_INSMOD_LOAD_MAP(
  36. //usage: "\n -m Output load map to stdout"
  37. //usage: )
  38. //usage: "\n -x Don't export externs"
  39. //usage: )
  40. //usage:#endif
  41. int insmod_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
  42. int insmod_main(int argc UNUSED_PARAM, char **argv)
  43. {
  44. char *filename;
  45. int rc;
  46. /* Compat note:
  47. * 2.6 style insmod has no options and required filename
  48. * (not module name - .ko can't be omitted).
  49. * 2.4 style insmod can take module name without .o
  50. * and performs module search in default directories
  51. * or in $MODPATH.
  52. */
  53. IF_FEATURE_2_4_MODULES(
  54. getopt32(argv, INSMOD_OPTS INSMOD_ARGS);
  55. argv += optind - 1;
  56. );
  57. filename = *++argv;
  58. if (!filename)
  59. bb_show_usage();
  60. rc = bb_init_module(filename, parse_cmdline_module_options(argv, /*quote_spaces:*/ 0));
  61. if (rc)
  62. bb_error_msg("can't insert '%s': %s", filename, moderror(rc));
  63. return rc;
  64. }