Merge pull request #2550 from uutils/redox

Fixes for Redox
This commit is contained in:
Sylvestre Ledru 2021-08-06 23:54:36 +02:00 committed by GitHub
commit d967a7a553
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
18 changed files with 57 additions and 73 deletions

26
Cargo.lock generated
View file

@ -719,7 +719,7 @@ checksum = "1d34cfa13a63ae058bfa601fe9e313bbdb3746427c1459185464ce0fcf62e1e8"
dependencies = [
"cfg-if 1.0.0",
"libc",
"redox_syscall 0.2.9",
"redox_syscall",
"winapi 0.3.9",
]
@ -1238,7 +1238,7 @@ dependencies = [
"cfg-if 1.0.0",
"instant",
"libc",
"redox_syscall 0.2.9",
"redox_syscall",
"smallvec 1.6.1",
"winapi 0.3.9",
]
@ -1532,15 +1532,9 @@ dependencies = [
[[package]]
name = "redox_syscall"
version = "0.1.57"
version = "0.2.10"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "41cc0f7e4d5d4544e8861606a285bb08d3e70712ccc7d2b84d7c0ccfaf4b05ce"
[[package]]
name = "redox_syscall"
version = "0.2.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5ab49abadf3f9e1c4bc499e8845e152ad87d2ad2d30371841171169e9d75feee"
checksum = "8383f39639269cde97d255a32bdb68c047337295414940c68bdd30c2e13203ff"
dependencies = [
"bitflags",
]
@ -1551,7 +1545,7 @@ version = "0.1.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8440d8acb4fd3d277125b4bd01a6f38aee8d814b3b5fc09b3f2b825d37d3fe8f"
dependencies = [
"redox_syscall 0.2.9",
"redox_syscall",
]
[[package]]
@ -1810,7 +1804,7 @@ dependencies = [
"cfg-if 1.0.0",
"libc",
"rand 0.8.4",
"redox_syscall 0.2.9",
"redox_syscall",
"remove_dir_all",
"winapi 0.3.9",
]
@ -1851,7 +1845,7 @@ checksum = "077185e2eac69c3f8379a4298e1e07cd36beb962290d4a51199acf0fdc10607e"
dependencies = [
"libc",
"numtoa",
"redox_syscall 0.2.9",
"redox_syscall",
"redox_termios",
]
@ -2499,7 +2493,7 @@ dependencies = [
"clap",
"crossterm",
"nix 0.13.1",
"redox_syscall 0.1.57",
"redox_syscall",
"redox_termios",
"unicode-segmentation",
"unicode-width",
@ -2858,7 +2852,7 @@ dependencies = [
"clap",
"libc",
"nix 0.20.0",
"redox_syscall 0.1.57",
"redox_syscall",
"uucore",
"uucore_procs",
"winapi 0.3.9",
@ -2881,7 +2875,7 @@ version = "0.0.7"
dependencies = [
"clap",
"libc",
"redox_syscall 0.1.57",
"redox_syscall",
"uucore",
"uucore_procs",
]

View file

@ -217,9 +217,8 @@ feat_os_unix_fuchsia = [
feat_os_unix_redox = [
"feat_common_core",
#
"uname",
"chmod",
"install",
"uname",
]
# "feat_os_windows_legacy" == slightly restricted set of utilities which can be built/run on early windows platforms (eg, "WinXP")
feat_os_windows_legacy = [

View file

@ -15,7 +15,7 @@ use chrono::{DateTime, FixedOffset, Local, Offset, Utc};
#[cfg(windows)]
use chrono::{Datelike, Timelike};
use clap::{crate_version, App, Arg};
#[cfg(all(unix, not(target_os = "macos")))]
#[cfg(all(unix, not(target_os = "macos"), not(target_os = "redox")))]
use libc::{clock_settime, timespec, CLOCK_REALTIME};
use std::fs::File;
use std::io::{BufRead, BufReader};
@ -67,10 +67,12 @@ static RFC_3339_HELP_STRING: &str = "output date/time in RFC 3339 format.
for date and time to the indicated precision.
Example: 2006-08-14 02:34:56-06:00";
#[cfg(not(target_os = "macos"))]
#[cfg(not(any(target_os = "macos", target_os = "redox")))]
static OPT_SET_HELP_STRING: &str = "set time described by STRING";
#[cfg(target_os = "macos")]
static OPT_SET_HELP_STRING: &str = "set time described by STRING (not available on mac yet)";
#[cfg(target_os = "redox")]
static OPT_SET_HELP_STRING: &str = "set time described by STRING (not available on redox yet)";
/// Settings for this program, parsed from the command line
struct Settings {
@ -357,7 +359,13 @@ fn set_system_datetime(_date: DateTime<Utc>) -> i32 {
1
}
#[cfg(all(unix, not(target_os = "macos")))]
#[cfg(target_os = "redox")]
fn set_system_datetime(_date: DateTime<Utc>) -> i32 {
eprintln!("date: setting the date is not supported by Redox");
1
}
#[cfg(all(unix, not(target_os = "macos"), not(target_os = "redox")))]
/// System call to set date (unix).
/// See here for more:
/// https://doc.rust-lang.org/libc/i686-unknown-linux-gnu/libc/fn.clock_settime.html

View file

@ -19,13 +19,15 @@ byte-unit = "4.0"
clap = { version = "2.33", features = [ "wrap_help" ] }
gcd = "2.0"
libc = "0.2"
signal-hook = "0.3.9"
uucore = { version=">=0.0.8", package="uucore", path="../../uucore" }
uucore_procs = { version=">=0.0.5", package="uucore_procs", path="../../uucore_procs" }
[dev-dependencies]
tempfile = "^3"
[target.'cfg(target_os = "linux")'.dependencies]
signal-hook = "0.3.9"
[[bin]]
name = "dd"
path = "src/main.rs"

View file

@ -1590,7 +1590,7 @@ fn display_uname(metadata: &Metadata, config: &Config) -> String {
}
}
#[cfg(unix)]
#[cfg(all(unix, not(target_os = "redox")))]
fn cached_gid2grp(gid: u32) -> String {
lazy_static! {
static ref GID_CACHE: Mutex<HashMap<u32, String>> = Mutex::new(HashMap::new());
@ -1603,7 +1603,7 @@ fn cached_gid2grp(gid: u32) -> String {
.clone()
}
#[cfg(unix)]
#[cfg(all(unix, not(target_os = "redox")))]
fn display_group(metadata: &Metadata, config: &Config) -> String {
if config.long.numeric_uid_gid {
metadata.gid().to_string()
@ -1612,6 +1612,11 @@ fn display_group(metadata: &Metadata, config: &Config) -> String {
}
}
#[cfg(target_os = "redox")]
fn display_group(metadata: &Metadata, config: &Config) -> String {
metadata.gid().to_string()
}
#[cfg(not(unix))]
fn display_uname(_metadata: &Metadata, _config: &Config) -> String {
"somebody".to_string()

View file

@ -25,7 +25,7 @@ unicode-segmentation = "1.7.1"
[target.'cfg(target_os = "redox")'.dependencies]
redox_termios = "0.1"
redox_syscall = "0.1"
redox_syscall = "0.2"
[target.'cfg(all(unix, not(target_os = "fuchsia")))'.dependencies]
nix = "<=0.13"

View file

@ -16,7 +16,7 @@ path = "src/pr.rs"
[dependencies]
clap = { version = "2.33", features = ["wrap_help"] }
uucore = { version=">=0.0.7", package="uucore", path="../../uucore", features=["utmpx", "entries"] }
uucore = { version=">=0.0.7", package="uucore", path="../../uucore", features=["entries"] }
uucore_procs = { version=">=0.0.6", package="uucore_procs", path="../../uucore_procs" }
getopts = "0.2.21"
time = "0.1.41"

View file

@ -22,7 +22,7 @@ uucore_procs = { version=">=0.0.6", package="uucore_procs", path="../../uucore_p
winapi = { version="0.3", features=["fileapi", "handleapi", "processthreadsapi", "synchapi", "winbase"] }
[target.'cfg(target_os = "redox")'.dependencies]
redox_syscall = "0.1"
redox_syscall = "0.2"
[target.'cfg(unix)'.dependencies]
nix = "0.20"

View file

@ -14,14 +14,8 @@ pub use self::unix::{stdin_is_pipe_or_fifo, supports_pid_checks, Pid, ProcessChe
#[cfg(windows)]
pub use self::windows::{supports_pid_checks, Pid, ProcessChecker};
#[cfg(target_os = "redox")]
pub use self::redox::{supports_pid_checks, Pid, ProcessChecker};
#[cfg(unix)]
mod unix;
#[cfg(windows)]
mod windows;
#[cfg(target_os = "redox")]
mod redox;

View file

@ -1,25 +0,0 @@
// spell-checker:ignore (ToDO) ENOSYS EPERM
use self::syscall::{Error, ENOSYS, EPERM};
pub type Pid = usize;
pub struct ProcessChecker {
pid: self::Pid,
}
impl ProcessChecker {
pub fn new(process_id: self::Pid) -> ProcessChecker {
ProcessChecker { pid: process_id }
}
// Borrowing mutably to be aligned with Windows implementation
pub fn is_dead(&mut self) -> bool {
let res = syscall::kill(self.pid, 0);
res != Ok(0) && res != Err(Error::new(EPERM))
}
}
pub fn supports_pid_checks(pid: self::Pid) -> bool {
true
}

View file

@ -21,7 +21,7 @@ uucore = { version=">=0.0.9", package="uucore", path="../../uucore" }
uucore_procs = { version=">=0.0.6", package="uucore_procs", path="../../uucore_procs" }
[target.'cfg(target_os = "redox")'.dependencies]
redox_syscall = "0.1"
redox_syscall = "0.2"
[[bin]]
name = "test"

View file

@ -16,7 +16,7 @@ edition = "2018"
path="src/lib/lib.rs"
[dependencies]
dns-lookup = "1.0.5"
dns-lookup = { version="1.0.5", optional=true }
dunce = "1.0.0"
getopts = "<= 0.2.21"
wild = "2.0.4"
@ -55,6 +55,6 @@ process = ["libc"]
ringbuffer = []
signals = []
utf8 = []
utmpx = ["time", "libc"]
utmpx = ["time", "libc", "dns-lookup"]
wide = []
zero-copy = ["nix", "libc", "lazy_static", "platform-info"]

View file

@ -29,6 +29,7 @@ pub mod signals;
#[cfg(all(
unix,
not(target_os = "fuchsia"),
not(target_os = "redox"),
not(target_env = "musl"),
feature = "utmpx"
))]

View file

@ -37,7 +37,9 @@
#[cfg(any(target_os = "freebsd", target_vendor = "apple"))]
use libc::time_t;
use libc::{c_char, c_int, gid_t, uid_t};
use libc::{getgrgid, getgrnam, getgroups, getpwnam, getpwuid, group, passwd};
#[cfg(not(target_os = "redox"))]
use libc::{getgrgid, getgrnam, getgroups};
use libc::{getpwnam, getpwuid, group, passwd};
use std::borrow::Cow;
use std::ffi::{CStr, CString};
@ -65,6 +67,7 @@ extern "C" {
/// > supplementary group IDs for the process is returned. This allows
/// > the caller to determine the size of a dynamically allocated list
/// > to be used in a further call to getgroups().
#[cfg(not(target_os = "redox"))]
pub fn get_groups() -> IOResult<Vec<gid_t>> {
let ngroups = unsafe { getgroups(0, ptr::null_mut()) };
if ngroups == -1 {
@ -104,7 +107,7 @@ pub fn get_groups() -> IOResult<Vec<gid_t>> {
/// > groups is the same (in the mathematical sense of ``set''). (The
/// > history of a process and its parents could affect the details of
/// > the result.)
#[cfg(all(unix, feature = "process"))]
#[cfg(all(unix, not(target_os = "redox"), feature = "process"))]
pub fn get_groups_gnu(arg_id: Option<u32>) -> IOResult<Vec<gid_t>> {
let groups = get_groups()?;
let egid = arg_id.unwrap_or_else(crate::features::process::getegid);
@ -319,6 +322,7 @@ macro_rules! f {
}
f!(getpwnam, getpwuid, uid_t, Passwd);
#[cfg(not(target_os = "redox"))]
f!(getgrnam, getgrgid, gid_t, Group);
#[inline]
@ -326,6 +330,7 @@ pub fn uid2usr(id: uid_t) -> IOResult<String> {
Passwd::locate(id).map(|p| p.name().into_owned())
}
#[cfg(not(target_os = "redox"))]
#[inline]
pub fn gid2grp(id: gid_t) -> IOResult<String> {
Group::locate(id).map(|p| p.name().into_owned())
@ -336,6 +341,7 @@ pub fn usr2uid(name: &str) -> IOResult<uid_t> {
Passwd::locate(name).map(|p| p.uid())
}
#[cfg(not(target_os = "redox"))]
#[inline]
pub fn grp2gid(name: &str) -> IOResult<gid_t> {
Group::locate(name).map(|p| p.gid())

View file

@ -15,8 +15,6 @@ use libc::{
use std::borrow::Cow;
use std::env;
use std::fs;
#[cfg(target_os = "redox")]
use std::io;
use std::io::Result as IOResult;
use std::io::{Error, ErrorKind};
#[cfg(any(unix, target_os = "redox"))]

View file

@ -94,7 +94,8 @@ pub use libc::statfs as StatFs;
target_os = "netbsd",
target_os = "openbsd",
target_os = "bitrig",
target_os = "dragonfly"
target_os = "dragonfly",
target_os = "redox"
))]
pub use libc::statvfs as StatFs;
@ -110,7 +111,8 @@ pub use libc::statfs as statfs_fn;
target_os = "netbsd",
target_os = "openbsd",
target_os = "bitrig",
target_os = "dragonfly"
target_os = "dragonfly",
target_os = "redox"
))]
pub use libc::statvfs as statfs_fn;
@ -438,6 +440,11 @@ pub fn read_fs_list() -> Vec<MountInfo> {
}
mounts
}
#[cfg(target_os = "redox")]
{
// No method to read mounts, yet
Vec::new()
}
}
#[derive(Debug, Clone)]

View file

@ -35,12 +35,6 @@ pub fn parse_symbolic(
#[cfg(unix)]
use libc::umask;
#[cfg(target_os = "redox")]
unsafe fn umask(_mask: u32) -> u32 {
// XXX Redox does not currently have umask
0
}
let (mask, pos) = parse_levels(mode);
if pos == mode.len() {
return Err(format!("invalid mode ({})", mode));

View file

@ -65,6 +65,7 @@ pub use crate::features::signals;
#[cfg(all(
unix,
not(target_os = "fuchsia"),
not(target_os = "redox"),
not(target_env = "musl"),
feature = "utmpx"
))]