X-Git-Url: https://git.lttng.org/?p=lttng-tools.git;a=blobdiff_plain;f=src%2Fbin%2Flttng-relayd%2Fmain.c;h=62a5bd7cefc16026ff05f3e3741e4b4258837fd1;hp=09e1b796346286987ee522c8c96980d52c16ba1c;hb=9898f786493c5e60dcf99fa3102bb95752ad73ed;hpb=ecd1a12fac39784bded85c0f06e47ace2dc98cde diff --git a/src/bin/lttng-relayd/main.c b/src/bin/lttng-relayd/main.c index 09e1b7963..62a5bd7ce 100644 --- a/src/bin/lttng-relayd/main.c +++ b/src/bin/lttng-relayd/main.c @@ -40,6 +40,7 @@ #include #include #include +#include #include #include @@ -1156,21 +1157,24 @@ send_reply: } } else { const uint32_t output_path_length = - strlen(session->output_path) + 1; + session ? strlen(session->output_path) + 1 : 0; reply.output_path_length = htobe32(output_path_length); - ret = lttng_dynamic_buffer_append(&reply_payload, &reply, - sizeof(reply)); + ret = lttng_dynamic_buffer_append( + &reply_payload, &reply, sizeof(reply)); if (ret) { ERR("Failed to append \"create session\" command reply header to payload buffer"); goto end; } - ret = lttng_dynamic_buffer_append(&reply_payload, - session->output_path, output_path_length); - if (ret) { - ERR("Failed to append \"create session\" command reply path to payload buffer"); - goto end; + if (output_path_length) { + ret = lttng_dynamic_buffer_append(&reply_payload, + session->output_path, + output_path_length); + if (ret) { + ERR("Failed to append \"create session\" command reply path to payload buffer"); + goto end; + } } } @@ -2298,40 +2302,7 @@ end_no_reply: return ret; } -static int init_session_output_directory_handle(struct relay_session *session, - struct lttng_directory_handle *handle) -{ - int ret; - /* - * relayd_output_path/session_directory - * e.g. /home/user/lttng-traces/hostname/session_name - */ - char *full_session_path = NULL; - - pthread_mutex_lock(&session->lock); - full_session_path = create_output_path(session->output_path); - if (!full_session_path) { - ret = -1; - goto end; - } - ret = utils_mkdir_recursive( - full_session_path, S_IRWXU | S_IRWXG, -1, -1); - if (ret) { - ERR("Failed to create session output path \"%s\"", - full_session_path); - goto end; - } - - ret = lttng_directory_handle_init(handle, full_session_path); - if (ret) { - goto end; - } -end: - pthread_mutex_unlock(&session->lock); - free(full_session_path); - return ret; -} /* * relay_create_trace_chunk: create a new trace chunk @@ -2418,13 +2389,6 @@ static int relay_create_trace_chunk(const struct lttcomm_relayd_hdr *recv_hdr, } } - ret = init_session_output_directory_handle( - conn->session, &session_output); - if (ret) { - reply_code = LTTNG_ERR_CREATE_DIR_FAIL; - goto end; - } - chunk_status = lttng_trace_chunk_set_credentials_current_user(chunk); if (chunk_status != LTTNG_TRACE_CHUNK_STATUS_OK) { reply_code = LTTNG_ERR_UNK; @@ -2432,7 +2396,14 @@ static int relay_create_trace_chunk(const struct lttcomm_relayd_hdr *recv_hdr, goto end; } + ret = session_init_output_directory_handle( + conn->session, &session_output); + if (ret) { + reply_code = LTTNG_ERR_CREATE_DIR_FAIL; + goto end; + } chunk_status = lttng_trace_chunk_set_as_owner(chunk, &session_output); + lttng_directory_handle_fini(&session_output); if (chunk_status != LTTNG_TRACE_CHUNK_STATUS_OK) { reply_code = LTTNG_ERR_UNK; ret = -1; @@ -2488,7 +2459,6 @@ end: end_no_reply: lttng_trace_chunk_put(chunk); lttng_trace_chunk_put(published_chunk); - lttng_directory_handle_fini(&session_output); return ret; } @@ -2499,7 +2469,7 @@ static int relay_close_trace_chunk(const struct lttcomm_relayd_hdr *recv_hdr, struct relay_connection *conn, const struct lttng_buffer_view *payload) { - int ret = 0; + int ret = 0, buf_ret; ssize_t send_ret; struct relay_session *session = conn->session; struct lttcomm_relayd_close_trace_chunk *msg; @@ -2660,17 +2630,17 @@ end_unlock_session: end: reply.generic.ret_code = htobe32((uint32_t) reply_code); reply.path_length = htobe32((uint32_t) path_length); - ret = lttng_dynamic_buffer_append( + buf_ret = lttng_dynamic_buffer_append( &reply_payload, &reply, sizeof(reply)); - if (ret) { + if (buf_ret) { ERR("Failed to append \"close trace chunk\" command reply header to payload buffer"); goto end_no_reply; } if (reply_code == LTTNG_OK) { - ret = lttng_dynamic_buffer_append(&reply_payload, + buf_ret = lttng_dynamic_buffer_append(&reply_payload, closed_trace_chunk_path, path_length); - if (ret) { + if (buf_ret) { ERR("Failed to append \"close trace chunk\" command reply path to payload buffer"); goto end_no_reply; }