From patchwork Thu Oct 15 18:06:45 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "H.J. Lu" X-Patchwork-Id: 40733 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 409653850424; Thu, 15 Oct 2020 18:06:52 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 409653850424 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1602785212; bh=Hi/GlSP/CKl92upkv35wpgmX+4cWoWxt09KjNfludaE=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=DnJ1bxa45l+jM+wMimr9PVo1hZUbdtVqIDVrlIcDX2umJ/j0yIxJFBn/JU/zaRYmK Ravhom9xxd51Mk6pdaXncIyXL0G7SB2EhCUg5uzwe7RlAdjg6Lma6AlsB5t68NZCD2 MdxYeoYEjM9D+RjEFbcWChXvf1rk5QNDiz/U0loQ= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-pl1-x642.google.com (mail-pl1-x642.google.com [IPv6:2607:f8b0:4864:20::642]) by sourceware.org (Postfix) with ESMTPS id 2E8CB3850424 for ; Thu, 15 Oct 2020 18:06:49 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 2E8CB3850424 Received: by mail-pl1-x642.google.com with SMTP id y1so2037101plp.6 for ; Thu, 15 Oct 2020 11:06:49 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=Hi/GlSP/CKl92upkv35wpgmX+4cWoWxt09KjNfludaE=; b=Bm6Nktbz43afa1W0MTvXkmhcZTrpoqASgjWcAM0NeVNuHOUNULuM4ius4BNxwvlzq7 /MyZPJ6mco8bYJDcUdenun7fm8ECodxBcFHCManRmY32iRh2391C7tCuF/p6wzUvx+64 g/b9DlWUT4e4XVRmri2+6RAXopInGIQpzuNsN9r9eKFsP37lYjLuw5w+KZ9yFuyy8kqs 5ZU/fZi4a45M1ZuoHKsQ2gVP8oCMZiZcM8UkooqLR1vis0/ktQWgjoHoOlbb4DiybVVA YXdpx+VI7eZllGdLmTj8hxovSdn0kwHXh4ls4psBmvoACv8JekdPPFIxCCzPKG66ejmz 76GA== X-Gm-Message-State: AOAM530IxCj8PWusp/Aiq2CjguMLWECgWlB+MeSJO+xJvoU9xKuH9zRT r7Of65BntmRLda2C1TriEZQ= X-Google-Smtp-Source: ABdhPJz4tUZatwbMePTtQOit2NRYNpeMACOrfbAfA46/gvt9B4EpBLkc+lewJXM+oEzcrdYVG/HnCw== X-Received: by 2002:a17:90a:bf8c:: with SMTP id d12mr58284pjs.157.1602785208005; Thu, 15 Oct 2020 11:06:48 -0700 (PDT) Received: from gnu-cfl-2.localdomain (c-69-181-90-243.hsd1.ca.comcast.net. [69.181.90.243]) by smtp.gmail.com with ESMTPSA id n16sm3917811pfo.150.2020.10.15.11.06.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 15 Oct 2020 11:06:47 -0700 (PDT) Received: from gnu-cfl-2.localdomain (localhost [IPv6:::1]) by gnu-cfl-2.localdomain (Postfix) with ESMTP id E64771A00DD; Thu, 15 Oct 2020 11:06:45 -0700 (PDT) To: libc-alpha@sourceware.org Subject: [PATCH] shm tests: Append PID to names passed to shm_open [BZ #26737] Date: Thu, 15 Oct 2020 11:06:45 -0700 Message-Id: <20201015180645.523000-1-hjl.tools@gmail.com> X-Mailer: git-send-email 2.26.2 MIME-Version: 1.0 X-Spam-Status: No, score=-3041.4 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.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) 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: "H.J. Lu via Libc-alpha" From: "H.J. Lu" Reply-To: "H.J. Lu" Errors-To: libc-alpha-bounces@sourceware.org Sender: "Libc-alpha" Append PID to names passed to shm_open in shm tests to avoid random FAIL: rt/tst-shm-cancel FAIL: rt/tst-shm due to the same name passed to shm_open and shm_unlink when more than one "make check" running in parallel on the same machine. Reviewed-by: Adhemerval Zanella --- rt/tst-shm-cancel.c | 11 ++++++++++- rt/tst-shm.c | 35 +++++++++++++++++++++++++---------- 2 files changed, 35 insertions(+), 11 deletions(-) diff --git a/rt/tst-shm-cancel.c b/rt/tst-shm-cancel.c index e787229ab2..67d8ce86d5 100644 --- a/rt/tst-shm-cancel.c +++ b/rt/tst-shm-cancel.c @@ -26,7 +26,14 @@ #include static sem_t sem; /* Use to sync with thread start. */ -static const char shm_name[] = "/glibc-shm_open-cancel"; +static char shm_name[sizeof "/glibc-shm_open-cancel-" + sizeof (pid_t) * 3]; + +static void +init_shm_name (void) +{ + snprintf (shm_name, sizeof (shm_name), "/glibc-shm_open-cancel-%u", + getpid ()); +} static void remove_shm (int status, void *arg) @@ -86,6 +93,8 @@ do_test (void) { pthread_t td; + init_shm_name (); + if (sem_init (&sem, 0, 0)) { printf ("error: sem_init failed: %m\n"); diff --git a/rt/tst-shm.c b/rt/tst-shm.c index 37a0ba5a50..5f866132d3 100644 --- a/rt/tst-shm.c +++ b/rt/tst-shm.c @@ -34,13 +34,26 @@ /* We want to see output immediately. */ #define STDOUT_UNBUFFERED +static char shm_test_name[sizeof "/glibc-shm-test-" + sizeof (pid_t) * 3]; +static char shm_escape_name[sizeof "/../escaped-" + sizeof (pid_t) * 3]; + +static void +init_shm_test_names (void) +{ + snprintf (shm_test_name, sizeof (shm_test_name), "/glibc-shm-test-%u", + getpid ()); + snprintf (shm_escape_name, sizeof (shm_escape_name), "/../escaped-%u", + getpid ()); +} + static void worker (int write_now) { struct timespec ts; struct stat64 st; int i; - int fd = shm_open ("/glibc-shm-test", O_RDWR, 0600); + + int fd = shm_open (shm_test_name, O_RDWR, 0600); if (fd == -1) error (EXIT_FAILURE, 0, "failed to open shared memory object: shm_open"); @@ -117,7 +130,9 @@ do_test (void) int status2; struct stat64 st; - fd = shm_open ("/../escaped", O_RDWR | O_CREAT | O_TRUNC | O_EXCL, 0600); + init_shm_test_names (); + + fd = shm_open (shm_escape_name, O_RDWR | O_CREAT | O_TRUNC | O_EXCL, 0600); if (fd != -1) { perror ("read file outside of SHMDIR directory"); @@ -126,7 +141,7 @@ do_test (void) /* Create the shared memory object. */ - fd = shm_open ("/glibc-shm-test", O_RDWR | O_CREAT | O_TRUNC | O_EXCL, 0600); + fd = shm_open (shm_test_name, O_RDWR | O_CREAT | O_TRUNC | O_EXCL, 0600); if (fd == -1) { /* If shm_open is unimplemented we skip the test. */ @@ -146,18 +161,18 @@ do_test (void) shared memory itself. */ perror ("failed to size of shared memory object: ftruncate"); close (fd); - shm_unlink ("/glibc-shm-test"); + shm_unlink (shm_test_name); return 0; } if (fstat64 (fd, &st) == -1) { - shm_unlink ("/glibc-shm-test"); + shm_unlink (shm_test_name); error (EXIT_FAILURE, 0, "initial stat failed"); } if (st.st_size != 4000) { - shm_unlink ("/glibc-shm-test"); + shm_unlink (shm_test_name); error (EXIT_FAILURE, 0, "initial size not correct"); } @@ -170,7 +185,7 @@ do_test (void) /* Couldn't create a second process. */ perror ("fork"); close (fd); - shm_unlink ("/glibc-shm-test"); + shm_unlink (shm_test_name); return 0; } @@ -185,7 +200,7 @@ do_test (void) kill (pid1, SIGTERM); waitpid (pid1, &ignore, 0); close (fd); - shm_unlink ("/glibc-shm-test"); + shm_unlink (shm_test_name); return 0; } @@ -194,7 +209,7 @@ do_test (void) waitpid (pid2, &status2, 0); /* Now we can unlink the shared object. */ - shm_unlink ("/glibc-shm-test"); + shm_unlink (shm_test_name); return (!WIFEXITED (status1) || WEXITSTATUS (status1) != 0 || !WIFEXITED (status2) || WEXITSTATUS (status2) != 0); @@ -203,7 +218,7 @@ do_test (void) static void cleanup_handler (void) { - shm_unlink ("/glibc-shm-test"); + shm_unlink (shm_test_name); } #define CLEANUP_HANDLER cleanup_handler