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

Victor Krapivensky krapivenskiy.va at phystech.edu
Mon Jun 5 11:46:34 UTC 2017


This will be needed for the pull-style API.

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

diff --git a/strace.c b/strace.c
index af5fd346..5accb141 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 ATTRIBUTE_NORETURN
+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,19 @@ 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);
 
-	return exit_code;
+	exit_code = !nprocs;
+
+	int status;
+	siginfo_t si;
+	while (dispatch_event(next_event(&status, &si), &status, &si))
+		;
+	terminate();
 }
-- 
2.11.0





More information about the Strace-devel mailing list