tcpscript.c
changeset 5 470463cba5cf
parent 3 01ec0b3b1135
child 6 07f184944f3f
--- a/tcpscript.c	Mon Jun 11 21:03:11 2007 +0200
+++ b/tcpscript.c	Wed Jul 04 21:12:09 2007 +0200
@@ -96,6 +96,7 @@
 enum {
     MAXCONNS = 10
 };
+static int accept_socket;
 
 static char *progname;
 
@@ -172,6 +173,8 @@
 	getmaster();
 	fixtty();
 
+    accept_socket = listen_tcp();
+
 	(void) signal(SIGCHLD, finish);
 	child = fork();
 	if (child < 0) {
@@ -187,9 +190,15 @@
 		if (child)
 			dooutput();
 		else
+        {
+            close(accept_socket);
 			doshell();
+        }
 	} else
+    {
+        close(accept_socket);
 		(void) signal(SIGWINCH, resize);
+    }
 	doinput();
 
 	return 0;
@@ -232,6 +241,7 @@
 
 void fatal()
 {
+    done();
     exit(-1);
 }
 
@@ -284,7 +294,6 @@
 dooutput() {
 	int cc;
 	char obuf[BUFSIZ];
-    int accept_socket;
     int conns[MAXCONNS];
     int nconns;
     int i;
@@ -297,7 +306,6 @@
     fd_set should_read_set;
     fd_set tcp_set;
 
-    accept_socket = listen_tcp();
     FD_ZERO(&should_read_set);
     FD_SET(accept_socket, &should_read_set);
     FD_SET(master, &should_read_set);