mirror of
git://git.sv.gnu.org/coreutils.git
synced 2026-04-20 18:56:39 +02:00
wc: don't miscount /sys and similar file systems
Fix similar problems in head, od, split, tac, and tail. Reported by George Shuklin in: http://bugs.gnu.org/18621 * NEWS: Document this. * src/head.c (elseek): Move up. (elide_tail_bytes_pipe, elide_tail_lines_pipe): New arg CURRENT_POS. All uses changed. (elide_tail_bytes_file, elide_tail_lines_file): New arg ST and remove arg SIZE. All uses changed. * src/head.c (elide_tail_bytes_file): * src/od.c (skip): Avoid optimization for /sys files, where st_size is bogus and st_size == st_blksize. Don't report error at EOF when not optimizing. * src/head.c, src/od.c, src/tail.c: Include "stat-size.h". * src/split.c (input_file_size): New function. (bytes_split, lines_chunk_split, bytes_chunk_extract): New arg INITIAL_READ. All uses changed. Use it to double-check st_size. * src/tac.c (tac_seekable): New arg FILE_POS. All uses changed. (copy_to_temp): Return size of temp file. All uses changed. * src/tac.c (tac_seekable): * src/tail.c (tail_bytes): * src/wc.c (wc): Don't trust st_size; double-check by reading. * src/wc.c (wc): New arg CURRENT_POS. All uses changed. * tests/local.mk (all_tests): Add tests/misc/wc-proc.sh, tests/misc/od-j.sh, tests/tail-2/tail-c.sh. * tests/misc/head-c.sh: * tests/misc/tac-2-nonseekable.sh: * tests/split/b-chunk.sh: Add tests for problems with /proc and /sys files. * tests/misc/od-j.sh, tests/misc/wc-proc.sh, tests/tail-2/tail-c.sh: New files.
This commit is contained in:
@@ -31,20 +31,29 @@ stat x?? 2>/dev/null && fail=1
|
||||
|
||||
printf '1\n2\n3\n4\n5\n' > in || framework_failure_
|
||||
|
||||
split -n 3 in > out || fail=1
|
||||
split -n 1/3 in > b1 || fail=1
|
||||
split -n 2/3 in > b2 || fail=1
|
||||
split -n 3/3 in > b3 || fail=1
|
||||
printf '1\n2' > exp-1
|
||||
printf '\n3\n' > exp-2
|
||||
printf '4\n5\n' > exp-3
|
||||
for file in in /proc/version /sys/kernel/profiling; do
|
||||
split -n 3 $file > out || fail=1
|
||||
split -n 1/3 $file > b1 || fail=1
|
||||
split -n 2/3 $file > b2 || fail=1
|
||||
split -n 3/3 $file > b3 || fail=1
|
||||
|
||||
compare exp-1 xaa || fail=1
|
||||
compare exp-2 xab || fail=1
|
||||
compare exp-3 xac || fail=1
|
||||
compare exp-1 b1 || fail=1
|
||||
compare exp-2 b2 || fail=1
|
||||
compare exp-3 b3 || fail=1
|
||||
test -f xad && fail=1
|
||||
case $file in
|
||||
in)
|
||||
printf '1\n2' > exp-1
|
||||
printf '\n3\n' > exp-2
|
||||
printf '4\n5\n' > exp-3
|
||||
|
||||
compare exp-1 xaa || fail=1
|
||||
compare exp-2 xab || fail=1
|
||||
compare exp-3 xac || fail=1
|
||||
;;
|
||||
esac
|
||||
|
||||
compare xaa b1 || fail=1
|
||||
compare xab b2 || fail=1
|
||||
compare xac b3 || fail=1
|
||||
cat xaa xab xac | compare - $file || fail=1
|
||||
test -f xad && fail=1
|
||||
done
|
||||
|
||||
Exit $fail
|
||||
|
||||
Reference in New Issue
Block a user