proposal: add setresuid() system call to python

Carl Banks pavlovevidence at gmail.com
Fri Aug 21 19:23:29 EDT 2009


On Aug 21, 1:50 pm, travis+ml-pyt... at subspacefield.org wrote:
> On Mon, Jul 20, 2009 at 04:10:35PM +0200, Hrvoje Niksic wrote:
> > To emulate the os-module-type calls, it's better to raise exceptions
> > than return negative values:
>
> > > def setresuid(ruid, euid, suid):
> > >     return _setresuid(__uid_t(ruid), __uid_t(euid), __uid_t(suid))
>
> > def setresuid(ruid, euid, suid):
> >     res = _setresuid(__uid_t(ruid), __uid_t(euid), __uid_t(suid))
> >     if res < 0:
> >         raise OSError('[Errno %d] %s' % (os.errno, errno.strerror(os.errno)))
>
> I am working on a module to implement all of this, but that raise command
> won't work in Python 2.6.1; it turns out that os.errno is a module, not
> an integer.  Does anyone know how to do what I want (that is, how to access
> the errno set in C functions)?

You are using ctypes, I presume?  Try replacing raise OSError with
this:

ctypes.pythonapi.PyErr_SetFromErrno(ctypes.py_object(OSError))

Not entirely sure it'll work with Python built with a static library,
but I think it will.


Carl Banks



More information about the Python-list mailing list