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

tail: fix handling of -f with non regular files

This makes uu_tail pass the "gnu/tests/tail-2/inotify-only-regular" test
again by adding support for charater devices.

test_tail:
* add test_follow_inotify_only_regular
* add clippy fixes for windows
This commit is contained in:
Jan Scheer 2022-04-21 22:52:17 +02:00
parent 7228902e55
commit 4a56d2916d
No known key found for this signature in database
GPG key ID: C62AD4C29E2B9828
2 changed files with 49 additions and 17 deletions

View file

@ -12,20 +12,22 @@ extern crate tail;
use crate::common::util::*;
use std::char::from_digit;
use std::io::{Read, Write};
#[cfg(unix)]
use std::thread::sleep;
#[cfg(unix)]
use std::time::Duration;
#[cfg(target_os = "linux")]
pub static BACKEND: &str = "inotify";
#[cfg(all(unix, not(target_os = "linux")))]
pub static BACKEND: &str = "kqueue";
#[cfg(target_os = "windows")]
pub static BACKEND: &str = "ReadDirectoryChanges";
static FOOBAR_TXT: &str = "foobar.txt";
static FOOBAR_2_TXT: &str = "foobar2.txt";
static FOOBAR_WITH_NULL_TXT: &str = "foobar_with_null.txt";
#[cfg(unix)]
static FOLLOW_NAME_TXT: &str = "follow_name.txt";
#[cfg(unix)]
static FOLLOW_NAME_SHORT_EXP: &str = "follow_name_short.expected";
#[cfg(target_os = "linux")]
static FOLLOW_NAME_EXP: &str = "follow_name.expected";
@ -1407,6 +1409,25 @@ fn test_follow_name_move() {
}
}
#[test]
#[cfg(unix)]
fn test_follow_inotify_only_regular() {
// The GNU test inotify-only-regular.sh uses strace to ensure that `tail -f`
// doesn't make inotify syscalls and only uses inotify for regular files or fifos.
// We just check if tailing a character device has the same behaviour than GNU's tail.
let ts = TestScenario::new(util_name!());
let mut p = ts.ucmd().arg("-f").arg("/dev/null").run_no_wait();
sleep(Duration::from_millis(200));
p.kill().unwrap();
let (buf_stdout, buf_stderr) = take_stdout_stderr(&mut p);
assert_eq!(buf_stdout, "".to_string());
assert_eq!(buf_stderr, "".to_string());
}
fn take_stdout_stderr(p: &mut std::process::Child) -> (String, String) {
let mut buf_stdout = String::new();
let mut p_stdout = p.stdout.take().unwrap();