Record Locking with fcntl(): what to do if unlock (F_UNLCK) fails?



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?

.



Relevant Pages

  • Record Locking with fcntl(): what to do if unlock (F_UNLCK) fails?
    ... Following the example in "Advanced Programming in the UNIX Environment" ... lock_register(int fd, int type) ... And these header macros define the actual set & remove lock function ...
    (comp.unix.programmer)
  • [git pull] core kernel updates for v2.6.29, #2
    ... swiotlb extensions to make it available to 32-bit ... lock debug: sit tight when we are already in a panic ... extern void unblock_signals; ... extern int force_iommu, no_iommu; ...
    (Linux-Kernel)
  • [git pull] core kernel updates for v2.6.29
    ... swiotlb extensions to make it available to 32-bit ... lock debug: sit tight when we are already in a panic ... extern void unblock_signals; ... extern int force_iommu, no_iommu; ...
    (Linux-Kernel)
  • [PATCH 3/6] lockdep: reduce the ifdeffery
    ... Move code around to get fewer but larger #ifdef sections. ... We put the lock dependency chains into a hash-table as well, ... +static int static_obj ...
    (Linux-Kernel)
  • [patch] PI-futex: -V2
    ... It's a "lock this chain" function call. ... +static int fastcall noinline __sched ... struct hrtimer_sleeper *timeout, ...
    (Linux-Kernel)