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

[Truffle] Improved exec #4386

Merged
merged 6 commits into from Dec 15, 2016
Merged

[Truffle] Improved exec #4386

merged 6 commits into from Dec 15, 2016

Conversation

nirvdrum
Copy link
Contributor

No description provided.

@nirvdrum nirvdrum added this to the truffle-dev milestone Dec 14, 2016
@bjfish
Copy link
Contributor

bjfish commented Dec 14, 2016

@nirvdrum I think there are some spec failures on Mac. Here is my console output:
https://gist.github.com/bjfish/d70799f5362123df458d3b35671a6618

@nirvdrum
Copy link
Contributor Author

Hmm . . . I'll have to get access to a Mac to see what's going on. Thanks for the heads up.

@nirvdrum
Copy link
Contributor Author

@bjfish Oops. When I added my comments, I accidentally deleted a line of legitimate code. Good thing I didn't use [skip ci].

pgroup = options[:pgroup]
if pgroup
Truffle::POSIX.setpgid(0, pgroup)
end
Copy link
Member

@eregon eregon Dec 15, 2016

Choose a reason for hiding this comment

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

Style note: I like assignment in a if like if pgroup = options[:pgroup], but do as you prefer.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I can adapt. I've just been burned too many times by = vs == in other environments. I think Java gets this right.

Copy link
Member

Choose a reason for hiding this comment

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

Somehow I adapted and don't recall having an unintentional = in a if for ages. I think it's not the worse mistake and relatively easy to catch.

def spawn_setup
require 'fcntl'

env = options&.delete(:unsetenv_others) ? {} : ENV.to_hash
Copy link
Member

Choose a reason for hiding this comment

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

I think options should always be a Hash. Unfortunately it seems the constructor doesn't do that, even though its documentation says it does:

         # Assigns @environment, @command, @argv, @redirects, @options. All
         # elements are guaranteed to be non-nil. When no env or options are
         # given, empty hashes are returned.

Could you fix the constructor?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

@@ -109,6 +110,7 @@ def initialize(env_or_cmd, *args)

@command = command
@argv = argv
@env_array = []
Copy link
Member

Choose a reason for hiding this comment

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

I would not initialize it, so it remains nil until it's properly set and not empty.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks. This was leftover from when I used to bail early if @options wasn't defined. Setting that in the constructor fixes everything.

if b == 0x00
raise ArgumentError.new("string contains null byte")
end
end
Copy link
Member

Choose a reason for hiding this comment

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

Rubinius::Type.check_null_safe

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks. I didn't know about that one.

command, args = '/bin/sh', ['/bin/sh', '-c', command]
else
raise Errno::ENOENT.new("No such file or directory - #{command}")
end
Copy link
Member

@eregon eregon Dec 15, 2016

Choose a reason for hiding this comment

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

Can't we let the shell do the lookup in $PATH in both cases?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Do you mean by running /usr/bin/env? Otherwise, in one of these cases we're not supposed to run in the shell at all. In the other case, we'd end up with a different error than MRI (and the specs check for that).

Copy link
Member

Choose a reason for hiding this comment

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

I meant by just giving the command to /bin/sh. But indeed if the error must be different than the shell error it's better this way. We need the search for the other case anyway.

@nirvdrum nirvdrum merged commit 28f3c3d into truffle-head Dec 15, 2016
@nirvdrum nirvdrum deleted the truffle-improved-exec branch December 15, 2016 14:55
@enebo enebo added this to the Non-Release milestone Dec 7, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants