ioctl 返回 -1,errno 设置为 EPERM
我有一个 C 程序,它调用 ioctl() 但它返回 -1 且 errno 设置为 EPERM。 但我已将该文件的模式更改为“777”。
您能告诉我为什么 ioctl() 仍然返回 -1 而 errno 设置为 EPERM 吗?
I have a C program which calls ioctl() but it returns -1 and errno set to EPERM.
But I have changed mode of that file to "777".
Can you please tell me why ioctl() still returns -1 with errno set to EPERM?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您调用 ioctl 的设备可能包含一些代码,用于在执行您请求的操作之前检查功能。 在这种情况下,将特殊文件的权限设置为 777 是不够的。 如果您想深入研究支持相关设备的驱动程序的源代码,您可以查找类似以下内容的内容来确定实际需要什么功能。
您可能想要了解功能或只是像其他人建议的那样以 root 身份运行您的应用程序。
Linux 功能手册页
The device you are calling ioctl on may include some code that checks for capabilities before performing the action you requested. Setting the permissions for the special file to 777 will not be sufficient in this case. If you want to dig into the source for the driver that supports the device in question you can look for something like the following to figure out what capability is actually required.
You may want to read up on capabilities or just run your application as root as others have suggested.
Linux Man Page for Capabilities
是的,EPERM(不允许操作)错误表明您没有足够的权限来执行该操作。按照liw.fi的建议,尝试以 root 权限执行或告诉我们要执行什么操作。
Yea, EPERM (Operation not permitted) error indicate you don't have sufficient permissions to execute the operation.As liw.fi suggested,try executing with root privilege or tell us what is the operation to be done.