#include <urcu/rculist.h>
#include <unistd.h>
#include <fcntl.h>
+#include <strings.h>
#include <lttng/lttng.h>
#include <common/common.h>
}
} 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;
+ }
}
}
}
reply_code = LTTNG_OK;
+ ret = 0;
end:
if (stream) {
stream_put(stream);
send_ret);
ret = -1;
}
-
- ret = 0;
end_no_reply:
lttng_trace_chunk_put(next_trace_chunk);
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
}
}
- 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;
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;
end_no_reply:
lttng_trace_chunk_put(chunk);
lttng_trace_chunk_put(published_chunk);
- lttng_directory_handle_fini(&session_output);
return ret;
}
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;
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;
}
struct lttcomm_relayd_trace_chunk_exists *msg;
struct lttcomm_relayd_trace_chunk_exists_reply reply = {};
struct lttng_buffer_view header_view;
- struct lttng_trace_chunk *chunk = NULL;
uint64_t chunk_id;
+ bool chunk_exists;
if (!session || !conn->version_check_done) {
ERR("Trying to close a trace chunk before version check");
msg = (typeof(msg)) header_view.data;
chunk_id = be64toh(msg->chunk_id);
- chunk = sessiond_trace_chunk_registry_get_chunk(
+ ret = sessiond_trace_chunk_registry_chunk_exists(
sessiond_trace_chunk_registry,
conn->session->sessiond_uuid,
conn->session->id,
- chunk_id);
-
- reply = (typeof(reply)) {
- .generic.ret_code = htobe32((uint32_t) LTTNG_OK),
- .trace_chunk_exists = !!chunk,
+ chunk_id, &chunk_exists);
+ /*
+ * If ret is not 0, send the reply and report the error to the caller.
+ * It is a protocol (or internal) error and the session/connection
+ * should be torn down.
+ */
+ reply = (typeof(reply)){
+ .generic.ret_code = htobe32((uint32_t)
+ (ret == 0 ? LTTNG_OK : LTTNG_ERR_INVALID_PROTOCOL)),
+ .trace_chunk_exists = ret == 0 ? chunk_exists : 0,
};
- send_ret = conn->sock->ops->sendmsg(conn->sock,
- &reply, sizeof(reply), 0);
+ send_ret = conn->sock->ops->sendmsg(
+ conn->sock, &reply, sizeof(reply), 0);
if (send_ret < (ssize_t) sizeof(reply)) {
ERR("Failed to send \"create trace chunk\" command reply (ret = %zd)",
send_ret);
ret = -1;
}
end_no_reply:
- lttng_trace_chunk_put(chunk);
return ret;
}