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:
Michael Forney 2019-06-13 13:45:37 -07:00
parent 9a17de569a
commit 01b5105e0c
1 changed files with 4 additions and 12 deletions

View File

@ -14,14 +14,12 @@ usage(void)
int
main(int argc, char *argv[])
{
mode_t mode = 0666, mask;
int mflag = 0, ret = 0;
mode_t mode = 0666;
int ret = 0;
ARGBEGIN {
case 'm':
mflag = 1;
mask = getumask();
mode = parsemode(EARGF(usage()), mode, mask);
mode = parsemode(EARGF(usage()), mode, umask(0));
break;
default:
usage();
@ -31,15 +29,9 @@ main(int argc, char *argv[])
usage();
for (; *argv; argc--, argv++) {
if (mkfifo(*argv, S_IRUSR | S_IWUSR | S_IRGRP |
S_IWGRP | S_IROTH | S_IWOTH) < 0) {
if (mkfifo(*argv, mode) < 0) {
weprintf("mkfifo %s:", *argv);
ret = 1;
} else if (mflag) {
if (chmod(*argv, mode) < 0) {
weprintf("chmod %s:", *argv);
ret = 1;
}
}
}