Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .github/workflows/CICD.yml
Original file line number Diff line number Diff line change
Expand Up @@ -367,6 +367,7 @@ jobs:
name: Build
needs: [ min_version, deps ]
runs-on: ${{ matrix.job.os }}
continue-on-error: ${{ matrix.job.target == 'x86_64-unknown-redox' }}
timeout-minutes: 90
env:
DOCKER_OPTS: '--volume /etc/passwd:/etc/passwd --volume /etc/group:/etc/group'
Expand Down Expand Up @@ -394,7 +395,7 @@ jobs:
- { os: ubuntu-latest , target: x86_64-unknown-linux-gnu , features: "feat_os_unix,openssl,uudoc" , use-cross: no, workspace-tests: true, pgo: PGO }
- { os: ubuntu-latest , target: x86_64-unknown-linux-musl , features: feat_os_unix_musl , use-cross: use-cross }
- { os: ubuntu-latest , target: x86_64-unknown-netbsd, features: "feat_os_unix", use-cross: use-cross , skip-tests: true , check-only: true }
# - { os: ubuntu-latest , target: x86_64-unknown-redox , features: feat_os_unix_redox , use-cross: redoxer , skip-tests: true , check-only: true }
- { os: ubuntu-latest , target: x86_64-unknown-redox , features: feat_os_unix_redox , use-cross: redoxer , skip-tests: true , check-only: true }
- { os: ubuntu-latest , target: wasm32-wasip1, default-features: false, features: feat_wasm, skip-tests: true }
- { os: ubuntu-latest , target: wasm32-wasip2, default-features: false, features: feat_wasm, skip-tests: true }
- { os: macos-latest , target: aarch64-apple-darwin , features: "feat_os_unix,openssl", workspace-tests: true, pgo: PGO } # M1 CPU
Expand Down
12 changes: 12 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ rand = { version = "0.10.1", features = ["std_rng"] }
rand_chacha = { version = "0.10.0" }
rayon = "1.10"
regex = "1.10.4"
rlimit = "0.11.0"
rstest = "0.27.0"
rstest_reuse = "0.7.0"
rustc-hash = "2.1.1"
Expand Down Expand Up @@ -394,6 +395,7 @@ runcon = { optional = true, version = "0.13.0", package = "uu_runcon", path = "s

[target.'cfg(unix)'.dev-dependencies]
nix = { workspace = true, features = ["fs", "signal"] }
rlimit = { workspace = true }
rustix = { workspace = true, features = ["net", "process"] }

[build-dependencies]
Expand Down
10 changes: 10 additions & 0 deletions fuzz/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions src/uu/sort/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ ctrlc = { workspace = true }
[target.'cfg(unix)'.dependencies]
libc = { workspace = true }
rustix = { workspace = true, features = ["fs"] }
rlimit = { workspace = true }

[dev-dependencies]
divan = { workspace = true }
Expand Down
40 changes: 7 additions & 33 deletions src/uu/sort/src/sort.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// For the full copyright and license information, please view the LICENSE
// file that was distributed with this source code.

// spell-checker:ignore (misc) kKMGTPEZYRQ HFKJFK Mbdfhn getrlimit Nofile rlim bigdecimal extendedbigdecimal hexdigit behaviour keydef GETFD localeconv foldhash
// spell-checker:ignore (misc) kKMGTPEZYRQ HFKJFK Mbdfhn getrlimit NOFILE rlim bigdecimal extendedbigdecimal hexdigit behaviour keydef GETFD localeconv foldhash
// spell-checker:ignore (misc) uppercased qsort getmonth juin juil

// Although these links don't always seem to describe reality, check out the POSIX and GNU specs:
Expand Down Expand Up @@ -1524,49 +1524,23 @@ fn make_sort_mode_arg(mode: &'static str, short: char, help: String) -> Arg {
.action(ArgAction::SetTrue)
}

#[cfg(all(
unix,
not(any(
target_os = "redox",
target_os = "fuchsia",
target_os = "haiku",
target_os = "solaris",
target_os = "illumos"
))
))]
#[cfg(unix)]
fn get_rlimit() -> UResult<usize> {
use rustix::process::{Resource, getrlimit};
use rlimit::{Resource, getrlimit};

let rlim_cur = getrlimit(Resource::Nofile)
.current
.ok_or_else(|| UUsageError::new(2, translate!("sort-failed-fetch-rlimit")))?;
let (rlim_cur, _) = getrlimit(Resource::NOFILE)
.map_err(|_| UUsageError::new(2, translate!("sort-failed-fetch-rlimit")))?;

usize::try_from(rlim_cur)
.map_err(|_| UUsageError::new(2, translate!("sort-failed-fetch-rlimit")))
}

#[cfg(all(
unix,
not(any(
target_os = "redox",
target_os = "fuchsia",
target_os = "haiku",
target_os = "solaris",
target_os = "illumos"
))
))]
#[cfg(unix)]
pub(crate) fn fd_soft_limit() -> Option<usize> {
get_rlimit().ok()
}

