From 99b72dc0657875cee4a10bf4c855e99a1b1d1f9c Mon Sep 17 00:00:00 2001 From: Pierre-Marc Fournier Date: Fri, 11 Sep 2009 15:35:21 -0400 Subject: [PATCH] make forking while tracing work correctly --- libinterfork/interfork.c | 1 - libust/tracectl.c | 27 ++++++++++++++++++++++++--- libust/tracer.c | 2 +- libustcomm/ustcomm.c | 17 +++++++++++++++++ libustcomm/ustcomm.h | 1 + 5 files changed, 43 insertions(+), 5 deletions(-) diff --git a/libinterfork/interfork.c b/libinterfork/interfork.c index e57b7e5..a8db252 100644 --- a/libinterfork/interfork.c +++ b/libinterfork/interfork.c @@ -34,7 +34,6 @@ pid_t fork(void) } } - printf("IN FORK!\n"); retval = plibc_func(); if(retval == 0) diff --git a/libust/tracectl.c b/libust/tracectl.c index 412cca2..a52b208 100644 --- a/libust/tracectl.c +++ b/libust/tracectl.c @@ -1109,14 +1109,35 @@ static void __attribute__((destructor)) keepalive() void ust_fork(void) { + struct blocked_consumer *bc; + struct blocked_consumer *deletable_bc = NULL; + int result; + DBG("ust: forking"); ltt_trace_stop("auto"); ltt_trace_destroy("auto"); - ltt_trace_alloc("auto"); - ltt_trace_start("auto"); - init_socket(); + /* Delete all active connections */ + ustcomm_close_all_connections(&ustcomm_app.server); + + /* Delete all blocked consumers */ + list_for_each_entry(bc, &blocked_consumers, list) { + free(deletable_bc); + deletable_bc = bc; + list_del(&bc->list); + } + have_listener = 0; create_listener(); + init_socket(); + ltt_trace_setup("auto"); + result = ltt_trace_set_type("auto", "ustrelay"); + if(result < 0) { + ERR("ltt_trace_set_type failed"); + return (void *)1; + } + + ltt_trace_alloc("auto"); + ltt_trace_start("auto"); inform_consumer_daemon("auto"); } diff --git a/libust/tracer.c b/libust/tracer.c index cc1dbfd..6f19213 100644 --- a/libust/tracer.c +++ b/libust/tracer.c @@ -807,7 +807,7 @@ traces_error: //ust// } /* Must be called while sure that trace is in the list. */ -static int _ltt_trace_destroy(struct ltt_trace_struct *trace) +static int _ltt_trace_destroy(struct ltt_trace_struct *trace) { int err = -EPERM; diff --git a/libustcomm/ustcomm.c b/libustcomm/ustcomm.c index 1f4bce9..e773f71 100644 --- a/libustcomm/ustcomm.c +++ b/libustcomm/ustcomm.c @@ -191,6 +191,23 @@ int ustcomm_send_reply(struct ustcomm_server *server, char *msg, struct ustcomm_ return 0; } +/* Called after a fork. */ + +int ustcomm_close_all_connections(struct ustcomm_server *server) +{ + struct ustcomm_connection *conn; + struct ustcomm_connection *deletable_conn = NULL; + + list_for_each_entry(conn, &server->connections, list) { + free(deletable_conn); + deletable_conn = conn; + close(conn->fd); + list_del(&conn->list); + } + + return 0; +} + /* @timeout: max blocking time in milliseconds, -1 means infinity * * returns 1 to indicate a message was received diff --git a/libustcomm/ustcomm.h b/libustcomm/ustcomm.h index 7620940..b7d8839 100644 --- a/libustcomm/ustcomm.h +++ b/libustcomm/ustcomm.h @@ -71,6 +71,7 @@ extern int ustcomm_connect_path(const char *path, struct ustcomm_connection *con extern int ustcomm_send_request(struct ustcomm_connection *conn, const char *req, char **reply); extern int ustcomm_send_reply(struct ustcomm_server *server, char *msg, struct ustcomm_source *src); extern int ustcomm_disconnect(struct ustcomm_connection *conn); +extern int ustcomm_close_all_connections(struct ustcomm_server *server); extern int nth_token_is(char *str, char *token, int tok_no); -- 2.34.1