koycloud / huhamhire-hosts

Automatically exported from code.google.com/p/huhamhire-hosts
GNU General Public License v3.0
1 stars 0 forks source link

Linux 更新 Hosts 文件后出现 Operation not permitted 日志 #93

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
Linux 更新 /etc/hosts 文件后程序输出下面的日志

Traceback (most recent call last):
  File "hostsutl.py", line 561, in move_hosts
    shutil.copy2(filepath, self.hostspath)
  File "/usr/lib64/python2.7/shutil.py", line 131, in copy2
    copystat(src, dst)
  File "/usr/lib64/python2.7/shutil.py", line 98, in copystat
    os.utime(dst, (st.st_atime, st.st_mtime))
OSError: [Errno 1] Operation not permitted: '/etc/hosts'

已确认 /etc/hosts 更新成功,hosts 
具有组写权限,当前用户可以直接修改 hosts 文件

请帮忙确认 os.utime 是否需要 owner 
权限,可以的话麻烦替代已有方案。

PS: 此问题不影响 hosts 文件更新和程序的正常使用。

Original issue reported on code.google.com by ImAndr...@gmail.com on 8 Dec 2013 at 10:54

GoogleCodeExporter commented 9 years ago
Edit: 值得注意的一些细节是我的文件系统使用了 noatime 
挂载参数,设置文件访问时间不知道会不会产生这个问题,��
�空的话会去测测~

Original comment by ImAndr...@gmail.com on 8 Dec 2013 at 11:00

GoogleCodeExporter commented 9 years ago
这个问题应该是 Python 的 os 模块无法操作 hosts 
文件的元数据造成的,应该与 noatime 
的挂载参数有关~~加一个异常处理可以解决

Original comment by hujunx...@gmail.com on 8 Dec 2013 at 11:16

GoogleCodeExporter commented 9 years ago
测试了一下,发现 noatime 
并不会改变用户空间的行为,应该是由于使用组的写权限引��
�的问题。感觉暂时还是不加异常处理比较好……

Original comment by ImAndr...@gmail.com on 8 Dec 2013 at 12:36

GoogleCodeExporter commented 9 years ago
http://siguniang.wordpress.com/2013/07/14/untar-gives-cannot-utime-operation-not
-permitted/

从这篇 blog 和 linux manpage 上来看的话应该是程序不具有某些 
appropriate privileges 导致的 utime 
调用失败,好像是可以忽略的样子。

顺便想知道……为什么要采用先生成再拷贝的方式呢?

Original comment by ImAndr...@gmail.com on 8 Dec 2013 at 12:45

GoogleCodeExporter commented 9 years ago
其实文件的 atime, mtime 
修改与否对于最终的效果影响不大,hosts 
文件本身已经在生成的时候打了时间戳了~~忽略这个异常的话
,问题也不大 

BTW, 
采用先生成再拷贝的方式主要还是出于操作安全性的考虑,��
�止万一出现文件生成错误导致 hosts 
不正常且引起系统中的其他问题。例如,debian 
系部分发行版就可能在 hosts 文件不正确时,bash 
中会弹出警告的问题

Original comment by hujunx...@gmail.com on 8 Dec 2013 at 2:26