How to prevent an application from closing a file


 
Thread Tools Search this Thread
Operating Systems AIX How to prevent an application from closing a file
# 1  
Old 01-06-2008
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?
# 2  
Old 01-06-2008
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".
# 3  
Old 01-06-2008
Quote:
Originally Posted by porter
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.
# 4  
Old 01-06-2008
I suggest you change the close code to...

Code:
#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.
# 5  
Old 01-06-2008
Thanks - the forced dismount is likely the best option since we are not permitted to modify code for formal testing.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Closing a graphical application by pid

Hi all, I have a small graphical application whose only purpose is to pop up certain types of messages. Currently, I'm using it in a Bash script like this: ./MyProg "this is my message" while do ... do things ... done What I want to do is after the while loop is over (it does... (4 Replies)
Discussion started by: Zel2008
4 Replies

2. Programming

How to prevent a C++ program reading a file that is still being written to.?

Hi, Hopefully someone can help. We have a process that writes a file using Connect Direct to our local Solaris server and then our C++ program will pick up the file and process it. Unfortunately, because of the size of the file, the C++ program is processing the file before it has finished... (7 Replies)
Discussion started by: chris01010
7 Replies

3. Shell Programming and Scripting

Prevent word splitting with file with spaces in name

Hello, I have a script that "validates" a ZIP file that look like this AAA_20120801.zip => x~back end~20120801.TXT y~time in~20120801.TXT z~heat_chamber~20120801.TXT AAA_20120801.ctlMy task is to compare its contents (i.e the list of files contained inside) with the control file that is... (2 Replies)
Discussion started by: alan
2 Replies

4. UNIX for Dummies Questions & Answers

Prevent terminal from closing after command execution

Hello, I want to create application which launches some terminal, then some command is executed on that terminal and then prevent terminal from closing. I started to do on gnome-terminal because the Gnome is the most widely used desktop-manager in the Linux distributions. I want to do... (3 Replies)
Discussion started by: tyanata
3 Replies

5. Shell Programming and Scripting

Closing open file descriptors from /proc/pid/fd

Hi guys, i need to write a shell script that will close file descriptors from /proc/pid/fd will calling exec 4<&- solve the problem ? thanks in advance :) (15 Replies)
Discussion started by: alpha_romeo
15 Replies

6. Shell Programming and Scripting

bash: closing file descriptors from a process

Below is a test script to illustrate a problem from a larger script I am writing. $ cat /tmp/loggingtest #!/bin/bash lvcreate -s -l 100%FREE -n var-data-snapshot vg00/var-data 2> >(logger -t "loggingtest.crit") 1> >(logger -t "loggingtest.info") sync & wait lvremove -f... (1 Reply)
Discussion started by: jelloir
1 Replies

7. Shell Programming and Scripting

prevent errors/warnings from being written to log file

i have this script which works fine but shows errors when it runs..these are more like warnings and the script runs fine.. i am on a sun machine.. i know it writes all the error messages to a master log file.. is there any way i can turn off these warnings/error messages and prevent them from being... (2 Replies)
Discussion started by: npatwardhan
2 Replies

8. Shell Programming and Scripting

Prevent file from being mailed multiple times from a job

We have a ksh which runs once every 15 minutes. Based on a certain condition (for invalid data) we are spooling a file and if the file is of length greater than 0 bytes, then we are mailing this file to a group of users. Upon receiving the file, users correct the data so that on its next run the... (2 Replies)
Discussion started by: Sree_2503
2 Replies

9. Programming

Error closing read file

Every time I close a file that I opened for reading I get the following error: ”Memory fault(coredump)”. And, although it does not (I think) affect the overall process (I write another file based on the file I am reading); it is something I would rather not happen. I don't know why this is... (1 Reply)
Discussion started by: ALTRUNVRSOFLN
1 Replies

10. UNIX for Dummies Questions & Answers

prevent file size is too large

We have EDP members will do some testing job in my system , but sometimes these process will generate some error to the system log or any file ( usually the members don't know the log is reached to this level ) , then make the system crashed , could suggest the way how can to prevent this problem ?... (2 Replies)
Discussion started by: ust
2 Replies
Login or Register to Ask a Question