assert(session);
ASSERT_LOCKED(session->lock);
+ if (!viewer_trace_chunk) {
+ ERR("Internal error: viewer session associated with session \"%s\" has a NULL trace chunk",
+ session->session_name);
+ ret = -1;
+ goto error;
+ }
+
if (session->connection_closed) {
*closed = true;
}
error_unlock:
rcu_read_unlock();
+error:
return ret;
}
}
pthread_mutex_lock(&session->lock);
- if (!session->current_trace_chunk) {
- /*
- * Means the session is being destroyed. React the same way
- * as if it could not be found at all.
- */
- DBG("Relay session %" PRIu64 " has no current trace chunk, replying LTTNG_VIEWER_NEW_STREAMS_ERR",
- session_id);
- response.status = htobe32(LTTNG_VIEWER_NEW_STREAMS_ERR);
- goto send_reply_unlock;
- }
-
- if (!conn->viewer_session->current_trace_chunk &&
- session->current_trace_chunk) {
- ret = viewer_session_set_trace_chunk(conn->viewer_session,
- session->current_trace_chunk);
- if (ret) {
- goto error_unlock_session;
- }
- }
ret = make_viewer_streams(session,
conn->viewer_session->current_trace_chunk,
LTTNG_VIEWER_SEEK_LAST, &nb_total, &nb_unsent,
struct lttng_viewer_attach_session_request request;
struct lttng_viewer_attach_session_response response;
struct relay_session *session = NULL;
+ enum lttng_viewer_attach_return_code viewer_attach_status;
bool closed = false;
uint64_t session_id;
}
send_streams = 1;
- ret = viewer_session_attach(conn->viewer_session, session);
- if (ret) {
- DBG("Already a viewer attached");
- response.status = htobe32(LTTNG_VIEWER_ATTACH_ALREADY);
+ viewer_attach_status = viewer_session_attach(conn->viewer_session,
+ session);
+ if (viewer_attach_status != LTTNG_VIEWER_ATTACH_OK) {
+ response.status = htobe32(viewer_attach_status);
goto send_reply;
}
goto send_reply;
}
- if (!conn->viewer_session->current_trace_chunk &&
- session->current_trace_chunk) {
- ret = viewer_session_set_trace_chunk(conn->viewer_session,
- session->current_trace_chunk);
- if (ret) {
- goto end_put_session;
- }
- }
ret = make_viewer_streams(session,
conn->viewer_session->current_trace_chunk, seek_type,
&nb_streams, NULL, NULL, &closed);
}
/* The existence of session must be guaranteed by the caller. */
-int viewer_session_attach(struct relay_viewer_session *vsession,
+enum lttng_viewer_attach_return_code viewer_session_attach(
+ struct relay_viewer_session *vsession,
struct relay_session *session)
{
- int ret = 0;
+ enum lttng_viewer_attach_return_code viewer_attach_status =
+ LTTNG_VIEWER_ATTACH_OK;
ASSERT_LOCKED(session->lock);
/* Will not fail, as per the ownership guarantee. */
if (!session_get(session)) {
- ret = -1;
+ viewer_attach_status = LTTNG_VIEWER_ATTACH_UNK;
goto end;
}
if (session->viewer_attached) {
- ret = -1;
+ viewer_attach_status = LTTNG_VIEWER_ATTACH_ALREADY;
} else {
+ int ret;
+
+ assert(session->current_trace_chunk);
+ assert(!vsession->current_trace_chunk);
session->viewer_attached = true;
+
+ ret = viewer_session_set_trace_chunk(vsession,
+ session->current_trace_chunk);
+ if (ret) {
+ /*
+ * The live protocol does not define a generic error
+ * value for the "attach" command. The "unknown"
+ * status is used so that the viewer may handle this
+ * failure as if the session didn't exist anymore.
+ */
+ DBG("Failed to create a viewer trace chunk from the current trace chunk of session \"%s\", returning LTTNG_VIEWER_ATTACH_UNK",
+ session->session_name);
+ viewer_attach_status = LTTNG_VIEWER_ATTACH_UNK;
+ }
}
- if (!ret) {
+ if (viewer_attach_status == LTTNG_VIEWER_ATTACH_OK) {
pthread_mutex_lock(&vsession->session_list_lock);
/* Ownership is transfered to the list. */
cds_list_add_rcu(&session->viewer_session_node,
session_put(session);
}
end:
- return ret;
+ return viewer_attach_status;
}
/* The existence of session must be guaranteed by the caller. */
void viewer_session_destroy(struct relay_viewer_session *vsession);
void viewer_session_close(struct relay_viewer_session *vsession);
-int viewer_session_attach(struct relay_viewer_session *vsession,
+enum lttng_viewer_attach_return_code viewer_session_attach(
+ struct relay_viewer_session *vsession,
struct relay_session *session);
int viewer_session_is_attached(struct relay_viewer_session *vsession,
struct relay_session *session);