简体   繁体   English

Inotify不适用于etc / passwd

[英]Inotify is not working for etc/passwd

I am trying to set listner for passwd file in /etc directory and I am getting notification only for first password change. 我正在尝试在/ etc目录中为passwd文件设置侦听器,并且仅在第一次更改密码时收到通知。

fd = inotify_init();
wd = inotify_add_watch (fd, "/etc/passwd", IN_MODIFY);
while(1)
{
 read (fd, buff, BUFF_SIZE);
 struct inotify_event *event = ( struct inotify_event * ) &buff[ i ];
 printf("Event Len -  %d  wd %d \n", event->len, event->wd);
}

why it works first time and not later?I Am seeing timestamp change everytime when I change password. 为什么它第一次工作而不是以后工作?每次更改密码时,我都会看到时间戳更改。 Same set of code working fine for some other file. 相同的代码集可以很好地处理其他文件。

When changing the /etc/passwd , most application create a new file and rename it. 更改/etc/passwd ,大多数应用程序都会创建一个新文件并将其重命名。 This give a new inode number. 这给出了一个新的索引节点号。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM