From owner-freebsd-current@freebsd.org Wed Jul 13 03:58:46 2016 Return-Path: Delivered-To: freebsd-current@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 13A9DB93349 for ; Wed, 13 Jul 2016 03:58:46 +0000 (UTC) (envelope-from markjdb@gmail.com) Received: from mail-pa0-x234.google.com (mail-pa0-x234.google.com [IPv6:2607:f8b0:400e:c03::234]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (Client CN "smtp.gmail.com", Issuer "Google Internet Authority G2" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id D5E441EA2 for ; Wed, 13 Jul 2016 03:58:45 +0000 (UTC) (envelope-from markjdb@gmail.com) Received: by mail-pa0-x234.google.com with SMTP id fi15so13285712pac.1 for ; Tue, 12 Jul 2016 20:58:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=sender:date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=ZWIiw1pPfjVRCtsOtDJ1F6UW7gKDHMOnKQaX8unpwRY=; b=goYIHWUgUyMrXO1m52X3mSE/GaPKGywiTtRn0CwmiU3kb7p0lKeBTLwB8hM4Y56xW6 PF2K3GTmMwvx13RjqegiGF+PysfFy588KSWddrON4tFlnRBJsrznIbWsZVb2ZUHEfyv4 adcOmKWhv+GCX+TpyhNzwjvCqTLH4JMGyKfXY2jtC7Whk+kDQM0CwLMzMx6s5di7P5k4 uY+2kDsevBvznbXRcBuzK/2yM7T9BO9vmEoZmZj+7YszYDU70iNmKJPrGKVpdNr5+8nf 4dT0en99uyO/IPLgHbW67vmjAtQHFp3kHvAbt9Kp+nI5pjCpLydz+SKS65qdZB3jNqrz O9UA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:sender:date:from:to:cc:subject:message-id :references:mime-version:content-disposition:in-reply-to:user-agent; bh=ZWIiw1pPfjVRCtsOtDJ1F6UW7gKDHMOnKQaX8unpwRY=; b=Lq8q+A5D7FsRJ7T9gi6y2Y2FKyVAYWHVjrEjnZlbgIFG+PY3PSR6nfdAK8PW4W/C0g lEoH26UaenTRHNjf9NcKjC+dDcPyMUfkgFpCJo/CSWN4uLEn26dUsiB/49gH1cHqhH/5 /o8hn7k9ECn9DuhsARBDsKcH8frqqAtG3Zv0GPWIzbot/0kwG60nc/TV9JjT0wQHw+WX MOzaMbphI++Vj6QJ8xVyeOfbgys5ny88YEPB8ifyjQtWicQM6isMwJQQgGkwLfxfN1R3 EC9ajjN3BQoYkl0TyYxLu9mcdO5V26hUTY61/B3wie08tYQ5matm4II3AfdA2bRp1fic xXUQ== X-Gm-Message-State: ALyK8tIjtXaSIfzLGAQXbm+h7vFFSXfB298bDbOT+7w3eY0vvhkO7ZMAAO1IXp5srjbflw== X-Received: by 10.67.8.69 with SMTP id di5mr9782374pad.123.1468382325454; Tue, 12 Jul 2016 20:58:45 -0700 (PDT) Received: from wkstn-mjohnston.west.isilon.com (c-76-104-201-218.hsd1.wa.comcast.net. [76.104.201.218]) by smtp.gmail.com with ESMTPSA id w3sm427823pax.30.2016.07.12.20.58.44 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 12 Jul 2016 20:58:44 -0700 (PDT) Sender: Mark Johnston Date: Tue, 12 Jul 2016 21:02:10 -0700 From: Mark Johnston To: Konstantin Belousov Cc: freebsd-current@FreeBSD.org Subject: Re: ptrace attach in multi-threaded processes Message-ID: <20160713040210.GA89573@wkstn-mjohnston.west.isilon.com> References: <20160712011938.GA51319@wkstn-mjohnston.west.isilon.com> <20160712055753.GI38613@kib.kiev.ua> <20160712170502.GA71220@wkstn-mjohnston.west.isilon.com> <20160712175150.GP38613@kib.kiev.ua> <20160712182414.GC71220@wkstn-mjohnston.west.isilon.com> <20160713033036.GR38613@kib.kiev.ua> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20160713033036.GR38613@kib.kiev.ua> User-Agent: Mutt/1.6.1 (2016-04-27) X-BeenThere: freebsd-current@freebsd.org X-Mailman-Version: 2.1.22 Precedence: list List-Id: Discussions about the use of FreeBSD-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 13 Jul 2016 03:58:46 -0000 On Wed, Jul 13, 2016 at 06:30:36AM +0300, Konstantin Belousov wrote: > On Tue, Jul 12, 2016 at 11:24:14AM -0700, Mark Johnston wrote: > > On Tue, Jul 12, 2016 at 08:51:50PM +0300, Konstantin Belousov wrote: > > > On Tue, Jul 12, 2016 at 10:05:02AM -0700, Mark Johnston wrote: > > > > On Tue, Jul 12, 2016 at 08:57:53AM +0300, Konstantin Belousov wrote: > > > > I suppose it is not strictly incorrect. I find it surprising that a > > > > PT_ATTACH followed by a PT_DETACH may leave the process in a different > > > > state than it was in before the attach. This means that it is not > > > > possible to gcore a process without potentially leaving it stopped, for > > > > instance. This result may occur in a single-threaded process > > > > as well, since a signal may already be queued when the PT_ATTACH handler > > > > sends SIGSTOP. > > > I still miss somethine. Isn't this an expected outcome from sending a > > > signal with STOP action ? > > > > It is. But I also expect a PT_DETACH operation to resume a stopped > > process, assuming that a second SIGSTOP was not posted while the > > process was suspended. > But as far as the situation was discussed, it seems that real SIGSTOP raced > with PT_ATTACH. And the offered interpretation that SIGSTOP was delivered > 'a bit later' than PT_ATTACH would fit into the description. Hm, the only SIGSTOP in my scenario is the one generated by PT_ATTACH. The problem occurs when this SIGSTOP races with *any* other signal that's being delivered to the process and for which the process has registered a handler. For instance, SIGHUP after a log rotation. If a real SIGSTOP races with PT_ATTACH, then I would indeed expect to find the process in a stopped state after the detach. Does this make more sense?