Bug 243177 - open(2): Add O_CREATFIFO flag
Summary: open(2): Add O_CREATFIFO flag
Status: Open
Alias: None
Product: Base System
Classification: Unclassified
Component: kern (show other bugs)
Version: 12.0-RELEASE
Hardware: Any Any
: --- Affects Some People
Assignee: freebsd-bugs (Nobody)
URL:
Keywords: feature, needs-patch
Depends on:
Blocks:
 
Reported: 2020-01-08 07:56 UTC by Ronald F. Guilmette
Modified: 2020-01-08 08:08 UTC (History)
0 users

See Also:
koobs: mfc-stable12?


Attachments

Note You need to log in before you can comment on or make changes to this bug.
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.