1828986 Members
2296 Online
109986 Solutions
New Discussion

HP UNIX open and lockf

 
Ronald Heyn
Occasional Advisor

HP UNIX open and lockf

I am dealing with legacy software. There exists an open call which sets both O_RDWR | O_SYNC. Will the inclusion of O_SYNC effect the use of lockf?

I have a case of the data in the file seemingly getting corrupted.

More than one process can call the function that opens the file, locks the file reads the file, adds 1 to a field in the file, writes it back and then unlocks the file. The value being incremented is getting incremented by alot. Note these calls are happening from copies of a program that are potentially handling lots of data (many calls).
4 REPLIES 4
James R. Ferguson
Acclaimed Contributor

Re: HP UNIX open and lockf

Hi:

> Will the inclusion of O_SYNC effect the use of lockf?

No. 'O_SYNC' simply means that the writing process will not be informed of an IO complete until both the updated data and the file's metadata are committed to disk.

As for file locking, remember that locking is only advisory regardless of whether they are exclusive attempts or shared ones. Hence, if all of your code isn't "playing nice" and observing locks, not-so-nice things can happen.

by the way, it would be appropriate for you to evaluate the responses you received in your earlier thread:

http://h30499.www3.hp.com/t5/Languages-and-Scripting/Automatic-Dayligh-Saving-Setting/m-p/4714709#M29056


Regards!

...JRF...

Ronald Heyn
Occasional Advisor

Re: HP UNIX open and lockf

Thankyou for the quick response. I think the code is effectively checking locks before reading and updating the file. The functions that try to do this open the file, attempt to lock it until 0 is returned and the read and update and write backto the file. One of the library routines unlocs and closes the file before exiting, the other simply closes the file.

There is a comment in the man page that I want to be sure I understand. It is "All locks for a process are released upon
the first close of the file, even if the process still has the file
opened,"

Can I assume the first close for this process is what is meant and it will not affect locks for another process?

Thanks,

Ron
Dennis Handly
Acclaimed Contributor

Re: HP UNIX open and lockf

>Can I assume the first close for this process is what is meant and it will not affect locks for another process?

The words seem clear in lockf(2):
WARNINGS When a file descriptor is closed, all locks on the file from the calling process are deleted, even if other file descriptors for that file still exist.
Ronald Heyn
Occasional Advisor

Re: HP UNIX open and lockf

Thanks, I was quite sure that was the answer, but because we are having the problem we are, I just wanted to be sure. I am at my wits end looking for the cause of the problem. It is hapening at more than one site and as of the moment I am stumped.

Ron