def METHOD_NAME():
    """Get the real user ID when running in sudo mode"""
    if 'posix' != os.name:
        raise RuntimeError('getrealuid() requires POSIX')
    if os.getenv('SUDO_UID'):
        return int(os.getenv('SUDO_UID'))
    try:
        login = os.getlogin()
        # On Ubuntu 9.04, getlogin() under sudo returns non-root user.
        # On Fedora 11, getlogin() under sudo returns 'root'.
        # On Fedora 11, getlogin() under su returns non-root user.
    except:
        login = os.getenv('LOGNAME')
    if login and 'root' != login:
        import pwd
        return pwd.getpwnam(login)[3]
    return os.getuid()