Subject: bin/2686: [dM] mkdir -p -m ignores -m
To: None <gnats-bugs@NetBSD.ORG>
From: der Mouse <mouse@Collatz.McRCIM.McGill.EDU>
List: netbsd-bugs
Date: 08/12/1996 10:15:28
>Number:         2686
>Category:       bin
>Synopsis:       [dM] mkdir -p -m ignores -m
>Confidential:   no
>Severity:       non-critical
>Priority:       medium
>Responsible:    bin-bug-people (Utility Bug People)
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Mon Aug 12 10:35:00 1996
>Originator:     der Mouse
>Release:        -current (1.2 release branch), $NetBSD: mkdir.c,v 1.14 1995/06/25 21:59:21 mycroft Exp $
	Any (noticed on Sun-3/260, verified on SPARC IPC)
	When -p is given to mkdir, any -m argument is ignored.

	Incidentally, this would have been caught by -Wunused, since
	without the fix, the second argument to mkpath() is unused.

	Secondarily (this isn't a bug, just an efficiency concern), it
	might be worth instrumenting mkdir -p to determine how many
	directories need to be made in the "average" mkdir -p run.  If,
	as I suspect, the number is small (probably less than one), it
	would save syscalls to walk the path starting with the full
	path and trimming components off the end, instead of (as it
	does now) walking from the start, stat()ing until a nonexistent
	directory is found.
	[Callisto] 16> umask
	[Callisto] 17> mkdir -m 0710 -p /tmp/foo/bar/blee
	[Callisto] 18> ls -lR /tmp/foo
	total 1
	drwxr-xr-x  3 mouse         512 Aug 12 10:05 bar
	total 1
	drwxr-xr-x  2 mouse         512 Aug 12 10:05 blee
	total 0
	[Callisto] 19> 

	(notice that blee, the terminal directory, is the same mode
	0755 as the rest, ignoring the -m 0710).
	This works for me, fixing the bug.  I haven't addressed the
	efficiency concern mentioned under "Description".

--- OLD/bin/mkdir/mkdir.c	Thu Jan  1 00:00:00 1970
+++ NEW/bin/mkdir/mkdir.c	Thu Jan  1 00:00:00 1970
@@ -149,7 +149,7 @@
 		*slash = '\0';
 		if (stat(path, &sb)) {
-			if (errno != ENOENT || mkdir(path, dir_mode)) {
+			if (errno != ENOENT || mkdir(path, done?mode:dir_mode)) {
 				warn("%s", path);
 				return (-1);

					der Mouse
		    01 EE 31 F6 BB 0C 34 36  00 F3 7C 5A C1 A0 67 1D