2007-11-03  Jan Kratochvil  <jan.kratochvil@redhat.com>

	* strace.c (main): Move the STARTUP_CHILD call before setting up the
	signal handlers.  New comment about the valid internal states.
diff --git a/strace.c b/strace.c
index 9d82f58..b71e093 100644
--- a/strace.c
+++ b/strace.c
@@ -817,6 +817,20 @@
 		interactive = 0;
 		qflag = 1;
 	}
+	/* Valid states here:
+	   optind < argc	pflag_seen	outfname	interactive
+	   1			0		0		1
+	   0			1		0		1
+	   1			0		1		0
+	   0			1		1		1
+	 */
+
+	/* STARTUP_CHILD must be called before the signal handlers get
+	   installed below as they are inherited into the spawned process.
+	   Also we do not need to be protected by them as during interruption
+	   in the STARTUP_CHILD mode we kill the spawned process anyway.  */
+	if (!pflag_seen)
+		startup_child(&argv[optind]);
 
 	sigemptyset(&empty_set);
 	sigemptyset(&blocked_set);
@@ -857,8 +871,6 @@
 
 	if (pflag_seen)
 		startup_attach();
-	else
-		startup_child(&argv[optind]);
 
 	if (trace() < 0)
 		exit(1);