From nobody Thu Apr 28 07:41:46 2022 X-Original-To: dev-commits-src-main@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 53A8A199A751; Thu, 28 Apr 2022 07:41:46 +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 4Kpncp1xQ7z4gCQ; Thu, 28 Apr 2022 07:41:46 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1651131706; 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=TIVhpi5ivGIGMS6DVflPxq/QLRfQ0WOOdCENM9HHL+Y=; b=W40RUH/tRLOTPid3l2bMyC1N/uDpXxuBIOZevRGnd+9f/HQaxVGff/XjyBJo7S0XUr/H5o jE82v13r2OEie2G/DppdJExbSJGCrxUGegMElRO9UxN75L9LmlV4GYNaHqLMJHDmTjJa2n kFvRmxnj4JYFPpbMdQ2vYDBZrHD5xehJxc+SiY9ficntIGC/yF4OlgCTGW/l3kvUOb++5/ WA3ZiuSOult+6rTBWsDaWjNAmSzwiUOkKWT2mDov3aa7z13OoRty+sU0bQ+RmTzLAprFPv Zy0lc3By89l5WII5IGlmrDB89ovkcxAgmqX0MpaH95LEztJKG3nupvYV7o1cWQ== 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 2240D144DC; Thu, 28 Apr 2022 07:41:46 +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 23S7fkpG044583; Thu, 28 Apr 2022 07:41:46 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 23S7fkZG044582; Thu, 28 Apr 2022 07:41:46 GMT (envelope-from git) Date: Thu, 28 Apr 2022 07:41:46 GMT Message-Id: <202204280741.23S7fkZG044582@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Peter Holm Subject: git: 8a5c1f58dd0e - main - stress2: Added a regression test List-Id: Commit messages for the main branch of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-main List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-main@freebsd.org X-BeenThere: dev-commits-src-main@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: pho X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 8a5c1f58dd0e81f667b684e48462732eb773c6a9 Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1651131706; 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=TIVhpi5ivGIGMS6DVflPxq/QLRfQ0WOOdCENM9HHL+Y=; b=Ab9wnwJOWzsxo7qfdB+TE9Rkz41w9I3AYOCQcrtglqUujLihfn5FYJOq3gc3euxgNpJ2JL 9IzkzjLz/OnmEDAY5HdHf0owHMmNcEA8ZfaK9++en3aRNwIxJJgqf0sxX5oOxpsQ40kXMd foBjlfxflfPTUUWREK0XpIn4E1245OrLy04or9fw+707dtjEXvvjwc67v+pVSdNCDPHsZI fQbsymbOTV7M/t26iDNmG8AxwX0kiTKM9eN/2gyr6bEsSmHRTXDEl4/ahhg7Gzj6pi8SxJ NWxk8ivSnjw+WqSxlQtkwAuoZBn40OGz8XZWr651cpKafUmh3wLpe48WaNtSCg== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1651131706; a=rsa-sha256; cv=none; b=sGCvjDJOacA3tJKnrE2SpXf1AzhiJsmMeswySeR+L416epZ7tcLiB0lHA1/tXwRH6QYcl+ OkGIyzoOxEJud/Z1LEpmg7mE0+TrSUU7y9WAUjYlaoym44YJdU1uOjWmW+FTDdC9+CJD1M 5HzWlUr042AdV4T0h1oKrF/Xw02aPmInKGKN37PCIGSbMvmJzJBB8S3ErPQpQewwAg/Dww ctsMS0VY76E5ji0AwaofAoen7wzPSo/8Edu3r9pTmZqjjkuZRvle4C9Y1TaXsvllBBPf+9 bkAUxxPr1V4TcL/G1FMasBOLQk+o8+du8spOTDwehZ6Gao+EAAyT/1UYe3/dFg== ARC-Authentication-Results: i=1; mx1.freebsd.org; none X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by pho: URL: https://cgit.FreeBSD.org/src/commit/?id=8a5c1f58dd0e81f667b684e48462732eb773c6a9 commit 8a5c1f58dd0e81f667b684e48462732eb773c6a9 Author: Peter Holm AuthorDate: 2022-04-28 07:41:27 +0000 Commit: Peter Holm CommitDate: 2022-04-28 07:41:27 +0000 stress2: Added a regression test --- tools/test/stress2/misc/reaper.sh | 108 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 108 insertions(+) diff --git a/tools/test/stress2/misc/reaper.sh b/tools/test/stress2/misc/reaper.sh new file mode 100755 index 000000000000..1d2d5ade8c6e --- /dev/null +++ b/tools/test/stress2/misc/reaper.sh @@ -0,0 +1,108 @@ +#!/bin/sh + +# +# SPDX-License-Identifier: BSD-2-Clause-FreeBSD +# +# Copyright (c) 2022 Peter Holm +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# 1. Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# 2. Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# +# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND +# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE +# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +# SUCH DAMAGE. +# + +# Demonstrate lingering child process after a timeout(1) timeout +# Test scenario suggestions by kib + +# Fixed by: 709783373e57 - main - Fix another race between fork(2) and +# PROC_REAP_KILL subtree + +eval prog=reaper.$$ +cat > /tmp/$prog.c < +#include +#include +#include +#include + +#define MAXP 10000 + +int +main(void) +{ + pid_t pids[MAXP]; + int i, parallel; + char *cmdline[] = { "SLP", "86400", NULL }; + + for (;;) { + parallel = arc4random() % MAXP + 1; + for (i = 0; i < parallel; i++) { + if ((pids[i] = fork()) == 0) { + setproctitle("child"); + if ((arc4random() % 100) < 10) { + if (execve(cmdline[0], cmdline, + NULL) == -1) + err(1, "execve"); + } else { + for (;;) + pause(); + } + _exit(0); /* never reached */ + } + if (pids[i] == -1) + err(1, "fork()"); + } + + usleep(arc4random() % 500); + + for (i = 0; i < parallel; i++) { + if (kill(pids[i], SIGINT) == -1) + err(1, "kill(%d)", pids[i]); + if (waitpid(pids[i], NULL, 0) != pids[i]) + err(1, "waitpid(%d)", pids[i]); + } + } +} +EOF +sed -i '' "s#SLP#/tmp/$prog.sleep#" /tmp/$prog.c +cc -o /tmp/$prog -Wall -Wextra -O0 /tmp/$prog.c || exit 1 +rm /tmp/$prog.c + +cp /bin/sleep /tmp/$prog.sleep +n=1 +start=`date +%s` +while true; do + timeout 2s /tmp/$prog + for i in `jot 50`; do + pgrep -q $prog || break + sleep .5 + done + if pgrep -q $prog; then + e=$((`date +%s` - start)) + echo "Failed in loop #$n after $e seconds." + pgrep "$prog|timeout" | xargs ps -lp + pkill $prog + rm -f /tmp/$prog /tmp/$prog.sleep + exit 1 + fi + [ $((`date +%s` - start)) -ge 600 ] && break + n=$((n + 1)) +done +rm /tmp/$prog /tmp/$prog.sleep +exit 0