blob: e9d420ed8d9bc374d6b4352dadc6e33ad08aff71 [file] [log] [blame]
Erik Andersene49d5ec2000-02-08 19:58:47 +00001/* vi: set sw=4 ts=4: */
Eric Andersen19db07b1999-12-11 08:41:28 +00002/*
Manuel Novoa III cad53642003-03-19 09:13:01 +00003 * mkfifo implementation for busybox
Eric Andersen19db07b1999-12-11 08:41:28 +00004 *
Manuel Novoa III cad53642003-03-19 09:13:01 +00005 * Copyright (C) 2003 Manuel Novoa III <mjn3@codepoet.org>
Eric Andersen19db07b1999-12-11 08:41:28 +00006 *
Denys Vlasenko0ef64bd2010-08-16 20:14:46 +02007 * Licensed under GPLv2 or later, see file LICENSE in this source tree.
Eric Andersen19db07b1999-12-11 08:41:28 +00008 */
Denys Vlasenkoaf3f4202016-11-23 14:46:56 +01009//config:config MKFIFO
Denys Vlasenkob097a842018-12-28 03:20:17 +010010//config: bool "mkfifo (3.8 kb)"
Denys Vlasenkoaf3f4202016-11-23 14:46:56 +010011//config: default y
12//config: help
Denys Vlasenko72089cf2017-07-21 09:50:55 +020013//config: mkfifo is used to create FIFOs (named pipes).
14//config: The 'mknod' program can also create FIFOs.
Denys Vlasenkoaf3f4202016-11-23 14:46:56 +010015
16//applet:IF_MKFIFO(APPLET_NOEXEC(mkfifo, mkfifo, BB_DIR_USR_BIN, BB_SUID_DROP, mkfifo))
17
18//kbuild:lib-$(CONFIG_MKFIFO) += mkfifo.o
Eric Andersen19db07b1999-12-11 08:41:28 +000019
Manuel Novoa III cad53642003-03-19 09:13:01 +000020/* BB_AUDIT SUSv3 compliant */
21/* http://www.opengroup.org/onlinepubs/007904975/utilities/mkfifo.html */
22
Pere Orga34425382011-03-31 14:43:25 +020023//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"
Pere Orga34425382011-03-31 14:43:25 +020027//usage: "\n -m MODE Mode (default a=rw)"
28//usage: IF_SELINUX(
29//usage: "\n -Z Set security context"
30//usage: )
31
Denis Vlasenkob6adbf12007-05-26 19:00:18 +000032#include "libbb.h"
Manuel Novoa III cad53642003-03-19 09:13:01 +000033#include "libcoreutils/coreutils.h"
Eric Andersen19db07b1999-12-11 08:41:28 +000034
Dan Fandrich2d1a78b2010-09-30 14:31:12 -070035/* This is a NOEXEC applet. Be very careful! */
36
Denis Vlasenko9b49a5e2007-10-11 10:05:36 +000037int mkfifo_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
Denis Vlasenkoa60f84e2008-07-05 09:18:54 +000038int mkfifo_main(int argc UNUSED_PARAM, char **argv)
Eric Andersen19db07b1999-12-11 08:41:28 +000039{
Manuel Novoa III cad53642003-03-19 09:13:01 +000040 mode_t mode;
41 int retval = EXIT_SUCCESS;
Eric Andersen19db07b1999-12-11 08:41:28 +000042
Denis Vlasenko68404f12008-03-17 09:00:54 +000043 mode = getopt_mk_fifo_nod(argv);
Erik Andersene49d5ec2000-02-08 19:58:47 +000044
Denis Vlasenko99912ca2007-04-10 15:43:37 +000045 argv += optind;
46 if (!*argv) {
Manuel Novoa III cad53642003-03-19 09:13:01 +000047 bb_show_usage();
Erik Andersene49d5ec2000-02-08 19:58:47 +000048 }
Manuel Novoa III cad53642003-03-19 09:13:01 +000049
50 do {
51 if (mkfifo(*argv, mode) < 0) {
Denys Vlasenkoe4dcba12010-10-28 18:57:19 +020052 bb_simple_perror_msg(*argv); /* Avoid multibyte problems. */
Manuel Novoa III cad53642003-03-19 09:13:01 +000053 retval = EXIT_FAILURE;
54 }
55 } while (*++argv);
56
57 return retval;
Eric Andersen19db07b1999-12-11 08:41:28 +000058}