diff options
author | Todd C. Miller <millert@cvs.openbsd.org> | 2008-09-30 23:25:32 +0000 |
---|---|---|
committer | Todd C. Miller <millert@cvs.openbsd.org> | 2008-09-30 23:25:32 +0000 |
commit | e89b3f0092a8505990d497ffabbc37a1a87536b5 (patch) | |
tree | e928f8c54ce9e6ed82363d8889a47ee18d4fe638 | |
parent | ecda100a3342be4858dba3733f7ef7690838e004 (diff) |
Fix a problem in the last commit. Upon closer reading of POSIX, in
-p mode we only want to change the mode on directories we actually created.
-rw-r--r-- | bin/mkdir/mkdir.c | 15 |
1 files changed, 7 insertions, 8 deletions
diff --git a/bin/mkdir/mkdir.c b/bin/mkdir/mkdir.c index 2e2bb386b7e..719f0207b14 100644 --- a/bin/mkdir/mkdir.c +++ b/bin/mkdir/mkdir.c @@ -1,4 +1,4 @@ -/* $OpenBSD: mkdir.c,v 1.22 2008/09/30 16:01:56 millert Exp $ */ +/* $OpenBSD: mkdir.c,v 1.23 2008/09/30 23:25:31 millert Exp $ */ /* $NetBSD: mkdir.c,v 1.14 1995/06/25 21:59:21 mycroft Exp $ */ /* @@ -40,7 +40,7 @@ static char copyright[] = #if 0 static char sccsid[] = "@(#)mkdir.c 8.2 (Berkeley) 1/25/94"; #else -static char rcsid[] = "$OpenBSD: mkdir.c,v 1.22 2008/09/30 16:01:56 millert Exp $"; +static char rcsid[] = "$OpenBSD: mkdir.c,v 1.23 2008/09/30 23:25:31 millert Exp $"; #endif #endif /* not lint */ @@ -158,7 +158,10 @@ mkpath(char *path, mode_t mode, mode_t dir_mode) continue; } - if (mkdir(path, done ? mode : dir_mode) < 0) { + if (mkdir(path, done ? mode : dir_mode) == 0) { + if (mode > 0777 && chmod(path, mode) < 0) + return (-1); + } else { if (!exists) { /* Not there */ return (-1); @@ -168,11 +171,7 @@ mkpath(char *path, mode_t mode, mode_t dir_mode) errno = ENOTDIR; return (-1); } - if (mode != (sb.st_mode & ALLPERMS)) - /* Is there, but mode is wrong */ - if (chmod(path, mode) < 0) - return (-1); - } + } if (done) break; |