#[cfg(any(
not(unix),
target_os = "redox",
target_os = "fuchsia",
target_os = "haiku",
target_os = "solaris",
target_os = "illumos"
))]
#[cfg(not(unix))]
pub(crate) fn fd_soft_limit() -> Option<usize> {
None
}
Expand Down
7 changes: 4 additions & 3 deletions src/uu/test/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,16 @@ readme.workspace = true
path = "src/test.rs"
doctest = false

[dependencies]
[target.'cfg(not(target_os = "redox"))'.dependencies]
clap = { workspace = true }
fluent = { workspace = true }
thiserror = { workspace = true }
uucore = { workspace = true, features = ["fs", "i18n-collator", "wide"] }

[target.'cfg(not(any(windows, target_os = "wasi")))'.dependencies]
[target.'cfg(not(any(windows, target_os = "redox", target_os = "wasi")))'.dependencies]
rustix = { workspace = true, features = ["fs", "process"] }

[target.'cfg(not(windows))'.dependencies]
[target.'cfg(not(any(windows, target_os = "redox")))'.dependencies]
libc = { workspace = true }

[target.'cfg(windows)'.dependencies]
Expand All @@ -48,3 +48,4 @@ workspace = true
[[bin]]
name = "test"
path = "src/main.rs"
required-features = ["uucore/default"]
2 changes: 2 additions & 0 deletions src/uu/test/src/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@

// spell-checker:ignore (vars) egid euid faccessat

#![cfg(not(target_os = "redox"))]

mod diagnostics;
pub(crate) mod error;
#[cfg(not(any(windows, target_os = "wasi")))]
Expand Down
6 changes: 3 additions & 3 deletions tests/by-util/test_cat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
// For the full copyright and license information, please view the LICENSE
// file that was distributed with this source code.

// spell-checker:ignore Nofile nonewline cmdline setrlimit ELOOP bcde acde
// spell-checker:ignore NOFILE nonewline cmdline setrlimit ELOOP bcde acde

#[cfg(any(target_os = "linux", target_os = "android"))]
use rustix::process::Resource;
use rlimit::Resource;
#[cfg(unix)]
use std::fs::File;
use std::fs::OpenOptions;
Expand Down Expand Up @@ -135,7 +135,7 @@ fn test_closes_file_descriptors() {
"alpha.txt",
"alpha.txt",
])
.limit(Resource::Nofile, 9, 9)
.limit(Resource::NOFILE, 9, 9)
.succeeds();
}

Expand Down
6 changes: 3 additions & 3 deletions tests/by-util/test_cp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// For the full copyright and license information, please view the LICENSE
// file that was distributed with this source code.

// spell-checker:ignore (flags) reflink (fs) tmpfs (linux) filefrag rlimit Rlim Nofile clob btrfs neve ROOTDIR USERDIR outfile subvolume uufs xattrs ELOOP
// spell-checker:ignore (flags) reflink (fs) tmpfs (linux) filefrag rlimit Rlim NOFILE clob btrfs neve ROOTDIR USERDIR outfile subvolume uufs xattrs ELOOP
// spell-checker:ignore bdfl hlsl IRWXO IRWXG nconfined matchpathcon libselinux-devel prwx doesnotexist reftests subdirs mksocket srwx dstlink mcstransd

