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 <howardjp@wam.umd.edu> Reviewed by: bde
This commit is contained in:
parent
1428ce0f83
commit
513c0475ca
@ -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.
|
||||
|
@ -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 <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
|
||||
#include <err.h>
|
||||
#include <errno.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#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);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user