[GNU Manual] [POSIX requirement] [Linux man] [FreeBSD man]
Summary
mkfifo - make fifos (named pipes)
Lines of code: 183
Principal syscall: mkfifo() (BSD syscall, otherwise this is standard library call to mknod())
Support syscalls: fchmodat() via lchmod()
for links
Options: 6 (2 short, 4 long)
Descended from mknod introduced in Version 6 UNIX (1975)
Added to Fileutils in October 1992 [First version]
Number of revisions: 129 [Code Evolution]
- None
die()
- Exit with mandatory non-zero error and message to stderrerror()
- Outputs error message to standard error with possible process terminationmode_adjust()
- Performs file permissions changesmode_compile()
- Creates an array of mode change operationsquote()
- Outputs a printable stringquoteaf()
- Outputs a printable argument
Setup
mkfifo initializes local variables in main()
, including:
newmode
- A file mode in UGO format*specified_mode
- A file mode as input by the userexit_status
- Utility exit status (EXIT_*)optc
- The next option to process*scontext
- The user specified security contextset_security_context
- Flag to check security context labels in SELinux
Parsing
Parsing mkfifo considers two questions:
- What access mode is the named pipe?
- Are there security considerations? (SELinux / Smack)
Parsing failures
These failure cases are explicitly checked:
- Security context provided without a compliant kernel
- No operand provided
- Mode includes extraneous permissions
This failure result in a short error message followed by the usage instructions.
Execution
The utility has to prepare input arguments in to a usable form by the mkfifo()
call. The syscall/function call has this prototype:
int mkfifo(const char *path, mode_t mode);
While the user passes this to the utility:
mkfifo [option] nameā¦
The name is passed to path, while the utility must provide a proper mode.
The mkfifo
utility follows this logic:
- Verify the security context for file creation
- For each file:
- Set the security context
- Make the via
mkfifo()
or change file vialchmod()
- Return exit status (any failure forces EXIT_FAILURE)
Execution may fail if the mkfifo()
syscall is unable to create the file, or if the lchmod()
syscall cannot set permissions.