From patchwork Tue Aug 3 20:39:07 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: DJ Delorie X-Patchwork-Id: 1513086 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=sourceware.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=sourceware.org; envelope-from=libc-alpha-bounces+incoming=patchwork.ozlabs.org@sourceware.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; secure) header.d=sourceware.org header.i=@sourceware.org header.a=rsa-sha256 header.s=default header.b=bas7FEVj; dkim-atps=neutral Received: from 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 RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4GfRYt0SGYz9sPf for ; Wed, 4 Aug 2021 06:39:29 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 21225385DC3D for ; Tue, 3 Aug 2021 20:39:27 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 21225385DC3D DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1628023167; bh=+rxqe9YqQvF3ZVV0Wr04Xe8DuugrtjOYZS5VuX7W4tg=; h=Date:To:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=bas7FEVjzHKs+vkmDUNaNAW05MRsrKYz5PimONg9IXKVUYN8MyCBRZ+LWt8fm0Nn+ okr/lJGByik6f9MHLB3ZugHDpU7cNdAlU3Wqc7tq76AkH9v9Y/lRFVxBRqcW+CfUM6 v0SHm1ioXJfrY/UhM2mz7M4DFcH5U/6vpGfSXeao= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by sourceware.org (Postfix) with ESMTP id C35E13858C27 for ; Tue, 3 Aug 2021 20:39:11 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org C35E13858C27 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-80-sgBmYY8AOMW9vw9uESbzgA-1; Tue, 03 Aug 2021 16:39:10 -0400 X-MC-Unique: sgBmYY8AOMW9vw9uESbzgA-1 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id A1BD51006C80 for ; Tue, 3 Aug 2021 20:39:09 +0000 (UTC) Received: from greed.delorie.com (ovpn-112-6.rdu2.redhat.com [10.10.112.6]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 701321F5 for ; Tue, 3 Aug 2021 20:39:09 +0000 (UTC) Received: from greed.delorie.com.redhat.com (localhost [127.0.0.1]) by greed.delorie.com (8.15.2/8.15.2) with ESMTP id 173Kd7es1023875 for ; Tue, 3 Aug 2021 16:39:08 -0400 Date: Tue, 03 Aug 2021 16:39:07 -0400 Message-Id: To: libc-alpha@sourceware.org Subject: [PATCH] test-dlclose-exit-race: avoid hang on pthread_create error X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-12.9 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H4, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_NONE, TXREP autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: DJ Delorie via Libc-alpha From: DJ Delorie Reply-To: DJ Delorie Errors-To: libc-alpha-bounces+incoming=patchwork.ozlabs.org@sourceware.org Sender: "Libc-alpha" This test depends on the "last" function being called in a different thread than the "first" function, as "last" posts a semaphore that "first" is waiting on. However, if pthread_create fails - for example, if running in an older container before the clone3()-in-container-EPERM fixes - exit() is called in the same thread as everything else, the semaphore never gets posted, and first hangs. The fix is to pre-post that semaphore before a single-threaded exit. Reviewed-by: Arjun Shankar --- stdlib/test-dlclose-exit-race.c | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/stdlib/test-dlclose-exit-race.c b/stdlib/test-dlclose-exit-race.c index b4632532813..2c44efdde6d 100644 --- a/stdlib/test-dlclose-exit-race.c +++ b/stdlib/test-dlclose-exit-race.c @@ -29,6 +29,7 @@ #include #include +#include #include #include #include @@ -64,6 +65,7 @@ last (void) int main (void) { + int value; void *dso; pthread_t thread; @@ -71,7 +73,17 @@ main (void) dso = xdlopen ("$ORIGIN/test-dlclose-exit-race-helper.so", RTLD_NOW|RTLD_GLOBAL); - thread = xpthread_create (NULL, exit_thread, NULL); + if ((value = pthread_create (&thread, NULL, exit_thread, NULL)) != 0) + { + /* If pthread_create fails, then exit() is called in the main + thread instead of a second thread, so the semaphore post that + would have happened in 'last' gets blocked behind the call to + first() - which is waiting on the semaphore, and thus + hangs. */ + sem_post (&order2); + errno = value; + FAIL_EXIT1 ("pthread_create: %m"); + } xdlclose (dso); xpthread_join (thread);