我在嘗試運行一段非常簡單的代碼時遇到了一些麻煩,無法找出原因。試圖從.ko
文件(KO_NAME)安裝一個Linux內核模塊時爲什麼在嘗試安裝Linux內核模塊時會「不允許操作」?
我越來越
操作不允許
。
這是代碼的摘錄:
if (strcmp(argv[1], "-init")==0) {
fd=open(KO_NAME, O_RDONLY|O_CLOEXEC);
if (fd<0) {
perror("Error");
printf("Error number: %d\n", errno);
} else {
printf("fd: %d\n", fd);
}
uid=getuid();
if (uid!=ROOT_UID) {
printf("Error: not root\n");
return -1;
}
if (access(KO_NAME, F_OK)==-1) {
printf("Error: File \"%s\" doesn't exist\n", argv[2]);
return -1;
}
rc=syscall(__NR_finit_module, fd, "", 0);
close(fd);
if (rc!=0) {
perror("Error");
printf("rc=%d\n", rc);
printf("Error number: %d\n", errno);
}
,這是結果運行時:
fd: 3
rc=-1
Error number: 1
爲什麼會出現錯誤number 1
?
操作不允許
您是否試過'/ sbin/insmod'?這可能是因爲modue文件不適合你的內核。 –
Tsyvarev
僅供參考:該系統調用有'finit_module()'封裝,請參閱[man init_module](http://man7.org/linux/man-pages/man2/init_module.2.html)。 –