Bug 19302

Summary: read("/proc/net/tcp") fails with buffer <= 128 bytes.
Product: [Retired] Red Hat Linux Reporter: Sam Varshavchik <mrsam>
Component: kernelAssignee: Arjan van de Ven <arjanv>
Status: CLOSED CURRENTRELEASE QA Contact: Brian Brock <bbrock>
Severity: medium Docs Contact:
Priority: medium    
Version: 7.0CC: arjan
Target Milestone: ---   
Target Release: ---   
Hardware: i386   
OS: Linux   
Whiteboard:
Fixed In Version: Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2002-12-16 04:08:44 UTC Type: ---
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:
Attachments:
Description Flags
An example none

Description Sam Varshavchik 2000-10-18 03:13:54 UTC
Make sure the machine has at least a few dozen TCP sockets open:

dd if=/proc/net/tcp bs=129          -- shows all open TCP sockets

dd if=/proc/net/tcp bs=128          -- does not

I stumbled across this when I tried to run less on /proc/net/tcp, and got
far fewer sockets than I knew I had. After tracking down what was going on,
I discovered that if you keep doing a read on /proc/net/tcp with a buffer
size of 128 bytes or less, you're going to get a premature EOF indication.

Comment 1 Sam Varshavchik 2000-10-18 03:14:21 UTC
Created attachment 4309 [details]
An example

Comment 2 Arjan van de Ven 2000-10-18 17:27:34 UTC
This is an off-by-one error; the patch below fixes it for me.

--- linux/net/ipv4/proc.c.org   Wed Oct 18 18:27:26 2000
+++ linux/net/ipv4/proc.c       Wed Oct 18 19:27:58 2000
@@ -186,7 +186,7 @@
                                if (req->sk)
                                        continue;
                                pos += 128;
-                               if (pos < offset)
+                               if (pos <= offset)
                                        continue;
                                get__openreq(sp, req, tmpbuf, i);
                                len += sprintf(buffer+len, "%-127s\n", tmpbuf);
@@ -196,7 +196,7 @@
                }

                pos += 128;
-               if (pos < offset)
+               if (pos <= offset)
                        goto next;

                get__sock(sp, tmpbuf, i, format);



Comment 3 Alan Cox 2002-12-16 04:08:44 UTC
Long fixed should have been closed