From 5ee026700b3c6922a1a12ece6a7ff4aa7bda5a84 Mon Sep 17 00:00:00 2001 From: sheldonh Date: Fri, 27 Aug 1999 10:40:27 +0000 Subject: Add -m option to specify a creation mode whcih is not affected by the umask of the calling process. PR: 13365 Reported by: James Howard Reviewed by: bde --- usr.bin/mkfifo/mkfifo.1 | 33 +++++++++++++++++++++++++++++---- usr.bin/mkfifo/mkfifo.c | 35 ++++++++++++++++++++++++++++++----- 2 files changed, 59 insertions(+), 9 deletions(-) diff --git a/usr.bin/mkfifo/mkfifo.1 b/usr.bin/mkfifo/mkfifo.1 index 3aa3ee9..44fe004 100644 --- a/usr.bin/mkfifo/mkfifo.1 +++ b/usr.bin/mkfifo/mkfifo.1 @@ -33,7 +33,7 @@ .\" SUCH DAMAGE. .\" .\" @(#)mkfifo.1 8.2 (Berkeley) 1/5/94 -.\" $Id$ +.\" $Id: mkfifo.1,v 1.4 1997/04/27 08:45:45 jmg Exp $ .\" .Dd January 5, 1994 .Dt MKFIFO 1 @@ -43,14 +43,39 @@ .Nd make fifos .Sh SYNOPSIS .Nm +.Op Fl m Ar mode .Ar fifo_name ... .Sh DESCRIPTION The .Nm -command creates the fifos requested, in the order specified, -using mode -.Li \&0777 . +command creates the fifos requested, in the order specified. .Pp +The options are as follows: +.Bl -tag -width indent +.It Fl m +Set the file permission bits of the created fifos to the +specified mode, ignoring the +.Xr umask 2 +of the calling process. +The mode argument takes any format that can be specified to the +.Xr chmod 1 +command. +If a symbolic mode is specified, the op symbols +.Dq + +(plus) and +.Dq - +(hyphen) are interpreted relative to an assumed initial mode of +.Dq a=rw +(read and write permissions for all). +.El +.Pp +If the +.Fl m +option is not specified, fifos are created with mode +.Li \&0666 +modified by the +.Xr umask 2 +of the calling process. The .Nm command requires write permission in the parent directory. diff --git a/usr.bin/mkfifo/mkfifo.c b/usr.bin/mkfifo/mkfifo.c index 1172cb7..270951a 100644 --- a/usr.bin/mkfifo/mkfifo.c +++ b/usr.bin/mkfifo/mkfifo.c @@ -42,29 +42,41 @@ static const char copyright[] = static char sccsid[] = "@(#)mkfifo.c 8.2 (Berkeley) 1/5/94"; #endif static const char rcsid[] = - "$Id$"; + "$Id: mkfifo.c,v 1.3 1997/07/24 07:02:55 charnier Exp $"; #endif /* not lint */ #include #include #include +#include #include #include #include +#define BASEMODE S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | \ + S_IROTH | S_IWOTH + static void usage __P((void)); +static int f_mode; + int main(argc, argv) int argc; char *argv[]; { - extern int optind; + char *modestr; + void *modep; + mode_t fifomode; int ch, exitval; - while ((ch = getopt(argc, argv, "")) != -1) + while ((ch = getopt(argc, argv, "m:")) != -1) switch(ch) { + case 'm': + f_mode = 1; + modestr = optarg; + break; case '?': default: usage(); @@ -74,8 +86,21 @@ main(argc, argv) if (argv[0] == NULL) usage(); + if (f_mode) { + umask(0); + errno = 0; + if ((modep = setmode(modestr)) == NULL) { + if (errno) + err(1, "setmode"); + errx(1, "invalid file mode: %s", modestr); + } + fifomode = getmode(modep, BASEMODE); + } else { + fifomode = BASEMODE; + } + for (exitval = 0; *argv != NULL; ++argv) - if (mkfifo(*argv, S_IRWXU | S_IRWXG | S_IRWXO) < 0) { + if (mkfifo(*argv, fifomode) < 0) { warn("%s", *argv); exitval = 1; } @@ -85,6 +110,6 @@ main(argc, argv) static void usage() { - (void)fprintf(stderr, "usage: mkfifo fifoname ...\n"); + (void)fprintf(stderr, "usage: mkfifo [-m mode] fifo_name ...\n"); exit(1); } -- cgit v1.1