mkfifo: Simplify -m handling
Rather than create the FIFO with incorrect permissions at first, then restore with chmod(2), just clear the umask when -m is specified, and pass the parsed mode to mkfifo(2).
This commit is contained in:
parent
9a17de569a
commit
01b5105e0c
16
mkfifo.c
16
mkfifo.c
|
@ -14,14 +14,12 @@ usage(void)
|
||||||
int
|
int
|
||||||
main(int argc, char *argv[])
|
main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
mode_t mode = 0666, mask;
|
mode_t mode = 0666;
|
||||||
int mflag = 0, ret = 0;
|
int ret = 0;
|
||||||
|
|
||||||
ARGBEGIN {
|
ARGBEGIN {
|
||||||
case 'm':
|
case 'm':
|
||||||
mflag = 1;
|
mode = parsemode(EARGF(usage()), mode, umask(0));
|
||||||
mask = getumask();
|
|
||||||
mode = parsemode(EARGF(usage()), mode, mask);
|
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
usage();
|
usage();
|
||||||
|
@ -31,15 +29,9 @@ main(int argc, char *argv[])
|
||||||
usage();
|
usage();
|
||||||
|
|
||||||
for (; *argv; argc--, argv++) {
|
for (; *argv; argc--, argv++) {
|
||||||
if (mkfifo(*argv, S_IRUSR | S_IWUSR | S_IRGRP |
|
if (mkfifo(*argv, mode) < 0) {
|
||||||
S_IWGRP | S_IROTH | S_IWOTH) < 0) {
|
|
||||||
weprintf("mkfifo %s:", *argv);
|
weprintf("mkfifo %s:", *argv);
|
||||||
ret = 1;
|
ret = 1;
|
||||||
} else if (mflag) {
|
|
||||||
if (chmod(*argv, mode) < 0) {
|
|
||||||
weprintf("chmod %s:", *argv);
|
|
||||||
ret = 1;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user