dep.c 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. /*
  2. Exports the lkmc_dep which dep2.ko uses.
  3. insmod /dep.ko
  4. # dmesg => 0
  5. # dmesg => 0
  6. # dmesg => ...
  7. insmod /dep2.ko
  8. # dmesg => 1
  9. # dmesg => 2
  10. # dmesg => ...
  11. rmmod dep
  12. # Fails because dep2 uses it.
  13. rmmod dep2
  14. # Dmesg stops incrementing.
  15. rmmod dep
  16. sys visibility:
  17. dmesg -n 1
  18. insmod /dep.ko
  19. insmod /dep2.ko
  20. ls -l /sys/module/dep/holders
  21. # => ../../dep2
  22. cat refcnt
  23. # => 1
  24. depmod:
  25. grep dep "/lib/module/"*"/depmod"
  26. # extra/dep2.ko: extra/dep.ko
  27. # extra/dep.ko:
  28. modprobe dep
  29. # lsmod
  30. # Both dep and dep2 were loaded.
  31. TODO: at what point does buildroot / busybox generate that file?
  32. */
  33. #include <linux/delay.h> /* usleep_range */
  34. #include <linux/kernel.h>
  35. #include <linux/kthread.h>
  36. #include <linux/module.h>
  37. MODULE_LICENSE("GPL");
  38. int lkmc_dep = 0;
  39. EXPORT_SYMBOL(lkmc_dep);
  40. static struct task_struct *kthread;
  41. static int work_func(void *data)
  42. {
  43. while (!kthread_should_stop()) {
  44. printk(KERN_INFO "%d\n", lkmc_dep);
  45. usleep_range(1000000, 1000001);
  46. }
  47. return 0;
  48. }
  49. static int myinit(void)
  50. {
  51. kthread = kthread_create(work_func, NULL, "mykthread");
  52. wake_up_process(kthread);
  53. return 0;
  54. }
  55. static void myexit(void)
  56. {
  57. kthread_stop(kthread);
  58. }
  59. module_init(myinit)
  60. module_exit(myexit)