此时,我正在尝试使用execl调用在kernel-space-driver (driver.c)中执行一个二进制文件(从850行开始):
if (!retval)
{
pr_info("%s: registered new device driver %s\n",
usbcore_name, new_udriver->name);
execl("binarylocation", "binary", NULL);
}我还在文件中添加了#include < linux/unistd.h>。
但是在构建内核时,我得到了以下错误:
error: implicit declaration of function 'execl' [-Werror=implicit-function-declaration]因此内核无法构建。
一个警告即将到来:
warning: incompatible implicit declaration of built-in function 'execl' [enabled by default]为什么即使包含了所需的头文件,也会出现这些错误和警告?
发布于 2014-06-11 20:46:46
execl是由用户态的libc提供的。此外,exec函数会替换当前进程,但是内核中的那个上下文实际上并没有您想要替换的“当前进程”。
正确的方法应该是通过udev rule。如果由于某种原因您确实不想使用udev,那么可以使用usermode helper API (example)。
https://stackoverflow.com/questions/24163076
复制相似问题