Skip to content

Commit 2702e40

Browse files
authored
gh-84461: Fix Emscripten umask and permission issues (GH-94002)
- Emscripten's default umask is too strict, see emscripten-core/emscripten#17269 - getuid/getgid and geteuid/getegid are stubs that always return 0 (root). Disable effective uid/gid syscalls and fix tests that use chmod() current user. - Cannot drop X bit from directory.
1 parent 476d302 commit 2702e40

File tree

4 files changed

+23
-0
lines changed

4 files changed

+23
-0
lines changed

Lib/test/libregrtest/main.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -600,6 +600,16 @@ def save_xml_result(self):
600600
for s in ET.tostringlist(root):
601601
f.write(s)
602602

603+
def fix_umask(self):
604+
if support.is_emscripten:
605+
# Emscripten has default umask 0o777, which breaks some tests.
606+
# see https://github.com/emscripten-core/emscripten/issues/17269
607+
old_mask = os.umask(0)
608+
if old_mask == 0o777:
609+
os.umask(0o027)
610+
else:
611+
os.umask(old_mask)
612+
603613
def set_temp_dir(self):
604614
if self.ns.tempdir:
605615
self.tmp_dir = self.ns.tempdir
@@ -660,6 +670,8 @@ def main(self, tests=None, **kwargs):
660670

661671
self.set_temp_dir()
662672

673+
self.fix_umask()
674+
663675
if self.ns.cleanup:
664676
self.cleanup()
665677
sys.exit(0)

Lib/test/test_posix.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -787,6 +787,7 @@ def check_stat(uid, gid):
787787
check_stat(uid, gid)
788788

789789
@os_helper.skip_unless_working_chmod
790+
@unittest.skipIf(support.is_emscripten, "getgid() is a stub")
790791
def test_chown(self):
791792
# raise an OSError if the file does not exist
792793
os.unlink(os_helper.TESTFN)
@@ -798,6 +799,7 @@ def test_chown(self):
798799

799800
@os_helper.skip_unless_working_chmod
800801
@unittest.skipUnless(hasattr(posix, 'fchown'), "test needs os.fchown()")
802+
@unittest.skipIf(support.is_emscripten, "getgid() is a stub")
801803
def test_fchown(self):
802804
os.unlink(os_helper.TESTFN)
803805

@@ -1356,6 +1358,7 @@ def test_chmod_dir_fd(self):
13561358

13571359
@unittest.skipUnless(hasattr(os, 'chown') and (os.chown in os.supports_dir_fd),
13581360
"test needs dir_fd support in os.chown()")
1361+
@unittest.skipIf(support.is_emscripten, "getgid() is a stub")
13591362
def test_chown_dir_fd(self):
13601363
with self.prepare_file() as (dir_fd, name, fullname):
13611364
posix.chown(name, os.getuid(), os.getgid(), dir_fd=dir_fd)

Lib/test/test_pydoc.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -934,6 +934,7 @@ def test_apropos_with_unreadable_dir(self):
934934
self.assertEqual(err.getvalue(), '')
935935

936936
@os_helper.skip_unless_working_chmod
937+
@unittest.skipIf(is_emscripten, "cannot remove x bit")
937938
def test_apropos_empty_doc(self):
938939
pkgdir = os.path.join(TESTFN, 'walkpkg')
939940
os.mkdir(pkgdir)

Tools/wasm/config.site-wasm32-emscripten

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,13 @@ ac_cv_func_symlinkat=no
4343
ac_cv_func_lchmod=no
4444
ac_cv_func_lchown=no
4545

46+
# geteuid / getegid are stubs and always return 0 (root). The stub breaks
47+
# code that assume effective user root has special permissions.
48+
ac_cv_func_geteuid=no
49+
ac_cv_func_getegid=no
50+
ac_cv_func_seteuid=no
51+
ac_cv_func_setegid=no
52+
4653
# Syscalls not implemented in emscripten
4754
# [Errno 52] Function not implemented
4855
ac_cv_func_preadv2=no

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy