Fix/native proc exec bugs#43
Merged
Merged
Conversation
When the child of cpproc_forkAndExec fails to chdir or exec, the failure is never reported to the parent: the child simply calls abort(). Running a non-existing binary appears to succeed, and the failure is only observable as a SIGABRT exit code (-6) from Process.waitFor(), instead of an IOException thrown from Runtime.exec() or ProcessBuilder.start(). Fix this with an extra pipe (FD_CLOEXEC) between child and parent: if chdir or exec fails, the child writes its errno to the pipe and exits; on success the exec itself closes the pipe. The parent blocks reading the pipe: EOF means success, otherwise it reaps the failed child and returns the child's errno, which surfaces as an IOException. Also initialize the output fds so that the caller never sees stale values in them if the spawn fails, or in the unused stderr entry when redirection is requested. Fixes #41 (BZ#111585) Signed-off-by: Guillermo Rodríguez <grodriguez@ingelabs.com>
When cpproc_forkAndExec receives a non-NULL environment array (which is always the case for ProcessBuilder), the PATH is not searched. This happens because cpproc_forkAndExec internally uses execve when a non-NULL environment is passed, and execvp otherwise. What we'd want here is execvpe, but this is not POSIX; it is a GNU extension introduced in glibc 2.11. (Additionally, POSIX does not list execvp as async-signal-safe, so it shouldn't be used after fork() in a multi-threaded process. For a precedent, see [1].) Fix this by implementing an execvpe replacement which emulates its behaviour (pass environment if one is supplied, search parent's PATH, fallback to running via /bin/sh if execv/execve fails with ENOEXEC). Error handling follows execvp semantics: an empty command name fails with ENOENT, broken PATH entries are skipped, and EACCES is sticky. Both the null and non-null environment cases now go through the same implementation, so both spawn paths behave identically. [1] https://git.kernel.org/pub/scm/git/git.git/commit/?id=e3a434468f ("run-command: use the async-signal-safe execv instead of execvp") Fixes #42 (BZ#111586) Signed-off-by: Guillermo Rodríguez <grodriguez@ingelabs.com>
phvega
approved these changes
Jul 10, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.