This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author eryksun
Recipients eryksun, jaystrict, r.david.murray
Date 2015-10-27.06:22:00
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1445926922.26.0.793935653314.issue25481@psf.upfronthosting.co.za>
In-reply-to
Content
In subprocess.py there's the following code that builds a sequence of potential paths for the executable [1]:

    executable = os.fsencode(executable)
    if os.path.dirname(executable):
        executable_list = (executable,)
    else:
        # This matches the behavior of os._execvpe().
        executable_list = tuple(
            os.path.join(os.fsencode(dir), executable)
            for dir in os.get_exec_path(env))

In this case it tries to execute "/home/user1/bin/asdf", which fails with EACCES (to log this using strace, use -f to follow the fork). This occurs in child_exec in _posixsubprocess.c, in the following loop [2]:

    /* This loop matches the Lib/os.py _execvpe()'s PATH search when */
    /* given the executable_list generated by Lib/subprocess.py.     */
    saved_errno = 0;
    for (i = 0; exec_array[i] != NULL; ++i) {
        const char *executable = exec_array[i];
        if (envp) {
            execve(executable, argv, envp);
        } else {
            execv(executable, argv);
        }
        if (errno != ENOENT && errno != ENOTDIR && saved_errno == 0) {
            saved_errno = errno;
        }
    }
    /* Report the first exec error, not the last. */
    if (saved_errno)
        errno = saved_errno;

saved_errno will be set to EACCES and stored back to errno after all attempts to execute potential paths fail. This is then reported back to the parent process, which raises a PermissionError.

[1]: https://hg.python.org/cpython/file/3.5/Lib/subprocess.py#l1463
[2]: https://hg.python.org/cpython/file/3.5/Modules/_posixsubprocess.c#l487
History
Date User Action Args
2015-10-27 06:22:02eryksunsetrecipients: + eryksun, r.david.murray, jaystrict
2015-10-27 06:22:02eryksunsetmessageid: <1445926922.26.0.793935653314.issue25481@psf.upfronthosting.co.za>
2015-10-27 06:22:02eryksunlinkissue25481 messages
2015-10-27 06:22:01eryksuncreate