diff options
author | Steven Rostedt (Red Hat) <rostedt@goodmis.org> | 2016-09-12 13:26:30 -0400 |
---|---|---|
committer | Steven Rostedt <rostedt@goodmis.org> | 2016-10-30 19:46:49 -0400 |
commit | 3ab8dcc7dee835a0a52ad61219024b48872109b4 (patch) | |
tree | 9c1ae077dd66faa1fe3f7a6b2fa164ea86e3dbcd | |
parent | c3149d9b4cc399ab6ad4da953593c9a16b38ad72 (diff) | |
download | trace-cmd-3ab8dcc7dee835a0a52ad61219024b48872109b4.tar.gz |
trace-cmd listen: Do not clean up in signal handler
Doing a memmove in the signal handler is racy with the updates of the main
process. Especially if it does a realloc, and the memory moves. Do the clean
up from the main process instead checking for EINTR in errno.
Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
-rw-r--r-- | trace-listen.c | 15 |
1 files changed, 11 insertions, 4 deletions
diff --git a/trace-listen.c b/trace-listen.c index 4bbda14b..7e75ea63 100644 --- a/trace-listen.c +++ b/trace-listen.c @@ -795,7 +795,7 @@ static void kill_clients(void) saved_pids = 0; } -static void clean_up(int sig) +static void clean_up(void) { int status; int ret; @@ -819,9 +819,10 @@ static void do_accept_loop(int sfd) do { cfd = accept(sfd, (struct sockaddr *)&peer_addr, &peer_addr_len); - printf("connected!\n"); - if (cfd < 0 && errno == EINTR) + if (cfd < 0 && errno == EINTR) { + clean_up(); continue; + } if (cfd < 0) pdie("connecting"); @@ -830,6 +831,8 @@ static void do_accept_loop(int sfd) add_process(pid); } while (!done); + /* Get any final stragglers */ + clean_up(); } static void make_pid_file(void) @@ -854,6 +857,10 @@ static void make_pid_file(void) close(fd); } +static void sigstub(int sig) +{ +} + static void do_listen(char *port) { struct addrinfo hints; @@ -861,7 +868,7 @@ static void do_listen(char *port) int sfd, s; if (!debug) - signal_setup(SIGCHLD, clean_up); + signal_setup(SIGCHLD, sigstub); make_pid_file(); |