From patchwork Sat Oct 16 22:41:54 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stafford Horne X-Patchwork-Id: 46307 X-Patchwork-Delegate: azanella@linux.vnet.ibm.com Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 4ABB4385781E for ; Sat, 16 Oct 2021 22:42:22 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 4ABB4385781E DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1634424142; bh=Yda6eP5AvqymqNeFNkQ1q58we35mSEejC27F2RqvRpA=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=WxhClyucU6o6nSUtU1KGmXTe1dCfI7UO0eCyVhDwcO8Jfuq73ubuOBVdeCevXGuSB 3H5579lF02uwrcCG9vXTlFBIz+Q0kTUVs68/FX05hTVdwOn65p/lL9GYCzf+Ia4903 4p7dgcjf2vAwIbByFpoq9C9jjzC7mYF2ax4G+wUU= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-pf1-x430.google.com (mail-pf1-x430.google.com [IPv6:2607:f8b0:4864:20::430]) by sourceware.org (Postfix) with ESMTPS id E84C03858D35 for ; Sat, 16 Oct 2021 22:42:00 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org E84C03858D35 Received: by mail-pf1-x430.google.com with SMTP id f11so7688617pfc.12 for ; Sat, 16 Oct 2021 15:42:00 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=Yda6eP5AvqymqNeFNkQ1q58we35mSEejC27F2RqvRpA=; b=7pvpHswG/2z85J0lqT+uJNKk/w1K1zyl2tqlxrQn4Wuz4nz7aSZ10cd5zzJm9sZeiX 4zfe1ELTfNY7eYMAPMNdHe1kQ9O2ZAUQyXcWKiSQ7bH67v9Upr7cdv+ny5d3/+FvClYf RjhsUxm2kwCr4lmhETL/3ad9Oxg+4GTFcEIBQuXhz3CLhZ/1a2AupUPm5Hta0E2AE/Tq GMGg4k894EwutYuCD7qdBLh/ruZ9o+c2bTcJCfhWMZb3FmFdEtNbG7036+tzhY0GuHlT J3IH66LBHPL5dltqKZRQiXXBpmucRWPjN0MCGUbOojU/x6+rDDGn3Ot+r9s0yXCsWb+Q nMMw== X-Gm-Message-State: AOAM531/q+2tkwsW/xDzAwV49pHmx9Rjpk+HsvaZlv/f7dPcbISeY4o4 c/hdmxeNoQFQv5citxVGk9hqufI59Uc= X-Google-Smtp-Source: ABdhPJybEgNPBFJGwqD1T36WrAr3yzieQLrD6VimXlcVsHDNLfh1F5ePK+MKn7q6uSdFmS96TOHn+A== X-Received: by 2002:a63:d60a:: with SMTP id q10mr15913849pgg.335.1634424119739; Sat, 16 Oct 2021 15:41:59 -0700 (PDT) Received: from localhost ([2409:10:24a0:4700:e8ad:216a:2a9d:6d0c]) by smtp.gmail.com with ESMTPSA id j7sm8980281pfu.73.2021.10.16.15.41.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 16 Oct 2021 15:41:58 -0700 (PDT) To: GLIBC patches Subject: [PATCH] nptl: Fix tst-cancel7 and tst-cancelx7 pidfile race Date: Sun, 17 Oct 2021 07:41:54 +0900 Message-Id: <20211016224154.2991161-1-shorne@gmail.com> X-Mailer: git-send-email 2.31.1 MIME-Version: 1.0 X-Spam-Status: No, score=-10.3 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, 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: Stafford Horne via Libc-alpha From: Stafford Horne Reply-To: Stafford Horne Errors-To: libc-alpha-bounces+patchwork=sourceware.org@sourceware.org Sender: "Libc-alpha" The check for waiting for the pidfile to be created looks wrong. At the point when ACCESS is run the pid file will always be created and accessible as it is created during DO_PREPARE. This means that thread cancellation may be performed before the pid is written to the pidfile. This was found to be flaky when testing on my OpenRISC platform. Fix this by using the semaphore to wait for pidfile pid write completion. Reviewed-by: Adhemerval Zanella --- nptl/tst-cancel7.c | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/nptl/tst-cancel7.c b/nptl/tst-cancel7.c index 54ed2a54ff..e926f4455c 100644 --- a/nptl/tst-cancel7.c +++ b/nptl/tst-cancel7.c @@ -115,16 +115,13 @@ do_test (void) { pthread_t th = xpthread_create (NULL, tf, NULL); - do - nanosleep (&(struct timespec) { .tv_sec = 0, .tv_nsec = 100000000 }, NULL); - while (access (pidfilename, R_OK) != 0); + /* Wait to cancel until after the pid is written. */ + if (sem_wait (sem) != 0) + FAIL_EXIT1 ("sem_wait: %m"); xpthread_cancel (th); void *r = xpthread_join (th); - if (sem_wait (sem) != 0) - FAIL_EXIT1 ("sem_wait: %m"); - FILE *f = xfopen (pidfilename, "r+"); long long ll;