#[cfg(unix)]
Expand Down Expand Up @@ -3448,7 +3448,7 @@ fn test_cp_reflink_insufficient_permission() {
#[cfg(target_os = "linux")]
#[test]
fn test_closes_file_descriptors() {
use rustix::process::Resource;
use rlimit::Resource;

let pid = std::process::id();
let fd_path = format!("/proc/{pid}/fd");
Expand All @@ -3468,7 +3468,7 @@ fn test_closes_file_descriptors() {
.arg("--reflink=auto")
.arg("dir_with_10_files/")
.arg("dir_with_10_files_new/")
.limit(Resource::Nofile, limit_fd, limit_fd)
.limit(Resource::NOFILE, limit_fd, limit_fd)
.succeeds();
}

Expand Down
10 changes: 5 additions & 5 deletions tests/by-util/test_dd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// For the full copyright and license information, please view the LICENSE
// file that was distributed with this source code.

// spell-checker:ignore fname, tname, fpath, specfile, testfile, unspec, ifile, ofile, outfile, fullblock, urand, fileio, atoe, atoibm, availible, behaviour, bmax, bremain, btotal, cflags, creat, ctable, ctty, datastructures, doesnt, etoa, fileout, fname, gnudd, iconvflags, iseek, nocache, noctty, noerror, nofollow, nolinks, nonblock, oconvflags, oseek, outfile, parseargs, rlen, rmax, rposition, rremain, rsofar, rstat, sigusr, sigval, wlen, wstat abcdefghijklm abcdefghi nabcde nabcdefg abcdefg fifoname FADV DONTNEED Fsize SIGXFSZ rusage maxrss cdefg ncdefg cdefh memfd ftruncate
// spell-checker:ignore fname, tname, fpath, specfile, testfile, unspec, ifile, ofile, outfile, fullblock, urand, fileio, atoe, atoibm, availible, behaviour, bmax, bremain, btotal, cflags, creat, ctable, ctty, datastructures, doesnt, etoa, fileout, fname, gnudd, iconvflags, iseek, nocache, noctty, noerror, nofollow, nolinks, nonblock, oconvflags, oseek, outfile, parseargs, rlen, rmax, rposition, rremain, rsofar, rstat, sigusr, sigval, wlen, wstat abcdefghijklm abcdefghi nabcde nabcdefg abcdefg fifoname FADV DONTNEED FSIZE SIGXFSZ rusage maxrss cdefg ncdefg cdefh memfd ftruncate

use uutests::at_and_ucmd;
use uutests::new_ucmd;
Expand Down Expand Up @@ -2508,14 +2508,14 @@ fn test_count_bytes_with_expanding_block_conv() {
#[test]
#[cfg(all(unix, not(target_vendor = "apple")))]
fn test_stats_are_reported_when_a_write_fails() {
use rustix::process::Resource;
use rlimit::Resource;

const CAP: u64 = 768 * 1024;

let (at, mut ucmd) = at_and_ucmd!();
let result = ucmd
.args(&["if=/dev/zero", "of=capped.bin", "bs=512K", "count=3"])
.limit(Resource::Fsize, CAP, CAP)
.limit(Resource::FSIZE, CAP, CAP)
.ignore_sigxfsz()
.fails();

Expand All @@ -2531,15 +2531,15 @@ fn test_stats_are_reported_when_a_write_fails() {
#[test]
#[cfg(all(unix, not(target_vendor = "apple")))]
fn test_block_stats_are_reported_when_a_write_fails() {
use rustix::process::Resource;
use rlimit::Resource;

const CAP: u64 = 200 * 1024;

let (at, mut ucmd) = at_and_ucmd!();
let result = ucmd
.args(&["conv=block", "cbs=1M", "obs=64K", "of=capped.bin"])
.pipe_in("x\n")
.limit(Resource::Fsize, CAP, CAP)
.limit(Resource::FSIZE, CAP, CAP)
.ignore_sigxfsz()
.fails();

Expand Down
4 changes: 2 additions & 2 deletions tests/by-util/test_expand.rs
Original file line number Diff line number Diff line change
Expand Up @@ -276,12 +276,12 @@ fn test_tabs_with_too_large_size() {
)]
#[test]
fn test_large_tab_stop_without_tabs_does_not_allocate() {
use rustix::process::Resource;
use rlimit::Resource;

const AS_LIMIT: u64 = 200 * 1024 * 1024;

new_ucmd!()
.limit(Resource::As, AS_LIMIT, AS_LIMIT)
.limit(Resource::AS, AS_LIMIT, AS_LIMIT)
.arg("--tabs=267672676527678256")
.pipe_in("hello\n")
.succeeds()
Expand Down
6 changes: 3 additions & 3 deletions tests/by-util/test_ls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
// file that was distributed with this source code.

// spell-checker:ignore (words) READMECAREFULLY birthtime doesntexist oneline somebackup lrwx somefile somegroup somehiddenbackup somehiddenfile tabsize aaaaaaaa bbbb cccc dddddddd ncccc neee naaaaa nbcdef nfffff dired subdired tmpfs mdir COLORTERM mexe bcdef mfoo timefile
// spell-checker:ignore (words) fakeroot setcap drwxr bcdlps mdangling mentry awith acolons Nofile NOTCAPABLE iproduct newfstatat isox
// spell-checker:ignore (words) fakeroot setcap drwxr bcdlps mdangling mentry awith acolons NOFILE NOTCAPABLE iproduct newfstatat isox

#![allow(
clippy::similar_names,
Expand All @@ -14,7 +14,7 @@

use regex::Regex;
#[cfg(unix)]
use rustix::process::Resource;
use rlimit::Resource;
#[cfg(not(target_os = "openbsd"))]
use std::collections::HashMap;
#[cfg(target_os = "linux")]
Expand Down Expand Up @@ -8169,7 +8169,7 @@ fn test_ls_recursive_no_fd_leak() {
.ucmd()
.arg("-R")
.arg("1")
.limit(Resource::Nofile, 20, 20)
.limit(Resource::NOFILE, 20, 20)
.succeeds()
.no_stderr();
}
Expand Down
4 changes: 2 additions & 2 deletions tests/by-util/test_pr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -563,13 +563,13 @@ fn test_large_page_width_does_not_panic() {
ignore = "WASI: wasmtime itself needs more memory than the guest's rlimit allows"
)]
fn test_offset_large_value_does_not_abort_under_memory_limit() {
use rustix::process::Resource;
use rlimit::Resource;
use std::process::Stdio;

const AS_LIMIT: u64 = 200 * 1024 * 1024;

new_ucmd!()
.limit(Resource::As, AS_LIMIT, AS_LIMIT)
.limit(Resource::AS, AS_LIMIT, AS_LIMIT)
.set_stdout(Stdio::null())
.args(&["-t", "-o", "999999999"])
.pipe_in("hi\n")
Expand Down
Loading
Loading