From nobody Wed Jan 19 00:46:14 2022 X-Original-To: dev-commits-src-branches@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 60B1D196142F; Wed, 19 Jan 2022 00:46:15 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4Jdn530SR0z4q7V; Wed, 19 Jan 2022 00:46:15 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1642553175; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=SsNAXOnRBRUvfLej6Ls3jHPjLUaTjOAn6dY3zhhqf5Q=; b=vxlfX1PbRu8eNm8XWo8xWwgB+vAF0q9AmtDDeX1bSveCIASHoD5UZ9ADUG9O6OxGFJBXZb UBlKirhf8Rxt2mziz9M9gpCyuuQmXHhLCO8/2bNZ5UeirrXMf8uMxLXScthCdUzla+YNdE 5srymWYk/y855rfqIWM+zmstiiuObfCl/uEC7qRE5+EdMI396IQWeuBcgm2SXz4Ow2xUFK N8tzWb0dCtW8wCiu3JUJxfGi8vawtzhwIn9g7vDklJGf3R3Stlpn4O2eF0ZBB9LYPHixsv vniWyzHrqbMemU8i4pZKH+R6Pxq1H1dPmW07BVIw3CUmjfVQFH0o6yiK0T7cMA== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id DFA243596; Wed, 19 Jan 2022 00:46:14 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 20J0kEYX016113; Wed, 19 Jan 2022 00:46:14 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 20J0kEfJ016112; Wed, 19 Jan 2022 00:46:14 GMT (envelope-from git) Date: Wed, 19 Jan 2022 00:46:14 GMT Message-Id: <202201190046.20J0kEfJ016112@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Konstantin Belousov Subject: git: 29887e602b6e - stable/13 - truss(1): detach more carefully List-Id: Commits to the stable branches of the FreeBSD src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-branches List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-branches@freebsd.org X-BeenThere: dev-commits-src-branches@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: kib X-Git-Repository: src X-Git-Refname: refs/heads/stable/13 X-Git-Reftype: branch X-Git-Commit: 29887e602b6e00d886348f3a5a65dc0070a7d7ef Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1642553175; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=SsNAXOnRBRUvfLej6Ls3jHPjLUaTjOAn6dY3zhhqf5Q=; b=eHS+kRzDKmDlWawWnHekx0/Y0Qgd9zOs7nRVwdcE3JV4+NhnZaw9BlYEIHeimkhbChlKhr XsVnfa0P5IkoiJ4rNmLU+HchKQTZee3G4vh+6bw9RaMDsabAC+dMc3nSNcrwoXFX4pY+EZ qSPS+4UJxxIqs/3UlPS+I90LdgE5dw3J/G4ifgRN2+LJlbNjTz+sipSnLOesc9SsXUyKys opeOh2vJfgRV09mdG7xrBOeuD/WtRFBJZJQIweOQaCXoflrwjoHoexsQngg7TuDytjHcQ7 IOOw85EgwXQuc6eIytX77tiwfNMhiEeJxDb5CI3cRxZZIe/bEDm2waZX7/qyeg== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1642553175; a=rsa-sha256; cv=none; b=wjceyHEYYHQyylt05K63suyxshfmNQJCDEIcu3JPTjPKc///dKt2osPlAXovQ6BFZCRIYQ u0Bk9jsHNW8XhMB6+RNOZhilTcERn9nbnLQLCZInaCdMEmPjoTOAqOwfOTKIHZVPMBmW5t BaWMavhDi3CcZO9E8Tn9Sb01/kOK+BLo5zOdCxtRquwKLWRNOkplScOS7n3gIcl4Hq0bR9 11HTg6G/arhrgq2fAdwm847KyjsSXgTihFYKXW2hShSGHwIyoAQ7d4Sf7qQcH5NDmw8yuG uq7yuQyHhPVyzlRO0iZZ4kMyKPxlzkU/IvsGaalriqdKXx6Wn1fZIs7IpasihQ== ARC-Authentication-Results: i=1; mx1.freebsd.org; none X-ThisMailContainsUnwantedMimeParts: N The branch stable/13 has been updated by kib: URL: https://cgit.FreeBSD.org/src/commit/?id=29887e602b6e00d886348f3a5a65dc0070a7d7ef commit 29887e602b6e00d886348f3a5a65dc0070a7d7ef Author: Konstantin Belousov AuthorDate: 2022-01-12 08:21:19 +0000 Commit: Konstantin Belousov CommitDate: 2022-01-19 00:46:08 +0000 truss(1): detach more carefully (cherry picked from commit 12f747e6ff675edfc1f2f95f7fc435dc01e0c29c) --- usr.bin/truss/setup.c | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/usr.bin/truss/setup.c b/usr.bin/truss/setup.c index 78be0c7f570f..d98e618d9c43 100644 --- a/usr.bin/truss/setup.c +++ b/usr.bin/truss/setup.c @@ -223,11 +223,24 @@ restore_proc(int signo __unused) static void detach_proc(pid_t pid) { + int sig, status; - /* stop the child so that we can detach */ + /* + * Stop the child so that we can detach. Filter out possible + * lingering SIGTRAP events buffered in the threads. + */ kill(pid, SIGSTOP); - if (waitpid(pid, NULL, 0) < 0) - err(1, "Unexpected stop in waitpid"); + for (;;) { + if (waitpid(pid, &status, 0) < 0) + err(1, "Unexpected error in waitpid"); + sig = WIFSTOPPED(status) ? WSTOPSIG(status) : 0; + if (sig == SIGSTOP) + break; + if (sig == SIGTRAP) + sig = 0; + if (ptrace(PT_CONTINUE, pid, (caddr_t)1, sig) < 0) + err(1, "Can not continue for detach"); + } if (ptrace(PT_DETACH, pid, (caddr_t)1, 0) < 0) err(1, "Can not detach the process");