Skip to content

Commit e265fa7

Browse files
committed
Merge branch 'main' into core-1
2 parents 0f80b3e + 62c2007 commit e265fa7

4 files changed

Lines changed: 46 additions & 8 deletions

File tree

src/uu/tail/src/tail.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -470,7 +470,7 @@ fn bounded_tail(file: &mut File, settings: &Settings) {
470470
file.seek(SeekFrom::Start(i as u64)).unwrap();
471471
}
472472
FilterMode::Lines(Signum::MinusZero, _) => {
473-
return;
473+
file.seek(SeekFrom::End(0)).unwrap();
474474
}
475475
FilterMode::Bytes(Signum::Negative(count)) => {
476476
if file.seek(SeekFrom::End(-(*count as i64))).is_err() {
@@ -484,7 +484,7 @@ fn bounded_tail(file: &mut File, settings: &Settings) {
484484
file.seek(SeekFrom::Start(*count - 1)).unwrap();
485485
}
486486
FilterMode::Bytes(Signum::MinusZero) => {
487-
return;
487+
file.seek(SeekFrom::End(0)).unwrap();
488488
}
489489
_ => {}
490490
}
@@ -524,6 +524,11 @@ fn unbounded_tail<T: Read>(reader: &mut BufReader<T>, settings: &Settings) -> UR
524524
chunks.fill(reader)?;
525525
chunks.print(&mut writer)?;
526526
}
527+
FilterMode::Lines(Signum::MinusZero, sep) => {
528+
let mut chunks = chunks::LinesChunkBuffer::new(*sep, 0);
529+
chunks.fill(reader)?;
530+
chunks.print(&mut writer)?;
531+
}
527532
FilterMode::Bytes(Signum::PlusZero | Signum::Positive(1)) => {
528533
io::copy(reader, &mut writer)?;
529534
}

src/uu/timeout/src/timeout.rs

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,14 @@ fn wait_or_kill_process(
270270
match process.wait_or_timeout(duration, None) {
271271
Ok(Some(status)) => {
272272
if preserve_status {
273-
Ok(status.code().unwrap_or_else(|| status.signal().unwrap()))
273+
let exit_code = status.code().unwrap_or_else(|| {
274+
status.signal().unwrap_or_else(|| {
275+
// Extremely rare: process exited but we have neither exit code nor signal.
276+
// This can happen on some platforms or in unusual termination scenarios.
277+
ExitStatus::TimeoutFailed.into()
278+
})
279+
});
280+
Ok(exit_code)
274281
} else {
275282
Ok(ExitStatus::TimeoutFailed.into())
276283
}
@@ -358,10 +365,14 @@ fn timeout(
358365
// structure of `wait_or_kill_process()`. They can probably be
359366
// refactored into some common function.
360367
match process.wait_or_timeout(duration, Some(&SIGNALED)) {
361-
Ok(Some(status)) => Err(status
362-
.code()
363-
.unwrap_or_else(|| preserve_signal_info(status.signal().unwrap()))
364-
.into()),
368+
Ok(Some(status)) => {
369+
let exit_code = status.code().unwrap_or_else(|| {
370+
status
371+
.signal()
372+
.map_or_else(|| ExitStatus::TimeoutFailed.into(), preserve_signal_info)
373+
});
374+
Err(exit_code.into())
375+
}
365376
Ok(None) => {
366377
report_if_verbose(signal, &cmd[0], verbose);
367378
send_signal(process, signal, foreground);

tests/by-util/test_tail.rs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,28 @@ fn test_nc_0_wo_follow2() {
233233
.no_output();
234234
}
235235

236+
#[test]
237+
#[cfg(not(target_os = "windows"))]
238+
fn test_n0_with_follow() {
239+
let (at, mut ucmd) = at_and_ucmd!();
240+
let test_file = "test.txt";
241+
// Create file with multiple lines
242+
at.write(test_file, "line1\nline2\nline3\n");
243+
244+
let mut child = ucmd.arg("-n0").arg("-f").arg(test_file).run_no_wait();
245+
child.make_assertion_with_delay(500).is_alive();
246+
247+
// Append a new line
248+
at.append(test_file, "new\n");
249+
250+
// Should only print the newly appended line
251+
child
252+
.make_assertion_with_delay(DEFAULT_SLEEP_INTERVAL_MILLIS)
253+
.with_current_output()
254+
.stdout_only("new\n");
255+
child.kill();
256+
}
257+
236258
// TODO: Add similar test for windows
237259
#[test]
238260
#[cfg(unix)]

util/build-gnu.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ else
141141
cp -f src/getlimits "${UU_BUILD_DIR}"
142142

143143
# Hardcoded in tests/env/env.sh . Can GNU support it?
144-
ln -v target/${PROFILE}/echo src/echo
144+
ln -v "${UU_BUILD_DIR}"/echo src/echo
145145

146146
# Handle generated factor tests
147147
t_first=00

0 commit comments

Comments
 (0)