xref: /aosp_15_r20/external/toybox/toys/posix/mkfifo.c (revision cf5a6c84e2b8763fc1a7db14496fd4742913b199)
1 /* mkfifo.c - Create FIFOs (named pipes)
2  *
3  * Copyright 2012 Georgi Chorbadzhiyski <[email protected]>
4  *
5  * See http://opengroup.org/onlinepubs/9699919799/utilities/mkfifo.html
6 
7 USE_MKFIFO(NEWTOY(mkfifo, "<1"USE_MKFIFO_Z("Z:")"m:", TOYFLAG_USR|TOYFLAG_BIN))
8 
9 config MKFIFO
10   bool "mkfifo"
11   default y
12   help
13     usage: mkfifo [NAME...]
14 
15     Create FIFOs (named pipes).
16 
17 config MKFIFO_Z
18   bool
19   default y
20   depends on MKFIFO && !TOYBOX_LSM_NONE
21   help
22     usage: mkfifo [-Z CONTEXT]
23 
24     -Z	Security context
25 */
26 
27 #define FOR_mkfifo
28 #include "toys.h"
29 
30 GLOBALS(
31   char *m, *Z;
32 
33   mode_t mode;
34 )
35 
mkfifo_main(void)36 void mkfifo_main(void)
37 {
38   char **s;
39 
40   TT.mode = 0666;
41   if (FLAG(m)) TT.mode = string_to_mode(TT.m, 0);
42 
43   if (CFG_MKFIFO_Z && FLAG(Z))
44     if (0>lsm_set_create(TT.Z))
45       perror_exit("-Z '%s' failed", TT.Z);
46 
47   for (s = toys.optargs; *s; s++)
48     if (mknod(*s, S_IFIFO | TT.mode, 0) < 0) perror_msg_raw(*s);
49 }
50