Why "Close pipe and wait for the pipe process termination"?

Dmitry V. Levin ldv at altlinux.org
Thu Sep 13 15:56:16 UTC 2012


Hi,

On Thu, Sep 13, 2012 at 09:55:43AM +0200, Denys Vlasenko wrote:
> Hi Dmitry,
> 
> Why is the below change necessary?
> Was there any bad behavior in this area before it?

Before this change, strace used to exit before the pipe process
termination, there were no convenient method to wait for its
completion, and that behavior wasn't documented.  As result,
strace users sometimes experienced unexpected data losses.

Is there any regressions with the change?

> commit cf53436f737c0273028503186fc0f837c7191085
> Author: Dmitry V. Levin <ldv at altlinux.org>
> Date:   Thu Jul 12 20:54:46 2012 +0000
> 
>     Close pipe and wait for the pipe process termination
> 
>     In case of normal strace termination, when the trace output is
>     redirected to a file or a pipe, close it and wait for the pipe
>     process termination.
> 
>     * strace.c (main): Before normal exit, close shared_log when it
>     differs from stderr, and wait for popen_pid termination.
> 
> diff --git a/strace.c b/strace.c
> index e6d6d68..799fce5 100644
> --- a/strace.c
> +++ b/strace.c
> @@ -2214,6 +2214,12 @@ main(int argc, char *argv[])
> 
>         cleanup();
>         fflush(NULL);
> +       if (shared_log != stderr)
> +               fclose(shared_log);
> +       if (popen_pid) {
> +               while (waitpid(popen_pid, NULL, 0) < 0 && errno == EINTR)
> +                       ;
> +       }
>         if (exit_code > 0xff) {
>                 /* Avoid potential core file clobbering.  */
>                 struct rlimit rlim = {0, 0};

-- 
ldv
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 198 bytes
Desc: not available
URL: <http://lists.strace.io/pipermail/strace-devel/attachments/20120913/28ab71f6/attachment.bin>


More information about the Strace-devel mailing list