1 /* mkfifo.c - Create FIFOs (named pipes)
2  *
3  * Copyright 2012 Georgi Chorbadzhiyski <georgi@unixsol.org>
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 
GLOBALS(char * m_string;char * Z;mode_t mode;)30 GLOBALS(
31   char *m_string;
32   char *Z;
33 
34   mode_t mode;
35 )
36 
37 void mkfifo_main(void)
38 {
39   char **s;
40 
41   TT.mode = 0666;
42   if (toys.optflags & FLAG_m) TT.mode = string_to_mode(TT.m_string, 0);
43 
44   if (CFG_MKFIFO_Z && (toys.optflags&FLAG_Z))
45     if (0>lsm_set_create(TT.Z))
46       perror_exit("-Z '%s' failed", TT.Z);
47 
48   for (s = toys.optargs; *s; s++)
49     if (mknod(*s, S_IFIFO | TT.mode, 0) < 0) perror_msg_raw(*s);
50 }
51