Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 1 | /* vi: set sw=4 ts=4: */ |
Eric Andersen | 19db07b | 1999-12-11 08:41:28 +0000 | [diff] [blame] | 2 | /* |
Manuel Novoa III | cad5364 | 2003-03-19 09:13:01 +0000 | [diff] [blame] | 3 | * mkfifo implementation for busybox |
Eric Andersen | 19db07b | 1999-12-11 08:41:28 +0000 | [diff] [blame] | 4 | * |
Manuel Novoa III | cad5364 | 2003-03-19 09:13:01 +0000 | [diff] [blame] | 5 | * Copyright (C) 2003 Manuel Novoa III <mjn3@codepoet.org> |
Eric Andersen | 19db07b | 1999-12-11 08:41:28 +0000 | [diff] [blame] | 6 | * |
Denys Vlasenko | 0ef64bd | 2010-08-16 20:14:46 +0200 | [diff] [blame] | 7 | * Licensed under GPLv2 or later, see file LICENSE in this source tree. |
Eric Andersen | 19db07b | 1999-12-11 08:41:28 +0000 | [diff] [blame] | 8 | */ |
Denys Vlasenko | af3f420 | 2016-11-23 14:46:56 +0100 | [diff] [blame] | 9 | //config:config MKFIFO |
Denys Vlasenko | 4eed2c6 | 2017-07-18 22:01:24 +0200 | [diff] [blame] | 10 | //config: bool "mkfifo (3.7 kb)" |
Denys Vlasenko | af3f420 | 2016-11-23 14:46:56 +0100 | [diff] [blame] | 11 | //config: default y |
| 12 | //config: help |
Denys Vlasenko | 72089cf | 2017-07-21 09:50:55 +0200 | [diff] [blame] | 13 | //config: mkfifo is used to create FIFOs (named pipes). |
| 14 | //config: The 'mknod' program can also create FIFOs. |
Denys Vlasenko | af3f420 | 2016-11-23 14:46:56 +0100 | [diff] [blame] | 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 |
Eric Andersen | 19db07b | 1999-12-11 08:41:28 +0000 | [diff] [blame] | 19 | |
Manuel Novoa III | cad5364 | 2003-03-19 09:13:01 +0000 | [diff] [blame] | 20 | /* BB_AUDIT SUSv3 compliant */ |
| 21 | /* http://www.opengroup.org/onlinepubs/007904975/utilities/mkfifo.html */ |
| 22 | |
Pere Orga | 3442538 | 2011-03-31 14:43:25 +0200 | [diff] [blame] | 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" |
Pere Orga | 3442538 | 2011-03-31 14:43:25 +0200 | [diff] [blame] | 27 | //usage: "\n -m MODE Mode (default a=rw)" |
| 28 | //usage: IF_SELINUX( |
| 29 | //usage: "\n -Z Set security context" |
| 30 | //usage: ) |
| 31 | |
Denis Vlasenko | b6adbf1 | 2007-05-26 19:00:18 +0000 | [diff] [blame] | 32 | #include "libbb.h" |
Manuel Novoa III | cad5364 | 2003-03-19 09:13:01 +0000 | [diff] [blame] | 33 | #include "libcoreutils/coreutils.h" |
Eric Andersen | 19db07b | 1999-12-11 08:41:28 +0000 | [diff] [blame] | 34 | |
Dan Fandrich | 2d1a78b | 2010-09-30 14:31:12 -0700 | [diff] [blame] | 35 | /* This is a NOEXEC applet. Be very careful! */ |
| 36 | |
Denis Vlasenko | 9b49a5e | 2007-10-11 10:05:36 +0000 | [diff] [blame] | 37 | int mkfifo_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; |
Denis Vlasenko | a60f84e | 2008-07-05 09:18:54 +0000 | [diff] [blame] | 38 | int mkfifo_main(int argc UNUSED_PARAM, char **argv) |
Eric Andersen | 19db07b | 1999-12-11 08:41:28 +0000 | [diff] [blame] | 39 | { |
Manuel Novoa III | cad5364 | 2003-03-19 09:13:01 +0000 | [diff] [blame] | 40 | mode_t mode; |
| 41 | int retval = EXIT_SUCCESS; |
Eric Andersen | 19db07b | 1999-12-11 08:41:28 +0000 | [diff] [blame] | 42 | |
Denis Vlasenko | 68404f1 | 2008-03-17 09:00:54 +0000 | [diff] [blame] | 43 | mode = getopt_mk_fifo_nod(argv); |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 44 | |
Denis Vlasenko | 99912ca | 2007-04-10 15:43:37 +0000 | [diff] [blame] | 45 | argv += optind; |
| 46 | if (!*argv) { |
Manuel Novoa III | cad5364 | 2003-03-19 09:13:01 +0000 | [diff] [blame] | 47 | bb_show_usage(); |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 48 | } |
Manuel Novoa III | cad5364 | 2003-03-19 09:13:01 +0000 | [diff] [blame] | 49 | |
| 50 | do { |
| 51 | if (mkfifo(*argv, mode) < 0) { |
Denys Vlasenko | e4dcba1 | 2010-10-28 18:57:19 +0200 | [diff] [blame] | 52 | bb_simple_perror_msg(*argv); /* Avoid multibyte problems. */ |
Manuel Novoa III | cad5364 | 2003-03-19 09:13:01 +0000 | [diff] [blame] | 53 | retval = EXIT_FAILURE; |
| 54 | } |
| 55 | } while (*++argv); |
| 56 | |
| 57 | return retval; |
Eric Andersen | 19db07b | 1999-12-11 08:41:28 +0000 | [diff] [blame] | 58 | } |