diff options
author | etheisen <etheisen@cvs.openbsd.org> | 1996-08-28 07:31:52 +0000 |
---|---|---|
committer | etheisen <etheisen@cvs.openbsd.org> | 1996-08-28 07:31:52 +0000 |
commit | b8dca4b76ac15a97714916dbf440d3bff7b48186 (patch) | |
tree | f6d5793bb8175e3bbbc601b021e69ac9fa13b8cf /usr.bin | |
parent | 307e214ac824cbb928e0346645f83ff41ccf92d0 (diff) |
mkfifo now generates AF_UNIX sockets as well as fifos. Use the -s opt to
generate sockets.
Diffstat (limited to 'usr.bin')
-rw-r--r-- | usr.bin/mkfifo/mkfifo.1 | 20 | ||||
-rw-r--r-- | usr.bin/mkfifo/mkfifo.c | 46 |
2 files changed, 54 insertions, 12 deletions
diff --git a/usr.bin/mkfifo/mkfifo.1 b/usr.bin/mkfifo/mkfifo.1 index 63a1352deb9..10f72708b4f 100644 --- a/usr.bin/mkfifo/mkfifo.1 +++ b/usr.bin/mkfifo/mkfifo.1 @@ -1,4 +1,4 @@ -.\" $OpenBSD: mkfifo.1,v 1.2 1996/06/26 05:37:11 deraadt Exp $ +.\" $OpenBSD: mkfifo.1,v 1.3 1996/08/28 07:31:49 etheisen Exp $ .\" $NetBSD: mkfifo.1,v 1.4 1994/12/23 07:16:54 jtc Exp $ .\" .\" Copyright (c) 1990, 1993 @@ -42,14 +42,15 @@ .Os BSD 4.4 .Sh NAME .Nm mkfifo -.Nd make fifos +.Nd make fifos or sockets .Sh SYNOPSIS .Nm mkfifo .Op Fl m Ar mode -.Ar fifo_name ... +.Op Fl s +.Ar filename ... .Sh DESCRIPTION .Nm Mkfifo -creates the fifos requested, in the order specified, +creates the fifos or AF_UNIX sockets requested, in the order specified, using mode .Li \&0666 modified by the current @@ -68,6 +69,9 @@ and .Dq - operators are interpreted relative to an assumed initial mode of .Dq a=rw +.It Fl s +Create AF_UNIX socket names in the file system. +This is a non-standard extension. .El .Pp .Nm Mkfifo @@ -79,9 +83,13 @@ exits 0 if successful, and >0 if an error occurred. .Xr mkdir 1 , .Xr mknod 1 , .Xr rm 1 , -.Xr mkfifo 2 +.Xr mkfifo 2 , +.Xr socket 2 , +.Xr bind 2 .Sh STANDARDS -The +With the exception of the +.Fl s +flag, the .Nm mkfifo utility is expected to be .St -p1003.2-92 diff --git a/usr.bin/mkfifo/mkfifo.c b/usr.bin/mkfifo/mkfifo.c index 38517d752b0..58736052c46 100644 --- a/usr.bin/mkfifo/mkfifo.c +++ b/usr.bin/mkfifo/mkfifo.c @@ -1,4 +1,4 @@ -/* $OpenBSD: mkfifo.c,v 1.2 1996/06/26 05:37:11 deraadt Exp $ */ +/* $OpenBSD: mkfifo.c,v 1.3 1996/08/28 07:31:51 etheisen Exp $ */ /* $NetBSD: mkfifo.c,v 1.7 1994/12/23 07:16:56 jtc Exp $ */ /* @@ -44,7 +44,7 @@ static char copyright[] = #if 0 static char sccsid[] = "@(#)mkfifo.c 8.2 (Berkeley) 1/5/94"; #endif -static char rcsid[] = "$OpenBSD: mkfifo.c,v 1.2 1996/06/26 05:37:11 deraadt Exp $"; +static char rcsid[] = "$OpenBSD: mkfifo.c,v 1.3 1996/08/28 07:31:51 etheisen Exp $"; #endif /* not lint */ #include <stdio.h> @@ -53,12 +53,16 @@ static char rcsid[] = "$OpenBSD: mkfifo.c,v 1.2 1996/06/26 05:37:11 deraadt Exp #include <locale.h> #include <errno.h> #include <sys/types.h> +#include <sys/socket.h> +#include <sys/un.h> #include <sys/stat.h> #include <unistd.h> #include <err.h> static void usage(); +int mksocket; + int main(argc, argv) int argc; @@ -67,6 +71,8 @@ main(argc, argv) int ch, exitval; void * set; mode_t mode; + int sock; + struct sockaddr_un name; setlocale (LC_ALL, ""); @@ -75,7 +81,7 @@ main(argc, argv) modified by the file creation mask */ mode = 0666 & ~umask(0); - while ((ch = getopt(argc, argv, "m:")) != -1) + while ((ch = getopt(argc, argv, "m:s")) != -1) switch(ch) { case 'm': if (!(set = setmode(optarg))) { @@ -87,6 +93,9 @@ main(argc, argv) a=rw. */ mode = getmode (set, 0666); break; + case 's': + mksocket = 1; + break; case '?': default: usage(); @@ -96,18 +105,43 @@ main(argc, argv) if (argv[0] == NULL) usage(); - for (exitval = 0; *argv; ++argv) { - if (mkfifo(*argv, mode) < 0) { + if (mksocket) { + for (exitval = 0; *argv; ++argv) { + if ((sock = socket(AF_UNIX, SOCK_DGRAM, 0)) < 0) + goto error; + + name.sun_family = AF_UNIX; + strncpy(name.sun_path, *argv, sizeof(name.sun_path)-1); + name.sun_path[sizeof(name.sun_path) - 1]; + if (bind(sock, (struct sockaddr *)&name, + SUN_LEN(&name)) < 0) + goto error; + + if (chmod(*argv, mode) < 0) { + unlink(*argv); + goto error; + } + + continue; +error: warn("%s", *argv); exitval = 1; } } + else { + for (exitval = 0; *argv; ++argv) { + if (mkfifo(*argv, mode) < 0) { + warn("%s", *argv); + exitval = 1; + } + } + } exit(exitval); } void usage() { - (void)fprintf(stderr, "usage: mkfifo [-m mode] fifoname ...\n"); + (void)fprintf(stderr, "usage: mkfifo [-m mode] [-s] filename ...\n"); exit(1); } |