[prev in list] [next in list] [prev in thread] [next in thread] 

List:       busybox
Subject:    [BusyBox] [ PATCH ]  nc will spin if stdin closed
From:       Paul Fox <pgf () brightstareng ! com>
Date:       2004-11-30 20:35:00
Message-ID: 2045.1101846900 () brightstareng ! com
[Download RAW message or body]

hi --

if stdin to the nc command is closed before the network
socket is finished, then nc will spin, continuously being
informed by select() of stdin's closure.  this can easily happen
if stdin is connected to /dev/null (for instance if started from
busybox init with no console).  usually this isn't an issue, since
shutting down the sending half of the socket will cause the other
end to close.  but this isn't always the case.

this diff is against current busybox CVS.

paul

Index: networking/nc.c
===================================================================
RCS file: /var/cvs/busybox/networking/nc.c,v
retrieving revision 1.24
diff -u -r1.24 nc.c
--- networking/nc.c	27 Mar 2004 10:02:43 -0000	1.24
+++ networking/nc.c	30 Nov 2004 20:24:51 -0000
@@ -161,8 +161,11 @@
 						exit(0);
 					ofd = STDOUT_FILENO;
 				} else {
-					if (nread == 0)
-						shutdown(sfd, 1);
+					if (nread <= 0) {
+						shutdown(sfd, 1 /* send */ );
+						close(STDIN_FILENO);
+						FD_CLR(STDIN_FILENO, &readfds);
+					}
 					ofd = sfd;
 				}
 

=---------------------
 paul fox, pgf@brightstareng.com


_______________________________________________
busybox mailing list
busybox@mail.busybox.net
http://codepoet.org/mailman/listinfo/busybox


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic