#include "liblttsessiondcomm.h"
#include "ltt-sessiond.h"
#include "lttngerr.h"
+#include "kernel-ctl.h"
#include "session.h"
#include "trace.h"
#include "traceable-app.h"
static int client_sock;
static int apps_sock;
static int kconsumerd_err_sock;
+static int kernel_tracer_fd;
/*
* thread_manage_kconsumerd
notify_apps(default_global_apps_pipe);
while (1) {
+ DBG("Accepting application registration");
/* Blocking call, waiting for transmission */
sock = lttcomm_accept_unix_sock(apps_sock);
if (sock < 0) {
continue;
}
- DBG("Sending response to client (size: %d)", cmd_ctx->lttng_msg_size);
+ DBG("Sending response (size: %d, retcode: %d)",
+ cmd_ctx->lttng_msg_size, cmd_ctx->llm->ret_code);
ret = send_unix_sock(sock, cmd_ctx->llm, cmd_ctx->lttng_msg_size);
if (ret < 0) {
ERR("Failed to send data back to client");
break;
}
+ /* Check command for kernel tracing */
+ switch (cmd_ctx->lsm->cmd_type) {
+ case KERNEL_CREATE_SESSION:
+ case KERNEL_CREATE_CHANNEL:
+ if (kernel_tracer_fd == 0) {
+ ret = LTTCOMM_KERN_NA;
+ goto error;
+ }
+ break;
+ }
+
/* Connect to ust apps if available pid */
if (cmd_ctx->lsm->pid > 0) {
/* Connect to app using ustctl API */
/* Process by command type */
switch (cmd_ctx->lsm->cmd_type) {
+ case KERNEL_CREATE_SESSION:
+ {
+ ret = setup_lttng_msg(cmd_ctx, 0);
+ if (ret < 0) {
+ goto setup_error;
+ }
+
+ DBG("Creating kernel session");
+
+ ret = kernel_create_session(cmd_ctx, kernel_tracer_fd);
+ if (ret < 0) {
+ ret = LTTCOMM_KERN_SESS_FAIL;
+ goto error;
+ }
+
+ ret = LTTCOMM_OK;
+ break;
+ }
+ case KERNEL_CREATE_CHANNEL:
+ {
+ ret = setup_lttng_msg(cmd_ctx, 0);
+ if (ret < 0) {
+ goto setup_error;
+ }
+
+ DBG("Creating kernel session");
+
+ ret = kernel_create_channel(cmd_ctx);
+ if (ret < 0) {
+ ret = LTTCOMM_KERN_CHAN_FAIL;
+ goto error;
+ }
+
+ ret = LTTCOMM_OK;
+ break;
+ }
+ case KERNEL_ENABLE_EVENT:
+ {
+ /* Setup lttng message with no payload */
+ ret = setup_lttng_msg(cmd_ctx, 0);
+ if (ret < 0) {
+ goto setup_error;
+ }
+
+ DBG("Enabling kernel event %s", cmd_ctx->lsm->u.event.event_name);
+
+ ret = LTTCOMM_OK;
+ break;
+ }
case LTTNG_CREATE_SESSION:
{
/* Setup lttng message with no payload */
return ret;
error:
- DBG("Return code to client %d", ret);
-
if (cmd_ctx->llm == NULL) {
DBG("Missing llm structure. Allocating one.");
- ret = setup_lttng_msg(cmd_ctx, 0);
- if (ret < 0) {
+ if (setup_lttng_msg(cmd_ctx, 0) < 0) {
goto setup_error;
}
}
return ret;
}
+/*
+ * init_kernel_tracer
+ *
+ * Setup necessary data for kernel tracer action.
+ */
+static void init_kernel_tracer(void)
+{
+ /* Set the global kernel tracer fd */
+ kernel_tracer_fd = open(DEFAULT_KERNEL_TRACER_PATH, O_RDWR);
+ if (kernel_tracer_fd < 0) {
+ WARN("No kernel tracer available");
+ kernel_tracer_fd = 0;
+ }
+}
+
/*
* set_kconsumerd_sockets
*
if (ret < 0) {
goto error;
}
+
+ /* Setup kernel tracer */
+ init_kernel_tracer();
} else {
if (strlen(apps_unix_sock_path) == 0) {
snprintf(apps_unix_sock_path, PATH_MAX,
}
}
+ DBG("Client socket path %s", client_unix_sock_path);
+ DBG("Application socket path %s", apps_unix_sock_path);
+
/* See if daemon already exist. If any of the two
* socket needed by the daemon are present, this test fails
*/