diff options
author | Todd C. Miller <millert@cvs.openbsd.org> | 1999-04-18 19:40:42 +0000 |
---|---|---|
committer | Todd C. Miller <millert@cvs.openbsd.org> | 1999-04-18 19:40:42 +0000 |
commit | 4d9f93dd72e2e01f1a67a9921877781abbdba645 (patch) | |
tree | 1f35d0a77aa42378c5028aec45d0fec4e98dca97 | |
parent | e5c20e136bcb15eb3420a59a8c1e38f3210e6171 (diff) |
merge mknod and mkfifo, support 'p' in mknod
-rw-r--r-- | sbin/mknod/Makefile | 8 | ||||
-rw-r--r-- | sbin/mknod/mkfifo.1 | 94 | ||||
-rw-r--r-- | sbin/mknod/mknod.8 | 36 | ||||
-rw-r--r-- | sbin/mknod/mknod.c | 131 |
4 files changed, 228 insertions, 41 deletions
diff --git a/sbin/mknod/Makefile b/sbin/mknod/Makefile index 0649c92d29d..d163a7b237a 100644 --- a/sbin/mknod/Makefile +++ b/sbin/mknod/Makefile @@ -1,6 +1,10 @@ -# $OpenBSD: Makefile,v 1.3 1997/09/21 11:36:55 deraadt Exp $ +# $OpenBSD: Makefile,v 1.4 1999/04/18 19:40:41 millert Exp $ PROG= mknod -MAN= mknod.8 +MAN= mknod.8 mkfifo.1 +LINKS= ${BINDIR}/mknod ${BINDIR}/mkfifo .include <bsd.prog.mk> + +beforeinstall: + ln -f -s ../../sbin/mknod ${DESTDIR}/usr/bin/mkfifo diff --git a/sbin/mknod/mkfifo.1 b/sbin/mknod/mkfifo.1 new file mode 100644 index 00000000000..2bda345f04a --- /dev/null +++ b/sbin/mknod/mkfifo.1 @@ -0,0 +1,94 @@ +.\" $OpenBSD: mkfifo.1,v 1.1 1999/04/18 19:40:41 millert Exp $ +.\" $NetBSD: mkfifo.1,v 1.4 1994/12/23 07:16:54 jtc 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. All advertising materials mentioning features or use of this software +.\" must display the following acknowledgement: +.\" This product includes software developed by the University of +.\" California, Berkeley and its contributors. +.\" 4. 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 BSD 4.4 +.Sh NAME +.Nm mkfifo +.Nd make FIFOs +.Sh SYNOPSIS +.Nm mkfifo +.Op Fl m Ar mode +.Ar fifo_name ... +.Sh DESCRIPTION +.Nm mkfifo +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 Ar mode +Set the file permission bits of newly-created directories 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 mkfifo +requires write permission in the parent directory. +.Pp +The +.Nm mkfifo +utility exits 0 on success or >0 if an error occurred. +.Sh SEE ALSO +.Xr mkdir 1 , +.Xr rm 1 , +.Xr mkfifo 2 , +.Xr mknod 8 +.Sh STANDARDS +The +.Nm mkfifo +utility is expected to be +.St -p1003.2-92 +compliant. +.Sh HISTORY +The +.Nm +command appeared in +.Bx 4.4 . diff --git a/sbin/mknod/mknod.8 b/sbin/mknod/mknod.8 index 9df329e40ae..e94a912614b 100644 --- a/sbin/mknod/mknod.8 +++ b/sbin/mknod/mknod.8 @@ -1,4 +1,4 @@ -.\" $OpenBSD: mknod.8,v 1.6 1998/12/15 01:20:32 aaron Exp $ +.\" $OpenBSD: mknod.8,v 1.7 1999/04/18 19:40:41 millert Exp $ .\" $NetBSD: mknod.8,v 1.9 1995/08/10 23:47:32 jtc Exp $ .\" .\" Copyright (c) 1980, 1991, 1993 @@ -34,17 +34,22 @@ .\" .\" @(#)mknod.8 8.2 (Berkeley) 12/11/93 .\" -.Dd December 11, 1993 +.Dd April 18, 1999 .Dt MKNOD 8 -.Os BSD 4 +.Os .Sh NAME .Nm mknod .Nd build special file .Sh SYNOPSIS .Nm mknod +.Op Fl m Ar mode .Ar name .Op Cm c | Cm b .Ar major minor +.Nm mknod +.Op Fl m Ar mode +.Ar name +.Cm p .Sh DESCRIPTION The .Nm @@ -56,16 +61,16 @@ is used to create special files for commonly known devices; it executes with the appropriate arguments and can make all the files required for the device. .Pp -To make nodes manually, the four required arguments are: +To make nodes manually, the arguments are: .Bl -tag -width majorx .It Ar name -Device name, for example +Device or FIFO name. For example .Dq sd -for a SCSI disk on an HP300 or a +for a SCSI disk or a .Dq pty -for pseudo-devices. -.It Cm b | Cm c -Type of device. If the +for pseudo-devices. FIFOs may be named arbitrarily by the user. +.It Cm b | Cm c | Cm p +Type of device or FIFO. If the device is a block type device such as a tape or disk drive which needs both cooked and raw special files, the type is @@ -73,19 +78,14 @@ the type is All other devices are character type devices, such as terminal and pseudo devices, and are type .Cm c . +A FIFO (also known as a named pipe) is type +.Cm p . .It Ar major The major device number is an integer number which tells the kernel which device driver entry point to use. To learn what major device number to use for a particular device, check the file .Pa /dev/MAKEDEV -to see if the device is known, or check -the system dependent device configuration file: -.Bd -filled -offset indent -.Dq Pa /usr/src/sys/conf/device. Ns Em architecture -.Ed -.Pp -(for example -.Pa device.hp300 ) . +to see if the device is known. .It Ar minor The minor device number tells the kernel which subunit the node corresponds to on the device; for example, @@ -101,6 +101,8 @@ indicates a hexadecimal number, and a leading will cause the number to be interpreted as octal. .El .Sh SEE ALSO +.Xr mkfifo 1 , +.Xr mkfifo 2 , .Xr mknod 2 , .Xr MAKEDEV 8 .Sh HISTORY diff --git a/sbin/mknod/mknod.c b/sbin/mknod/mknod.c index 4f8549ecf0d..bf8ac60a0f1 100644 --- a/sbin/mknod/mknod.c +++ b/sbin/mknod/mknod.c @@ -1,8 +1,8 @@ -/* $OpenBSD: mknod.c,v 1.5 1997/10/04 19:30:16 deraadt Exp $ */ +/* $OpenBSD: mknod.c,v 1.6 1999/04/18 19:40:41 millert Exp $ */ /* $NetBSD: mknod.c,v 1.8 1995/08/11 00:08:18 jtc Exp $ */ /* - * Copyright (c) 1989, 1993 + * Copyright (c) 1989, 1990, 1993 * The Regents of the University of California. All rights reserved. * * This code is derived from software contributed to Berkeley by @@ -47,7 +47,7 @@ static char copyright[] = #if 0 static char sccsid[] = "@(#)mknod.c 8.1 (Berkeley) 6/5/93"; #else -static char rcsid[] = "$OpenBSD: mknod.c,v 1.5 1997/10/04 19:30:16 deraadt Exp $"; +static char rcsid[] = "$OpenBSD: mknod.c,v 1.6 1999/04/18 19:40:41 millert Exp $"; #endif #endif /* not lint */ @@ -55,43 +55,104 @@ static char rcsid[] = "$OpenBSD: mknod.c,v 1.5 1997/10/04 19:30:16 deraadt Exp $ #include <sys/stat.h> #include <stdio.h> #include <stdlib.h> +#include <string.h> #include <unistd.h> +#include <locale.h> #include <err.h> -static void usage(); +extern char *__progname; + +int domknod __P((int, char **, mode_t)); +int domkfifo __P((int, char **, mode_t)); +void usage __P((int)); int main(argc, argv) int argc; char **argv; { - dev_t dev; - char *endp; - u_int major, minor; + int ch, ismkfifo = 0; + void *set = NULL; mode_t mode; - if (argc != 5) { - usage(); - /* NOTREACHED */ + setlocale (LC_ALL, ""); + + if (strcmp(__progname, "mkfifo") == 0) + ismkfifo = 1; + + while ((ch = getopt(argc, argv, "m:")) != -1) + switch(ch) { + case 'm': + if (!(set = setmode(optarg))) { + errx(1, "invalid file mode."); + /* 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(ismkfifo); + } + argc -= optind; + argv += optind; + + if (argv[0] == NULL) + usage(ismkfifo); + if (!ismkfifo) { + if (argc == 2 && argv[1][0] == 'p') { + ismkfifo = 2; + argc--; + argv[1] = NULL; + } else if (argc != 4) { + usage(ismkfifo); + /* NOTREACHED */ + } } - mode = 0666; - if (argv[2][0] == 'c') + /* 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 */ + if (!set) + mode = 0666; + + if (ismkfifo) + exit(domkfifo(argc, argv, mode)); + else + exit(domknod(argc, argv, mode)); +} + +int +domknod(argc, argv, mode) + int argc; + char **argv; + mode_t mode; +{ + dev_t dev; + char *endp; + u_int major, minor; + + if (argv[1][0] == 'c') mode |= S_IFCHR; - else if (argv[2][0] == 'b') + else if (argv[1][0] == 'b') mode |= S_IFBLK; else { errx(1, "node must be type 'b' or 'c'."); /* NOTREACHED */ } - major = (long)strtoul(argv[3], &endp, 10); - if (endp == argv[3] || *endp != '\0') { + major = (long)strtoul(argv[2], &endp, 10); + if (endp == argv[2] || *endp != '\0') { errx(1, "non-numeric major number."); /* NOTREACHED */ } - minor = (long)strtoul(argv[4], &endp, 10); - if (endp == argv[4] || *endp != '\0') { + minor = (long)strtoul(argv[3], &endp, 10); + if (endp == argv[3] || *endp != '\0') { errx(1, "non-numeric minor number."); /* NOTREACHED */ } @@ -100,17 +161,43 @@ main(argc, argv) errx(1, "major or minor number too large"); /* NOTREACHED */ } - if (mknod(argv[1], mode, dev) < 0) { - err(1, "%s", argv[1]); + if (mknod(argv[0], mode, dev) < 0) { + err(1, "%s", argv[0]); /* NOTREACHED */ } + return(0); +} - exit(0); +int +domkfifo(argc, argv, mode) + int argc; + char **argv; + mode_t mode; +{ + int rv; + + for (rv = 0; *argv; ++argv) { + if (mkfifo(*argv, mode) < 0) { + warn("%s", *argv); + rv = 1; + } + } + return(rv); } void -usage() +usage(ismkfifo) + int ismkfifo; { - fprintf(stderr, "usage: mknod name [b | c] major minor\n"); + + if (ismkfifo == 1) + (void)fprintf(stderr, "usage: %s [-m mode] fifoname ...\n", + __progname); + else { + (void)fprintf(stderr, "usage: %s [-m mode] name [b | c] major minor\n", + __progname); + (void)fprintf(stderr, "usage: %s [-m mode] name p\n", + __progname); + } exit(1); } |