blob: 84d8d99ddd52ef148ac82bb1da6a44db88a9256d [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 */
9
Manuel Novoa III cad53642003-03-19 09:13:01 +000010/* BB_AUDIT SUSv3 compliant */
11/* http://www.opengroup.org/onlinepubs/007904975/utilities/mkfifo.html */
12
Pere Orga34425382011-03-31 14:43:25 +020013//usage:#define mkfifo_trivial_usage
14//usage: "[-m MODE] " IF_SELINUX("[-Z] ") "NAME"
15//usage:#define mkfifo_full_usage "\n\n"
16//usage: "Create named pipe\n"
17//usage: "\nOptions:"
18//usage: "\n -m MODE Mode (default a=rw)"
19//usage: IF_SELINUX(
20//usage: "\n -Z Set security context"
21//usage: )
22
Denis Vlasenkob6adbf12007-05-26 19:00:18 +000023#include "libbb.h"
Manuel Novoa III cad53642003-03-19 09:13:01 +000024#include "libcoreutils/coreutils.h"
Eric Andersen19db07b1999-12-11 08:41:28 +000025
Dan Fandrich2d1a78b2010-09-30 14:31:12 -070026/* This is a NOEXEC applet. Be very careful! */
27
Denis Vlasenko9b49a5e2007-10-11 10:05:36 +000028int mkfifo_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
Denis Vlasenkoa60f84e2008-07-05 09:18:54 +000029int mkfifo_main(int argc UNUSED_PARAM, char **argv)
Eric Andersen19db07b1999-12-11 08:41:28 +000030{
Manuel Novoa III cad53642003-03-19 09:13:01 +000031 mode_t mode;
32 int retval = EXIT_SUCCESS;
Eric Andersen19db07b1999-12-11 08:41:28 +000033
Denis Vlasenko68404f12008-03-17 09:00:54 +000034 mode = getopt_mk_fifo_nod(argv);
Erik Andersene49d5ec2000-02-08 19:58:47 +000035
Denis Vlasenko99912ca2007-04-10 15:43:37 +000036 argv += optind;
37 if (!*argv) {
Manuel Novoa III cad53642003-03-19 09:13:01 +000038 bb_show_usage();
Erik Andersene49d5ec2000-02-08 19:58:47 +000039 }
Manuel Novoa III cad53642003-03-19 09:13:01 +000040
41 do {
42 if (mkfifo(*argv, mode) < 0) {
Denys Vlasenkoe4dcba12010-10-28 18:57:19 +020043 bb_simple_perror_msg(*argv); /* Avoid multibyte problems. */
Manuel Novoa III cad53642003-03-19 09:13:01 +000044 retval = EXIT_FAILURE;
45 }
46 } while (*++argv);
47
48 return retval;
Eric Andersen19db07b1999-12-11 08:41:28 +000049}