Fix possible use of uninitialized variable
[lttng-tools.git] / ltt-sessiond / main.c
index 825fa4371cb67b0316fcf9ce8b6e677dd1f0f115..46c98a5611b9e818c0c99e7e7a64bcd56a02b60e 100644 (file)
@@ -50,7 +50,7 @@
 #include "kernel-ctl.h"
 #include "ltt-sessiond.h"
 #include "shm.h"
-#include "traceable-app.h"
+#include "ust-app.h"
 #include "ust-ctl.h"
 #include "utils.h"
 #include "ust-ctl.h"
@@ -344,7 +344,7 @@ static void cleanup(void)
        }
 
        DBG("Closing all UST sockets");
-       clean_traceable_apps_list();
+       ust_app_clean_list();
 
        pthread_mutex_destroy(&kconsumerd_pid_mutex);
 
@@ -701,6 +701,12 @@ static void *thread_manage_kernel(void *data)
 
        while (1) {
                if (update_poll_flag == 1) {
+                       /*
+                        * Reset number of fd in the poll set. Always 2 since there is the thread
+                        * quit pipe and the kernel pipe.
+                        */
+                       events.nb_fd = 2;
+
                        ret = update_kernel_poll(&events);
                        if (ret < 0) {
                                goto error;
@@ -986,7 +992,7 @@ static void *thread_manage_apps(void *data)
                                        }
 
                                        /* Register applicaton to the session daemon */
-                                       ret = register_traceable_app(&ust_cmd.reg_msg,
+                                       ret = ust_app_register(&ust_cmd.reg_msg,
                                                        ust_cmd.sock);
                                        if (ret < 0) {
                                                /* Only critical ENOMEM error can be returned here */
@@ -999,7 +1005,7 @@ static void *thread_manage_apps(void *data)
                                                 * If the registration is not possible, we simply
                                                 * unregister the apps and continue
                                                 */
-                                               unregister_traceable_app(ust_cmd.sock);
+                                               ust_app_unregister(ust_cmd.sock);
                                        } else {
                                                /*
                                                 * We just need here to monitor the close of the UST
@@ -1028,7 +1034,7 @@ static void *thread_manage_apps(void *data)
                                        }
 
                                        /* Socket closed */
-                                       unregister_traceable_app(pollfd);
+                                       ust_app_unregister(pollfd);
                                        break;
                                }
                        }
@@ -1432,12 +1438,13 @@ static int mount_debugfs(char *path)
 
        ret = mkdir_recursive(path, S_IRWXU | S_IRWXG, geteuid(), getegid());
        if (ret < 0) {
+               PERROR("Cannot create debugfs path");
                goto error;
        }
 
        ret = mount(type, path, type, 0, NULL);
        if (ret < 0) {
-               perror("mount debugfs");
+               PERROR("Cannot mount debugfs");
                goto error;
        }
 
@@ -1487,6 +1494,7 @@ static void init_kernel_tracer(void)
                }
                ret = mount_debugfs(debugfs_path);
                if (ret < 0) {
+                       perror("Cannot mount debugfs");
                        goto error;
                }
        }
@@ -1565,18 +1573,19 @@ static int create_ust_session(struct ltt_session *session,
                struct lttng_domain *domain)
 {
        int ret;
-       struct ltt_ust_session *lus;
-       struct ltt_traceable_app *app;
+       struct ltt_ust_session *lus = NULL;
+       struct ust_app *app;
 
        switch (domain->type) {
        case LTTNG_DOMAIN_UST_PID:
-               app = traceable_app_get_by_pid(domain->attr.pid);
+               app = ust_app_get_by_pid(domain->attr.pid);
                if (app == NULL) {
                        ret = LTTCOMM_APP_NOT_FOUND;
                        goto error;
                }
                break;
        default:
+               ret = LTTCOMM_UNKNOWN_DOMAIN;
                goto error;
        }
 
@@ -1739,6 +1748,9 @@ static void list_lttng_events(struct ltt_kernel_channel *kchan,
                        case LTTNG_KERNEL_SYSCALL:
                                events[i].type = LTTNG_EVENT_SYSCALL;
                                break;
+                       case LTTNG_KERNEL_ALL:
+                               assert(0);
+                               break;
                }
                i++;
        }
@@ -1775,6 +1787,42 @@ error:
        return ret;
 }
 
+/*
+ * Copy channel from attributes and set it in the application channel list.
+ */
+static int copy_ust_channel_to_app(struct ltt_ust_session *usess,
+               struct lttng_channel *attr, struct ust_app *app)
+{
+       int ret;
+       struct ltt_ust_channel *uchan, *new_chan;
+
+       uchan = trace_ust_get_channel_by_name(attr->name, usess);
+       if (uchan == NULL) {
+               ret = LTTCOMM_FATAL;
+               goto error;
+       }
+
+       new_chan = trace_ust_create_channel(attr, usess->path);
+       if (new_chan == NULL) {
+               PERROR("malloc ltt_ust_channel");
+               ret = LTTCOMM_FATAL;
+               goto error;
+       }
+
+       ret = channel_ust_copy(new_chan, uchan);
+       if (ret < 0) {
+               ret = LTTCOMM_FATAL;
+               goto error;
+       }
+
+       /* Add channel to the ust app channel list */
+       cds_list_add(&new_chan->list, &app->channels.head);
+       app->channels.count++;
+
+error:
+       return ret;
+}
+
 /*
  * Command LTTNG_ENABLE_CHANNEL processed by the client thread.
  */
