OSDN Git Service

Shell $(netcat) won't return unless child's stdin/stdout/stderr are closed.
authorRob Landley <rob@landley.net>
Sun, 16 Nov 2008 08:41:04 +0000 (02:41 -0600)
committerRob Landley <rob@landley.net>
Sun, 16 Nov 2008 08:41:04 +0000 (02:41 -0600)
toys/netcat.c

index e1cfc07..0ed2a36 100644 (file)
@@ -149,8 +149,12 @@ void netcat_main(void)
                        }
                        // Do we need to return immediately because -l has arguments?
 
-                       if ((toys.optflags&FLAG_l) && toys.optc)
+                       if ((toys.optflags&FLAG_l) && toys.optc) {
                                if (fork()) goto cleanup;
+                               close(0);
+                               close(1);
+                               close(2);
+                       }
 
                        for (;;) {
                                pid_t child = 0;