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
O_EVTONLY caches the modified time for successive queries.