@@ -1806,10 +1854,10 @@ static int cmd_enable_channel(struct ltt_session *session,
        }
        case LTTNG_DOMAIN_UST_PID:
        {
-               struct ltt_ust_event *uevent, *new_uevent;
+               int sock;
+               struct ltt_ust_channel *uchan;
                struct ltt_ust_session *usess;
-               struct ltt_ust_channel *uchan, *app_chan;
-               struct ltt_traceable_app *app;
+               struct ust_app *app;
 
                usess = trace_ust_get_session_by_pid(&session->ust_session_list,
                                domain->attr.pid);
@@ -1818,59 +1866,29 @@ static int cmd_enable_channel(struct ltt_session *session,
                        goto error;
                }
 
-               app = traceable_app_get_by_pid(domain->attr.pid);
+               app = ust_app_get_by_pid(domain->attr.pid);
                if (app == NULL) {
                        ret = LTTCOMM_APP_NOT_FOUND;
                        goto error;
                }
+               sock = app->sock;
 
                uchan = trace_ust_get_channel_by_name(attr->name, usess);
                if (uchan == NULL) {
-                       ret = channel_ust_create(usess, attr, app->sock);
+                       ret = channel_ust_create(usess, attr, sock);
                } else {
-                       ret = channel_ust_enable(usess, uchan, app->sock);
+                       ret = channel_ust_enable(usess, uchan, sock);
                }
 
                if (ret != LTTCOMM_OK) {
                        goto error;
                }
 
-               /*TODO: This should be put in an external function */
-
-               /* Copy UST channel to add to the traceable app */
-               uchan = trace_ust_get_channel_by_name(attr->name, usess);
-               if (uchan == NULL) {
-                       ret = LTTCOMM_FATAL;
-                       goto error;
-               }
-
-               app_chan = trace_ust_create_channel(attr, session->path);
-               if (app_chan == NULL) {
-                       PERROR("malloc ltt_ust_channel");
-                       ret = LTTCOMM_FATAL;
+               ret = copy_ust_channel_to_app(usess, attr, app);
+               if (ret != LTTCOMM_OK) {
                        goto error;
                }
 
-               memcpy(app_chan, uchan, sizeof(struct ltt_ust_channel));
-               CDS_INIT_LIST_HEAD(&app_chan->events.head);
-
-               cds_list_for_each_entry(uevent, &uchan->events.head, list) {
-                       new_uevent = malloc(sizeof(struct ltt_ust_event));
-                       if (new_uevent == NULL) {
-                               PERROR("malloc ltt_ust_event");
-                               ret = LTTCOMM_FATAL;
-                               goto error;
-                       }
-
-                       memcpy(new_uevent, uevent, sizeof(struct ltt_ust_event));
-                       cds_list_add(&new_uevent->list, &app_chan->events.head);
-                       app_chan->events.count++;
-               }
-
-               /* Add channel to traceable_app */
-               cds_list_add(&app_chan->list, &app->channels.head);
-               app->channels.count++;
-
                DBG("UST channel %s created for app sock %d with pid %d",
                                attr->name, app->sock, domain->attr.pid);
                break;
@@ -1904,7 +1922,7 @@ static int cmd_disable_event(struct ltt_session *session, int domain,
                        goto error;
                }
 
-               ret = event_kernel_disable(session->kernel_session, kchan, event_name);
+               ret = event_kernel_disable_tracepoint(session->kernel_session, kchan, event_name);
                if (ret != LTTCOMM_OK) {
                        goto error;
                }
@@ -2021,7 +2039,7 @@ static int cmd_enable_event(struct ltt_session *session, int domain,
                        goto error;
                }
 
-               ret = event_kernel_enable(session->kernel_session, kchan, event);
+               ret = event_kernel_enable_tracepoint(session->kernel_session, kchan, event);
                if (ret != LTTCOMM_OK) {
                        goto error;
                }
@@ -2071,18 +2089,28 @@ static int cmd_enable_event_all(struct ltt_session *session, int domain,
                        goto error;
                }
 
-               if (event_type == LTTNG_KERNEL_SYSCALL) {
-                       ret = event_kernel_enable_syscalls(session->kernel_session,
+               switch (event_type) {
+               case LTTNG_KERNEL_SYSCALL:
+                       ret = event_kernel_enable_all_syscalls(session->kernel_session,
                                        kchan, kernel_tracer_fd);
-               } else {
+                       break;
+               case LTTNG_KERNEL_TRACEPOINT:
                        /*
-                        * This call enables all LTTNG_KERNEL_TRACEPOINTS and events
-                        * already registered to the channel.
+                        * This call enables all LTTNG_KERNEL_TRACEPOINTS and
+                        * events already registered to the channel.
                         */
+                       ret = event_kernel_enable_all_tracepoints(session->kernel_session,
+                                       kchan, kernel_tracer_fd);
+                       break;
+               case LTTNG_KERNEL_ALL:
+                       /* Enable syscalls and tracepoints */
                        ret = event_kernel_enable_all(session->kernel_session,
                                        kchan, kernel_tracer_fd);
+                       break;
+               default:
+                       ret = LTTCOMM_KERN_ENABLE_FAIL;
+                       goto error;
                }
-
                if (ret != LTTCOMM_OK) {
                        goto error;
                }
@@ -2285,7 +2313,7 @@ static int cmd_destroy_session(struct ltt_session *session, char *name)
                perror("write kernel poll pipe");
        }
 
-       ret = session_destroy(name);
+       ret = session_destroy(session);
 
        return ret;
 }
This page took 0.027548 seconds and 4 git commands to generate.