-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Unix: Add _PATH_BSHELL and _PATH_DEFPATH where available
#5449
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -32,6 +32,7 @@ SIGSEGV | |
| SIGTERM | ||
| SOL_SOCKET | ||
| SOMAXCONN | ||
| _PATH_BSHELL | ||
| __errno | ||
| cmsghdr | ||
| dirent | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -138,3 +138,11 @@ pub const fn replace_array_items<T: Copy, const N: usize>( | |
| } | ||
| dst | ||
| } | ||
|
|
||
| /// Constructs a compile time cstring literal from a byte array | ||
| // FIXME(msrv): we can opt to use C-string literals directly in 1.77 | ||
| #[allow(unused)] | ||
| pub(crate) const fn cstr(bytes: &[u8]) -> *const c_char { | ||
| assert!(!bytes.is_empty() && bytes[bytes.len() - 1] == 0); | ||
| bytes.as_ptr().cast::<i8>() | ||
| } | ||
|
Comment on lines
+142
to
+148
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,5 @@ | ||
| use crate::prelude::*; | ||
| use crate::types::cstr; | ||
|
|
||
| pub type off_t = i64; | ||
| pub type useconds_t = u32; | ||
|
|
@@ -480,6 +481,9 @@ cfg_if! { | |
| } | ||
| } | ||
|
|
||
| // include/paths.h | ||
| pub const _PATH_BSHELL: *const c_char = cstr(b"/bin/sh\0"); | ||
|
Comment on lines
+484
to
+485
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Copy this to each of the modules so it's next to |
||
|
|
||
| f! { | ||
| pub unsafe fn CMSG_FIRSTHDR(mhdr: *const crate::msghdr) -> *mut cmsghdr { | ||
| if (*mhdr).msg_controllen as usize >= size_of::<cmsghdr>() { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,5 @@ | ||
| use crate::prelude::*; | ||
| use crate::types::cstr; | ||
| use crate::*; | ||
|
|
||
| pub type wchar_t = c_ushort; | ||
|
|
@@ -1678,6 +1679,12 @@ pub const FALLOC_FL_COLLAPSE_RANGE: c_int = 0x0008; | |
| pub const FALLOC_FL_INSERT_RANGE: c_int = 0x0010; | ||
| pub const FALLOC_FL_KEEP_SIZE: c_int = 0x1000; | ||
|
|
||
| // include/paths.h | ||
| // Only defined in winsup/cygwin/include/paths.h | ||
| pub const _PATH_DEFPATH: *const c_char = cstr(b"/bin\0"); | ||
| // This is defined in both winsup/cygwin/include/paths.h and newlib/libc/include/paths.h | ||
| pub const _PATH_BSHELL: *const c_char = cstr(b"/bin/sh\0"); | ||
|
Comment on lines
+1682
to
+1686
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I believe the |
||
|
|
||
| f! { | ||
| pub unsafe fn FD_CLR(fd: c_int, set: *mut fd_set) -> () { | ||
| let fd = fd as usize; | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,5 @@ | ||
| use crate::prelude::*; | ||
| use crate::types::cstr; | ||
|
|
||
| pub type sa_family_t = u16; | ||
| pub type speed_t = c_uint; | ||
|
|
@@ -1497,6 +1498,28 @@ pub const ARPHRD_IEEE802154: u16 = 804; | |
| pub const ARPHRD_VOID: u16 = 0xFFFF; | ||
| pub const ARPHRD_NONE: u16 = 0xFFFE; | ||
|
|
||
| // include/paths.h | ||
| cfg_if! { | ||
| if #[cfg(target_os = "android")] { | ||
| pub const _PATH_DEFPATH: *const c_char = cstr(b"/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\0"); | ||
| pub const _PATH_BSHELL: *const c_char = cstr(b"/system/bin/sh\0"); | ||
| } else { | ||
| cfg_if! { | ||
| if #[cfg(any(target_env = "musl", target_env = "ohos"))] { | ||
| pub const _PATH_DEFPATH: *const c_char = cstr(b"/usr/local/bin:/bin:/usr/bin\0"); | ||
| } else if #[cfg(any(target_env = "gnu", target_env = "uclibc"))] { | ||
| // pub const _PATH_DEFPATH: *const c_char = c"/usr/bin:/bin".as_ptr(); | ||
| pub const _PATH_DEFPATH: *const c_char = cstr(b"/usr/bin:/bin\0"); | ||
| } else { | ||
| // Unknown target_env | ||
| } | ||
| } | ||
| pub const _PATH_BSHELL: *const c_char = cstr(b"/bin/sh\0"); | ||
| } | ||
| } | ||
|
Comment on lines
+1502
to
+1521
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. emscripten is mentioned but not actually covered here, it doesn't set But could you actually split this to |
||
|
|
||
| cfg_if! { | ||
| if #[cfg(not(any(target_os = "emscripten", target_os = "l4re")))] { | ||
| // linux/if_tun.h | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,5 @@ | ||
| use crate::prelude::*; | ||
| use crate::types::cstr; | ||
|
|
||
| pub type blkcnt_t = i32; | ||
| pub type blksize_t = i32; | ||
|
|
@@ -842,6 +843,9 @@ pub const PRIO_PROCESS: c_int = 0; | |
| pub const PRIO_PGRP: c_int = 1; | ||
| pub const PRIO_USER: c_int = 2; | ||
|
|
||
| // include/paths.h from newlib's libc | ||
| pub const _PATH_BSHELL: *const c_char = cstr(b"/bin/sh\0"); | ||
|
Comment on lines
+846
to
+847
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Note that the linked https://github.com/ourairquality/newlib/blob/0dea38754696422d526543262274703acd8317c5/newlib/libc/include/paths.h#L7 is a pretty old repo, hasn't gotten updated in 8 years. But unsurprisingly the value is still the same :) https://github.com/cygwin/cygwin/blob/cf61e0140e3d6cd21e743a38d35efc98194b63f3/newlib/libc/include/paths.h#L7 |
||
|
|
||
| f! { | ||
| pub unsafe fn FD_CLR(fd: c_int, set: *mut fd_set) -> () { | ||
| let bits = size_of_val(&(*set).fds_bits[0]) * 8; | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
c_char, noti8(on some platforms this isu8)