【发布时间】:2015-12-13 21:13:59
【问题描述】:
我正在尝试向 Linux task_struct 添加一些东西。
在这个区域,我从用户那里复制了一个字符串并尝试将它存储在我的结构中。
我尝试通过添加将打印复制的字符串的printk 来调试我的代码。
这是代码的调试部分:
newTODO->TODO_description=(char*)(kmalloc(in_description_size+1,0));
if( newTODO->TODO_description){
kfree(newTODO);
return -1;
}
res=copy_from_user(newTODO->TODO_description, in_TODO_description, in_description_size);
if (res) // error copying from user space, 1 or more char werent copied.
{
printk(KERN_ALERT "function: create element failed to copy from user\n");
return -EFAULT;
}
newTODO->TODO_description[in_description_size]='\o';
printk(KERN_ALERT "the copied string is: %s \n",newTODO->TODO_description);
对我来说必须重要的印刷品是
printk(KERN_ALERT "the copied string is: %s \n",newTODO->TODO_description);
会有用吗?
了解 printk:
什么时候我会在调用 printk 时从终端运行我的测试文件,它会将输出打印到工作终端?
【问题讨论】:
-
使用
dmesg查看内核日志。 -
='\o';看起来很可疑。你是说='\0';(或者只是= 0;)
标签: c linux linux-kernel kernel printk