I just noticed I broke nc -kl. Here is the fix:

--- netcat.c.list       Mon Mar 31 21:03:39 2014
+++ netcat.c    Mon Mar 31 21:03:44 2014
@@ -763,7 +763,7 @@
        if (nostdin && Nflag) shutdown(nfd, SHUT_WR);
        if (nostdout) shutdown(nfd, SHUT_RD);
 
-       while (pfd[0].fd != -1 || pfd[1].fd != -1) {
+       while (!nostdin || !nostdout) {
                if (iflag)
                        sleep(iflag);
 
@@ -783,6 +783,7 @@
                                        shutdown(nfd, SHUT_WR);
                                shutdown(wfd, SHUT_RD);
                                pfd[0].fd = -1;
+                               nostdin = 1;
                        } else {
                                if (atomicio(vwrite, nfd, buf, n) != n)
                                        return;
@@ -794,8 +795,10 @@
                                return;
                        else if (n == 0) {
                                shutdown(nfd, SHUT_RD);
-                               shutdown(lfd, SHUT_WR);
-                               close(lfd);
+                               if (!kflag) {
+                                       shutdown(lfd, SHUT_WR);
+                                       close(lfd);
+                               }
                                /*if (!Nflag)*/ return;
                                pfd[1].fd = -1;
                                pfd[2].events = POLLHUP;
@@ -817,6 +820,7 @@
                if (pfd[1].revents & POLLHUP) {
                        shutdown(nfd, SHUT_RD);
                        pfd[1].fd = -1;
+                       nostdout = 1;
                }
        }
 }



-- 
http://gmerlin.de
OpenPGP: http://gmerlin.de/christopher.pub
F190 D013 8F01 AA53 E080  3F3C F17F B0A1 D44E 4FEE

Reply via email to