Skip to content
Merged
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
12 changes: 1 addition & 11 deletions Cargo.lock

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

2 changes: 0 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -391,7 +391,6 @@ 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 @@ -675,7 +674,6 @@ 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
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
// spell-checker:ignore Nofile nonewline cmdline setrlimit ELOOP

#[cfg(any(target_os = "linux", target_os = "android"))]
use rlimit::Resource;
use rustix::process::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)]
use rstest::rstest;
Expand Down Expand Up @@ -3114,7 +3114,7 @@ fn test_cp_reflink_insufficient_permission() {
#[cfg(target_os = "linux")]
#[test]
fn test_closes_file_descriptors() {
use rlimit::Resource;
use rustix::process::Resource;

let pid = std::process::id();
let fd_path = format!("/proc/{pid}/fd");
Expand All @@ -3134,7 +3134,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
6 changes: 3 additions & 3 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 sighandler
// 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 sighandler

use uutests::at_and_ucmd;
use uutests::new_ucmd;
Expand Down Expand Up @@ -2303,7 +2303,7 @@ 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 rlimit::Resource;
use rustix::process::Resource;

// Restores the previous SIGXFSZ disposition even if an assertion panics.
struct SigxfszGuard(libc::sighandler_t);
Expand All @@ -2325,7 +2325,7 @@ fn test_stats_are_reported_when_a_write_fails() {
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)
.fails();

// Under a 768 KiB cap, the first 512 KiB block is written in full, the
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 rlimit::Resource;
use rustix::process::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
// spell-checker:ignore (words) fakeroot setcap drwxr bcdlps mdangling mentry awith acolons Nofile NOTCAPABLE

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

use regex::Regex;
#[cfg(unix)]
use rlimit::Resource;
use rustix::process::Resource;
#[cfg(not(target_os = "openbsd"))]
use std::collections::HashMap;
#[cfg(target_os = "linux")]
Expand Down Expand Up @@ -7855,7 +7855,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 @@ -559,13 +559,13 @@ fn test_large_page_width_does_not_panic() {
#[cfg(target_os = "linux")]
#[test]
fn test_offset_large_value_does_not_abort_under_memory_limit() {
use rlimit::Resource;
use rustix::process::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
22 changes: 11 additions & 11 deletions tests/by-util/test_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 (words) ints (linux) NOFILE dfgi abmon avril
// spell-checker:ignore (words) ints (linux) Nofile dfgi abmon avril
#![allow(clippy::cast_possible_wrap)]

use std::env;
Expand Down Expand Up @@ -1744,14 +1744,14 @@ fn test_merge_batch_size() {
// #[cfg(any(target_os = "linux", target_os = "android"))]
#[cfg(target_os = "linux")]
fn test_merge_batch_size_with_limit() {
use rlimit::Resource;
use rustix::process::Resource;
// Currently need...
// 3 descriptors for stdin, stdout, stderr
// 2 descriptors for CTRL+C handling logic (to be reworked at some point)
// 2 descriptors for the input files (i.e. batch-size of 2).
let limit_fd = 3 + 2 + 2;
new_ucmd!()
.limit(Resource::NOFILE, limit_fd, limit_fd)
.limit(Resource::Nofile, limit_fd, limit_fd)
.arg("--batch-size=2")
.arg("-m")
.arg("--unique")
Expand All @@ -1769,13 +1769,13 @@ fn test_merge_batch_size_with_limit() {
// TODO(#7542): Re-enable on Android once we figure out why setting limit is broken.
#[cfg(target_os = "linux")]
fn test_batch_size_above_fd_limit_is_rejected() {
use rlimit::Resource;
use rustix::process::Resource;
// Only stdin, stdout and stderr are unavailable for merge inputs, so the
// largest acceptable --batch-size is the soft limit minus 3, here 27 - 3.
let limit_fd = 27;
let (at, mut ucmd) = at_and_ucmd!();
at.write("gamma.txt", "delta\nalpha\n");
ucmd.limit(Resource::NOFILE, limit_fd, limit_fd)
ucmd.limit(Resource::Nofile, limit_fd, limit_fd)
.arg("--batch-size=31")
.arg("gamma.txt")
.fails_with_code(2)
Expand All @@ -1787,12 +1787,12 @@ fn test_batch_size_above_fd_limit_is_rejected() {
#[test]
#[cfg(target_os = "linux")]
fn test_batch_size_at_fd_limit_is_accepted() {
use rlimit::Resource;
use rustix::process::Resource;
let limit_fd = 27;
let (at, mut ucmd) = at_and_ucmd!();
at.write("gamma.txt", "delta\nalpha\n");
// 24 is the largest value the limit above allows, and sorting must still happen.
ucmd.limit(Resource::NOFILE, limit_fd, limit_fd)
ucmd.limit(Resource::Nofile, limit_fd, limit_fd)
.arg("--batch-size=24")
.arg("gamma.txt")
.succeeds()
Expand All @@ -1802,7 +1802,7 @@ fn test_batch_size_at_fd_limit_is_accepted() {
#[test]
#[cfg(target_os = "linux")]
fn test_merge_more_files_than_fd_limit() {
use rlimit::Resource;
use rustix::process::Resource;
let (at, mut ucmd) = at_and_ucmd!();
// 40 single-line files cannot all be open at once with a soft limit of 24,
// so sort has to merge them in several batches through temporary files.
Expand All @@ -1818,7 +1818,7 @@ fn test_merge_more_files_than_fd_limit() {
writeln!(expected, "{i:02}").unwrap();
}
let limit_fd = 24;
ucmd.limit(Resource::NOFILE, limit_fd, limit_fd)
ucmd.limit(Resource::Nofile, limit_fd, limit_fd)
.arg("-m")
.args(&names)
.succeeds()
Expand All @@ -1828,7 +1828,7 @@ fn test_merge_more_files_than_fd_limit() {
#[test]
#[cfg(target_os = "linux")]
fn test_more_files_than_fd_limit() {
use rlimit::Resource;
use rustix::process::Resource;
let (at, mut ucmd) = at_and_ucmd!();
// The inputs are read one after another, so sorting must not need more open
// file descriptors than the soft limit allows, no matter how many inputs there are.
Expand All @@ -1844,7 +1844,7 @@ fn test_more_files_than_fd_limit() {
writeln!(expected, "{i:02}").unwrap();
}
let limit_fd = 24;
ucmd.limit(Resource::NOFILE, limit_fd, limit_fd)
ucmd.limit(Resource::Nofile, limit_fd, limit_fd)
.args(&names)
.succeeds()
.stdout_only(expected);
Expand Down
6 changes: 3 additions & 3 deletions tests/by-util/test_split.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
// For the full copyright and license information, please view the LICENSE
// file that was distributed with this source code.

// spell-checker:ignore xzaaa sixhundredfiftyonebytes ninetyonebytes threebytes asciilowercase ghijkl mnopq rstuv wxyz fivelines twohundredfortyonebytes onehundredlines nbbbb dxen ncccc rlimit NOFILE
// spell-checker:ignore xzaaa sixhundredfiftyonebytes ninetyonebytes threebytes asciilowercase ghijkl mnopq rstuv wxyz fivelines twohundredfortyonebytes onehundredlines nbbbb dxen ncccc rlimit Nofile

use rand::{RngExt as _, SeedableRng, rng};
use regex::Regex;
#[cfg(any(target_os = "linux", target_os = "android"))]
use rlimit::Resource;
use rustix::process::Resource;
#[cfg(not(windows))]
use std::env;
#[cfg(target_os = "linux")]
Expand Down Expand Up @@ -1701,7 +1701,7 @@ fn test_round_robin() {
fn test_round_robin_limited_file_descriptors() {
new_ucmd!()
.args(&["-n", "r/40", "onehundredlines.txt"])
.limit(Resource::NOFILE, 9, 9)
.limit(Resource::Nofile, 9, 9)
.succeeds();
}

Expand Down
2 changes: 1 addition & 1 deletion tests/uutests/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ uucore = { workspace = true, features = [

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

[target.'cfg(all(unix, not(any(target_os = "macos", target_os = "openbsd"))))'.dependencies]
xattr = { workspace = true }
Expand Down
27 changes: 12 additions & 15 deletions tests/uutests/src/lib/util.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 (linux) rlimit prlimit coreutil ggroups uchild uncaptured scmd SHLVL canonicalized openpty
//spell-checker: ignore (linux) winsize xpixel ypixel setrlimit FSIZE SIGBUS SIGSEGV sigbus tmpfs mksocket
//spell-checker: ignore (linux) winsize xpixel ypixel setrlimit Fsize SIGBUS SIGSEGV sigbus tmpfs mksocket
//spell-checker: ignore (ToDO) ttyname

#![allow(dead_code)]
Expand All @@ -25,7 +25,7 @@ use nix::sys;
use nix::sys::stat::{self, SFlag};
use pretty_assertions::assert_eq;
#[cfg(unix)]
use rlimit::setrlimit;
use rustix::process::{Resource, Rlimit, setrlimit};
use std::borrow::Cow;
use std::collections::VecDeque;
use std::ffi::{OsStr, OsString};
Expand Down Expand Up @@ -1543,7 +1543,7 @@ pub struct UCommand {
stderr: Option<Stdio>,
bytes_into_stdin: Option<Vec<u8>>,
#[cfg(unix)]
limits: Vec<(rlimit::Resource, u64, u64)>,
limits: Vec<(Resource, u64, u64)>,
stderr_to_stdout: bool,
timeout: Option<Duration>,
#[cfg(unix)]
Expand Down Expand Up @@ -1706,12 +1706,7 @@ impl UCommand {
}

#[cfg(unix)]
pub fn limit(
&mut self,
resource: rlimit::Resource,
soft_limit: u64,
hard_limit: u64,
) -> &mut Self {
pub fn limit(&mut self, resource: Resource, soft_limit: u64, hard_limit: u64) -> &mut Self {
self.limits.push((resource, soft_limit, hard_limit));
self
}
Expand Down Expand Up @@ -2052,7 +2047,13 @@ impl UCommand {
let limits_copy = self.limits.clone();
let closure = move || -> Result<()> {
for &(resource, soft_limit, hard_limit) in &limits_copy {
setrlimit(resource, soft_limit, hard_limit)?;
setrlimit(
resource,
Rlimit {
current: Some(soft_limit),
maximum: Some(hard_limit),
},
)?;
}
Ok(())
};
Expand Down Expand Up @@ -3671,11 +3672,7 @@ mod tests {
let ts = TestScenario::new("util");
ts.cmd("sh")
.args(&["-c", "ulimit -Sf; ulimit -Hf"])
.limit(
rlimit::Resource::FSIZE,
8 * unit_size_bytes,
16 * unit_size_bytes,
)
.limit(Resource::Fsize, 8 * unit_size_bytes, 16 * unit_size_bytes)
.succeeds()
.no_stderr()
.stdout_is("8\n16\n");
Expand Down
Loading