From owner-dev-commits-src-main@freebsd.org Thu May 27 16:45:16 2021 Return-Path: Delivered-To: dev-commits-src-main@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id 6F1C3640DAD; Thu, 27 May 2021 16:45:16 +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 4FrYb02gt2z4X5P; Thu, 27 May 2021 16:45:16 +0000 (UTC) (envelope-from git@FreeBSD.org) 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 432622795F; Thu, 27 May 2021 16:45:16 +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 14RGjG0L066554; Thu, 27 May 2021 16:45:16 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 14RGjGDE066553; Thu, 27 May 2021 16:45:16 GMT (envelope-from git) Date: Thu, 27 May 2021 16:45:16 GMT Message-Id: <202105271645.14RGjGDE066553@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Eric van Gyzen Subject: git: 427f12f150e8 - main - libprocstat kstack: fix race with thread creation MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: vangyzen X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 427f12f150e875c40acb84f292a80bfa0b90a1a2 Auto-Submitted: auto-generated X-BeenThere: dev-commits-src-main@freebsd.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Commit messages for the main branch of the src repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 27 May 2021 16:45:16 -0000 The branch main has been updated by vangyzen: URL: https://cgit.FreeBSD.org/src/commit/?id=427f12f150e875c40acb84f292a80bfa0b90a1a2 commit 427f12f150e875c40acb84f292a80bfa0b90a1a2 Author: Eric van Gyzen AuthorDate: 2021-05-27 16:33:22 +0000 Commit: Eric van Gyzen CommitDate: 2021-05-27 16:44:00 +0000 libprocstat kstack: fix race with thread creation When collecting kernel stacks for a target process, if the process adds a thread between the two calls to sysctl, ignore the additional threads. Previously, procstat would print only a useless error message. Now, it prints a consistent snapshot of the stacks. We know that snapshot is already stale, but it could still be stale even with a more complex fix to reallocate and retry, so such a fix is hardly worth the effort. Reported by: Daniel.Mitchell@emc.com MFC after: 1 week Sponsored by: Dell EMC Isilon --- lib/libprocstat/libprocstat.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/libprocstat/libprocstat.c b/lib/libprocstat/libprocstat.c index 7ccf6c343705..b754bc568e99 100644 --- a/lib/libprocstat/libprocstat.c +++ b/lib/libprocstat/libprocstat.c @@ -2609,7 +2609,8 @@ procstat_getkstack_sysctl(pid_t pid, int *cntp) warn("malloc(%zu)", len); return (NULL); } - if (sysctl(name, nitems(name), kkstp, &len, NULL, 0) == -1) { + if (sysctl(name, nitems(name), kkstp, &len, NULL, 0) == -1 && + errno != ENOMEM) { warn("sysctl: kern.proc.pid: %d", pid); free(kkstp); return (NULL);