Repository navigation
Conversation
|
r? @joboet rustbot has assigned @joboet. Use Why was this reviewer chosen?The reviewer was selected based on:
|
This comment has been minimized.
This comment has been minimized.
There was a problem hiding this comment.
I highly recommend having a look at the POSIX specification – GNU/Linux mostly follows that, but the specification sometimes leaves some things unspecified and we should be careful not to break those.
Also, this is currently unsound, we cannot perform any memory allocation in do_exec, since it's called after fork for the standard spawn path. You probably need to preallocate some memory when creating the Command (or when setting certain parameters).
| None => c"/bin:/usr/bin".to_bytes_with_nul(), | ||
| } | ||
| } | ||
| None => parent_path.as_bytes_with_nul(), |
There was a problem hiding this comment.
I recommend moving the environment variable lookup here so that it's only performed when actually needed.
|
Reminder, once the PR becomes ready for a review, use |
This comment has been minimized.
This comment has been minimized.
213bb02 to
8319b09
Compare
This comment has been minimized.
This comment has been minimized.
| assert_failed(index, len); | ||
| } | ||
|
|
||
| self.ptrs.insert(index, item.into_raw()); |
There was a problem hiding this comment.
This leaks the string if insert panics (see #155748, I made this mistake before).
|
The final comment period, with a disposition to merge, as per the review above, is now complete. As the automated representative of the governance process, I would like to thank the author for their work and everyone else who contributed. |
You don't have to wait, you can do it here. I'd suggest putting it into a separate commit, just so you could drop it easily if another PR with a bump gets merged in the meantime. |
I'm not sure if I could bump up @tgross35 how does release schedule work for |
…nd opt to use execve and resolve path manually
…confstr_as_cstring added to get a CString value returned by confstr, added CStringArray::from_ptr, added default_path and shell_argv fields to unix Command, and refactored do_exec code
…om a single passthrough in envp, match on errno values directly instead of ErrorKind, fix shell_argv CStringArray value.
…remove confstr_as_cstr, remove unnecessary shell_argv field/funtions + unused functions from CStringArray, use slice::split to delimit on colons
…cumentation for returning an error from execve
|
The relevant |
|
Yep, I saw. I was actually working on it before the notif I received for the I have to check a couple of other platforms that wasn't listed earlier to see how execvp works.
Do we know what we want to do for certain platforms like Solaris/AIX? I think those platforms are closed-source, so I couldn't find info about
|
71e457f to
0289d85
Compare
|
This PR was rebased onto a different main commit. Here's a range-diff highlighting what actually changed. Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers. |
This comment has been minimized.
This comment has been minimized.
0289d85 to
4c2289e
Compare
This comment has been minimized.
This comment has been minimized.
4c2289e to
78a1404
Compare
| all(target_os = "linux", target_env = "gnu") => { | ||
| confstr(libc::_CS_PATH, None).unwrap_or(OsString::new()) | ||
| } | ||
| any( |
There was a problem hiding this comment.
@joboet see my comment earlier #157144 (comment)
Unresolved question here is should we just directly use ":/bin:/usr/bin" for uclibc's execvp default fallback path? This is different from its _PATH_DEFPATH value which is "/usr/bin:/bin"
This comment has been minimized.
This comment has been minimized.
…H on Apple, Android, OpenBSD, FreeBSD, and DragonflyBSD as the default fallback path when the PATH environment variable was not found from maybe_envp/environ(); furthermore, added support for invoking the shell when execve returns an ENOEXEC error on Android, all Linux platforms (except musl), OpenBSD, NetBSD (for exec, but not posix_spawn), Apple, DragonFlyBSD, and Haiku.
78a1404 to
4359483
Compare
|
@rustbot ready |
View all comments
This PR fixes the bug described in #156951 where
CommandExt::execmutating the global environment pointer could cause correctness issue with concurrentexeccalls (also this function holds an environment read lock, so it shouldn't cause any writes to the global environment pointer anyways). We do everything withinCommandExt::execviaexecvethanexecvp, which means we have to resolve the path manually.I took reference to what was done in an archived (Feb 2026) upstream mirror of glibc's
execvpandexecvpe. I also took reference to #55359 on how they implemented the concerned portion ofCommandExt::execwithexecve. There's also this OpenBSD libc implementation ofexecvpethat I saw, but I didn't deeply take a look at this one and saw how it differ.Other than that, I'm unsure how to handle the error
ETIMEOUT/TimedOutas glibc breaks parsing through thePATHenvironment variable value and returns the error while #55359 continues parsing.Let me know if you also want me to put some of
execvecode in a helper function or refactor it in other ways.From @joboet comment in #157144 (comment), this table contain platform behavior on the default fallback path with execvp and whether it invokes shell or not on
ENOEXEC.process_spawnpexecvpPATHPATH_DEFPATHposix_spawnpcalls shell onENOEXECexecvpcalls shell onENOEXECCS_PATH=/bin:/usr/bin(same asconfstr(_CS_PATH), but different from_PATH_DEFPATH=/usr/bin:/bin)confstr(_CS_PATH)_PATH_DEFPATH=/usr/bin:/bin(notably, this is different fromconfstr(_CS_PATH)=sysctl(..)=/usr/bin:/bin:/usr/sbin:/sbin)/usr/local/bin:/bin:/usr/bin=_PATH_DEFPATH(not equal toconfstr(_CS_PATH)=/bin:/usr/bin__execvpe_PATH_DEFPATH=/sbin:/bin:/usr/sbin:/usr/bin:(not equal toconfstr(_CS_PATH)=_PATH_STDPATH=/usr/bin:/bin:/usr/sbin:/sbin)execvpe_PATH_DEFPATH=/usr/bin:/bin:/usr/sbin:/sbin:/usr/X11R6/bin:/usr/local/bin:/usr/local/sbin(currently equal toconfstr(_CS_PATH)=_PATH_STDPATH)execvpe_PATH_DEFPATH=/usr/bin:/bin:/usr/pkg/bin:/usr/local/bin(not equal toconfstr(_CS_PATH=sysctl(..)=_PATH_STDPATH=/usr/bin:/bin:/usr/sbin:/sbin:/usr/pkg/bin:/usr/pkg/sbin:/usr/local/bin:/usr/local/sbin)