Add tags from ctags to gitignore
[lttng-tools.git] / ltt-sessiond / main.c
index c50bfd88c5d7538638081c3d7f44511848724d8a..9b76a56adce2486efca5aecd66f29b2aca1343e3 100644 (file)
@@ -40,6 +40,7 @@
 #include "liblttsessiondcomm.h"
 #include "ltt-sessiond.h"
 #include "lttngerr.h"
+#include "kernel-ctl.h"
 #include "session.h"
 #include "trace.h"
 #include "traceable-app.h"
@@ -95,6 +96,7 @@ static char kconsumerd_cmd_unix_sock_path[PATH_MAX];  /* kconsumerd command Unix
 static int client_sock;
 static int apps_sock;
 static int kconsumerd_err_sock;
+static int kernel_tracer_fd;
 
 /*
  *  thread_manage_kconsumerd
@@ -160,6 +162,7 @@ static void *thread_manage_apps(void *data)
        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) {
@@ -263,7 +266,8 @@ static void *thread_manage_clients(void *data)
                        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");
@@ -453,6 +457,24 @@ static int process_client_msg(struct command_ctx *cmd_ctx)
                break;
        }
 
+       /* Check command for kernel tracing */
+       switch (cmd_ctx->lsm->cmd_type) {
+       case KERNEL_CREATE_SESSION:
+       case KERNEL_CREATE_CHANNEL:
+       case KERNEL_DISABLE_EVENT:
+       case KERNEL_ENABLE_EVENT:
+       case KERNEL_OPEN_METADATA:
+       case KERNEL_START_TRACE:
+       case KERNEL_STOP_TRACE:
+               /* TODO: reconnect to kernel tracer to check if
+                * it's loadded */
+               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 */
@@ -465,6 +487,80 @@ static int process_client_msg(struct command_ctx *cmd_ctx)
 
        /* 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 = kernel_enable_event(cmd_ctx->session->kernel_session->channel, cmd_ctx->lsm->u.event.event_name);
+               if (ret < 0) {
+                       ret = LTTCOMM_KERN_ENABLE_FAIL;
+                       goto error;
+               }
+
+               ret = LTTCOMM_OK;
+               break;
+       }
+       case KERNEL_OPEN_METADATA:
+       {
+               /* Setup lttng message with no payload */
+               ret = setup_lttng_msg(cmd_ctx, 0);
+               if (ret < 0) {
+                       goto setup_error;
+               }
+
+               DBG("Open kernel metadata");
+
+               ret = kernel_open_metadata(cmd_ctx->session->kernel_session);
+               if (ret < 0) {
+                       ret = LTTCOMM_KERN_META_FAIL;
+                       goto error;
+               }
+
+               ret = LTTCOMM_OK;
+               break;
+       }
        case LTTNG_CREATE_SESSION:
        {
                /* Setup lttng message with no payload */
@@ -624,12 +720,9 @@ static int process_client_msg(struct command_ctx *cmd_ctx)
        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;
                }
        }
@@ -897,6 +990,21 @@ 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
  *
@@ -1038,6 +1146,9 @@ static void cleanup()
        if (ret < 0) {
                ERR("Unable to clean " LTTNG_RUNDIR);
        }
+
+       // TODO Clean kernel trace fds
+       close(kernel_tracer_fd);
 }
 
 /*
@@ -1089,6 +1200,9 @@ int main(int argc, char **argv)
                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,
@@ -1102,6 +1216,9 @@ int main(int argc, char **argv)
                }
        }
 
+       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
         */
This page took 0.028322 seconds and 5 git commands to generate.