commit 01b5105e0c7439a358d095fe4703e88c31095178
parent 9a17de569a49b376068a210073885c97530a79cd
Author: Michael Forney <mforney@mforney.org>
Date: Thu, 13 Jun 2019 13:45:37 -0700
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).
Diffstat:
1 file changed, 4 insertions(+), 12 deletions(-)
diff --git a/mkfifo.c b/mkfifo.c
@@ -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;
- }
}
}