#include <common/buffer-view.h>
#include <common/string-utils/format.h>
+#include "version.h"
#include "cmd.h"
#include "ctf-trace.h"
#include "index.h"
/* command line options */
char *opt_output_path;
-static int opt_daemon, opt_background;
+static int opt_daemon, opt_background, opt_print_version;
/*
* We need to wait for listener and live listener threads, as well as
static const char *config_ignore_options[] = { "help", "config", "version" };
+static void print_version(void) {
+ fprintf(stdout, "%s\n", VERSION);
+}
+
+static void relayd_config_log(void)
+{
+ DBG("LTTng-relayd " VERSION " - " VERSION_NAME "%s%s",
+ GIT_VERSION[0] == '\0' ? "" : " - " GIT_VERSION,
+ EXTRA_VERSION_NAME[0] == '\0' ? "" : " - " EXTRA_VERSION_NAME);
+ if (EXTRA_VERSION_DESCRIPTION[0] != '\0') {
+ DBG("LTTng-relayd extra version description:\n\t" EXTRA_VERSION_DESCRIPTION "\n");
+ }
+ if (EXTRA_VERSION_PATCHES[0] != '\0') {
+ DBG("LTTng-relayd extra patches:\n\t" EXTRA_VERSION_PATCHES "\n");
+ }
+}
+
/*
* Take an option from the getopt output and set it in the right variable to be
* used later.
}
exit(EXIT_FAILURE);
case 'V':
- fprintf(stdout, "%s\n", VERSION);
- exit(EXIT_SUCCESS);
+ opt_print_version = 1;
+ break;
case 'o':
if (lttng_is_setuid_setgid()) {
WARN("Getting '%s' argument from setuid/setgid binary refused for security reasons.",
}
} 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;
}
}
- 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_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;
}
if (ret < 0) {
goto error;
}
- lttng_poll_add(&events, conn->sock->fd,
+ ret = lttng_poll_add(&events,
+ conn->sock->fd,
LPOLLIN | LPOLLRDHUP);
+ if (ret) {
+ ERR("Failed to add new connection file descriptor to poll set");
+ goto error;
+ }
connection_ht_add(relay_connections_ht, conn);
DBG("Connection socket %d added", conn->sock->fd);
} else if (revents & (LPOLLERR | LPOLLHUP | LPOLLRDHUP)) {
goto exit_options;
}
+ relayd_config_log();
+
+ if (opt_print_version) {
+ print_version();
+ retval = 0;
+ goto exit_options;
+ }
+
/* Try to create directory if -o, --output is specified. */
if (opt_output_path) {
if (*opt_output_path != '/') {