Index: Modules/posixmodule.c =================================================================== --- Modules/posixmodule.c (revision 88680) +++ Modules/posixmodule.c (working copy) @@ -2929,6 +2929,7 @@ PyObject *opath; char *path; int mode = 0777; + int mask; #ifdef MS_WINDOWS PyUnicodeObject *po; @@ -2974,6 +2975,11 @@ res = mkdir(path); #else res = mkdir(path, mode); + if (res == 0) { + mask = umask(0); + umask(mask); + res = chmod(path, mode ^ mask); + } #endif Py_END_ALLOW_THREADS if (res < 0) @@ -8314,6 +8320,7 @@ PyObject *opath; char *path; int mode = 0777; + int mask; if (!PyArg_ParseTuple(args, "iO&|i:mkdirat", &dirfd, PyUnicode_FSConverter, &opath, &mode)) @@ -8321,6 +8328,13 @@ path = PyBytes_AsString(opath); Py_BEGIN_ALLOW_THREADS res = mkdirat(dirfd, path, mode); +#ifdef HAVE_FCHMODAT + if (res == 0) { + mask = umask(0); + umask(mask); + res = fchmodat(dirfd, path, mode ^ mask, 0); + } +#endif Py_END_ALLOW_THREADS Py_DECREF(opath); if (res < 0)