directory creation temporarily changes the umask
In unix/tclUnixFCmd.c the following code is used to determine the process's current "umask":
In the (usually miniscule) period between the two calls, the umask is temporarily set to 0 which results in elevated permissions for newly created files at that point. As noted in the umask man page for modern Linux systems with a /proc filesystem there is a better way to determine the umask. It might make sense to use this when available.mode = umask(0); umask(mode)
14f40fe36fFix [cd609219f5] and [623585ffff]: Call mkdir(path, 0777) and let the kernel apply the umask or ACL check-in2026-11-27 14:21:199ed74cfc29Ticket [623585ffff] [file mkdir] does not use default acl status still Open with 4 other changes ticket2026-10-17 09:00:115d7e74108fFix [cd609219f5] and [623585ffff]: [file mkdir] read the umask with umask(0) + umask(mode), which threads could leave at 0 for the whole process, and masked the mode itself, which overrode a default ACL of the parent directory. Call mkdir(path, 0777) and let the kernel apply the umask or ACL. check-in2026-10-17 08:58:08
Note that in a multi-threaded application this code can be highly problematic: if two threads simultaneously try to create a directory, both might be stepping through these lines at the same time. If it happens in this sequence the processes' umask will end up permanently set to "0":
thread 1 | thread 2
mode = umask(0); |
| mode = umask(0);
umask(mode) |
| umask(mode)
If a multithreaded process spawns a pool of threads which all try to create the same directory on startup that might not be an unlikely coincidence.
Confirmed, and worse than temporary: with several threads running [file mkdir], the process umask ends up permanently at 0, so later files are created world-writable (main, 9.0, 8.6). Proposed fix in branch mkdir-no-umask-call, with [623585ffff]: call mkdir(path, 0777) and let the kernel apply the umask; umask() is not called any more. The permissions of new directories do not change. Test unixFCmd-5.2. The old code also meant to always add u+rwx, but that never worked, because mkdir() applies the umask once more (umask 0700 gives 077). It could be done with chmod() after mkdir(), but that would change the permissions of new directories under such umasks, and it is not documented, so the branch does not do it.
Merged to [ 14f40fe36f|trunk]