I am experiencing an interesting issue that makes no sense to me. I am writing to a file, and 2 seconds later a hardware watchdog is triggered, and the computer resets. However, I am not seeing my last write to the file. I put a print statement after fsync and fclose, which is being printed out, so I know they are being called with plenty of time to spare...yet it doesn't seem to actually be written to the file. This is in C++. I have to put a delay in of 6 seconds in order to see the write show up. Any idea's what could cause this behavior???
Asked
Active
Viewed 383 times
1
-
first thing - any kind of HD cache/buffer which is not flushed by fsync – Iłya Bursov Oct 15 '13 at 18:10
-
I just read on the linux man page: "Calling fsync() does not necessarily ensure that the entry in the directory containing the file has also reached disk. For that an explicit fsync() on a file descriptor for the directory is also needed." Not sure how to find the fd for directory, but this could maybe solve it?? – user2494298 Oct 15 '13 at 18:19
-
@user2494298 That's not Posix conform. However, you might try opening with `O_SYNC | O_DSYNC`. – James Kanze Oct 15 '13 at 18:23
-
1its really hard to tell, try at least adding fflush before fsync, if it doesnt work - try opendir to flush directory – Iłya Bursov Oct 15 '13 at 18:24
-
@IlyaBursov Good point with the `fflush`. Every time I've used `fsync`, it has been on a file opened with `open`, and written with `write`, so internal buffering didn't matter. – James Kanze Oct 15 '13 at 18:29
-
Nice, fflush() fixed it!!!!!!!!!!!!!!!!! THANK YOU!!!!! – user2494298 Oct 15 '13 at 18:54