public inbox for glibc-cvs@sourceware.org
help / color / mirror / Atom feed
* [glibc] shm tests: Append PID to names passed to shm_open [BZ #26737]
@ 2020-10-15 21:06 H.J. Lu
0 siblings, 0 replies; only message in thread
From: H.J. Lu @ 2020-10-15 21:06 UTC (permalink / raw)
To: glibc-cvs
https://sourceware.org/git/gitweb.cgi?p=glibc.git;h=9030377480effce89f382499ff47a22467112436
commit 9030377480effce89f382499ff47a22467112436
Author: H.J. Lu <hjl.tools@gmail.com>
Date: Thu Oct 15 10:59:04 2020 -0700
shm tests: Append PID to names passed to shm_open [BZ #26737]
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 <adhemerval.zanella@linaro.org>
Diff:
---
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 <stdlib.h>
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
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2020-10-15 21:06 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-10-15 21:06 [glibc] shm tests: Append PID to names passed to shm_open [BZ #26737] H.J. Lu
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).