--- tcpspy.c	2001/06/01 12:18:45	1.39
+++ tcpspy.c	2001/07/02 11:55:36	1.39.1.3
@@ -28,7 +28,7 @@
  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
  * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  *
- * $Id: tcpspy.c,v 1.39 2001/06/01 12:18:45 tim Stab $
+ * $Id: tcpspy.c,v 1.39.1.3 2001/07/02 11:55:36 tim Stab $
  */
 
 #include <arpa/inet.h>
@@ -59,7 +59,7 @@
 #include "rcsid.h"
 #include "rule.h"
 
-RCSID("$Id: tcpspy.c,v 1.39 2001/06/01 12:18:45 tim Stab $");
+RCSID("$Id: tcpspy.c,v 1.39.1.3 2001/07/02 11:55:36 tim Stab $");
 
 /*
  * Defaults for compile-time settings. Descriptions of these are in
@@ -354,7 +354,7 @@
 	char uidbuf[32];
 	char *user;
 	struct servent *se;
-	char lport[6], rport[6]; /* assume 16 bit unsigned */
+	char lport[64], rport[64];
 
 	assert (c != NULL);
 	assert (action != NULL);
@@ -496,6 +496,8 @@
 					 */
 					rule_gen_or ();
 				firstrule = 0;
+				/* Hide rule from `ps' */
+				memset (optarg, '\0', strlen (optarg));
 				break;
 			case 'f':
 			{
@@ -617,11 +619,23 @@
 	}
 
 	/*
-	 * Become a daemon..
+	 * Become a daemon by double-forking and detaching completely from
+	 * the terminal.
 	 */
 
 	if (debug == 0) {
 		pid_t p;
+
+		/* 1st fork */
+		p = fork();
+		if (p < 0) {
+			fprintf (stderr, "tcpspy: fork: %s\n",
+					strerror (errno));
+			exit (EXIT_FAILURE);
+		} else if (p != 0)
+			exit (0);
+
+		/* 2nd fork */
 		p = fork();
 		if (p < 0) {
 			fprintf (stderr, "tcpspy: fork: %s\n",
@@ -637,6 +651,8 @@
 		close (STDIN_FILENO); 
 		close (STDOUT_FILENO); 
 		close (STDERR_FILENO);
+		setpgid (0, 0);
+		chdir ("/");
 	} else
 		fprintf (stderr, "tcpspy 1.7 started (debug)\n");
 
