summaryrefslogtreecommitdiffstats
path: root/bin/mkdir/mkdir.c
diff options
context:
space:
mode:
authormsmith <msmith@FreeBSD.org>1998-10-22 21:42:20 +0000
committermsmith <msmith@FreeBSD.org>1998-10-22 21:42:20 +0000
commitc4aa0cf6f77d3320883b9363e359ae996632fb1a (patch)
tree90e20510dd8e11de6e09d41fcc8f60375e15419d /bin/mkdir/mkdir.c
parent6149131893758193d60549cec216e0c325c1c069 (diff)
downloadFreeBSD-src-c4aa0cf6f77d3320883b9363e359ae996632fb1a.zip
FreeBSD-src-c4aa0cf6f77d3320883b9363e359ae996632fb1a.tar.gz
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.
Diffstat (limited to 'bin/mkdir/mkdir.c')
-rw-r--r--bin/mkdir/mkdir.c29
1 files changed, 10 insertions, 19 deletions
diff --git a/bin/mkdir/mkdir.c b/bin/mkdir/mkdir.c
index 6921701..89e9eba 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);
OpenPOWER on IntegriCloud