Commit c14dd7ff authored by Cedric Roux's avatar Cedric Roux

T: use PID for the SHM name

That allows to run several programs using this mechanism on the
same computer (say both eNB and UE, to debug).
parent 7576e3fa
...@@ -88,7 +88,7 @@ static void new_thread(void *(*f)(void *), void *data) ...@@ -88,7 +88,7 @@ static void new_thread(void *(*f)(void *), void *data)
/* defined in local_tracer.c */ /* defined in local_tracer.c */
void T_local_tracer_main(int remote_port, int wait_for_tracer, 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. /* We monitor the tracee and the local tracer processes.
* When one dies we forcefully kill the other. * 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) ...@@ -113,6 +113,9 @@ void T_init(int remote_port, int wait_for_tracer, int dont_fork)
int s; int s;
int T_shm_fd; int T_shm_fd;
int child1, child2; 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)) if (socketpair(AF_UNIX, SOCK_STREAM, 0, socket_pair))
{ perror("socketpair"); abort(); } { perror("socketpair"); abort(); }
...@@ -122,7 +125,8 @@ void T_init(int remote_port, int wait_for_tracer, int dont_fork) ...@@ -122,7 +125,8 @@ void T_init(int remote_port, int wait_for_tracer, int dont_fork)
child1 = fork(); if (child1 == -1) abort(); child1 = fork(); if (child1 == -1) abort();
if (child1 == 0) { if (child1 == 0) {
close(socket_pair[1]); 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); exit(0);
} }
close(socket_pair[0]); close(socket_pair[0]);
...@@ -142,13 +146,13 @@ void T_init(int remote_port, int wait_for_tracer, int dont_fork) ...@@ -142,13 +146,13 @@ void T_init(int remote_port, int wait_for_tracer, int dont_fork)
T_socket = s; T_socket = s;
/* setup shared memory */ /* setup shared memory */
T_shm_fd = shm_open(T_SHM_FILENAME, O_RDWR /*| O_SYNC*/, 0666); T_shm_fd = shm_open(shm_file, O_RDWR /*| O_SYNC*/, 0666);
shm_unlink(T_SHM_FILENAME); shm_unlink(shm_file);
if (T_shm_fd == -1) { perror(T_SHM_FILENAME); abort(); } if (T_shm_fd == -1) { perror(shm_file); abort(); }
T_cache = mmap(NULL, T_CACHE_SIZE * sizeof(T_cache_t), T_cache = mmap(NULL, T_CACHE_SIZE * sizeof(T_cache_t),
PROT_READ | PROT_WRITE, MAP_SHARED, T_shm_fd, 0); PROT_READ | PROT_WRITE, MAP_SHARED, T_shm_fd, 0);
if (T_cache == MAP_FAILED) if (T_cache == MAP_FAILED)
{ perror(T_SHM_FILENAME); abort(); } { perror(shm_file); abort(); }
close(T_shm_fd); close(T_shm_fd);
new_thread(T_receive_thread, NULL); new_thread(T_receive_thread, NULL);
......
...@@ -326,17 +326,17 @@ static void wait_message(void) ...@@ -326,17 +326,17 @@ static void wait_message(void)
while (T_local_cache[T_busylist_head].busy == 0) usleep(1000); 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 i;
int s = shm_open(T_SHM_FILENAME, O_RDWR | O_CREAT /*| O_SYNC*/, 0666); int s = shm_open(shm_file, O_RDWR | O_CREAT /*| O_SYNC*/, 0666);
if (s == -1) { perror(T_SHM_FILENAME); abort(); } if (s == -1) { perror(shm_file); abort(); }
if (ftruncate(s, T_CACHE_SIZE * sizeof(T_cache_t))) 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), T_local_cache = mmap(NULL, T_CACHE_SIZE * sizeof(T_cache_t),
PROT_READ | PROT_WRITE, MAP_SHARED, s, 0); PROT_READ | PROT_WRITE, MAP_SHARED, s, 0);
if (T_local_cache == MAP_FAILED) if (T_local_cache == MAP_FAILED)
{ perror(T_SHM_FILENAME); abort(); } { perror(shm_file); abort(); }
close(s); close(s);
/* let's garbage the memory to catch some potential problems /* let's garbage the memory to catch some potential problems
...@@ -347,7 +347,7 @@ static void init_shm(void) ...@@ -347,7 +347,7 @@ static void init_shm(void)
} }
void T_local_tracer_main(int remote_port, int wait_for_tracer, void T_local_tracer_main(int remote_port, int wait_for_tracer,
int local_socket) int local_socket, char *shm_file)
{ {
int s; int s;
int port = remote_port; int port = remote_port;
...@@ -357,7 +357,7 @@ void T_local_tracer_main(int remote_port, int wait_for_tracer, ...@@ -357,7 +357,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 */ /* write on a socket fails if the other end is closed and we get SIGPIPE */
if (signal(SIGPIPE, SIG_IGN) == SIG_ERR) abort(); if (signal(SIGPIPE, SIG_IGN) == SIG_ERR) abort();
init_shm(); init_shm(shm_file);
s = local_socket; s = local_socket;
if (dont_wait) { if (dont_wait) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment