[PATCH] USE_SEIZE: fix detaching from stopped processes

Denys Vlasenko dvlasenk at redhat.com
Tue Jun 18 15:57:50 UTC 2013


On 06/10/2013 04:55 PM, Dmitry V. Levin wrote:
> * strace.c (detach) [USE_SEIZE]: If PTRACE_SEIZE API is in use, stop
> the tracee using PTRACE_INTERRUPT instead of sending it a SIGSTOP.
> * tests/detach: New test.
> * tests/Makefile.am (TESTS): Add it.
> 
> Reported-by: Raghavendra D Prabhu <raghu.prabhu13 at gmail.com>
> ---
> Denys, please have a look whether this fix is correct.
> 
> --- a/strace.c
> +++ b/strace.c
> @@ -769,7 +769,15 @@ detach(struct tcb *tcp)
>  			if (errno != ESRCH)
>  				perror_msg("detach: checking sanity");
>  		}
> -		else if (!sigstop_expected && my_tkill(tcp->pid, SIGSTOP) < 0) {
> +#if USE_SEIZE
> +		else if (!sigstop_expected && use_seize
> +			 && ptrace(PTRACE_INTERRUPT, tcp->pid, 0, 0) < 0) {
> +			if (errno != ESRCH)
> +				perror_msg("detach: ptrace(PTRACE_INTERRUPT, ...)");
> +		}
> +#endif
> +		else if (!sigstop_expected && !use_seize
> +			 && my_tkill(tcp->pid, SIGSTOP) < 0) {
>  			if (errno != ESRCH)
>  				perror_msg("detach: stopping child");
>  		}

The logic was:

                else if (!sigstop_expected && my_tkill(tcp->pid, SIGSTOP) < 0) {
                        if (errno != ESRCH)
                                perror_msg("detach: stopping child");
                }
                else
                        sigstop_expected = 1;

which, if my_tkill succeeded, was setting sigstop_expected = 1.

Now if we send PTRACE_INTERRUPT, we also set sigstop_expected = 1.

But there will be no SIGSTOP (unless tracee is already stopped, then yes) -
PTRACE_INTERRUPT generates SIGTRAP-stop!

I propose the attached patch.
Sorry, Thunderbird mangles inline patches :(
-------------- next part --------------
A non-text attachment was scrubbed...
Name: z.diff
Type: text/x-patch
Size: 2923 bytes
Desc: not available
URL: <http://lists.strace.io/pipermail/strace-devel/attachments/20130618/01e01fec/attachment.bin>


More information about the Strace-devel mailing list