commit f53e14e24b9d5572770186d4483656b362c0749e
parent a680926bbc89d0fc44ae0011e71ce467a368e71c
Author: Kyle Milz <kyle@0x30.net>
Date: Sat, 20 Aug 2016 16:03:19 -0600
src: add CITRUN_SHMPATH env var override
Diffstat:
8 files changed, 31 insertions(+), 12 deletions(-)
diff --git a/src/runtime.c b/src/runtime.c
@@ -20,7 +20,7 @@
#include <err.h>
#include <fcntl.h> /* O_CREAT */
#include <limits.h> /* PATH_MAX */
-#include <stdlib.h> /* getprogname */
+#include <stdlib.h> /* get{env,progname} */
#include <string.h> /* strnlen */
#include <unistd.h> /* get{cwd,pid,ppid,pgrp} */
@@ -33,12 +33,6 @@ static int init = 0;
static int shm_fd = 0;
static size_t shm_len = 0;
-__attribute__((destructor))
-static void clean_up()
-{
- (void) shm_unlink(SHM_PATH);
-}
-
size_t
add_1(uint8_t *shm, size_t shm_pos, uint8_t data)
{
@@ -118,12 +112,18 @@ write_header()
static int
get_shm_fd()
{
+ char *shm_path;
+
assert(shm_fd >= 0);
if (shm_fd > 0)
return shm_fd;
- if ((shm_fd = shm_open(SHM_PATH, O_CREAT | O_EXCL | O_CLOEXEC | O_RDWR, S_IRUSR | S_IWUSR)) < 0)
+ if ((shm_path = getenv("CITRUN_SHMPATH")) == NULL)
+ shm_path = SHM_PATH;
+
+ if ((shm_fd = shm_open(shm_path, O_CREAT | O_CLOEXEC | O_RDWR,
+ S_IRUSR | S_IWUSR)) < 0)
err(1, "shm_open");
if (init > 0)
@@ -152,7 +152,6 @@ citrun_node_add(uint8_t node_major, uint8_t node_minor, struct citrun_node *n)
errx(1, "libcitrun %i.%i: incompatible node version %i.%i",
citrun_major, citrun_minor,
node_major, node_minor);
- return;
}
fd = get_shm_fd();
diff --git a/src/shm.cc b/src/shm.cc
@@ -6,16 +6,19 @@
#include <cassert>
#include <err.h>
#include <fcntl.h> // O_RDONLY
+#include <stdlib.h> // getenv
#include <unistd.h>
-#define SHM_PATH "/tmp/citrun.shared"
-
shm::shm() :
m_fd(0),
m_mem(NULL),
m_pos(0)
{
- if ((m_fd = shm_open(SHM_PATH, O_RDONLY, S_IRUSR | S_IWUSR)) < 0)
+ const char *shm_path;
+ if ((shm_path = getenv("CITRUN_SHMPATH")) == NULL)
+ shm_path = "/tmp/citrun.shared";
+
+ if ((m_fd = shm_open(shm_path, O_RDONLY, S_IRUSR | S_IWUSR)) < 0)
err(1, "shm_open");
struct stat sb;
@@ -27,6 +30,7 @@ shm::shm() :
m_mem = (uint8_t *)mmap(NULL, sb.st_size, PROT_READ, MAP_SHARED, m_fd, 0);
if (m_mem == MAP_FAILED)
err(1, "mmap");
+
m_size = sb.st_size;
}
diff --git a/t/inst_correct.sh b/t/inst_correct.sh
@@ -57,3 +57,5 @@ check_diff 2
./fib 12 # = 6765
[ $? -eq 144 ] && echo ok
+
+unlink_shm
diff --git a/t/inst_stdout.sh b/t/inst_stdout.sh
@@ -34,3 +34,5 @@ $TEST_TOOLS/citrun-check > check.out
[ "`./hello`" = "hello, world!" ] && echo ok program prints
check_diff 3
+
+unlink_shm
diff --git a/t/rt_dynamic.sh b/t/rt_dynamic.sh
@@ -11,3 +11,5 @@ test_total_execs 2
kill -USR1 $pid
wait
+
+unlink_shm
diff --git a/t/rt_source.sh b/t/rt_source.sh
@@ -23,3 +23,5 @@ echo >> three.c
test_diff 2 "one.c diff runtime and disk" one.c one.c.runtime
test_diff 3 "two.c diff runtime and disk" two.c two.c.runtime
test_diff 4 "three.c diff runtime and disk" three.c three.c.runtime
+
+unlink_shm
diff --git a/t/rt_static.sh b/t/rt_static.sh
@@ -28,3 +28,5 @@ three.c 9
two.c 11
EOF
filelist_diff 4
+
+unlink_shm
diff --git a/test/utils.sh b/test/utils.sh
@@ -8,10 +8,16 @@ tmpdir=`mktemp -d /tmp/citrun.XXXXXXXXXX`
trap "rm -rf $tmpdir" EXIT
export TEST_TOOLS="`pwd`/src";
+export CITRUN_SHMPATH="$tmpdir"
cd $tmpdir
echo "ok 1 - tmp dir created"
+function unlink_shm
+{
+ $TEST_TOOLS/citrun-dump -u $CITRUN_SHMPATH
+}
+
#
# Run citrun-dump -t 60 times and check that each time was greater than the last
#