1 /* vi: set sw=4 ts=4: */
2 /*
3  * mkfifo implementation for busybox
4  *
5  * Copyright (C) 2003  Manuel Novoa III  <mjn3@codepoet.org>
6  *
7  * Licensed under GPLv2 or later, see file LICENSE in this source tree.
8  */
9 //config:config MKFIFO
10 //config:	bool "mkfifo (3.8 kb)"
11 //config:	default y
12 //config:	help
13 //config:	mkfifo is used to create FIFOs (named pipes).
14 //config:	The 'mknod' program can also create FIFOs.
15 
16 //applet:IF_MKFIFO(APPLET_NOEXEC(mkfifo, mkfifo, BB_DIR_USR_BIN, BB_SUID_DROP, mkfifo))
17 
18 //kbuild:lib-$(CONFIG_MKFIFO) += mkfifo.o
19 
20 /* BB_AUDIT SUSv3 compliant */
21 /* http://www.opengroup.org/onlinepubs/007904975/utilities/mkfifo.html */
22 
23 //usage:#define mkfifo_trivial_usage
24 //usage:       "[-m MODE] " IF_SELINUX("[-Z] ") "NAME"
25 //usage:#define mkfifo_full_usage "\n\n"
26 //usage:       "Create named pipe\n"
27 //usage:     "\n	-m MODE	Mode (default a=rw)"
28 //usage:	IF_SELINUX(
29 //usage:     "\n	-Z	Set security context"
30 //usage:	)
31 
32 #include "libbb.h"
33 #include "libcoreutils/coreutils.h"
34 
35 /* This is a NOEXEC applet. Be very careful! */
36 
37 int mkfifo_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
mkfifo_main(int argc UNUSED_PARAM,char ** argv)38 int mkfifo_main(int argc UNUSED_PARAM, char **argv)
39 {
40 	mode_t mode;
41 	int retval = EXIT_SUCCESS;
42 
43 	mode = getopt_mk_fifo_nod(argv);
44 
45 	argv += optind;
46 	if (!*argv) {
47 		bb_show_usage();
48 	}
49 
50 	do {
51 		if (mkfifo(*argv, mode) < 0) {
52 			bb_simple_perror_msg(*argv);  /* Avoid multibyte problems. */
53 			retval = EXIT_FAILURE;
54 		}
55 	} while (*++argv);
56 
57 	return retval;
58 }
59