Feature #3252


Need a proper flock() implementation

Added by Robert Mustacchi almost 10 years ago. Updated over 6 years ago.

Start date:
Due date:
% Done:


Estimated time:
Gerrit CR:


Several pieces of software look for and require support for flock(). While this issue was originally about bringing in the version in libucb, it was obviously toxic because it didn't actually honor flock's semantics. This has instead been repurposed to add native support for flock.

Actions #1

Updated by Gary Mills almost 10 years ago

I hope it's defined in terms of lockf(). Most configure scripts test for the presence of flock() before lockf() and then adjust the code to call the one that they find.

Actions #3

Updated by Joseph Holsten almost 8 years ago

Looks like the one in libc isn't supporting non-blocking locks:

Also, it's not possible to implement flock(2) with lockf(3c) because lockf doesn't support shared logs.

Actions #4

Updated by Robert Mustacchi almost 8 years ago

  • Assignee changed from Robert Mustacchi to Joshua M. Clulow
  • % Done changed from 80 to 0

There are a lot more fundamental problems with this which is why this has stalled, which is that the semantics the libucb version has are unsafe at any speed for folks who are trying to use flock properly. This is something that Josh has been looking at in great detail.

Actions #5

Updated by Joseph Holsten almost 8 years ago

Ah, that's not fun. I'm trying to add illumos support to a flock(1) impl. I was going to attempt reimplementing the version I've got working on darwin, freebsd & linux to just use fcntl(2). But perhaps I should help investigate.

I'm starting over at which discusses the reason they implement flock() as its own syscall instead of a wrapper around fcntl().

I'll probably look into freebsd's implementation next.

Actions #6

Updated by Joseph Holsten almost 8 years ago

looks like freebsd's got a contrib doc on "BSD to HP-UX Porting Tricks" with a flock impl

and here's the syscall implementation:

Actions #7

Updated by Robert Mustacchi over 7 years ago

  • Subject changed from Move flock from libucb to libc to Need a proper flock() implementation
  • Category changed from lib - userland libraries to kernel
  • Status changed from New to In Progress
  • Assignee changed from Joshua M. Clulow to Jerry Jelinek
  • Priority changed from Low to Normal
  • % Done changed from 0 to 90
  • Difficulty changed from Medium to Hard
Actions #8

Updated by Robert Mustacchi over 7 years ago

As part of this Keith Wesolowski originally did a survey of the various differences between POSIX locks set through fcntl, lockf, flock, and the newer GNU OFD (open file descriptor) locks which are trying to tackle and more broadly standardize the notion of locks being set upon an open file descriptor. Based on this, he determined that a flock is basically a specialized type of OFD, hence implementation of similar APIs here.

Actions #9

Updated by Electric Monk over 6 years ago

  • Status changed from In Progress to Closed
  • % Done changed from 90 to 100

git commit 7a5aac98bc37534537d4896efd4efd30627d221e

commit  7a5aac98bc37534537d4896efd4efd30627d221e
Author: Jerry Jelinek <>
Date:   2015-11-25T00:26:22.000Z

    3252 Need a proper flock() implementation
    Reviewed by: Robert Mustacchi <>
    Reviewed by: Gordon Ross <>
    Reviewed by: Josef 'Jeff' Sipek <>
    Reviewed by: Jason King <>
    Approved by: Garrett D'Amore <>


Also available in: Atom PDF