X-Git-Url: http://git.efficios.com/?p=lttng-tools.git;a=blobdiff_plain;f=src%2Fbin%2Flttng-relayd%2Fmain.c;h=4a2258d34abeb96be16ddcc0ae34a42c167d23f3;hp=62e1cf9309e4355c7b6e892fc999a20c665557a9;hb=7145f5e9af16907c65a514fe9112e99564cf6333;hpb=5c0551f9f5b0d30cf9fb7fb148720b99a5c9b24e diff --git a/src/bin/lttng-relayd/main.c b/src/bin/lttng-relayd/main.c index 62e1cf930..4a2258d34 100644 --- a/src/bin/lttng-relayd/main.c +++ b/src/bin/lttng-relayd/main.c @@ -977,6 +977,23 @@ static int close_sock(void *data, int *in_fd) return sock->ops->close(sock); } +static int accept_sock(void *data, int *out_fd) +{ + int ret = 0; + /* Socks is an array of in_sock, out_sock. */ + struct lttcomm_sock **socks = data; + struct lttcomm_sock *in_sock = socks[0]; + + socks[1] = in_sock->ops->accept(in_sock); + if (!socks[1]) { + ret = -1; + goto end; + } + *out_fd = socks[1]->fd; +end: + return ret; +} + /* * Create and init socket from uri. */ @@ -1035,6 +1052,27 @@ error: return NULL; } +static +struct lttcomm_sock *accept_relayd_sock(struct lttcomm_sock *listening_sock, + const char *name) +{ + int out_fd, ret; + struct lttcomm_sock *socks[2] = { listening_sock, NULL }; + struct lttcomm_sock *new_sock = NULL; + + ret = fd_tracker_open_unsuspendable_fd( + the_fd_tracker, &out_fd, + (const char **) &name, + 1, accept_sock, &socks); + if (ret) { + goto end; + } + new_sock = socks[1]; + DBG("%s accepted, socket %d", name, new_sock->fd); +end: + return new_sock; +} + /* * This thread manages the listening for new connections on the network */ @@ -1133,20 +1171,18 @@ restart: */ int val = 1; struct relay_connection *new_conn; - struct lttcomm_sock *newsock; + struct lttcomm_sock *newsock = NULL; enum connection_type type; if (pollfd == data_sock->fd) { type = RELAY_DATA; - newsock = data_sock->ops->accept(data_sock); - DBG("Relay data connection accepted, socket %d", - newsock->fd); + newsock = accept_relayd_sock(data_sock, + "Data socket to relayd"); } else { assert(pollfd == control_sock->fd); type = RELAY_CONTROL; - newsock = control_sock->ops->accept(control_sock); - DBG("Relay control connection accepted, socket %d", - newsock->fd); + newsock = accept_relayd_sock(control_sock, + "Control socket to relayd"); } if (!newsock) { PERROR("accepting sock"); @@ -2632,7 +2668,6 @@ static int relay_create_trace_chunk(const struct lttcomm_relayd_hdr *recv_hdr, struct lttng_trace_chunk *chunk = NULL, *published_chunk = NULL; enum lttng_error_code reply_code = LTTNG_OK; enum lttng_trace_chunk_status chunk_status; - struct lttng_directory_handle *session_output = NULL; const char *new_path; if (!session || !conn->version_check_done) { @@ -2689,6 +2724,7 @@ static int relay_create_trace_chunk(const struct lttcomm_relayd_hdr *recv_hdr, reply_code = LTTNG_ERR_NOMEM; goto end; } + lttng_trace_chunk_set_fd_tracker(chunk, the_fd_tracker); if (msg->override_name_length) { const char *name; @@ -2729,15 +2765,9 @@ static int relay_create_trace_chunk(const struct lttcomm_relayd_hdr *recv_hdr, goto end; } - session_output = session_create_output_directory_handle( - conn->session); - if (!session_output) { - reply_code = LTTNG_ERR_CREATE_DIR_FAIL; - goto end; - } - chunk_status = lttng_trace_chunk_set_as_owner(chunk, session_output); - lttng_directory_handle_put(session_output); - session_output = NULL; + assert(conn->session->output_directory); + chunk_status = lttng_trace_chunk_set_as_owner(chunk, + conn->session->output_directory); if (chunk_status != LTTNG_TRACE_CHUNK_STATUS_OK) { reply_code = LTTNG_ERR_UNK; ret = -1; @@ -2796,7 +2826,6 @@ end: end_no_reply: lttng_trace_chunk_put(chunk); lttng_trace_chunk_put(published_chunk); - lttng_directory_handle_put(session_output); return ret; } @@ -3730,7 +3759,8 @@ static void cleanup_connection_pollfd(struct lttng_poll_event *events, int pollf (void) lttng_poll_del(events, pollfd); - ret = close(pollfd); + ret = fd_tracker_close_unsuspendable_fd(the_fd_tracker, &pollfd, 1, + fd_tracker_util_close_fd, NULL); if (ret < 0) { ERR("Closing pollfd %d", pollfd); } @@ -4117,6 +4147,7 @@ int main(int argc, char **argv) bool thread_is_rcu_registered = false; int ret = 0, retval = 0; void *status; + char *unlinked_file_directory_path = NULL, *output_path = NULL; /* Parse environment variables */ ret = parse_env_options(); @@ -4207,7 +4238,23 @@ int main(int argc, char **argv) rcu_register_thread(); thread_is_rcu_registered = true; - the_fd_tracker = fd_tracker_create(lttng_opt_fd_pool_size); + output_path = create_output_path(""); + if (!output_path) { + ERR("Failed to get output path"); + retval = -1; + goto exit_options; + } + ret = asprintf(&unlinked_file_directory_path, "%s/%s", output_path, + DEFAULT_UNLINKED_FILES_DIRECTORY); + free(output_path); + if (ret < 0) { + ERR("Failed to format unlinked file directory path"); + retval = -1; + goto exit_options; + } + the_fd_tracker = fd_tracker_create( + unlinked_file_directory_path, lttng_opt_fd_pool_size); + free(unlinked_file_directory_path); if (!the_fd_tracker) { retval = -1; goto exit_options;