gpt4 book ai didi

c - inotify_rm_watch 总是返回 EINVAL

转载 作者:太空宇宙 更新时间:2023-11-04 12:04:59 25 4
gpt4 key购买 nike

我有以下两个功能:

static int MessAttrManager_inotifyUnregister(MessPropertyManager* base, int wd){
MessAttrManager* self = base->_derived;
int ret;

printf("INOTIFY REMOV %d\n",wd);
if ((ret = inotify_rm_watch(self->inotify.descriptor, wd)) < 0)
return ret;
printf("INOTIFY REMOV END %d\n",wd);

return 0;
}

static int MessAttrManager_inotifyRegister(MessPropertyManager* base, char* dir, long flags){
MessAttrManager* self = base->_derived;
int wd, ret;

printf("INOTIFY ADD START %s\n",dir);
if ((wd = inotify_add_watch(self->inotify.descriptor, dir, flags)) < 0)
return wd;
printf("INOTIFY ADD %d %s\n",wd,dir);

return 0;
}

它们是唯一使用 inotify_rm/add_watch 的代码 在日志中我可以清楚地看到 MessAttrManager_inotifyRegister 成功创建了 watch。还可以正确检测到事件。我还看到 MessAttrManager_inotifyUnregister 正在删除完全相同的监视描述符。然而,第二个函数几乎总是返回 EINVAL。我有监视目录的嵌套层次结构(递归),inotify_rm_watch 仅在我递归删除所有监视时在最后一个目录(根目录)上成功执行。

这是嵌套 watch 的标准行为吗?

最佳答案

inotify自行从删除的目录中删除 watches 并抛出 EINVAL如果有人试图从已删除的目录中明确删除 watch 。结合 inotify 事件不包含 wd 的事实删除的 child 和那个IN_IGNORED标志包含在 IN_DELETE 中父目录事件而不是 IN_DELETE_SELF实际目录非常不方便。

关于c - inotify_rm_watch 总是返回 EINVAL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51046507/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com