]> granicus.if.org Git - strace/commitdiff
strace.c: move termination code to a separate function
authorVictor Krapivensky <krapivenskiy.va@phystech.edu>
Mon, 5 Jun 2017 11:46:34 +0000 (14:46 +0300)
committerDmitry V. Levin <ldv@altlinux.org>
Mon, 5 Jun 2017 11:48:47 +0000 (11:48 +0000)
This will be needed for the pull-style API.

* strace.c (terminate): New function.
(main): Use it.

strace.c

index 6d5c29aac143117e488eb9619b8442f6f479d81e..08efbdd2e3898ac8d98cad476e38275e79e0e65c 100644 (file)
--- a/strace.c
+++ b/strace.c
@@ -2573,18 +2573,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)
@@ -2619,6 +2610,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();
 }