Bug 9741 - 'cat' broken for kernel < 3.0
Summary: 'cat' broken for kernel < 3.0
Status: NEW
Alias: None
Product: Busybox
Classification: Unclassified
Component: Other (show other bugs)
Version: unspecified
Hardware: All Linux
: P5 normal
Target Milestone: ---
Assignee: unassigned
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2017-03-13 21:01 UTC by Grant Edwards
Modified: 2017-03-13 22:07 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Grant Edwards 2017-03-13 21:01:47 UTC
The 'cat' utility fails on older kernel versions with multiple files
when stdout is a file.

In older kernel versions, the sendfile() system call that 'cat' uses
does not update the output file position.  When 'cat' stdout is a
file, this results in each input file overwriting the previous one:

   # ls -l
   total 12
   -rw-r--r--    1 root     root            29 Mar 13 17:44 d1
   -rw-r--r--    1 root     root            29 Mar 13 17:44 d2
   -rw-r--r--    1 root     root            29 Mar 13 17:44 d3
   
   # cat d1 d2 d3
   Mon Mar 13 17:44:35 UTC 2017
   Mon Mar 13 17:44:40 UTC 2017
   Mon Mar 13 17:44:43 UTC 2017
   
   # cat d1 d2 d3 >foo
   
   # ls -l
   total 16
   -rw-r--r--    1 root     root            29 Mar 13 17:44 d1
   -rw-r--r--    1 root     root            29 Mar 13 17:44 d2
   -rw-r--r--    1 root     root            29 Mar 13 17:44 d3
   -rw-r--r--    1 root     root            29 Mar 13 20:56 foo
   
   # cat foo
   Mon Mar 13 17:44:43 UTC 2017
   
   # cat d1 d2 d3 | cat >foo
   
   # ls -l foo
   -rw-r--r--    1 root     root            87 Mar 13 20:56 foo
   
   # cat foo
   Mon Mar 13 17:44:35 UTC 2017
   Mon Mar 13 17:44:40 UTC 2017
   Mon Mar 13 17:44:43 UTC 2017
   
I'm not sure exactly which kernel version breaks this.  It fails with
kernel 2.6.33, but is OK with 3.8.13.
Comment 1 Grant Edwards 2017-03-13 21:57:37 UTC
I've confirmed 'cat' that it works on a 3.2.86 kernel.

At the moment, I don't have means to build/test kernels between 2.6.33 and 3.2.
Comment 2 Grant Edwards 2017-03-13 22:07:03 UTC
My apologies -- 

I finally stumbled across CONFIG_FEATURE_USE_SENDFILE