Import mkfifo(1) from NetBSD

This commit is contained in:
Arun Thomas 2010-11-06 20:43:49 +00:00
parent 8f0846e68c
commit a575be430d
5 changed files with 189 additions and 210 deletions

View file

@ -1,4 +1,6 @@
# $NetBSD: Makefile,v 1.3 1994/12/23 07:16:52 jtc Exp $
# @(#)Makefile 8.1 (Berkeley) 6/6/93
PROG= mkfifo
MAN=
.include <bsd.prog.mk>

87
commands/mkfifo/mkfifo.1 Normal file
View file

@ -0,0 +1,87 @@
.\" $NetBSD: mkfifo.1,v 1.11 2004/10/08 22:32:35 wiz Exp $
.\"
.\" Copyright (c) 1990, 1993
.\" The Regents of the University of California. All rights reserved.
.\"
.\" This code is derived from software contributed to Berkeley by
.\" the Institute of Electrical and Electronics Engineers, Inc.
.\"
.\" Redistribution and use in source and binary forms, with or without
.\" modification, are permitted provided that the following conditions
.\" are met:
.\" 1. Redistributions of source code must retain the above copyright
.\" notice, this list of conditions and the following disclaimer.
.\" 2. Redistributions in binary form must reproduce the above copyright
.\" notice, this list of conditions and the following disclaimer in the
.\" documentation and/or other materials provided with the distribution.
.\" 3. Neither the name of the University nor the names of its contributors
.\" may be used to endorse or promote products derived from this software
.\" without specific prior written permission.
.\"
.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
.\" @(#)mkfifo.1 8.2 (Berkeley) 1/5/94
.\"
.Dd January 5, 1994
.Dt MKFIFO 1
.Os
.Sh NAME
.Nm mkfifo
.Nd make fifos
.Sh SYNOPSIS
.Nm
.Op Fl m Ar mode
.Ar fifo_name ...
.Sh DESCRIPTION
.Nm
creates the fifos requested, in the order specified,
using mode
.Li \&0666
modified by the current
.Xr umask 2 .
.Pp
The options are as follows:
.Bl -tag -width Ds
.It Fl m
Set the file permission bits of newly-created fifos to
.Ar mode .
The mode is specified as in
.Xr chmod 1 .
In symbolic mode strings, the
.Dq +
and
.Dq -
operators are interpreted relative to an assumed initial mode of
.Dq a=rw
.El
.Pp
.Nm
requires write permission in the parent directory.
.Pp
.Nm
exits 0 if successful, and \*[Gt]0 if an error occurred.
.Sh SEE ALSO
.Xr mkdir 1 ,
.Xr rm 1 ,
.Xr mkfifo 2 ,
.Xr mknod 8
.Sh STANDARDS
The
.Nm
utility is expected to be
.St -p1003.2-92
compliant.
.Sh HISTORY
.Nm
command appeared in
.Bx 4.4 .

View file

