我是內核和KLD編程的新手。我正在修改FreeBSD中用於系統調用模塊的示例文件。我的問題是,是否有可能在系統調用函數內部進行fork或exec?像下面的例子一樣?FreeBSD kldload:無法加載,沒有這樣的文件或目錄
#include <sys/types.h>
#include <sys/param.h>
#include <sys/proc.h>
#include <sys/module.h>
#include <sys/sysent.h>
#include <sys/kernel.h>
#include <sys/systm.h>
/*
* The function for implementing the syscall.
*/
static int hello (struct thread *td, void *arg)
{
printf("Running...\n");
/******************************************************/
/*Something like this?*/
/******************************************************/
execl("/bin/pwd", "pwd", NULL);
return 0;
}
/*
* The `sysent' for the new syscall
*/
static struct sysent hello_sysent = {
0, /* sy_narg */
hello /* sy_call */
};
/*
* The offset in sysent where the syscall is allocated.
*/
static int offset = NO_SYSCALL;
/*
* The function called at load/unload.
*/
static int
load (struct module *module, int cmd, void *arg)
{
int error = 0;
switch (cmd) {
case MOD_LOAD :
uprintf ("syscall loaded at %d\n", offset);
break;
case MOD_UNLOAD :
uprintf ("syscall unloaded from %d\n", offset);
break;
default :
uprintf("There was some error!");
error = EINVAL;
break;
}
return error;
}
SYSCALL_MODULE(syscall, &offset, &hello_sysent, load, NULL);
沒有編譯錯誤(系統調用),但在使用命令kldload加載它,它會返回一個錯誤: 命令kldload:無法加載./syscall.ko:沒有這樣的文件或目錄
有什麼我可以閱讀和了解更多關於爲什麼會發生這種情況,我能做些什麼?
你試過給它一個完整的路徑嗎? – kichik 2014-11-20 16:23:56
是的,我試過了。我可以看到syscall.ko文件在那裏。 – 2014-11-20 16:28:32
使用kldload -v ./syscall.ko和文件syscall.ko檢查dmesg輸出。確保你正在運行正在運行的內核的源代碼樹和右拱(例如i386 vs amd64)。 – 2014-11-21 04:48:56