[PATCH v1 2/2] strace.c: move termination code to a separate function

Victor Krapivensky krapivenskiy.va at phystech.edu
Sat Jun 3 23:00:06 UTC 2017


This will be needed for the pull-style API.

* strace.c (terminate): New function.
(main): Use it.
---
 strace.c | 30 ++++++++++++++++++------------
 1 file changed, 18 insertions(+), 12 deletions(-)

diff --git a/strace.c b/strace.c
index 55c6fe76..2657bcf7 100644
--- a/strace.c
+++ b/strace.c
@@ -2593,18 +2593,9 @@ dispatch_event(enum trace_event ret, int *pstatus, siginfo_t *si)
 extern void __gcov_flush();
 #endif
 
-int
-main(int argc, char *argv[])
+static void
+terminate(void)
 {
-	init(argc, argv);
-
-	exit_code = !nprocs;
-
-	int status;
-	siginfo_t si;
-	while (dispatch_event(next_event(&status, &si), &status, &si))
-		;
-
 	cleanup();
 	fflush(NULL);
 	if (shared_log != stderr)
@@ -2639,6 +2630,21 @@ main(int argc, char *argv[])
 		   Exit with 128 + signo then.  */
 		exit_code += 128;
 	}
+	exit(exit_code);
+}
+
+int
+main(int argc, char *argv[])
+{
+	init(argc, argv);
+
+	exit_code = !nprocs;
+
+	int status;
+	siginfo_t si;
+	while (dispatch_event(next_event(&status, &si), &status, &si))
+		;
 
-	return exit_code;
+	terminate();
+	return 0; /* stub */
 }
-- 
2.11.0





More information about the Strace-devel mailing list