Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
Bug 89163 - netcat doesnt stop reading when it should
Summary: netcat doesnt stop reading when it should
Status: RESOLVED WORKSFORME
Alias: None
Product: Gentoo Linux
Classification: Unclassified
Component: [OLD] Core system (show other bugs)
Hardware: x86 Linux
: High enhancement (vote)
Assignee: SpanKY
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2005-04-15 01:50 UTC by Wouter Coppens
Modified: 2006-04-10 20:43 UTC (History)
0 users

See Also:
Package list:
Runtime testing required: ---


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Wouter Coppens 2005-04-15 01:50:48 UTC
When we take an image of a server we often use find in combination with cpio. 
In one shell we do: nc -l -p 1234 > files.cpio.gz
In the other we do: find . | cpio -ovH newc | gzip -9c | nc localhost 1234

The strange thing is that when we run this command on a Redhat Linux (all versions), the find exists properly when it's done.
When we run the same command on a gentoo server, the find command keeps on waiting when it's done searching and doesn't exit. It looks like it doesn't send an exit code when it's done. We already tried to add the option '-print' and so on, but no result.

Is this a bug or is this normal behaviour? And how can it be changed?

Thanks in advance,

Wouter 

Reproducible: Always
Steps to Reproduce:
1. nc -l -p 1234 > files.cpio.gz
2. find . | cpio -ovH newc | gzip -9c | nc localhost 1234
3.




# emerge info
Portage 2.0.51.19 (default-linux/x86/2005.0, gcc-3.3.5-20050130, glibc-
2.3.4.20041102-r1,uclibc-0.9.26-r7,uclibc-0.9.27-r0, 2.6.10-gentoo-r5 i686)
=================================================================
System uname: 2.6.10-gentoo-r5 i686 Intel(R) Xeon(TM) CPU 2.40GHz
Gentoo Base System version 1.4.16
Python:              dev-lang/python-2.3.4-r1 [2.3.4 (#1, Mar 23 2005, 
10:22:03)]
dev-lang/python:     2.3.4-r1
sys-devel/autoconf:  2.59-r6, 2.13
sys-devel/automake:  1.7.9-r1, 1.8.5-r3, 1.5, 1.4_p6, 1.6.3, 1.9.4
sys-devel/binutils:  2.15.92.0.2-r7
sys-devel/libtool:   1.5.14
virtual/os-headers:  2.6.8.1-r2, 2.4.19-r1
ACCEPT_KEYWORDS="x86"
AUTOCLEAN="yes"
CFLAGS="-march=pentium3 -O3 -pipe"
CHOST="i686-pc-linux-gnu"
CONFIG_PROTECT="/etc /usr/kde/2/share/config /usr/kde/3/share/config /usr/share
/config /var/qmail/control"
CONFIG_PROTECT_MASK="/etc/gconf /etc/terminfo /etc/env.d"
CXXFLAGS="-march=pentium3 -O3 -pipe"
DISTDIR="/usr/portage/distfiles"
FEATURES="autoaddcvs autoconfig ccache distlocks sandbox sfperms"
GENTOO_MIRRORS="http://distfiles.gentoo.org 
http://distro.ibiblio.org/pub/Linux/distributions/gentoo"
MAKEOPTS="-j2"
PKGDIR="/usr/portage/packages"
PORTAGE_TMPDIR="/var/tmp"
PORTDIR="/usr/portage"
SYNC="rsync://rsync.europe.gentoo.org/gentoo-portage"
USE="apache2 berkdb crypt libwww ncurses pam readline savedconfig ssl x86 xml2"
Unset:  ASFLAGS, CBUILD, CTARGET, LANG, LC_ALL, LDFLAGS, LINGUAS, 
PORTDIR_OVERLAY
Comment 1 SpanKY gentoo-dev 2005-04-15 11:04:47 UTC
run `find --version` on both the redhat and the gentoo machines

we have three different versions of find in portage at the moment ... you should try them and see if newer versions work properly ...
Comment 2 Wouter Coppens 2005-04-18 01:17:13 UTC
Gentoo:
# find --version
GNU find version 4.1.20

Redhat:
# cat /etc/redhat-release
Red Hat Enterprise Linux AS release 3 (Taroon Update 3)
# find --version
GNU find version 4.1.7
Comment 3 SpanKY gentoo-dev 2005-04-18 18:06:02 UTC
you could try 4.2.20 since we have that in portage too ...
Comment 4 Ciaran McCreesh 2005-05-22 00:29:57 UTC
Please try 4.2.20. If it fails, please give me some strace output of what it's
doing when it appears to be 'not exiting'.
Comment 5 Ciaran McCreesh 2005-05-25 01:08:42 UTC
Please reopen if you can provide the requested information.
Comment 6 Wouter Coppens 2005-05-25 01:28:09 UTC
I tried it again with:
# nc -l -p 1234 > /dev/null
# cd /usr/portage (other shell)
# find . | cpio -ovH newc | nc localhost 1234
...
./games-rpg/vegastrike/files/vegastrike-0.3.1-gcc3.patch
./games-rpg/vegastrike/vegastrike-0.3.1.ebuild
./games-rpg/vegastrike/vegastrike-0.4.1.ebuild
./games-rpg/vegastrike/ChangeLog
./games-rpg/vegastrike/metadata.xml
./games-rpg/metadata.xml
214215 blocks

