diff --git a/common/utils/T/T.c b/common/utils/T/T.c index f1fce835385a7e524b2b223e2b6de0e043538be9..92e70c221b6fd052e5f5c4804de8bc3f2edc4fff 100644 --- a/common/utils/T/T.c +++ b/common/utils/T/T.c @@ -88,7 +88,7 @@ static void new_thread(void *(*f)(void *), void *data) /* defined in local_tracer.c */ void T_local_tracer_main(int remote_port, int wait_for_tracer, - int local_socket); + int local_socket, char *shm_file); /* We monitor the tracee and the local tracer processes. * When one dies we forcefully kill the other. @@ -113,6 +113,9 @@ void T_init(int remote_port, int wait_for_tracer, int dont_fork) int s; int T_shm_fd; int child1, child2; + char shm_file[128]; + + sprintf(shm_file, "/%s%d", T_SHM_FILENAME, getpid()); if (socketpair(AF_UNIX, SOCK_STREAM, 0, socket_pair)) { perror("socketpair"); abort(); } @@ -122,7 +125,8 @@ void T_init(int remote_port, int wait_for_tracer, int dont_fork) child1 = fork(); if (child1 == -1) abort(); if (child1 == 0) { close(socket_pair[1]); - T_local_tracer_main(remote_port, wait_for_tracer, socket_pair[0]); + T_local_tracer_main(remote_port, wait_for_tracer, socket_pair[0], + shm_file); exit(0); } close(socket_pair[0]); @@ -142,13 +146,13 @@ void T_init(int remote_port, int wait_for_tracer, int dont_fork) T_socket = s; /* setup shared memory */ - T_shm_fd = shm_open(T_SHM_FILENAME, O_RDWR /*| O_SYNC*/, 0666); - shm_unlink(T_SHM_FILENAME); - if (T_shm_fd == -1) { perror(T_SHM_FILENAME); abort(); } + T_shm_fd = shm_open(shm_file, O_RDWR /*| O_SYNC*/, 0666); + shm_unlink(shm_file); + if (T_shm_fd == -1) { perror(shm_file); abort(); } T_cache = mmap(NULL, T_CACHE_SIZE * sizeof(T_cache_t), PROT_READ | PROT_WRITE, MAP_SHARED, T_shm_fd, 0); - if (T_cache == NULL) - { perror(T_SHM_FILENAME); abort(); } + if (T_cache == MAP_FAILED) + { perror(shm_file); abort(); } close(T_shm_fd); new_thread(T_receive_thread, NULL); diff --git a/common/utils/T/local_tracer.c b/common/utils/T/local_tracer.c index 67657634c4ed86a0146f4ab0a93ea50d68510f39..43680b40998b41ab43334c33d01756e5258c02cf 100644 --- a/common/utils/T/local_tracer.c +++ b/common/utils/T/local_tracer.c @@ -340,17 +340,17 @@ static void wait_message(void) while (T_local_cache[T_busylist_head].busy == 0) usleep(1000); } -static void init_shm(void) +static void init_shm(char *shm_file) { int i; - int s = shm_open(T_SHM_FILENAME, O_RDWR | O_CREAT /*| O_SYNC*/, 0666); - if (s == -1) { perror(T_SHM_FILENAME); abort(); } + int s = shm_open(shm_file, O_RDWR | O_CREAT /*| O_SYNC*/, 0666); + if (s == -1) { perror(shm_file); abort(); } if (ftruncate(s, T_CACHE_SIZE * sizeof(T_cache_t))) - { perror(T_SHM_FILENAME); abort(); } + { perror(shm_file); abort(); } T_local_cache = mmap(NULL, T_CACHE_SIZE * sizeof(T_cache_t), PROT_READ | PROT_WRITE, MAP_SHARED, s, 0); - if (T_local_cache == NULL) - { perror(T_SHM_FILENAME); abort(); } + if (T_local_cache == MAP_FAILED) + { perror(shm_file); abort(); } close(s); /* let's garbage the memory to catch some potential problems @@ -361,7 +361,7 @@ static void init_shm(void) } void T_local_tracer_main(int remote_port, int wait_for_tracer, - int local_socket) + int local_socket, char *shm_file) { int s; int port = remote_port; @@ -371,7 +371,7 @@ void T_local_tracer_main(int remote_port, int wait_for_tracer, /* write on a socket fails if the other end is closed and we get SIGPIPE */ if (signal(SIGPIPE, SIG_IGN) == SIG_ERR) abort(); - init_shm(); + init_shm(shm_file); s = local_socket; if (dont_wait) {