Difference between EACCES and EPERM

懵懂的女人 提交于 2020-01-11 01:48:16

问题


What is the difference between EACCES and EPERM exactly? EPERM is described here as "not super user", but I would usually associate that with EACCES. In fact, I can't recall ever seeing an EPERM in real life.


回答1:


EACCES is almost always used when the system call was passed a path that was inaccessible by the current user.

EPERM is used in various other situations where you need to be root to perform an action, e.g.

  • kill() on a process that you don't own
  • link() on a directory
  • reboot()



回答2:


According to Linux programmers, learn the difference between EACCES and EPERM already! - A Random Dev's Rants...

  • EACCES "Permission denied" should be used to mean that the user doesn't have sufficient privileges to do the action. The root user, or another user with sufficient user/group permissions should be able to do the action.
  • EPERM "Operation not permitted" should be used to mean the action is not possible or safe in general, regardless of whether the user is root or not. Examples would be:
    • chmoding a file on a FAT filesystem (the filesystem doesn't support permission bits)
  • Note that a lot of Linux code returns EPERM when it should really return EACCES.



回答3:


The Linux capabilities(7) figure into execve(2) so that if the exec'ing process lacks the correct inheritance/bounding-set/ambient to set the file-capabilities:

"If the process did not obtain the full set of file permitted capabilities, then execve(2) fails with the error EPERM."



来源:https://stackoverflow.com/questions/35023667/difference-between-eacces-and-eperm

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!