Reputation: 14261
The code is supposed to watch for filesystem changes, but fstat is producing different results than stat, why?
struct stat info;
struct stat finfo;
char *path = "test";
int fd = open(path, O_EVTONLY);
if (fd <= 0){
exit(-1);
}
wait_for_write(fd);
int err = fstat(fd, &finfo);
if (err){
exit(-1);
}
err = stat(path, &info);
if (err){
exit(-1);
}
if (finfo.st_mtimespec.tv_sec != info.st_mtimespec.tv_sec){
//This happens!
exit(-1);
}
finfo.st_mtimespec.tv_sec
is the value corresponding to the time before the write occured and info.st_mtimespec.tv_sec
is the value corresponding to after
Upvotes: 0
Views: 1126
Reputation: 44250
You should not use finfo.st_mtimespec.tv_sec
, as it is internal to the implementation; use finfo.st_mtime
instead. (this is not the answer to your 'problem', but it may avoid related problems in the future)
Upvotes: 1