Unix: Add _PATH_BSHELL and _PATH_DEFPATH where available - #5449
Conversation
436cb4f to
03110d3
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. |
_PATH_BSHELL and _PATH_DEFPATH constants to multiple unix platforms_PATH_BSHELL and _PATH_DEFPATH where available
There was a problem hiding this comment.
You'll need to use byte arrays to meet the MSRV. Add a function to
Lines 69 to 140 in b6d2732
fn cstr(bytes: &[u8]) -> *const c_char that asserts there's a single nul at the end and does the cast, with a FIXME(msrv) comment.
| /// Default search path | ||
| const _PATH_DEFPATH: *const c_char = c"/usr/bin:/bin".as_ptr(); |
There was a problem hiding this comment.
Drop the doc comments, libc expects you to read the manpages
| // include/paths.h (Bionics libc paths.h: https://android.googlesource.com/platform/bionic/+/refs/heads/main/libc/include/paths.h, | ||
| #[cfg(not(any(target_env = "musl", target_os = "android")))] | ||
| /// Default search path on glibc/uclibc Linux | ||
| pub const _PATH_DEFPATH: *const c_char = c"/usr/bin:/bin".as_ptr(); | ||
| #[cfg(all(target_env = "musl", not(target_os = "android")))] | ||
| /// Default search path on musl Linux platforms | ||
| pub const _PATH_DEFPATH: *const c_char = c"/usr/local/bin:/bin:/usr/bin".as_ptr(); | ||
| #[cfg(target_os = "android")] | ||
| /// Default search path on Android/Bionics libc | ||
| pub const _PATH_DEFPATH: *const c_char = c"/product/bin:/apex/com.android.runtime/bin:/apex/com.android.art/bin:/apex/com.android.virt/bin:/system_ext/bin:/system/bin:/system/xbin:/odm/bin:/vendor/bin:/vendor/xbin".as_ptr(); | ||
| /// Default shell path on Linux platforms (except Android) | ||
| #[cfg(not(target_os = "android"))] | ||
| pub const _PATH_BSHELL: *const c_char = c"/bin/sh".as_ptr(); | ||
| /// Default shell path on Android | ||
| #[cfg(target_os = "android")] | ||
| pub const _PATH_BSHELL: *const c_char = c"/system/bin/sh".as_ptr(); |
There was a problem hiding this comment.
Simplify this by using if cfg!(...) { ... } else { ... } rather than #[cfg]
| pub const _PATH_DEFPATH: *const c_char = c"/usr/local/bin:/bin:/usr/bin".as_ptr(); | ||
| #[cfg(target_os = "android")] | ||
| /// Default search path on Android/Bionics libc | ||
| pub const _PATH_DEFPATH: *const c_char = c"/product/bin:/apex/com.android.runtime/bin:/apex/com.android.art/bin:/apex/com.android.virt/bin:/system_ext/bin:/system/bin:/system/xbin:/odm/bin:/vendor/bin:/vendor/xbin".as_ptr(); |
|
Reminder, once the PR becomes ready for a review, use |
|
Two other things:
|
03110d3 to
415ba49
Compare
This comment has been minimized.
This comment has been minimized.
|
Going to update commit with permalinks |
415ba49 to
c193baa
Compare
This comment has been minimized.
This comment has been minimized.
…lowing are sources to each platform's `paths.h`: From BSD: * [Apple](https://github.com/apple-oss-distributions/Libc/blob/71bbe350ab79eef58113991d817ccc6165061a64/include/paths.h#L65): Has `_PATH_BSHELL` and `_PATH_DEFPATH` * [Dragonfly](https://github.com/DragonFlyBSD/DragonFlyBSD/blob/42aaacafd14ddb7f660730a5ca5da0a2d941723a/include/paths.h#L40): Has `_PATH_BSHELL` and `_PATH_DEFPATH` * [FreeBSD](https://github.com/freebsd/freebsd-src/blob/551b7c5e12bfea623a47edf97ad5689732a1233f/include/paths.h#L40): Has `_PATH_BSHELL` and `_PATH_DEFPATH` (verified same values on version 11+) * [NetBSD](https://github.com/NetBSD/src/blob/f66621237dc60126bd8a972b6064639892b344b7/include/paths.h#L43): Has `_PATH_BSHELL` and `_PATH_DEFPATH` * [OpenBSD](https://github.com/openbsd/src/blob/7d89a3e823169cb6a1d989e3f5f93f7f3c4b5db4/include/paths.h#L39): Has `_PATH_BSHELL` and `_PATH_DEFPATH` From Linux: * [Android](https://android.googlesource.com/platform/bionic/+/refs/heads/main/libc/include/paths.h#48): Has `_PATH_BSHELL` and `_PATH_DEFPATH` * [glibc](https://sourceware.org/git/?p=glibc.git;a=blob;f=sysdeps/unix/sysv/linux/paths.h;h=1342ab3a96ab12065311b718e57e7235e07587f8;hb=HEAD#l36): Has `_PATH_BSHELL` and `_PATH_DEFPATH` * [musl](https://git.musl-libc.org/cgit/musl/tree/include/paths.h?id=f21a96538f78fa8e2040831b4209b35f2fb581da#n4): Has `_PATH_BSHELL` and `_PATH_DEFPATH` * [uClibc](https://github.com/kraj/uClibc/blob/ca1c74d67dd115d059a875150e10b8560a9c35a8/include/paths.h#L36): Has `_PATH_BSHELL` and `_PATH_DEFPATH` * [emscripten](https://github.com/emscripten-core/emscripten/blob/a2059f978ed206b688daf4a8774211949610c2aa/system/lib/libc/musl/include/paths.h#L4): Has `_PATH_BSHELL` and `_PATH_DEFPATH` * l4re: There's [musl](https://github.com/l4re/l4re-core/blob/d09b1619c45d17786bc256ea219688f8ba3ff1fe/libc/musl/contrib/musl/include/paths.h#L4) and [uclibc](https://github.com/l4re/l4re-core/blob/d09b1619c45d17786bc256ea219688f8ba3ff1fe/libc/uclibc-ng/contrib/uclibc/include/paths.h#L36) `paths.h` file containing `_PATH_BSHELL` and `_PATH_DEFPATH` values Miscellaneous Platforms: * [Haiku](https://github.com/haiku/haiku/blob/8a33129223e93ea046dc62e9e09f8c93f45cfb7b/headers/compatibility/bsd/paths.h#L45): Has `_PATH_BSHELL` and `_PATH_DEFPATH` * [Hurd](https://github.com/joshumax/hurd/blob/83a6fc7641eecdb2b96c2dee2261da92573693de/hurd/paths.h#L20): Doesn't have `_PATH_BSHELL` and `_PATH_DEFPATH` in paths.h (wouldn't hurt to confirm this though in terminal) * [Cygwin](https://github.com/cygwin/cygwin/blob/cf61e0140e3d6cd21e743a38d35efc98194b63f3/winsup/cygwin/include/paths.h#L12): Has `_PATH_BSHELL` and `_PATH_DEFPATH` * [newlib](https://github.com/ourairquality/newlib/blob/0dea38754696422d526543262274703acd8317c5/newlib/libc/include/paths.h#L7): Has `_PATH_BSHELL` * [Redox](https://gitlab.redox-os.org/redox-os/relibc/-/blob/c3b3f2773a3a2622fdb632a9bfa1a77d68778150/include/paths.h): Has `_PATH_BSHELL` Platforms I'm unsure if they have `_PATH_BSHELL`/`_PATH_DEFPATH`: * Solarish: I'm unsure how to get this info since I believe Solaris is closed source? * AIX: I think this is also closed source? However, I saw this [archive repo](https://github.com/Arquivotheca/AIX-4.1.3/blob/d6fe8fe8299ececc0db4fae9c19cd3babffd28ae/bos/usr/include/paths.h#L36) of AIX 4.13 that has `_PATH_BSHELL`. * [nuttx](https://github.com/apache/nuttx): Couldn't find a `include/paths.h` file. * [NTO/QNX](https://github.com/qnx): Couldn't find a `include/paths.h` file.
c193baa to
d011d09
Compare
|
@tgross35 I'm unsure why I know But it is defined in their |
This PR adds
_PATH_BSHELLand_PATH_DEFPATHconstants frominclude/paths.hon multiple unix-based platforms (a couple platforms only have_PATH_BSHELL). The reason for why we need these macros could be seen from this Zulip chat #t-libs/crates > Including <paths.h> macros into libc? @ 💬 and PR.The following are sources to each platform's
paths.h:From BSD:
_PATH_BSHELLand_PATH_DEFPATH_PATH_BSHELLand_PATH_DEFPATH_PATH_BSHELLand_PATH_DEFPATH(verified same values on version 11+)_PATH_BSHELLand_PATH_DEFPATH_PATH_BSHELLand_PATH_DEFPATHFrom Linux:
_PATH_BSHELLand_PATH_DEFPATH_PATH_BSHELLand_PATH_DEFPATH_PATH_BSHELLand_PATH_DEFPATH_PATH_BSHELLand_PATH_DEFPATH_PATH_BSHELLand_PATH_DEFPATHpaths.hfile containing_PATH_BSHELLand_PATH_DEFPATHvaluesMiscellaneous Platforms:
_PATH_BSHELLand_PATH_DEFPATH_PATH_BSHELLand_PATH_DEFPATHin paths.h (wouldn't hurt to confirm this though in terminal)_PATH_BSHELLand_PATH_DEFPATH_PATH_BSHELL_PATH_BSHELLPlatforms I'm unsure if they have
_PATH_BSHELL/_PATH_DEFPATH:_PATH_BSHELL.include/paths.hfile.include/paths.hfile.Would be helpful if someone could go on terminal and print out
_PATH_BSHELLand see if that produces results?Other questions I have are:
_PATH_DEFPATHconcatenates theRESCUEDIRmacro in front of its string literal if it exists, should we also have that in our_PATH_DEFPATHmacro? I wasn't sure (I also don't know what the value ofRESCUEDIRis), and I was advised by Jonas to reach out to @he32 and @0323pin since they're experienced with NetBSD.This is also my first time contributing to libc. I've read through the
CONTRIBUTING.mdfile and hopefully I got everything done correctly. I know the md file also mentions about reorganization effort for moving from the hierarchial structure to the source-mapped structure insrc/new. If you want me to restructure the constants I'm introducing tosrc/new, I can try for that; I may need more clarity on how that process works.cc @joboet
@rustbot label stable-nominated