@ -1,194 +1,114 @@
/* mkfifo - Make FIFO special files Author: V. Archer */
/* $NetBSD: mkfifo.c,v 1.12 2008/07/21 14:19:24 lukem Exp $ */
/* Copyright 1991 by Vincent Archer
* You may freely redistribute this software, in source or binary
* form, provided that you do not alter this copyright mention in any
* way.
/*
* Copyright (c) 1990, 1993
* The Regents of the University of California. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
#include <sys/types.h>
#include <stdlib.h>
#include <sys/stat.h>
#include <string.h>
#include <unistd.h>
#include <minix/minlib.h>
#include <sys/cdefs.h>
#if 0
#ifndef lint
__COPYRIGHT("@(#) Copyright (c) 1990, 1993\
The Regents of the University of California. All rights reserved.");
#endif /* not lint */
#endif
#if 0
#ifndef lint
#if 0
static char sccsid[] = "@(#)mkfifo.c 8.2 (Berkeley) 1/5/94";
#endif
__RCSID("$NetBSD: mkfifo.c,v 1.12 2008/07/21 14:19:24 lukem Exp $");
#endif /* not lint */
#endif
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <locale.h>
#include <errno.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#include <err.h>
#define USR_MODES (S_ISUID|S_IRWXU)
#define GRP_MODES (S_ISGID|S_IRWXG)
#define EXE_MODES (S_IXUSR|S_IXGRP|S_IXOTH)
#ifdef S_ISVTX
#define ALL_MODES (USR_MODES|GRP_MODES|S_IRWXO|S_ISVTX)
#else
#define ALL_MODES (USR_MODES|GRP_MODES|S_IRWXO)
#endif
#define DEFAULT_MODE (S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP|S_IROTH|S_IWOTH)
int main __P((int, char **));
static void usage __P((void));
/* Global u_mask needed in changemode.h */
mode_t u_mask;
_PROTOTYPE(int main, (int argc, char **argv));
_PROTOTYPE(mode_t parsemode, (char *symbolic, mode_t oldmode));
_PROTOTYPE(void usage, (void));
/* Parse a P1003.2 4.7.7-conformant symbolic mode. */
mode_t parsemode(char *symbolic, mode_t oldmode)
int
main(argc, argv)
int argc;
char *argv[];
{
mode_t who, mask, newmode, tmpmask;
char action;
int ch, exitval;
void *set;
mode_t mode;
newmode = oldmode & ALL_MODES;
while (*symbolic) {
who = 0;
for (; *symbolic; symbolic++) {
if (*symbolic == 'a') {
who |= ALL_MODES;
continue;
}
if (*symbolic == 'u') {
who |= USR_MODES;
continue;
}
if (*symbolic == 'g') {
who |= GRP_MODES;
continue;
}
if (*symbolic == 'o') {
who |= S_IRWXO;
continue;
}
break;
}
if (!*symbolic || *symbolic == ',') usage();
while (*symbolic) {
if (*symbolic == ',') break;
switch (*symbolic) {
default:
setlocale (LC_ALL, "");
/* The default mode is the value of the bitwise inclusive or of
S_IRUSR, S_IWUSR, S_IRGRP, S_IWGRP, S_IROTH, and S_IWOTH
modified by the file creation mask */
mode = 0666 & ~umask(0);
while ((ch = getopt(argc, argv, "m:")) != -1)
switch(ch) {
case 'm':
if (!(set = setmode(optarg))) {
err(1, "Cannot set file mode `%s'", optarg);
/* NOTREACHED */
}
/* In symbolic mode strings, the + and - operators are
interpreted relative to an assumed initial mode of
a=rw. */
mode = getmode(set, 0666);
free(set);
break;
case '?':
default:
usage();
case '+':
case '-':
case '=': action = *symbolic++;
}
mask = 0;
for (; *symbolic; symbolic++) {
if (*symbolic == 'u') {
tmpmask = newmode & S_IRWXU;
mask |= tmpmask | (tmpmask << 3) | (tmpmask << 6);
symbolic++;
break;
}
if (*symbolic == 'g') {
tmpmask = newmode & S_IRWXG;
mask |= tmpmask | (tmpmask >> 3) | (tmpmask << 3);
symbolic++;
break;
}
if (*symbolic == 'o') {
tmpmask = newmode & S_IRWXO;
mask |= tmpmask | (tmpmask >> 3) | (tmpmask >> 6);
symbolic++;
break;
}
if (*symbolic == 'r') {
mask |= S_IRUSR | S_IRGRP | S_IROTH;
continue;
}
if (*symbolic == 'w') {
mask |= S_IWUSR | S_IWGRP | S_IWOTH;
continue;
}
if (*symbolic == 'x') {
mask |= EXE_MODES;
continue;
}
if (*symbolic == 's') {
mask |= S_ISUID | S_ISGID;
continue;
}
if (*symbolic == 'X') {
if (S_ISDIR(oldmode) || (oldmode & EXE_MODES))
mask |= EXE_MODES;
continue;
}
#ifdef S_ISVTX
if (*symbolic == 't') {
mask |= S_ISVTX;
who |= S_ISVTX;
continue;
}
#endif
break;
}
switch (action) {
case '=':
if (who)
newmode &= ~who;
else
newmode = 0;
case '+':
if (who)
newmode |= who & mask;
else
newmode |= mask & (~u_mask);
break;
case '-':
if (who)
newmode &= ~(who & mask);
else
newmode &= ~mask | u_mask;
argc -= optind;
argv += optind;
if (argv[0] == NULL)
usage();
for (exitval = 0; *argv; ++argv) {
if (mkfifo(*argv, mode) < 0) {
warn("%s", *argv);
exitval = 1;
}
}
if (*symbolic) symbolic++;
}
return(newmode);
exit(exitval);
}
/* Main module. Since only one option (-m mode) is allowed, there's no need
* to include the whole getopt() stuff.
*/
int main(argc, argv)
int argc;
char *argv[];
void
usage()
{
int errors = 0;
char *symbolic;
if (argc > 2 && *argv[1] == '-' && strcmp(argv[1], "-m") != 0) usage();
argc--;
argv++;
if (argc && strncmp(*argv, "-m", (size_t) 2) == 0) {
argc--;
if ((argv[0])[2])
symbolic = (*argv++) + 2;
else {
if (!argc--) usage();
argv++;
symbolic = *argv++;
}
u_mask = umask(0);
umask(u_mask);
} else
symbolic = (char *) 0;
if (!argc) usage();
for (; argc--; argv++)
if (mkfifo(*argv, DEFAULT_MODE)) {
perror(*argv);
errors = 1;
} else if (symbolic && chmod(*argv, parsemode(symbolic, DEFAULT_MODE))) {
unlink(*argv);
perror(*argv);
errors = 1;
}
return(errors);
}
/* Posix command prototype. */
void usage()
{
std_err("Usage: mkfifo [-m mode] file...\n");
exit(1);
(void)fprintf(stderr, "usage: mkfifo [-m mode] fifoname ...\n");
exit(1);
}

View file

@ -11,7 +11,7 @@ MAN= acd.1 anm.1 ar.1 ash.1 asize.1 at.1 banner.1 basename.1 \
install.1 isodir.1 isoinfo.1 isoread.1 join.1 kill.1 \
last.1 leave.1 loadfont.1 loadkeys.1 logger.1 login.1 \
look.1 lp.1 ls.1 lspci.1 M.1 mail.1 \
mesg.1 mixer.1 mkdep.1 mkdir.1 mkfifo.1 mkfs.1 \
mesg.1 mixer.1 mkdep.1 mkdir.1 mkfs.1 \
mkproto.1 modem.1 mount.1 mt.1 nice.1 nm.1 nohup.1 od.1 \
ossinfo.1 ossmix.1 ossplay.1 ossrecord.1 osstest.1 passwd.1 \
paste.1 ping.1 playwave.1 postmort.1 pr.1 prep.1 \

View file

@ -1,30 +0,0 @@
.TH MKFIFO 1
.SH NAME
mkfifo \- make a named pipe
.SH SYNOPSIS
\fBmkfifo [\fB\-m \fImode\fR] \fIfifo ...\fR
.br
.de FL
.TP
\\fB\\$1\\fR
\\$2
..
.de EX
.TP 20
\\fB\\$1\\fR
# \\$2
..
.SH OPTIONS
.FL "\-m" "Create fifo with specified mode"
.SH EXAMPLES
.EX "mkfifo pipe" "Create \fIpipe\fP in the current directory"
.EX "mkfifo -m a+w systatus" "Create the \fIsystatus\fP writable by all"
.SH DESCRIPTION
.PP
The specified fifo special files are created.
If the \fB\-m\fR flag is used, this will be equivalent to a chmod
on the fifo special file after its creation.
.SH "SEE ALSO"
.BR chmod (1),
.BR mknod (2),
.BR mknod (8).