]> granicus.if.org Git - strace/commitdiff
tests: make mq_sendrecv* test executables reenterable
authorDmitry V. Levin <ldv@altlinux.org>
Fri, 14 Apr 2017 16:43:18 +0000 (16:43 +0000)
committerDmitry V. Levin <ldv@altlinux.org>
Fri, 14 Apr 2017 16:43:18 +0000 (16:43 +0000)
* tests/mq_sendrecv.c (MQ_NAME): Remove.
(mq_name): New static variable.
(cleanup): Use it instead of MQ_NAME.
(main): Initialize it dynamically using the pid of process.  Use it
instead of MQ_NAME.

tests/mq_sendrecv.c

index ce67335bd319f13f1ae19243c0bccc4f45bf15f6..ab1d2ddef50d9d582bea2463dd345072c0213bf1 100644 (file)
 
 # include "sigevent.h"
 
-# ifndef MQ_NAME
-#  define MQ_NAME "mq_sendrecv.sample"
-# endif
-
 # ifndef DUMPIO_READ
 #  define DUMPIO_READ 0
 # endif
@@ -61,6 +57,7 @@
 #  define DUMPIO_WRITE 0
 # endif
 
+static char *mq_name;
 
 enum {
        NUM_ATTRS = 8,
@@ -124,8 +121,8 @@ cleanup(void)
 {
        long rc;
 
-       rc = syscall(__NR_mq_unlink, MQ_NAME);
-       printf("mq_unlink(\"" MQ_NAME "\") = %s\n", sprintrc(rc));
+       rc = syscall(__NR_mq_unlink, mq_name);
+       printf("mq_unlink(\"%s\") = %s\n", mq_name, sprintrc(rc));
 
        puts("+++ exited with 0 +++");
 }
@@ -430,12 +427,15 @@ main(void)
 
        /* Sending and receiving test */
 
+       if (asprintf(&mq_name, "strace-mq_sendrecv-%u.sample", getpid()) < 0)
+               perror_msg_and_fail("asprintf");
+
 # if DUMPIO_READ || DUMPIO_WRITE
        close(0);
 # endif
        bogus_attrs[1] = 2;
        bogus_attrs[2] = MSG_SIZE;
-       fd = rc = syscall(__NR_mq_open, MQ_NAME,
+       fd = rc = syscall(__NR_mq_open, mq_name,
                          O_CREAT|O_RDWR|O_NONBLOCK, S_IRWXU, bogus_attrs);
        errstr = sprintrc(rc);
        if (rc < 0)
@@ -448,11 +448,11 @@ main(void)
 # endif
        fill_memory_ex(bogus_attrs, sizeof(*bogus_attrs) * NUM_ATTRS,
                       0xbb, 0x70);
-       printf("mq_open(\"" MQ_NAME "\", O_RDWR|O_CREAT|O_NONBLOCK, "
-              "0700, {mq_flags=%#llx, mq_maxmsg=2, mq_msgsize=%u, "
+       printf("mq_open(\"%s\", O_RDWR|O_CREAT|O_NONBLOCK, 0700"
+              ", {mq_flags=%#llx, mq_maxmsg=2, mq_msgsize=%u, "
               "mq_curmsgs=%lld}) = %s\n",
-              (unsigned long long) (kernel_ulong_t) bogus_attrs[0], MSG_SIZE,
-              (long long) bogus_attrs[3], errstr);
+              mq_name, (unsigned long long) (kernel_ulong_t) bogus_attrs[0],
+              MSG_SIZE, (long long) bogus_attrs[3], errstr);
 
        rc = syscall(__NR_mq_getsetattr, fd, NULL, bogus_attrs);
        if (rc < 0)