Skip to content

[3.14] gh-127146: Emscripten: Make os.umask() actually work (GH-136706) #136711

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 16, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions Lib/test/test_os.py
Original file line number Diff line number Diff line change
Expand Up @@ -1918,11 +1918,9 @@ def test_makedir(self):
support.is_wasi,
"WASI's umask is a stub."
)
@unittest.skipIf(
support.is_emscripten,
"TODO: Fails in buildbot; see #135783"
)
def test_mode(self):
# Note: in some cases, the umask might already be 2 in which case this
# will pass even if os.umask is actually broken.
with os_helper.temp_umask(0o002):
base = os_helper.TESTFN
parent = os.path.join(base, 'dir1')
Expand Down
22 changes: 21 additions & 1 deletion Python/emscripten_syscalls.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
// defined with weak linkage so we can override it.
EM_JS(int, __syscall_getuid32_js, (void), {
// If we're in node and we can, report the native uid
if (typeof process !== "undefined" && typeof process.getuid === "function") {
if (ENVIRONMENT_IS_NODE) {
return process.getuid();
}
// Fall back to the stub case of returning 0.
Expand All @@ -17,3 +17,23 @@ EM_JS(int, __syscall_getuid32_js, (void), {
int __syscall_getuid32(void) {
return __syscall_getuid32_js();
}

EM_JS(int, __syscall_umask_js, (int mask), {
// If we're in node and we can, call native process.umask()
if (ENVIRONMENT_IS_NODE) {
try {
return process.umask(mask);
} catch(e) {
// oops...
// NodeJS docs: "In Worker threads, process.umask(mask) will throw an exception."
// umask docs: "This system call always succeeds"
return 0;
}
}
// Fall back to the stub case of returning 0.
return 0;
})

int __syscall_umask(int mask) {
return __syscall_umask_js(mask);
}
Loading