0

我对 linux 很陌生,我有一些关于内核模块编程的问题。我正在使用 ubuntu 和 C 来制作我的 .ko 文件。我正在尝试制作一个在调用程序 /a 时将执行程序 /b 而不是 /a 的模块。有小费吗?

此外,即使使用 printk (KERN_EMERG...),它也不会打印到终端。是否有我缺少的设置,或者 ubuntu 没有这样做?

非常感谢!

4

2 回答 2

1

您可能需要修改 中的设置/proc/sys/kernel/printk,这些设置控制将哪些级别打印到控制台。来自proc(5)

   /proc/sys/kernel/printk
          The four values in this file are console_loglevel,
          default_message_loglevel, minimum_console_level, and
          default_console_loglevel.  These values influence
          printk() behavior when printing or logging error
          messages.  See syslog(2) for more info on the
          different loglevels.  Messages with a higher priority
          than console_loglevel will be printed to the console.
          Messages without an explicit priority will be printed
          with priority default_message_level.
          minimum_console_loglevel is the minimum (highest)
          value to which console_loglevel can be set.
          default_console_loglevel is the default value for
          console_loglevel.

请注意,与nice(2)值一样,较低的值具有较高的优先级。

制作 for执行execve()路径的最简单方法是绑定安装在:/foo/a/foo/b/foo/b/foo/a

mount -obind /foo/b /foo/a

不需要内核模块。

使用内核模块执行相同的任务会显着增加工作量;LSM 界面可能会为您提供一些帮助,帮助您确定目标的确切执行时间。如果您正在寻找一个起点,do_execve()infs/exec.c是开始阅读的地方。确保已ctags安装、运行并知道如何使用您的编辑器的ctags集成,以显着更轻松地阅读代码。

于 2012-05-03T01:08:29.557 回答
0

Answer about printk:
It prints to the console, not the terminal. But what's the console?
You can find its TTY in /proc/cmdline. Normally it's tty0, which means the screen connected to the computer.
If you connect via SSH/TELNET, surely you won't see this.
If you're working in a graphical environment (Gnome/KDE), you may need something like alt-F1/F2 to switch to a text mode TTY.

You can also use the dmesg command to see the messages.

于 2012-05-03T08:10:43.370 回答