bug-coreutils
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

cp(1) fails to copy file from /proc


From: Jukka Salmi
Subject: cp(1) fails to copy file from /proc
Date: Thu, 16 Apr 2009 11:02:20 +0200
User-agent: Mutt/1.5.19 (2009-03-09)

(Please Cc: me on replies since I'm not subscribed to the list.)

Hello,

as [1]described on the Debian Users list cp(1) seems to have problems copying
files from /proc on at least Debian GNU/Linux 5.0 systems (tested on i686 and
x86_64).  I'm seeing this with coreutils 6.10 (using the Debian binary package
coreutils-6.10-6), but another list member [2]wrote that he could reproduce it
with coreutils 7.2.

The following description of the problem is more or less copied from my
[1]original post.

How I'm able to reproduce the problem:

$ wc -l /proc/cpuinfo
200 /proc/cpuinfo
$ cp /proc/cpuinfo /tmp
$ echo $?
0
$ wc -l /tmp/cpuinfo
125 /tmp/cpuinfo

The first part of the file is copied correctly, but the rest is missing.
Running strace(1) on cp reveals that cp requests to read 4 kB, receives less
(but still >0), writes the received data to the destination file and exits:

$ strace cp /proc/cpuinfo /tmp
[...]
open("/proc/cpuinfo", O_RDONLY)         = 3
fstat(3, {st_mode=S_IFREG|0444, st_size=0, ...}) = 0
open("/tmp/cpuinfo", O_WRONLY|O_CREAT|O_EXCL, 0444) = 4
fstat(4, {st_mode=S_IFREG|0444, st_size=0, ...}) = 0
read(3, "processor\t: 0\nvendor_id\t: Genuine"..., 4096) = 3535
write(4, "processor\t: 0\nvendor_id\t: Genuine"..., 3535) = 3535
close(4)                                = 0
close(3)                                = 0
close(0)                                = 0
close(1)                                = 0
close(2)                                = 0
exit_group(0)                           = ?

Subsequent read(2)s would have returned more data (and thus allowed cp to
successfully copy the file), as running strace on a simple test program shows:

$ strace ./a.out /proc/cpuinfo /tmp
[...]
open("/proc/cpuinfo", O_RDONLY)         = 3
open("/tmp/cpuinfo", O_WRONLY|O_CREAT|O_EXCL, 0777) = 4
read(3, "processor\t: 0\nvendor_id\t: Genuine"..., 8192) = 3535
write(4, "processor\t: 0\nvendor_id\t: Genuine"..., 3535) = 3535
read(3, "processor\t: 5\nvendor_id\t: Genuine"..., 8192) = 2121
write(4, "processor\t: 5\nvendor_id\t: Genuine"..., 2121) = 2121
read(3, ""..., 8192)                    = 0
exit_group(0)                           = ?


Please tell if you need more information.

TIA, Jukka

[1] http://lists.debian.org/debian-user/2009/04/msg01491.html
[2] http://lists.debian.org/debian-user/2009/04/msg01493.html

-- 
This email fills a much-needed gap in your mailbox.




reply via email to

[Prev in Thread] Current Thread [Next in Thread]