From patchwork Mon Aug 5 14:22:45 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Maciej W. Rozycki" X-Patchwork-Id: 1969076 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=sourceware.org (client-ip=8.43.85.97; helo=server2.sourceware.org; envelope-from=libc-alpha-bounces~incoming=patchwork.ozlabs.org@sourceware.org; receiver=patchwork.ozlabs.org) Received: from server2.sourceware.org (server2.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4WczDt3LgSz1yYD for ; Tue, 6 Aug 2024 00:23:10 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id B4E86385DDC4 for ; Mon, 5 Aug 2024 14:23:08 +0000 (GMT) X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from angie.orcam.me.uk (angie.orcam.me.uk [78.133.224.34]) by sourceware.org (Postfix) with ESMTP id 7BBFC385C6C8 for ; Mon, 5 Aug 2024 14:22:46 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 7BBFC385C6C8 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=orcam.me.uk Authentication-Results: sourceware.org; spf=none smtp.mailfrom=orcam.me.uk ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 7BBFC385C6C8 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=78.133.224.34 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1722867768; cv=none; b=LDYFlGfhiJTGowp4Zeikb85Duni/N1ipr+a68U6DxjhOp8k/ZfdTw6e+7YSxQssBfA4EE30cGNsTomrD3BpY2f+4nC9Zr2OCQifaBSL2nDgV6jhBwyY1VRMRYFmMkwScrKuPvPBw1O1ojvaxfyXK5jSKyrs3GsLtF+dPCJeg7vE= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1722867768; c=relaxed/simple; bh=ogi9e+3QqA2YPj5p5UlN31tIvkAW66Mkwo/tYiANbNU=; h=Date:From:To:Subject:Message-ID:MIME-Version; b=fselxSD9zgCiEEBi0MfgIPOL1VaOg2Toac4p+QjyIYEGn0jXXWyRkDE/nfMuZ4wIp50h9+x9ShQS6/13d2FwTngQWe5A46mBTxa9Kh+kSb4F1yXDQEAVwOqFlFnfSnxY1kJmr/sPMD1/Y+e+pXbC/18RtKFjzPffFSlCgHAoB1c= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by angie.orcam.me.uk (Postfix, from userid 500) id 0BD9192009C; Mon, 5 Aug 2024 16:22:46 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by angie.orcam.me.uk (Postfix) with ESMTP id 049E692009B; Mon, 5 Aug 2024 15:22:45 +0100 (BST) Date: Mon, 5 Aug 2024 15:22:45 +0100 (BST) From: "Maciej W. Rozycki" To: libc-alpha@sourceware.org cc: "Maciej W. Rozycki" Subject: [PATCH 1/2] nptl: Reorder semaphore release in tst-cancel7 In-Reply-To: Message-ID: References: User-Agent: Alpine 2.21 (DEB 202 2017-01-01) MIME-Version: 1.0 X-Spam-Status: No, score=-1162.7 required=5.0 tests=BAYES_00, KAM_DMARC_STATUS, KAM_INFOUSMEBIZ, KAM_LAZY_DOMAIN_SECURITY, KAM_NUMSUBJECT, SPF_HELO_NONE, SPF_NONE, TXREP autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: "Maciej W. Rozycki" Errors-To: libc-alpha-bounces~incoming=patchwork.ozlabs.org@sourceware.org From: Maciej W. Rozycki Move the release of the semaphore used to synchronize between an extra copy of the test run as a separate process and the main test process until after the PID file has been locked. It is so that if the cleanup function gets called by the test driver due to premature termination of the main test process, then the function does not get at the PID file before it has been locked and conclude that the extra copy of the test has already terminated. This won't usually happen due to a relatively high amount of time required to elapse before timeout triggers in the test driver, but it will change with the next change. There is still a small time window remaining with this change in place where the main test process gets killed for some reason between the extra copy of the test has been already started by pthread_create(3) and a successful return from the call to sem_wait(3), in which case the cleanup function can be reached before PID has been written to the PID file and the file locked. It seems that with the test case structured as it is now and PID-based process management we have no means to avoid it. Reviewed-by: Adhemerval Zanella --- nptl/tst-cancel7.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) glibc-tst-cancel7-sem-post.diff Index: glibc/nptl/tst-cancel7.c =================================================================== --- glibc.orig/nptl/tst-cancel7.c +++ glibc/nptl/tst-cancel7.c @@ -57,9 +57,6 @@ sl (void) fprintf (f, "%lld\n", (long long) getpid ()); fflush (f); - if (sem_post (sem) != 0) - FAIL_EXIT1 ("sem_post: %m"); - struct flock fl = { .l_type = F_WRLCK, @@ -70,6 +67,9 @@ sl (void) if (fcntl (fileno (f), F_SETLK, &fl) != 0) FAIL_EXIT1 ("fcntl (F_SETFL): %m"); + if (sem_post (sem) != 0) + FAIL_EXIT1 ("sem_post: %m"); + sigset_t ss; sigfillset (&ss); sigsuspend (&ss); @@ -116,7 +116,7 @@ do_test (void) { pthread_t th = xpthread_create (NULL, tf, NULL); - /* Wait to cancel until after the pid is written. */ + /* Wait to cancel until after the pid is written and file locked. */ if (sem_wait (sem) != 0) FAIL_EXIT1 ("sem_wait: %m"); From patchwork Mon Aug 5 14:22:51 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Maciej W. Rozycki" X-Patchwork-Id: 1969077 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=sourceware.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=server2.sourceware.org; envelope-from=libc-alpha-bounces~incoming=patchwork.ozlabs.org@sourceware.org; receiver=patchwork.ozlabs.org) Received: from server2.sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4WczDy0M1Fz1yYD for ; Tue, 6 Aug 2024 00:23:14 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id E1402385C6CF for ; Mon, 5 Aug 2024 14:23:11 +0000 (GMT) X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from angie.orcam.me.uk (angie.orcam.me.uk [78.133.224.34]) by sourceware.org (Postfix) with ESMTP id CED80385B50B for ; Mon, 5 Aug 2024 14:22:51 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org CED80385B50B Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=orcam.me.uk Authentication-Results: sourceware.org; spf=none smtp.mailfrom=orcam.me.uk ARC-Filter: OpenARC Filter v1.0.0 sourceware.org CED80385B50B Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=78.133.224.34 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1722867773; cv=none; b=v+ZRFEYfmNhAM3fEsnGjB9JvoCkvurXc37/C3qH3wBIfrnNcVbWAhRHQUKg4f/w9YpJAR6zuwLlt5Txw2w217wO9LgPJPhtJ2UFQ9QISgvduH5ZdjNRb5VUkBnqt+zCMUzvzb9FCQCMVXpAzTfvuq+SCXRfzEovTDHjM7gVuzAU= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1722867773; c=relaxed/simple; bh=ccEMZhd443St+XlQmkdBhM++P28lzjb2z7o38V/Jgoo=; h=Date:From:To:Subject:Message-ID:MIME-Version; b=jeAal2qVGTMWZYVzi/UYlR7BQ758U1BDDZ4BSNImWPIMQqvyZ9yEK+6uiX3awo4eyrzJcOhCiOBCz+dBjY8F6T5+VWM+XNQV1A/jFaD9lin5lsZ2ZNKIIXa7m1pTj0b/ALgSKHtofhMMs/F1Fm0N9YpU9jpEd3EC9qQO0zpxIT8= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by angie.orcam.me.uk (Postfix, from userid 500) id 649EF92009C; Mon, 5 Aug 2024 16:22:51 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by angie.orcam.me.uk (Postfix) with ESMTP id 5F2FE92009B; Mon, 5 Aug 2024 15:22:51 +0100 (BST) Date: Mon, 5 Aug 2024 15:22:51 +0100 (BST) From: "Maciej W. Rozycki" To: libc-alpha@sourceware.org cc: "Maciej W. Rozycki" Subject: [PATCH 2/2] nptl: Fix stray process left by tst-cancel7 blocking testing In-Reply-To: Message-ID: References: User-Agent: Alpine 2.21 (DEB 202 2017-01-01) MIME-Version: 1.0 X-Spam-Status: No, score=-1163.0 required=5.0 tests=BAYES_00, KAM_DMARC_STATUS, KAM_INFOUSMEBIZ, KAM_LAZY_DOMAIN_SECURITY, SPF_HELO_NONE, SPF_NONE, TXREP autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: "Maciej W. Rozycki" Errors-To: libc-alpha-bounces~incoming=patchwork.ozlabs.org@sourceware.org From: Maciej W. Rozycki Fix an issue with commit b74121ae4bc5 ("Update.") and prevent a stray process from being left behind by tst-cancel7 (and also tst-cancelx7, which is the same test built with '-fexceptions' additionally supplied to the compiler), which then blocks remote testing until the process has been killed by hand. This test case creates a thread that runs an extra copy of the test via system(3) and using the '--direct' option so that the test wrapper does not interfere with this instance. This extra copy executes its business and calls sigsuspend(2) and then never terminates by itself. Instead it relies on being killed by the main test process directly via a thread cancellation request or, should that fail, by issuing SIGKILL either at the conclusion of 'do_test' or by the test driver via 'do_cleanup' where the test timeout has been hit or the test driver interrupted. However if the main test process has been instead killed by a signal, such as due to incorrect execution, before it had a chance to kill the extra copy of the test case, then the test wrapper will terminate without running 'do_cleanup' and consequently the extra copy of the test case will remain forever in its suspended state, and in the remote case in particular it means that the remote test wrapper will wait forever for the SSH command to complete. This has been observed with the 'alpha-linux-gnu' target, where the main test process triggers SIGSEGV and the test wrapper correctly records: Didn't expect signal from child: got `Segmentation fault' in nptl/tst-cancel7.out and terminates, but then the calling SSH command continues waiting for the remaining process started in the same session on the remote target to complete. Address this problem by also registering 'do_cleanup' via atexit(3), observing that 'support_delete_temp_files' is registered by the test wrapper before the test initializing function 'do_prepare' is called and that we call all the functions registered in the reverse of the order in which they were registered, so it is safe to refer to 'pidfilename' in 'do_cleanup' invoked by exit(3) because by that time temporary files have not yet been deleted. A minor inconvenience is that if 'signal_handler' is invoked in the test wrapper as a result of SIGALRM rather than SIGINT, then 'do_cleanup' will be called twice, once as a cleanup handler and again by exit(3). In reality it is harmless though, because issuing SIGKILL is guarded by a record lock, so if the first call has succeeded in killing the extra copy of the test case, then the subsequent call will do nothing. Reviewed-by: Adhemerval Zanella --- nptl/tst-cancel7.c | 4 ++++ 1 file changed, 4 insertions(+) glibc-tst-cancel7-cleanup.diff Index: glibc/nptl/tst-cancel7.c =================================================================== --- glibc.orig/nptl/tst-cancel7.c +++ glibc/nptl/tst-cancel7.c @@ -38,6 +38,8 @@ static char *semfilename; static sem_t *sem; +static void do_cleanup (void); + static void * tf (void *arg) { @@ -108,6 +110,8 @@ do_prepare (int argc, char *argv[]) xwrite (fd, " ", 1); xclose (fd); + + atexit (do_cleanup); }