And here it stops and waits for ever.

# find --version
GNU find version 4.2.20
Features enabled: D_TYPE O_NOFOLLOW(enabled)

# emerge info
Portage 2.0.51.19 (default-linux/x86/2005.0, gcc-3.3.5-20050130, glibc-
2.3.4.20041102-r1, 2.6.11-gentoo-r8 i686)
=================================================================
System uname: 2.6.11-gentoo-r8 i686 Intel(R) Xeon(TM) CPU 2.40GHz
Gentoo Base System version 1.4.16
Python:              dev-lang/python-2.3.5 [2.3.5 (#1, May 23 2005, 13:35:20)]
dev-lang/python:     2.3.5
sys-apps/sandbox:    1.2.8
sys-devel/autoconf:  2.59-r6, 2.13
sys-devel/automake:  1.7.9-r1, 1.8.5-r3, 1.5, 1.4_p6, 1.6.3, 1.9.5
sys-devel/binutils:  2.15.92.0.2-r7
sys-devel/libtool:   1.5.16
virtual/os-headers:  2.6.8.1-r2
ACCEPT_KEYWORDS="x86"
AUTOCLEAN="yes"
CFLAGS="-O2 -mcpu=i686 -fomit-frame-pointer -pipe"
CHOST="i686-pc-linux-gnu"
CONFIG_PROTECT="/etc /usr/kde/2/share/config /usr/kde/3/share/config /usr/share
/config /var/qmail/control"
CONFIG_PROTECT_MASK="/etc/gconf /etc/terminfo /etc/env.d"
CXXFLAGS="-O2 -mcpu=i686 -fomit-frame-pointer -pipe"
DISTDIR="/usr/portage/distfiles"
FEATURES="autoaddcvs autoconfig ccache distlocks sandbox sfperms strict"
GENTOO_MIRRORS="http://distfiles.gentoo.org 
http://distro.ibiblio.org/pub/Linux/distributions/gentoo"
MAKEOPTS="-j2"
PKGDIR="/usr/portage/packages"
PORTAGE_TMPDIR="/var/tmp"
PORTDIR="/usr/portage"
SYNC="rsync://rsync.gentoo.org/gentoo-portage"
USE="x86 alsa apm arts avi berkdb bitmap-fonts crypt cups curl emboss encode 
fam foomaticdb fortran gdbm gif gpm gtk2 imlib ipv6 jpeg libg++ libwww mad 
mikmod motif mp3 mpeg ncurses nls nptl oggvorbis opengl oss pam pdflib perl 
png python quicktime readline samba sdl slang snmp spell ssl svga tcpd tiff 
truetype truetype-fonts type1-fonts xml xml2 xmms xv zlib userland_GNU 
kernel_linux elibc_glibc"
Unset:  ASFLAGS, CBUILD, CTARGET, LANG, LC_ALL, LDFLAGS, LINGUAS, 
PORTDIR_OVERLAY

Comment 7 Ciaran McCreesh 2005-05-25 01:32:49 UTC
Ok, what's it locking on according to strace?
Comment 8 Wouter Coppens 2005-05-25 01:48:50 UTC
Ok, it looks like it's not the find that's causing the problem but something 
else.

After running the command:
./games-rpg/vegastrike/vegastrike-0.4.1.ebuild
./games-rpg/vegastrike/ChangeLog
./games-rpg/vegastrike/metadata.xml
./games-rpg/metadata.xml
214215 blocks

# ps -ef
...
root     23698 23692  0 10:44 ?        00:00:00 -bash
root     23705 23698  0 10:44 ?        00:00:00 /bin/bash -i
root     23719 23677  3 10:45 ?        00:00:02 nc -l -p 1234
root     23722 23599  4 10:46 ?        00:00:03 nc localhost 1234
root     23725 23705  0 10:47 ?        00:00:00 ps -ef

# strace -p 23722
select(16, [0 3], NULL, NULL, NULL)     = 1 (in [0])
read(0, "\0\0\0\0MD5 1c4d9e64d526ac65f57259c3"..., 8192) = 5632
write(3, "\0\0\0\0MD5 1c4d9e64d526ac65f57259c3"..., 5632) = 5632
select(16, [0 3], NULL, NULL, NULL)     = 1 (in [0])
read(0, "n_down.png\"\n+#define TEXT_AREA_0"..., 8192) = 2048
write(3, "n_down.png\"\n+#define TEXT_AREA_0"..., 2048) = 2048
select(16, [0 3], NULL, NULL, NULL)     = 1 (in [0])
read(0, "=\"--enable-sdl --disable-nosdl\" "..., 8192) = 6144
write(3, "=\"--enable-sdl --disable-nosdl\" "..., 6144) = 6144
select(16, [0 3], NULL, NULL, NULL)     = 1 (in [0])
read(0, "n the spirit of Elite. You start"..., 8192) = 512
write(3, "n the spirit of Elite. You start"..., 512) = 512
select(16, [0 3], NULL, NULL, NULL)     = 1 (in [0])
read(0, "a4000000090000000200000000000000"..., 8192) = 1024
write(3, "a4000000090000000200000000000000"..., 1024) = 1024
select(16, [0 3], NULL, NULL, NULL)     = 1 (in [0])
read(0, "", 8192)                       = 0
close(0)                                = 0
select(16, [3], NULL, NULL, NULL
Comment 9 Wouter Coppens 2005-05-25 03:17:50 UTC
I did some additional tests and this is the result:

strace of 'find .'
lstat64("boot", {st_mode=S_IFDIR|0755, st_size=48, ...}) = 0
open("boot", O_RDONLY|O_NONBLOCK|O_LARGEFILE|O_DIRECTORY) = 4
fstat64(4, {st_mode=S_IFDIR|0755, st_size=48, ...}) = 0
fcntl64(4, F_SETFD, FD_CLOEXEC)         = 0
mmap2(NULL, 135168, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 
0xb7ea8000
getdents64(4, /* 2 entries */, 131072)  = 48
getdents64(4, /* 0 entries */, 131072)  = 0
munmap(0xb7ea8000, 135168)              = 0
close(4)                                = 0
open("boot", O_RDONLY|O_LARGEFILE|O_NOFOLLOW) = 4
fchdir(4)                               = 0
close(4)                                = 0
open("..", O_RDONLY|O_LARGEFILE|O_NOFOLLOW) = 4
fchdir(4)                               = 0
close(4)                                = 0
open("..", O_RDONLY|O_LARGEFILE|O_NOFOLLOW) = 4
fchdir(4)                               = 0
close(4)                                = 0
write(1, "a60\n./dev.old/vcsa61\n./dev.old/v"..., 3456) = 3456
close(1)                                = 0
munmap(0xb7fea000, 4096)                = 0
exit_group(1)                           = ?
Process 23788 detached

strace of 'cpio -ovH newc'
write(2, "./dev.old/inportbm\n", 19)    = 19
lstat64("./dev.old/fb3current", {st_mode=S_IFCHR|0620, st_rdev=makedev(29, 
96), ...}) = 0
write(2, "./dev.old/fb3current\n", 21)  = 21
lstat64("./RESTOREROOT", {st_mode=S_IFDIR|0755, st_size=72, ...}) = 0
write(2, "./RESTOREROOT\n", 14)         = 14
lstat64("./RESTOREROOT/boot", {st_mode=S_IFDIR|0755, st_size=48, ...}) = 0
write(1, "00198800002190000000000000001b00"..., 512) = 512
write(2, "./RESTOREROOT/boot\n", 19)    = 19
read(0, "", 4096)                       = 0
write(1, "0100085cf1000041ed00000000000000"..., 512) = 512
write(2, "5165657 blocks\n", 15)        = 15
close(1)                                = 0
exit_group(0)                           = ?
Process 23789 detached

strace of 'nc localhost 1234'
select(16, [0 3], NULL, NULL, NULL)     = 1 (in [0])
read(0, "00198800002190000000000000001b00"..., 8192) = 512
write(3, "00198800002190000000000000001b00"..., 512) = 512
select(16, [0 3], NULL, NULL, NULL)     = 1 (in [0])
read(0, "0100085cf1000041ed00000000000000"..., 8192) = 512
write(3, "0100085cf1000041ed00000000000000"..., 512) = 512
select(16, [0 3], NULL, NULL, NULL)     = 1 (in [0])
read(0, "", 8192)                       = 0
close(0)                                = 0
select(16, [3], NULL, NULL, NULL

So it looks like nc is waiting for something to generate a end.

Strange.
Comment 10 SpanKY gentoo-dev 2006-04-10 20:39:00 UTC
if this is a bug, it's in netcat

if you do:
find . | cpio -ovH newc | gzip -9c | nc localhost 1234 -q 0

it should work fine ...
Comment 11 SpanKY gentoo-dev 2006-04-10 20:43:04 UTC
ok, this "works" on redhat because they add a patch to automatically close the client connection when EOF is reached

in Gentoo/Debian, we add the '-q' option so the user can control the behavior