[BusyBox] [ PATCH ] nc will spin if stdin closed
Paul Fox
pgf at brightstareng.com
Tue Nov 30 20:35:00 UTC 2004
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 at brightstareng.com
More information about the busybox
mailing list