Record Locking with fcntl(): what to do if unlock (F_UNLCK) fails?
- From: denis.papathanasiou@xxxxxxxxx
- Date: 27 Sep 2006 07:02:56 -0700
Following the example in "Advanced Programming in the UNIX Environment"
book (http://apuebook.com/), I've written a function which will lock
and unlock an entire file:
int
lock_register(int fd, int type)
{
struct flock fl;
fl.l_type = type;
fl.l_start = 0;
fl.l_whence = SEEK_SET;
fl.l_len = 0;
return(fcntl(fd, F_SETLK, &fl));
}
And these header macros define the actual set & remove lock function
calls:
#define place_lock(fd) lock_register((fd), F_WRLCK)
#define remove_lock(fd) lock_register((fd), F_UNLCK)
It's been run in both debian and redhat environments, and in the tests
done so far, it works exactly as expected.
One potential problem, though, is what to do if the call to remove_lock
fails?
I'm concerned about the possibility about creating an unresolvable
deadlock in a case like this.
Is invoking a close() on the file descriptor enough to remove the lock,
or do we need to take other action when that occurs?
.
- Follow-Ups:
- Re: Record Locking with fcntl(): what to do if unlock (F_UNLCK) fails?
- From: Dances With Crows
- Re: Record Locking with fcntl(): what to do if unlock (F_UNLCK) fails?
- Prev by Date: Re: Where is GCC in Xubuntu?
- Next by Date: ADSENSE HELP GROUP IS A FRAUD
- Previous by thread: problem installation matlab
- Next by thread: Re: Record Locking with fcntl(): what to do if unlock (F_UNLCK) fails?
- Index(es):
Relevant Pages
|