全,
我试着用inotify写一个文件监视服务。这是我的代码:
m_fd = inotify_init1( IN_NONBLOCK );
if( m_fd == -1 )
{
syslog( LOG_ERR, "Failed to initialize inotify" );
m_isOK = false;
}
else
syslog( LOG_DEBUG, "Inotify initialize successfully" );
m_wd = inotify_add_watch( m_fd, log.c_str(), IN_CLOSE );
if( m_wd == -1 )
{
std::string error = "Failed to add log watching to inotify, error is " + std::to_string( errno );
syslog( LOG_ERR, error.c_str() );
m_isOK = false;
}
else
syslog( LOG_DEBUG, "Watching system intrusion file log added" );当我试图执行它时,它确实成功地运行了一次。然而,每次我尝试运行之后,我都会进入日志:
Failed to add log watching to inotify, error is 2.即使在重新启动系统之后也会发生这种情况。
由于错误2是File sharing错误,我想系统上存在一些lock_file,为了使inotify_add_watch()成功,我需要删除这些lock_file。
有人能帮忙吗?或者我完全错了还有别的事吗?
蒂娅!
编辑
我试图看看什么时候会在磁盘上创建这个文件,以便我可以开始处理它。我是不是用错面具了?
还修改行:
m_wd = inotify_add_watch( m_fd, log.c_str(), IN_CLOSE );改为:
m_wd = inotify_add_watch( m_fd, log.c_str(), IN_CREATE | IN_CLOSE );不会改变结果。我还是失败了,错误作为2。
/EDIT
发布于 2019-09-12 17:57:52
所以很明显,我不能看文件的创建。
我必须查看适当的目录,然后检查inotify_event是否创建了文件名。
谢谢你的阅读,也很抱歉交通堵塞。
https://stackoverflow.com/questions/57910083
复制相似问题