From 364728dba0faa53e14666830f9c4f2cf99893b83 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Sat, 21 Mar 2015 18:40:53 +0100 Subject: [PATCH] Move the comment about termination logic where it belongs Signed-off-by: Denys Vlasenko --- strace.c | 39 ++++++++++++++++++++------------------- 1 file changed, 20 insertions(+), 19 deletions(-) diff --git a/strace.c b/strace.c index 35089abe..513d7cf4 100644 --- a/strace.c +++ b/strace.c @@ -2043,8 +2043,26 @@ trace(void) if (interrupted) return false; - if (popen_pid != 0 && nprocs == 0) - return false; + /* + * Used to exit simply when nprocs hits zero, but in this testcase: + * int main() { _exit(!!fork()); } + * under strace -f, parent sometimes (rarely) manages + * to exit before we see the first stop of the child, + * and we are losing track of it: + * 19923 clone(...) = 19924 + * 19923 exit_group(1) = ? + * 19923 +++ exited with 1 +++ + * Exiting only when wait() returns ECHILD works better. + */ + if (popen_pid != 0) { + /* However, if -o|logger is in use, we can't do that. + * Can work around that by double-forking the logger, + * but that loses the ability to wait for its completion + * on exit. Oh well... + */ + if (nprocs == 0) + return false; + } if (interactive) sigprocmask(SIG_SETMASK, &empty_set, NULL); @@ -2269,23 +2287,6 @@ main(int argc, char *argv[]) { init(argc, argv); - /* - * Run main tracing loop. - * - * Used to be "while (nprocs != 0)", but in this testcase: - * int main() { _exit(!!fork()); } - * under strace -f, parent sometimes (rarely) manages - * to exit before we see the first stop of the child, - * and we are losing track of it: - * 19923 clone(...) = 19924 - * 19923 exit_group(1) = ? - * 19923 +++ exited with 1 +++ - * Waiting for ECHILD works better. - * (However, if -o|logger is in use, we can't do that. - * Can work around that by double-forking the logger, - * but that loses the ability to wait for its completion on exit. - * Oh well...) - */ while (trace()) ;