diff options
author | Mike Smith <msmith@FreeBSD.org> | 1998-10-22 21:42:20 +0000 |
---|---|---|
committer | Mike Smith <msmith@FreeBSD.org> | 1998-10-22 21:42:20 +0000 |
commit | 16c0b5195cae2394d27ba44d41b34d055a7161b4 (patch) | |
tree | e7017b3d7e4acc119a695f8130ccbf6c7990d6ca /bin/mkdir/mkdir.c | |
parent | 8d35fb65a015db74256acb20035b360b628a5ca1 (diff) | |
download | src-16c0b5195cae2394d27ba44d41b34d055a7161b4.tar.gz src-16c0b5195cae2394d27ba44d41b34d055a7161b4.zip |
Honour the spirit rather than the implementation of the previous changes;
if we are invoked with -m, use chmod() on the final directory component
in order to ensure the mode is correctly set.
Notes
Notes:
svn path=/head/; revision=40602
Diffstat (limited to 'bin/mkdir/mkdir.c')
-rw-r--r-- | bin/mkdir/mkdir.c | 29 |
1 files changed, 10 insertions, 19 deletions
diff --git a/bin/mkdir/mkdir.c b/bin/mkdir/mkdir.c index 69217016cc80..89e9ebafb6e6 100644 --- a/bin/mkdir/mkdir.c +++ b/bin/mkdir/mkdir.c @@ -42,7 +42,7 @@ static char const copyright[] = static char sccsid[] = "@(#)mkdir.c 8.2 (Berkeley) 1/25/94"; #endif static const char rcsid[] = - "$Id: mkdir.c,v 1.12 1998/10/20 06:37:01 msmith Exp $"; + "$Id: mkdir.c,v 1.13 1998/10/20 08:04:15 msmith Exp $"; #endif /* not lint */ #include <sys/types.h> @@ -99,19 +99,20 @@ main(argc, argv) if (pflag) { if (build(*argv, omode)) exitval = 1; - continue; - } - if (mkdir(*argv, omode) < 0) { + } else if (mkdir(*argv, omode) < 0) { warn("%s", *argv); exitval = 1; } /* * The mkdir() and umask() calls both honor only the low * nine bits, so if you try to set a mode including the - * sticky, setuid, setgid bits you lose them. So chmod(). + * sticky, setuid, setgid bits you lose them. Don't do + * this unless the user has specifically requested a mode, + * as chmod will (obviously) ignore the umask. */ - if (chmod(*argv, omode) == -1) { - warn("%s", *argv); + if ((exitval == 0) && + (mode != NULL) && (chmod(*argv, omode) == -1)) { + warn("chmod %s", *argv); exitval = 1; } } @@ -169,17 +170,6 @@ build(path, omode) retval = 1; break; } - /* - * The mkdir() and umask() calls both honor only the - * low nine bits, so if you try to set a mode - * including the sticky, setuid, setgid bits you lose - * them. So chmod() the last path component to try - * to do what the caller has asked for. - */ - if (last && (chmod(path, omode) == -1)) { - warn("%s", path); - retval = 1; - } } else if ((sb.st_mode & S_IFMT) != S_IFDIR) { if (last) @@ -190,7 +180,8 @@ build(path, omode) retval = 1; break; } - *p = '/'; + if (!last) + *p = '/'; } if (!first && !last) (void)umask(oumask); |