1
Fork 0
mirror of https://github.com/RGBCube/uutils-coreutils synced 2025-07-28 11:37:44 +00:00

Fix display of bad fd errors

This commit is contained in:
electricboogie 2022-01-15 22:39:07 -06:00
parent fd5310411e
commit 37ca6edfdc
2 changed files with 167 additions and 51 deletions

View file

@ -7,6 +7,11 @@ use crate::common::util::*;
extern crate regex;
use self::regex::Regex;
#[cfg(unix)]
use nix::unistd::{close, dup2};
#[cfg(unix)]
use std::os::unix::io::AsRawFd;
use std::collections::HashMap;
use std::path::Path;
use std::thread::sleep;
@ -128,10 +133,7 @@ fn test_ls_io_errors() {
at.symlink_file("does_not_exist", "some-dir2/dangle");
at.mkdir("some-dir3");
at.mkdir("some-dir3/some-dir4");
at.mkdir("some-dir3/some-dir5");
at.mkdir("some-dir3/some-dir6");
at.mkdir("some-dir3/some-dir7");
at.mkdir("some-dir3/some-dir8");
at.mkdir("some-dir4");
scene.ccmd("chmod").arg("000").arg("some-dir1").succeeds();
@ -177,6 +179,37 @@ fn test_ls_io_errors() {
.stderr_does_not_contain(
"ls: cannot access 'some-dir2/dangle': No such file or directory\nls: cannot access 'some-dir2/dangle': No such file or directory"
);
#[cfg(unix)]
{
at.touch("some-dir4/bad-fd.txt");
let fd1 = at.open("some-dir4/bad-fd.txt").as_raw_fd();
let fd2 = 25000;
let rv1 = dup2(fd1, fd2);
let rv2 = close(fd1);
scene
.ucmd()
.arg("-alR")
.arg(format!("/dev/fd/{}", fd2))
.fails()
.stderr_contains(format!(
"cannot access '/dev/fd/{}': Bad file descriptor",
fd2
))
.stdout_does_not_contain(format!("{}:\n", fd2));
scene
.ucmd()
.arg("-RiL")
.arg(format!("/dev/fd/{}", fd2))
.fails()
.stderr_contains(format!("cannot access '/dev/fd/{}': Bad file descriptor", fd2))
// test we only print bad fd error once
.stderr_does_not_contain(format!("ls: cannot access '/dev/fd/{fd}': Bad file descriptor\nls: cannot access '/dev/fd/{fd}': Bad file descriptor", fd = fd2));
let _ = close(fd2);
}
}
#[test]