Bug 243177

Summary: open(2): Add O_CREATFIFO flag
Product: Base System Reporter: Ronald F. Guilmette <rfg-freebsd>
Component: kernAssignee: freebsd-bugs (Nobody) <bugs>
Status: Open ---    
Severity: Affects Some People Keywords: feature, needs-patch
Priority: --- Flags: koobs: mfc-stable12?
Version: 12.0-RELEASE   
Hardware: Any   
OS: Any   

Description Ronald F. Guilmette 2020-01-08 07:56:06 UTC
The open(2) system call supports a number of optional flags which may be used to control the exact semantics of the open() operation.  Among these is O_CREAT which can be used to atomically create the specified file while effectively, from the userland point of view, simultaneously and uninterruptably creating the file.

The addition of the O_CREAT optional flag to the set of optional flags supported by open(2) was made decades ago in recognition of the fact that certain very troublesome race conditions could arise in userland programs in cases where the creation of a file and the opening of that same file might be performed non-atomically.

The exact same problem exists in the case where the file to be opened and created happens to be a POSIX FIFO file (POSIX 1003.1b-1993, Section 5.4.2.2.) however in this case it is currently necessary to make two separate, and therefore interruptable system calls (to mkfifo() and open()) in order to effect the creation and opening of a POSIX FIFO file, thus permitting troublesome race conditions of the kind that the O_CREAT flag for open(2) was created and implemented to eliminate.

The obvious solution is the addition a new option flag for the open(2) system call, analogous to the already existing O_CREAT flag, which will have the effect of both creating AND opening a POSIX FIFO file in a manner that is atomic and uninterruptable from the point of view of userland processes.  I would suggest the name O_CREATFIFO for this new flag, but any reasonable symbolic name will do, provided that the semantics implied are the atomic creation and opening of a FIFO file.