[Bug 199806] Add a new option letter "l" to make fopen() use O_SHLOCK or O_EXLOCK when calling open()

bugzilla-noreply at freebsd.org bugzilla-noreply at freebsd.org
Thu Apr 30 11:25:54 UTC 2015


https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=199806

            Bug ID: 199806
           Summary: Add a new option letter "l" to make fopen() use
                    O_SHLOCK or O_EXLOCK when calling open()
           Product: Base System
           Version: 11.0-CURRENT
          Hardware: Any
                OS: Any
            Status: New
          Severity: Affects Some People
          Priority: ---
         Component: kern
          Assignee: freebsd-bugs at FreeBSD.org
          Reporter: jau at iki.fi

Created attachment 156144
  --> https://bugs.freebsd.org/bugzilla/attachment.cgi?id=156144&action=edit
A patch to add the proposed new option letter to fopen()

This is a change proposal.

Since FreeBSD already has the open() flags O_SHLOCK and O_EXLOCK
it would make sense for the same feature to be also available when
calling fopen(). So, I propose adding a new option letter "l" to
force fopen() to add the suitable one of these locking flags when
calling open(), O_SHLOCK for "r" and O_EXLOCK for "w", "r+", etc.

Such an extension is of course non-standard, but when code portability
is not a big issue such an extension would make FreeBSD specific code
easier to read and write, and maybe also a bit more robust while avoiding
the need to go the extra mille passum to call fileno() and flock() later.

>From my point of view writing something like...

fp = fopen("whateverfile", "wb+lex");

... is a pretty neat idea. Either I get a handle to a completely
new file with the exclusive lock applied, and it will not be left
open after an exec*() call, or I get a NULL.

Obviously the same change applies to 10.1 as well, if the merits of
this idea are accepted.

-- 
You are receiving this mail because:
You are the assignee for the bug.


More information about the freebsd-bugs mailing list