Repository navigation
Conversation
There was a problem hiding this comment.
Warning
Copilot couldn't run its full agentic review because it didn't start before the timeout. Make sure your repository has a runner available, or add a copilot-code-review.yml file specifying one with the runs-on attribute. See the docs for more details.
Copilot review overview
1 open issue
What changed in this PR
Adds robust tail -f/-F support for character devices by switching follow mode to polling when needed and performing nonblocking reads so quiet devices don’t stall other inputs or PID checks.
Changes:
- Add regression test covering follow behavior on PTYs (character devices), including multiple inputs and partial lines.
- Update follow watcher to enable polling when any input is a character device.
- Refactor follow file handling to store concrete
BufReader<File>and perform nonblocking reads for character devices.
| File | Description |
|---|---|
| tests/by-util/test_tail.rs | Adds PTY/character-device follow regression test cases. |
| src/uu/tail/src/tail.rs | Adapts add_path call to new concrete reader type. |
| src/uu/tail/src/follow/watch.rs | Detects character-device inputs and forces polling mode. |
| src/uu/tail/src/follow/mod.rs | Updates WASI stubs to match new reader type signature. |
| src/uu/tail/src/follow/files.rs | Switches reader storage to BufReader<File> and adds nonblocking char-device read path. |
Review effort: Lite
There was a problem hiding this comment.
Warning
Copilot couldn't run its full agentic review because it didn't start before the timeout. Make sure your repository has a runner available, or add a copilot-code-review.yml file specifying one with the runs-on attribute. See the docs for more details.
Copilot review overview
5 open issues
The fd flags restoration can mask a read error (if the restorefcntl_setflfails, it will be… · Newtail_file()currently performs multiple syscalls on every polling iteration for character devices…reset_readerperforms multiple map lookups and re-canonicalizes the path separately. This can be… · New This adds device paths intopathsusingVec::contains, making the operation O(N*M) (N = paths,… · New If the condition is never met, the test will only fail later at the finalstdout_is, which makes… · New
Review effort: Lite
There was a problem hiding this comment.
Warning
Copilot couldn't run its full agentic review because it didn't start before the timeout. Make sure your repository has a runner available, or add a copilot-code-review.yml file specifying one with the runs-on attribute. See the docs for more details.
Copilot review overview
8 open issues
This introduces a new hard failure mode for follow: iffile.metadata()fails inside… · Newpaths.contains(path)compares rawPathBufs, butpathsmay contain an alias (e.g., a symlink… · New The polling loop breaks when the expected output appears, but there’s no explicit assertion… · New The fd flags restoration can mask a read error (if the restorefcntl_setflfails, it will be…tail_file()currently performs multiple syscalls on every polling iteration for character devices… If the condition is never met, the test will only fail later at the finalstdout_is, which makes… This adds device paths intopathsusingVec::contains, making the operation O(N*M) (N = paths,…reset_readerperforms multiple map lookups and re-canonicalizes the path separately. This can be…
Review effort: Lite
There was a problem hiding this comment.
Warning
Copilot couldn't run its full agentic review because it didn't start before the timeout. Make sure your repository has a runner available, or add a copilot-code-review.yml file specifying one with the runs-on attribute. See the docs for more details.
Copilot review overview
12 open issues
timeoutcan becomeDuration::ZERO(notably when-s0is used). With character devices present,… · Newtimeoutcan becomeDuration::ZERO(notably when-s0is used). With character devices present,… · New The polling loop breaks when the expected output appears, but there’s no explicit assertion…paths.contains(path)compares rawPathBufs, butpathsmay contain an alias (e.g., a symlink… This introduces a new hard failure mode for follow: iffile.metadata()fails inside… The fd flags restoration can mask a read error (if the restorefcntl_setflfails, it will be…tail_file()currently performs multiple syscalls on every polling iteration for character devices… This performs multiple canonicalizations/lookups (get_muttwice pluscanonicalize_path). It… · Newpaths.contains(path)is an O(n) scan inside a loop, making this O(n*m) when many files are… · New If the condition is never met, the test will only fail later at the finalstdout_is, which makes… This adds device paths intopathsusingVec::contains, making the operation O(N*M) (N = paths,…reset_readerperforms multiple map lookups and re-canonicalizes the path separately. This can be…
Review effort: Lite
There was a problem hiding this comment.
Warning
Copilot couldn't run its full agentic review because it didn't start before the timeout. Make sure your repository has a runner available, or add a copilot-code-review.yml file specifying one with the runs-on attribute. See the docs for more details.
Copilot review overview
16 open issues
This performs twofcntlsyscalls per device read (F_GETFL+F_SETFL, thenF_SETFLto… · NewPathData::newnow fails the whole follow setup ifmetadata()fails while detecting whether… · New Thisread_exactof 256 KiB with a 5s socket read timeout can be flaky on slower/contended CI,… · Newtimeoutcan becomeDuration::ZERO(notably when-s0is used). With character devices present,…timeoutcan becomeDuration::ZERO(notably when-s0is used). With character devices present,… The polling loop breaks when the expected output appears, but there’s no explicit assertion…paths.contains(path)compares rawPathBufs, butpathsmay contain an alias (e.g., a symlink… This introduces a new hard failure mode for follow: iffile.metadata()fails inside… The fd flags restoration can mask a read error (if the restorefcntl_setflfails, it will be…tail_file()currently performs multiple syscalls on every polling iteration for character devices…Self::canonicalize_path(path)is computed twice here. Since canonicalization can involve… · Newpaths.contains(path)is an O(n) scan inside a loop, making this O(n*m) when many files are… This performs multiple canonicalizations/lookups (get_muttwice pluscanonicalize_path). It… If the condition is never met, the test will only fail later at the finalstdout_is, which makes… This adds device paths intopathsusingVec::contains, making the operation O(N*M) (N = paths,…reset_readerperforms multiple map lookups and re-canonicalizes the path separately. This can be…
Review effort: Lite
There was a problem hiding this comment.
Warning
Copilot couldn't run its full agentic review because it didn't start before the timeout. Make sure your repository has a runner available, or add a copilot-code-review.yml file specifying one with the runs-on attribute. See the docs for more details.
Copilot review overview
20 open issues
Whenobserver.use_pollingis true, this block does not add character-device paths topaths. If… · New This togglesO_NONBLOCKon the FD for every device read (twofcntls per pass). For busy devices… · Newoutputhas a 5-second read timeout, andoutput.read(...).unwrap()will panic on timeout… · New Same issue as above: this loop can panic on a read timeout because it unwraps the read result.… · New Thisread_exactof 256 KiB with a 5s socket read timeout can be flaky on slower/contended CI,…PathData::newnow fails the whole follow setup ifmetadata()fails while detecting whether… This performs twofcntlsyscalls per device read (F_GETFL+F_SETFL, thenF_SETFLto…timeoutcan becomeDuration::ZERO(notably when-s0is used). With character devices present,…timeoutcan becomeDuration::ZERO(notably when-s0is used). With character devices present,… The polling loop breaks when the expected output appears, but there’s no explicit assertion…paths.contains(path)compares rawPathBufs, butpathsmay contain an alias (e.g., a symlink… This introduces a new hard failure mode for follow: iffile.metadata()fails inside… The fd flags restoration can mask a read error (if the restorefcntl_setflfails, it will be…tail_file()currently performs multiple syscalls on every polling iteration for character devices…Self::canonicalize_path(path)is computed twice here. Since canonicalization can involve…paths.contains(path)is an O(n) scan inside a loop, making this O(n*m) when many files are… This performs multiple canonicalizations/lookups (get_muttwice pluscanonicalize_path). It… If the condition is never met, the test will only fail later at the finalstdout_is, which makes… This adds device paths intopathsusingVec::contains, making the operation O(N*M) (N = paths,…reset_readerperforms multiple map lookups and re-canonicalizes the path separately. This can be…
Review effort: Lite
|
Binary size comparison: |
There was a problem hiding this comment.
Warning
Copilot couldn't run its full agentic review because it didn't start before the timeout. Make sure your repository has a runner available, or add a copilot-code-review.yml file specifying one with the runs-on attribute. See the docs for more details.
Copilot review overview
22 open issues
check_device_namesynthesizesEventKind::Modify(Name(RenameMode::To))with only the current… · New Whenobserver.use_pollingis true, this block does not add character-device paths topaths. If… This togglesO_NONBLOCKon the file description for every device poll (two fcntl syscalls per… · New Same issue as above: this loop can panic on a read timeout because it unwraps the read result.…outputhas a 5-second read timeout, andoutput.read(...).unwrap()will panic on timeout… This togglesO_NONBLOCKon the FD for every device read (twofcntls per pass). For busy devices… Thisread_exactof 256 KiB with a 5s socket read timeout can be flaky on slower/contended CI,…PathData::newnow fails the whole follow setup ifmetadata()fails while detecting whether… This performs twofcntlsyscalls per device read (F_GETFL+F_SETFL, thenF_SETFLto…timeoutcan becomeDuration::ZERO(notably when-s0is used). With character devices present,…timeoutcan becomeDuration::ZERO(notably when-s0is used). With character devices present,… The polling loop breaks when the expected output appears, but there’s no explicit assertion…paths.contains(path)compares rawPathBufs, butpathsmay contain an alias (e.g., a symlink… This introduces a new hard failure mode for follow: iffile.metadata()fails inside… The fd flags restoration can mask a read error (if the restorefcntl_setflfails, it will be…tail_file()currently performs multiple syscalls on every polling iteration for character devices…Self::canonicalize_path(path)is computed twice here. Since canonicalization can involve…paths.contains(path)is an O(n) scan inside a loop, making this O(n*m) when many files are… This performs multiple canonicalizations/lookups (get_muttwice pluscanonicalize_path). It… If the condition is never met, the test will only fail later at the finalstdout_is, which makes…
And 2 more that still need to be addressed.
Review effort: Lite
There was a problem hiding this comment.
Warning
Copilot couldn't run its full agentic review because it didn't start before the timeout. Make sure your repository has a runner available, or add a copilot-code-review.yml file specifying one with the runs-on attribute. See the docs for more details.
Copilot review overview
25 open issues
pd.reader.as_ref().unwrap()can panic if this path is being tracked withreader == None(e.g.,… · Newcheck_device_namesynthesizesEventKind::Modify(Name(RenameMode::To))with only the current… Whenobserver.use_pollingis true, this block does not add character-device paths topaths. If… UsingDuration::ZEROwhenread_devices_againis true can create a tight spin loop for… · New The final assertion always expects"deviceother file\n", but"other file\n"is only appended… · New This togglesO_NONBLOCKon the file description for every device poll (two fcntl syscalls per… Same issue as above: this loop can panic on a read timeout because it unwraps the read result.…outputhas a 5-second read timeout, andoutput.read(...).unwrap()will panic on timeout… This togglesO_NONBLOCKon the FD for every device read (twofcntls per pass). For busy devices… Thisread_exactof 256 KiB with a 5s socket read timeout can be flaky on slower/contended CI,…PathData::newnow fails the whole follow setup ifmetadata()fails while detecting whether… This performs twofcntlsyscalls per device read (F_GETFL+F_SETFL, thenF_SETFLto…timeoutcan becomeDuration::ZERO(notably when-s0is used). With character devices present,…timeoutcan becomeDuration::ZERO(notably when-s0is used). With character devices present,… The polling loop breaks when the expected output appears, but there’s no explicit assertion…paths.contains(path)compares rawPathBufs, butpathsmay contain an alias (e.g., a symlink… This introduces a new hard failure mode for follow: iffile.metadata()fails inside… The fd flags restoration can mask a read error (if the restorefcntl_setflfails, it will be…tail_file()currently performs multiple syscalls on every polling iteration for character devices…Self::canonicalize_path(path)is computed twice here. Since canonicalization can involve…
And 5 more that still need to be addressed.
Review effort: Lite
There was a problem hiding this comment.
Warning
Copilot couldn't run its full agentic review because it didn't start before the timeout. Make sure your repository has a runner available, or add a copilot-code-review.yml file specifying one with the runs-on attribute. See the docs for more details.
Copilot review overview
29 open issues
fill_buf()returns a&[u8], and calling.read(buf)on that value requires a mutable receiver… · Newpd.reader.as_ref().unwrap()can panic if this path is being tracked withreader == None(e.g.,…check_device_namesynthesizesEventKind::Modify(Name(RenameMode::To))with only the current… Whenobserver.use_pollingis true, this block does not add character-device paths topaths. If… This usesunwrap()onreaderand will panic if a tracked path is still in the… · Newwait_until(...)returns a boolean but the result is ignored here, which can make failures harder… · New Ifreadyis false, the test never appends"other file\n"but still asserts the combined stdout… · New The final assertion always expects"deviceother file\n", but"other file\n"is only appended… UsingDuration::ZEROwhenread_devices_againis true can create a tight spin loop for… This togglesO_NONBLOCKon the file description for every device poll (two fcntl syscalls per… Same issue as above: this loop can panic on a read timeout because it unwraps the read result.…outputhas a 5-second read timeout, andoutput.read(...).unwrap()will panic on timeout… This togglesO_NONBLOCKon the FD for every device read (twofcntls per pass). For busy devices… Thisread_exactof 256 KiB with a 5s socket read timeout can be flaky on slower/contended CI,…PathData::newnow fails the whole follow setup ifmetadata()fails while detecting whether… This performs twofcntlsyscalls per device read (F_GETFL+F_SETFL, thenF_SETFLto…timeoutcan becomeDuration::ZERO(notably when-s0is used). With character devices present,…timeoutcan becomeDuration::ZERO(notably when-s0is used). With character devices present,… The polling loop breaks when the expected output appears, but there’s no explicit assertion…paths.contains(path)compares rawPathBufs, butpathsmay contain an alias (e.g., a symlink…
And 9 more that still need to be addressed.
Review effort: Lite
There was a problem hiding this comment.
Warning
Copilot couldn't run its full agentic review because it didn't start before the timeout. Make sure your repository has a runner available, or add a copilot-code-review.yml file specifying one with the runs-on attribute. See the docs for more details.
Copilot review overview
18 open issues
pd.reader.as_ref().unwrap()can panic if the file is being followed by name but currently has no… · Newfill_buf()returns a&[u8], and calling.read(buf)on that value requires a mutable receiver…pd.reader.as_ref().unwrap()can panic if this path is being tracked withreader == None(e.g.,…check_device_namesynthesizesEventKind::Modify(Name(RenameMode::To))with only the current… Whenobserver.use_pollingis true, this block does not add character-device paths topaths. If…wait_for_outputrequires stdout to be exactlyexpected. Since stdout only grows, the test can… · New This call towait_for_outputignores the returned boolean, so the test can still pass even if the… · New This usesunwrap()onreaderand will panic if a tracked path is still in the… UsingDuration::ZEROwhenread_devices_againis true can create a tight spin loop for… Same issue as above: this loop can panic on a read timeout because it unwraps the read result.…outputhas a 5-second read timeout, andoutput.read(...).unwrap()will panic on timeout… Thisread_exactof 256 KiB with a 5s socket read timeout can be flaky on slower/contended CI,…PathData::newnow fails the whole follow setup ifmetadata()fails while detecting whether…timeoutcan becomeDuration::ZERO(notably when-s0is used). With character devices present,…timeoutcan becomeDuration::ZERO(notably when-s0is used). With character devices present,… The polling loop breaks when the expected output appears, but there’s no explicit assertion…paths.contains(path)compares rawPathBufs, butpathsmay contain an alias (e.g., a symlink… This introduces a new hard failure mode for follow: iffile.metadata()fails inside…
14 resolved since last review
Ifreadyis false, the test never appends"other file\n"but still asserts the combined stdout…wait_until(...)returns a boolean but the result is ignored here, which can make failures harder… The final assertion always expects"deviceother file\n", but"other file\n"is only appended… This togglesO_NONBLOCKon the file description for every device poll (two fcntl syscalls per… This togglesO_NONBLOCKon the FD for every device read (twofcntls per pass). For busy devices… This performs twofcntlsyscalls per device read (F_GETFL+F_SETFL, thenF_SETFLto… The fd flags restoration can mask a read error (if the restorefcntl_setflfails, it will be…tail_file()currently performs multiple syscalls on every polling iteration for character devices…Self::canonicalize_path(path)is computed twice here. Since canonicalization can involve…paths.contains(path)is an O(n) scan inside a loop, making this O(n*m) when many files are… This performs multiple canonicalizations/lookups (get_muttwice pluscanonicalize_path). It… If the condition is never met, the test will only fail later at the finalstdout_is, which makes… This adds device paths intopathsusingVec::contains, making the operation O(N*M) (N = paths,…reset_readerperforms multiple map lookups and re-canonicalizes the path separately. This can be…
Review effort: Lite
There was a problem hiding this comment.
Warning
Copilot couldn't run its full agentic review because it didn't start before the timeout. Make sure your repository has a runner available, or add a copilot-code-review.yml file specifying one with the runs-on attribute. See the docs for more details.
Copilot review overview
4 open issues
The new condition unconditionally unwrapspd.reader(pd.reader.as_ref().unwrap()), which can… · New This introduces a newwait_for_outputhelper with a different signature. There is already an… · New This treats any nonzeropoll()return value as 'readable'. However,poll()may report readiness… · Newwait_for_outputreturnsboolhere but the result is ignored. If the wait times out, the test… · New
18 resolved since last review
pd.reader.as_ref().unwrap()can panic if the file is being followed by name but currently has no…fill_buf()returns a&[u8], and calling.read(buf)on that value requires a mutable receiver…pd.reader.as_ref().unwrap()can panic if this path is being tracked withreader == None(e.g.,…check_device_namesynthesizesEventKind::Modify(Name(RenameMode::To))with only the current… Whenobserver.use_pollingis true, this block does not add character-device paths topaths. If… This call towait_for_outputignores the returned boolean, so the test can still pass even if the…wait_for_outputrequires stdout to be exactlyexpected. Since stdout only grows, the test can… This usesunwrap()onreaderand will panic if a tracked path is still in the… UsingDuration::ZEROwhenread_devices_againis true can create a tight spin loop for… Same issue as above: this loop can panic on a read timeout because it unwraps the read result.…outputhas a 5-second read timeout, andoutput.read(...).unwrap()will panic on timeout… Thisread_exactof 256 KiB with a 5s socket read timeout can be flaky on slower/contended CI,…PathData::newnow fails the whole follow setup ifmetadata()fails while detecting whether…timeoutcan becomeDuration::ZERO(notably when-s0is used). With character devices present,…timeoutcan becomeDuration::ZERO(notably when-s0is used). With character devices present,… The polling loop breaks when the expected output appears, but there’s no explicit assertion…paths.contains(path)compares rawPathBufs, butpathsmay contain an alias (e.g., a symlink… This introduces a new hard failure mode for follow: iffile.metadata()fails inside…
Review effort: Lite
| && !pd.reader.as_ref().unwrap().get_ref().metadata()?.file_id_eq(&new_md)) | ||
| || (self.use_polling && !old_md.file_id_eq(&new_md)) { | ||
| // Compare with the open reader: a device-name check may | ||
| // have handled the replacement before its native event. |
| #[cfg(unix)] | ||
| fn wait_for_output(child: &mut uutests::util::UChild, expected: &str) -> bool { | ||
| for _ in 0..500 { | ||
| if child.stdout_all() == expected { | ||
| return true; | ||
| } | ||
| child.delay(10); | ||
| } | ||
| child.stdout_all() == expected | ||
| } |
| use rustix::event::{PollFd, PollFlags, Timespec, poll}; | ||
|
|
||
| let mut fds = [PollFd::new(file, PollFlags::IN)]; | ||
| rustix::io::retry_on_intr(|| poll(&mut fds, Some(&Timespec::default()))) | ||
| .map(|ready| ready != 0) |
| ); | ||
| // A quiet device must not block output from the other input. | ||
| ts.fixtures.append("other", "other file\n"); | ||
| wait_for_output(&mut child, "new dataother file\n"); |
|
GNU testsuite comparison: |
Merging this PR will regress 28 benchmarks1 warning, 2 notes
Warning Please fix the performance issues or acknowledge them on CodSpeed. Performance Changes
Tip Investigate this regression by commenting Comparing Footnotes
|
There was a problem hiding this comment.
Warning
Copilot couldn't run its full agentic review because it didn't start before the timeout. Make sure your repository has a runner available, or add a copilot-code-review.yml file specifying one with the runs-on attribute. See the docs for more details.
Copilot review overview
7 open issues
open_follow_filereturns(File, is_character_device)butfrom_other_with_pathdiscards the… · New This introduces a newwait_for_outputhelper with a different signature. There is already an… The new condition unconditionally unwrapspd.reader(pd.reader.as_ref().unwrap()), which can…FileHandling::insert()canonicalizes paths before storing them, and several accessors (get,… · New On Apple,device_is_readableallocates anFdSetElementvector sized tofd + 1every time it… · New This treats any nonzeropoll()return value as 'readable'. However,poll()may report readiness…wait_for_outputreturnsboolhere but the result is ignored. If the wait times out, the test…
Review effort: Lite
| pub fn from_other_with_path(data: Self, path: &Path, nonblocking: bool) -> UResult<Self> { | ||
| // Remove old reader | ||
| let old_reader = data.reader; | ||
| let reader = if old_reader.is_some() { | ||
| // Use old reader with the same file descriptor if there is one | ||
| old_reader | ||
| } else if let Ok(file) = open_file(path, nonblocking) { | ||
| } else if let Ok((file, _)) = open_follow_file(path, nonblocking) { | ||
| // Open new file tail from start | ||
| Some(Box::new(BufReader::new(file)) as Box<dyn BufRead>) | ||
| Some(BufReader::new(file)) |
| } | ||
|
|
||
| pub fn contains_key(&self, k: &Path) -> bool { | ||
| self.map.contains_key(k) |
| #[cfg(target_vendor = "apple")] | ||
| fn device_is_readable(file: &File) -> io::Result<bool> { | ||
| use rustix::event::{FdSetElement, Timespec, fd_set_insert, fd_set_num_elements, select}; | ||
| use std::os::fd::AsRawFd; | ||
|
|
||
| // Apple's poll reports POLLNVAL for devices such as /dev/null and /dev/zero. | ||
| let fd = file.as_raw_fd(); | ||
| let mut read_fds = vec![FdSetElement::default(); fd_set_num_elements(1, fd + 1)]; | ||
| rustix::io::retry_on_intr(|| { | ||
| fd_set_insert(&mut read_fds, fd); | ||
| // SAFETY: file keeps the sole descriptor in the correctly sized set open. | ||
| unsafe { | ||
| select( | ||
| fd + 1, | ||
| Some(&mut read_fds), | ||
| None, | ||
| None, | ||
| Some(&Timespec::default()), | ||
| ) | ||
| } | ||
| }) | ||
| .map(|ready| ready != 0) | ||
| .map_err(io::Error::from) | ||
| } |
|
please squash commits for a clean branch history |
ffa06a1 to
a2dd8cb
Compare
a2dd8cb to
87392e7
Compare
left a comment
There was a problem hiding this comment.
Warning
Copilot couldn't run its full agentic review because it didn't start before the timeout. Make sure your repository has a runner available, or add a copilot-code-review.yml file specifying one with the runs-on attribute. See the docs for more details.
Copilot review overview
10 open issues
open_follow_filereturns(File, is_character_device)butfrom_other_with_pathdiscards the… This introduces a newwait_for_outputhelper with a different signature. There is already an… The new condition unconditionally unwrapspd.reader(pd.reader.as_ref().unwrap()), which can…character_devices()appears to be keyed by the canonicalized paths used byFileHandling… · New Same canonicalization issue as incheck_device_name:event.paths[0]may not match the canonical… · Newoutputhas a 5-second read timeout set earlier, soread()can return anErr(e.g.,… · New On Apple,device_is_readableallocates anFdSetElementvector sized tofd + 1every time it…FileHandling::insert()canonicalizes paths before storing them, and several accessors (get,… This treats any nonzeropoll()return value as 'readable'. However,poll()may report readiness…wait_for_outputreturnsboolhere but the result is ignored. If the wait times out, the test…
Review effort: Lite
| if !self.follow_name() || !self.files.character_devices().contains(path) { | ||
| return Ok(()); | ||
| } | ||
| let kind = match path.metadata() { | ||
| Ok(metadata) => { | ||
| // Compare with the open device: cached path metadata may already | ||
| // describe a replacement that arrived during the previous read. | ||
| let reader = self.files.get(path).reader.as_ref().unwrap(); | ||
| if reader.get_ref().metadata()?.file_id_eq(&metadata) { |
| if observer.files.character_devices().contains(path) { | ||
| // Device events can describe the old target after a rename. | ||
| // Check the current name in the print loop; -f keeps its FD. | ||
| if scheduled.insert(path.clone()) { | ||
| paths.push(path.clone()); |
| let deadline = Instant::now() + Duration::from_secs(5); | ||
| while marker.len() < b"other file\n".len() && Instant::now() < deadline { | ||
| let count = output.read(&mut buffer).unwrap(); | ||
| if count == 0 { | ||
| break; | ||
| } | ||
| marker.extend(buffer[..count].iter().copied().filter(|byte| *byte != 0)); | ||
| } |
87392e7 to
810ca92
Compare
left a comment
There was a problem hiding this comment.
Warning
Copilot couldn't run its full agentic review because it didn't start before the timeout. Make sure your repository has a runner available, or add a copilot-code-review.yml file specifying one with the runs-on attribute. See the docs for more details.
Copilot review overview
13 open issues
In--use-pollingmode, this block updateslast_device_pollbut intentionally skips adding… · New This adds a newwait_for_outputhelper with a different signature from the existing… · Newopen_follow_filereturns(File, is_character_device)butfrom_other_with_pathdiscards the… This introduces a newwait_for_outputhelper with a different signature. There is already an… The new condition unconditionally unwrapspd.reader(pd.reader.as_ref().unwrap()), which can… This Linux-only unit test relies on/procand/dev/ptsbeing present and having specific inode… · Newoutputhas a 5-second read timeout set earlier, soread()can return anErr(e.g.,… Same canonicalization issue as incheck_device_name:event.paths[0]may not match the canonical…character_devices()appears to be keyed by the canonicalized paths used byFileHandling… On Apple,device_is_readableallocates anFdSetElementvector sized tofd + 1every time it…FileHandling::insert()canonicalizes paths before storing them, and several accessors (get,… This treats any nonzeropoll()return value as 'readable'. However,poll()may report readiness…wait_for_outputreturnsboolhere but the result is ignored. If the wait times out, the test…
Review effort: Lite
| // The polling backend already includes every input above. | ||
| if !observer.use_polling { | ||
| paths.extend( | ||
| observer | ||
| .files | ||
| .character_devices() | ||
| .iter() | ||
| .filter(|path| scheduled.insert((*path).clone())) | ||
| .cloned(), | ||
| ); | ||
| } |
| #[cfg(unix)] | ||
| fn wait_for_output(child: &mut uutests::util::UChild, expected: &str) -> bool { | ||
| for _ in 0..500 { | ||
| if child.stdout_all() == expected { | ||
| return true; | ||
| } | ||
| child.delay(10); | ||
| } | ||
| child.stdout_all() == expected | ||
| } |
| let proc = std::fs::metadata("/proc").unwrap(); | ||
| let pts = std::fs::metadata("/dev/pts").unwrap(); | ||
| assert_eq!(proc.ino(), pts.ino()); | ||
| assert_ne!(proc.dev(), pts.dev()); | ||
| assert!(proc.file_id_eq(&std::fs::metadata("/proc").unwrap())); |
Poll character devices alongside native file watches so tail -f and -F continue reading after EOF. Keep owned device readers nonblocking, bound each read batch, and preserve inherited stdin flags. Watch device parents on native backends, reopen replacements by device and inode, and cover terminal input, aliases, replacement, and shutdown. Signed-off-by: rleungx <rleungx@gmail.com>
810ca92 to
fe8ede5
Compare
left a comment
There was a problem hiding this comment.
Warning
Copilot couldn't run its full agentic review because it didn't start before the timeout. Make sure your repository has a runner available, or add a copilot-code-review.yml file specifying one with the runs-on attribute. See the docs for more details.
Copilot review overview
17 open issues
pd.reader.as_ref().unwrap()can panic if a tracked path exists inself.filesbut currently has… · New This adds a newwait_for_outputhelper with a different signature from the existing… In--use-pollingmode, this block updateslast_device_pollbut intentionally skips adding…open_follow_filereturns(File, is_character_device)butfrom_other_with_pathdiscards the… This introduces a newwait_for_outputhelper with a different signature. There is already an… The new condition unconditionally unwrapspd.reader(pd.reader.as_ref().unwrap()), which can… UsingDuration::ZEROwhenread_devices_againis true can create a tight loop on always-ready… · New UsingDuration::ZEROwhenread_devices_againis true can create a tight loop on always-ready… · New This helper requires stdout to equalexpectedexactly; if any additional output appears (e.g., a… · New This Linux-only unit test relies on/procand/dev/ptsbeing present and having specific inode…outputhas a 5-second read timeout set earlier, soread()can return anErr(e.g.,… Same canonicalization issue as incheck_device_name:event.paths[0]may not match the canonical…character_devices()appears to be keyed by the canonicalized paths used byFileHandling… On Apple,device_is_readableallocates anFdSetElementvector sized tofd + 1every time it…FileHandling::insert()canonicalizes paths before storing them, and several accessors (get,… This treats any nonzeropoll()return value as 'readable'. However,poll()may report readiness…wait_for_outputreturnsboolhere but the result is ignored. If the wait times out, the test…
Review effort: Lite
| self.reopen(event_path)?; | ||
| } else if event.kind == EventKind::Modify(ModifyKind::Name(RenameMode::To)) | ||
| } else if (event.kind == EventKind::Modify(ModifyKind::Name(RenameMode::To)) | ||
| && !pd.reader.as_ref().unwrap().get_ref().metadata()?.file_id_eq(&new_md)) |
| let timeout = if read_devices_again { | ||
| Duration::ZERO | ||
| } else if observer.files.character_devices().is_empty() { | ||
| settings.sleep_sec | ||
| } else { | ||
| settings | ||
| .sleep_sec | ||
| .saturating_sub(last_device_poll.elapsed()) | ||
| }; |
| .unwrap() | ||
| .receiver | ||
| .recv_timeout(settings.sleep_sec); | ||
| .recv_timeout(timeout); |
| if child.stdout_all() == expected { | ||
| return true; | ||
| } | ||
| child.delay(10); | ||
| } | ||
| child.stdout_all() == expected |



tail -fandtail -Fstop picking up terminal input after the first EOF. They wait for file-change events, but typing into a terminal doesn't produce those events.This makes tail poll character devices instead. Reads are nonblocking so a terminal with nothing to read won't hold up other files or
--pid. The tests reproduce this with a pseudo-terminal.Related to #16643. #16670 covers the debug output.