Fix logging for "strace -o FILE -ff test/threaded_execve" test case

Our logic which was deciding whether to print "<unfinished ...>"
thingy wasn't working properly for -ff case.

* defs.h: Group log generation-related declarations together.
Add a large comment which explains how it works.
Add declaration of line_ended() function.
* strace.c (line_ended): New function which sets up internal data
to indicate that previous line was finished.
(printleader): Change logic to fix log generation in -ff mode.
(newoutf): Make check for -ff mode consistent with other places.
(droptcb): Print "<detached ...>" if last line for this tcp wasn't finished.
(cleanup): Remove code to print "<unfinished ...>", printleader()
or detach() will do it instead.
(trace): Remove code to print "<unfinished ...>".
Add code which finishes threaded execve's incomplete line
with " <pid changed to PID ...>" message. Replace printing_tcp = NULL
followed by fflush() by line_ended() call.
* process.c (sys_exit): Call line_ended() to indicate that we finished priting.
* syscall.c (trace_syscall_exiting): Set printing_tcp to current tcp.
Call line_ended() to indicate that we finished priting.
Remove call to fflush(), it is done by line_ended() now.

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
diff --git a/syscall.c b/syscall.c
index f54df0f..191127b 100644
--- a/syscall.c
+++ b/syscall.c
@@ -1915,6 +1915,17 @@
 		goto ret;
 	}
 
+	/* TODO: TCB_REPRINT is probably not necessary:
+	 * we can determine whether reprinting is needed
+	 * by examining printing_tcp. Something like:
+	 * if not in -ff mode, and printing_tcp != tcp,
+	 * then the log is not currenlty ends with *our*
+	 * syscall entry output, but with something else,
+	 * and we need to reprint.
+	 * If we'd implement this, printing_tcp = tcp
+	 * assignments in code below can be made more logical.
+	 */
+
 	if (tcp->flags & TCB_REPRINT) {
 		printleader(tcp);
 		if (!SCNO_IN_RANGE(tcp->scno))
@@ -1932,18 +1943,20 @@
 	}
 
 	if (res != 1) {
+		printing_tcp = tcp;
 		tprints(") ");
 		tabto();
 		tprints("= ? <unavailable>\n");
-		printing_tcp = NULL;
+		line_ended();
 		tcp->flags &= ~TCB_INSYSCALL;
 		return res;
 	}
 
 	if (!SCNO_IN_RANGE(tcp->scno)
-	    || (qual_flags[tcp->scno] & QUAL_RAW))
+	    || (qual_flags[tcp->scno] & QUAL_RAW)) {
+		printing_tcp = tcp;
 		sys_res = printargs(tcp);
-	else {
+	} else {
 	/* FIXME: not_failing_only (IOW, option -z) is broken:
 	 * failure of syscall is known only after syscall return.
 	 * Thus we end up with something like this on, say, ENOENT:
@@ -1954,6 +1967,7 @@
 	 */
 		if (not_failing_only && tcp->u_error)
 			goto ret;	/* ignore failed syscalls */
+		printing_tcp = tcp;
 		sys_res = (*sysent[tcp->scno].sys_func)(tcp);
 	}
 
@@ -2081,11 +2095,9 @@
 			(long) tv.tv_sec, (long) tv.tv_usec);
 	}
 	tprints("\n");
-	printing_tcp = NULL;
-
 	dumpio(tcp);
-	if (fflush(tcp->outf) == EOF)
-		return -1;
+	line_ended();
+
  ret:
 	tcp->flags &= ~TCB_INSYSCALL;
 	return 0;