[pypy-commit] pypy default: os.setresuid(), os.setresgid()
arigo
noreply at buildbot.pypy.org
Sat Nov 9 17:24:37 CET 2013
Author: Armin Rigo <arigo at tunes.org>
Branch:
Changeset: r67897:b4036daf7365
Date: 2013-11-09 16:03 +0100
http://bitbucket.org/pypy/pypy/changeset/b4036daf7365/
Log: os.setresuid(), os.setresgid()
diff --git a/pypy/module/posix/__init__.py b/pypy/module/posix/__init__.py
--- a/pypy/module/posix/__init__.py
+++ b/pypy/module/posix/__init__.py
@@ -157,7 +157,7 @@
'setpgrp', 'getppid', 'getpgid', 'setpgid', 'setreuid',
'setregid', 'getsid', 'setsid', 'fstatvfs', 'statvfs',
'setgroups', 'initgroups', 'tcgetpgrp', 'tcsetpgrp',
- 'getresuid', 'getresgid']:
+ 'getresuid', 'getresgid', 'setresuid', 'setresgid']:
if hasattr(os, name):
interpleveldefs[name] = 'interp_posix.%s' % (name,)
# not visible via os, inconsistency in nt:
diff --git a/pypy/module/posix/interp_posix.py b/pypy/module/posix/interp_posix.py
--- a/pypy/module/posix/interp_posix.py
+++ b/pypy/module/posix/interp_posix.py
@@ -1170,6 +1170,28 @@
space.wrap(egid),
space.wrap(sgid)])
+ at unwrap_spec(ruid=c_uid_t, euid=c_uid_t, suid=c_uid_t)
+def setresuid(space, ruid, euid, suid):
+ """ setresuid(ruid, euid, suid)
+
+ Set the current process's real, effective, and saved user ids.
+ """
+ try:
+ os.setresuid(ruid, euid, suid)
+ except OSError, e:
+ raise wrap_oserror(space, e)
+
+ at unwrap_spec(rgid=c_gid_t, egid=c_gid_t, sgid=c_gid_t)
+def setresgid(space, rgid, egid, sgid):
+ """ setresgid(rgid, egid, sgid)
+
+ Set the current process's real, effective, and saved group ids.
+ """
+ try:
+ os.setresgid(rgid, egid, sgid)
+ except OSError, e:
+ raise wrap_oserror(space, e)
+
def declare_new_w_star(name):
if name in RegisterOs.w_star_returning_int:
@unwrap_spec(status=c_int)
diff --git a/pypy/module/posix/test/test_posix2.py b/pypy/module/posix/test/test_posix2.py
--- a/pypy/module/posix/test/test_posix2.py
+++ b/pypy/module/posix/test/test_posix2.py
@@ -670,6 +670,18 @@
res = os.getresgid()
assert len(res) == 3
+ if hasattr(os, 'setresuid'):
+ def test_os_setresuid(self):
+ os = self.posix
+ a, b, c = os.getresuid()
+ os.setresuid(a, b, c)
+
+ if hasattr(os, 'setresgid'):
+ def test_os_setresgid(self):
+ os = self.posix
+ a, b, c = os.getresgid()
+ os.setresgid(a, b, c)
+
if hasattr(os, 'sysconf'):
def test_os_sysconf(self):
os = self.posix
diff --git a/rpython/rtyper/module/ll_os.py b/rpython/rtyper/module/ll_os.py
--- a/rpython/rtyper/module/ll_os.py
+++ b/rpython/rtyper/module/ll_os.py
@@ -878,6 +878,32 @@
return extdef([], (int, int, int), llimpl=c_getresgid_llimpl,
export_name='ll_os.ll_os_getresgid')
+ @registering_if(os, 'setresuid')
+ def register_os_setresuid(self):
+ c_setresuid = self.llexternal('setresuid', [rffi.INT] * 3, rffi.INT)
+
+ def c_setresuid_llimpl(ruid, euid, suid):
+ res = c_setresuid(ruid, euid, suid)
+ res = rffi.cast(lltype.Signed, res)
+ if res == -1:
+ raise OSError(rposix.get_errno(), "setresuid failed")
+
+ return extdef([int, int, int], None, llimpl=c_setresuid_llimpl,
+ export_name='ll_os.ll_os_setresuid')
+
+ @registering_if(os, 'setresgid')
+ def register_os_setresgid(self):
+ c_setresgid = self.llexternal('setresgid', [rffi.INT] * 3, rffi.INT)
+
+ def c_setresgid_llimpl(rgid, egid, sgid):
+ res = c_setresgid(rgid, egid, sgid)
+ res = rffi.cast(lltype.Signed, res)
+ if res == -1:
+ raise OSError(rposix.get_errno(), "setresgid failed")
+
+ return extdef([int, int, int], None, llimpl=c_setresgid_llimpl,
+ export_name='ll_os.ll_os_setresgid')
+
@registering_str_unicode(os.open)
def register_os_open(self, traits):
os_open = self.llexternal(traits.posix_function_name('open'),
diff --git a/rpython/rtyper/module/test/test_posix.py b/rpython/rtyper/module/test/test_posix.py
--- a/rpython/rtyper/module/test/test_posix.py
+++ b/rpython/rtyper/module/test/test_posix.py
@@ -264,3 +264,19 @@
res = self.interpret(f, [])
a, b, c = os.getresgid()
assert res == a + b * 37 + c * 1291
+
+ if hasattr(os, 'setresuid'):
+ def test_setresuid(self):
+ def f():
+ a, b, c = os.getresuid()
+ a = (a + 1) - 1
+ os.setresuid(a, b, c)
+ self.interpret(f, [])
+
+ if hasattr(os, 'setresgid'):
+ def test_setresgid(self):
+ def f():
+ a, b, c = os.getresgid()
+ a = (a + 1) - 1
+ os.setresgid(a, b, c)
+ self.interpret(f, [])
More information about the pypy-commit
mailing list