Implement execvpe_impl#16322
Conversation
ysbaddaden
left a comment
There was a problem hiding this comment.
I wonder if we could make the implementation feel more like Crystal and less like C. I mean it basically does the following which is much more readable (but allocates lots of String on each attempt just to throw them away):
ENV["PATH"].split(':') do |path|
next if path.bytesize + file.bytesize + 2 > LibC::PATH_MAX
path = "." if path.empty?
LibC.execve(File.join(path, file), argv, envp)
# execve failed: handle errno
endCo-authored-by: Julien Portalier <julien@portalier.com>
|
If we could make that idiomatic Crystal code work without allocations, I'm all ears =) This is one of the raw parts of the standard library which just needs to make a lot of concessions. FWIW the C-style code has the benefit of making it easier to compare with implementations in C libraries... 🤷 |
|
Yes, Anyway, that's out of scope :) |
Fills the stub
execvpe_implfallback for platforms withoutLibC.execvpewith a proper implementation.It's possible to choose our own implementation with the flag
-Dexecvpe_impl. This has proven to be useful for testing purposes, and we might keep it around for a while (there will be more follow-up changes where it could be useful), maybe indefinitely.Some of the design decisions for edge case behaviour were not exactly straightforward because system libraries handle things very differently sometimes. See #6464 (comment) for more details.
I usually opted for the most common and simple variant. We can refine details in the future if the need arises.
/usr/bin:/bin(like darwin and similar to mosts BSDs).execveNOEXECerror does not try to execute a shell script.The following system implementations served as role models: