Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Issue 20765 - Can't run processes with relative paths when specif… #7455

Merged
merged 1 commit into from Aug 10, 2020

Conversation

CyberShadow
Copy link
Member

…ying a working directory

Remove the dubious check which attempted to duplicate the operating
system's behavior.

@dlang-bot
Copy link
Contributor

Thanks for your pull request, @CyberShadow!

Bugzilla references

Auto-close Bugzilla Severity Description
20765 normal Can't run processes with relative paths when specifying a working directory

Testing this PR locally

If you don't have a local development environment setup, you can use Digger to test this PR:

dub run digger -- build "master + phobos#7455"

@n8sh
Copy link
Member

n8sh commented Apr 26, 2020

Remove the dubious check which attempted to duplicate the operating system's behavior.

Maybe the motivation was producing a better error message, or someone saw value in bailing out early when it can be determined early on that the process will fail (which is optimizing for a case that I assume is uncommon). The check could be modified to be:

    if (any!isDirSeparator(name))
    {	
        if (workDir.length == 0 && !isExecutable(name))	
            throw new ProcessException(text("Not an executable file: ", name));	
    }

Or it could be removed entirely as you did.

@CyberShadow
Copy link
Member Author

CyberShadow commented Apr 26, 2020

It is dangerous to make assumptions such as those made by the removed code, because things such as ACLs, virtual filesystems, and not-quite-POSIX systems may cause the result to differ from what is expected. Generally in such cases it is more correct to try the action and handle the outcome, rather than attempt to predict it.

@CyberShadow
Copy link
Member Author

It looks like the test for this fix uncovered an additional problem on FreeBSD.

@CyberShadow
Copy link
Member Author

I can't figure out why it's failing on FreeBSD.

I tried the following C program:

#include <stdio.h>
#include <fcntl.h>
#include <unistd.h>

int main()
{
	int fd = open("dir", O_RDONLY);
	fchdir(fd);
	static const char *argv[] = {"./test.sh", 0};
	execve(argv[0], argv, NULL);
}

But, it works as expected.

@jmdavis perhaps might know?

@kyllingstad
Copy link
Member

Remove the dubious check which attempted to duplicate the operating system's behavior.

Maybe the motivation was producing a better error message, or someone saw value in bailing out early when it can be determined early on that the process will fail (which is optimizing for a case that I assume is uncommon).

It was so the error could be handled in the parent, before the fork(). It predates the current pipe-based error transporting mechanism, which wasn't in there from the start. It can safely be removed now, and I agree that it should.

@CyberShadow
Copy link
Member Author

Fixed the FreeBSD failure. The cause was embarrassingly mundane - I used #!/bin/bash in the test script, and bash isn't part of FreeBSD.

Copy link
Member

@schveiguy schveiguy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Let the OS handle the error sounds good.

…ying a working directory

Remove the dubious check which attempted to duplicate the operating
system's behavior.
@dlang-bot dlang-bot merged commit e2fc53f into dlang:master Aug 10, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
6 participants