How to prevent an application from closing a file

I'm writing some software tests, & one of my test cases is to prevent an address space from closing a data file (file is closed & a new one opened every 15 minutes).

I can't remove or rename the file while it's being written to, any other ideas to prevent a file from being closed - or at least fake a return code from the system call so that the application thinks the close failed?

Do you have the source to the application?

Is this a reasonable test case given that the application does not do this normally?

What would you expect an application to do if it got an error from "close()"?

I, for one as a programmer, wouldn't assume the file was still open and continue to use the same filedescriptor. If I got an error from a close(), I would may report the error but have to treat the file descriptor as "undefined".

I do have access to the source code (albeit read only). This is an application that records system information to a file. The file is closed every 15 minutes and sent to Enterprise Storage. A new file is opened.

The application is supposed to post an alert in the event that it is unable to close the file when the timer pops. This is the case I am supposed to test. Failure to transfer the file is a separate test case.

I suggest you change the close code to...

#ifdef TEST_CLOSE_FAILED
         rc=-1;
         errno=EIO;
#else
         rc=close(fd);
#endif

However, an alternative would be to put this file on it's own partition then force a dismount of that partition, effectively simulating the loss of access to the storage media.

Thanks - the forced dismount is likely the best option since we are not permitted to modify code for formal testing.