Fix enable all syscalls
authorDavid Goulet <david.goulet@polymtl.ca>
Thu, 22 Sep 2011 20:22:02 +0000 (16:22 -0400)
committerDavid Goulet <david.goulet@polymtl.ca>
Thu, 22 Sep 2011 20:29:26 +0000 (16:29 -0400)
The -a -k --syscall was enabling all syscalls and all tracepoints.

Fix this issues by adding the enabel_kernel_event_syscalls.

At this commit, there is a problem with the list event that does not
list correctly all syscalls.

Signed-off-by: David Goulet <david.goulet@polymtl.ca>
liblttngctl/lttngctl.c
ltt-sessiond/event.c
ltt-sessiond/event.h
ltt-sessiond/main.c
lttng/commands/enable_events.c
tests/lttng/kernel_all_events_basic.c

index bec1dbb8503c60da423e2f2f7f44161382b69e27..0442a4f02bdbc686a868bf1abbc40a1896420894 100644 (file)
@@ -492,7 +492,7 @@ int lttng_enable_event(struct lttng_handle *handle,
 {
        struct lttcomm_session_msg lsm;
 
-       if (!handle) {
+       if (!handle || ev == NULL) {
                return -1;
        }
 
@@ -506,12 +506,12 @@ int lttng_enable_event(struct lttng_handle *handle,
 
        copy_lttng_domain(&lsm.domain, &handle->domain);
 
-       if (ev && ev->name[0] != '\0') {
+       if (ev->name[0] != '\0') {
                lsm.cmd_type = LTTNG_ENABLE_EVENT;
-               memcpy(&lsm.u.enable.event, ev, sizeof(lsm.u.enable.event));
        } else {
                lsm.cmd_type = LTTNG_ENABLE_ALL_EVENT;
        }
+       memcpy(&lsm.u.enable.event, ev, sizeof(lsm.u.enable.event));
 
        copy_string(lsm.session.name, handle->session_name,
                        sizeof(lsm.session.name));
index 3e3ecd32049c07b10e9979d967e1e12034676dbc..66e134e4641be8690f9fffbbb10086a96d229bdc 100644 (file)
 #include "event.h"
 #include "kernel-ctl.h"
 
+/*
+ * Setup a lttng_event used to enable *all* syscall tracing.
+ */
+static void init_syscalls_kernel_event(struct lttng_event *event)
+{
+       event->name[0] = '\0';
+       /*
+        * We use LTTNG_EVENT* here since the trace kernel creation will make the
+        * right changes for the kernel.
+        */
+       event->type = LTTNG_EVENT_SYSCALL;
+}
+
 /*
  * Disable kernel event for a channel from the kernel session.
  */
@@ -153,3 +166,27 @@ int event_kernel_enable_all(struct ltt_kernel_session *ksession,
 error:
        return ret;
 }
+
+/*
+ * Enable all kernel syscalls tracing.
+ */
+int event_kernel_enable_syscalls(struct ltt_kernel_session *ksession,
+               struct ltt_kernel_channel *kchan, int kernel_tracer_fd)
+{
+       int ret;
+       struct lttng_event event;
+
+       init_syscalls_kernel_event(&event);
+
+       DBG("Enabling all syscall tracing");
+
+       ret = kernel_create_event(&event, kchan);
+       if (ret < 0) {
+               goto error;
+       }
+
+       ret = LTTCOMM_OK;
+
+error:
+       return ret;
+}
index 3399466cf3065b631d4c1e6576a3d41308280265..0ef52fe7b272eb76993e2e9cea8a00f1627b3858 100644 (file)
@@ -30,5 +30,7 @@ int event_kernel_enable(struct ltt_kernel_session *ksession,
                struct ltt_kernel_channel *kchan, struct lttng_event *event);
 int event_kernel_enable_all(struct ltt_kernel_session *ksession,
                struct ltt_kernel_channel *kchan, int kernel_tracer_fd);
+int event_kernel_enable_syscalls(struct ltt_kernel_session *ksession,
+               struct ltt_kernel_channel *kchan, int kernel_tracer_fd);
 
 #endif /* _LTT_EVENT_H */
index 867ba4188e37419c2f419429248126c97143bae8..a1c7ff89e299bc6e2f637e5d6ef8612230ff18de 100644 (file)
@@ -1950,7 +1950,7 @@ error:
  * Command LTTNG_ENABLE_ALL_EVENT processed by the client thread.
  */
 static int cmd_enable_event_all(struct ltt_session *session, int domain,
-               char *channel_name)
+               char *channel_name, int event_type)
 {
        int ret;
        struct ltt_kernel_channel *kchan;
@@ -1977,8 +1977,18 @@ static int cmd_enable_event_all(struct ltt_session *session, int domain,
                        goto error;
                }
 
-               ret = event_kernel_enable_all(session->kernel_session,
-                               kchan, kernel_tracer_fd);
+               if (event_type == LTTNG_KERNEL_SYSCALL) {
+                       ret = event_kernel_enable_syscalls(session->kernel_session,
+                                       kchan, kernel_tracer_fd);
+               } else {
+                       /*
+                        * This call enables all LTTNG_KERNEL_TRACEPOINTS and events
+                        * already registered to the channel.
+                        */
+                       ret = event_kernel_enable_all(session->kernel_session,
+                                       kchan, kernel_tracer_fd);
+               }
+
                if (ret != LTTCOMM_OK) {
                        goto error;
                }
@@ -2501,7 +2511,8 @@ static int process_client_msg(struct command_ctx *cmd_ctx)
                DBG("Enabling all kernel event");
 
                ret = cmd_enable_event_all(cmd_ctx->session, cmd_ctx->lsm->domain.type,
-                               cmd_ctx->lsm->u.enable.channel_name);
+                               cmd_ctx->lsm->u.enable.channel_name,
+                               cmd_ctx->lsm->u.enable.event.type);
                break;
        }
        case LTTNG_LIST_TRACEPOINTS:
index 85fd86a08c4b89e27692eacaa736b99c947d84a0..78227be1fdcff05cf2102a468b62404913390d52 100644 (file)
@@ -213,33 +213,38 @@ static int enable_events(char *session_name)
        }
 
        if (opt_enable_all) {
+               /* Default setup for enable all */
+               ev.name[0] = '\0';
+               ev.type = opt_event_type;
+
+               ret = lttng_enable_event(handle, &ev, channel_name);
+               if (ret < 0) {
+                       goto error;
+               }
+
                switch (opt_event_type) {
                case LTTNG_EVENT_TRACEPOINT:
                        if (opt_kernel) {
-                               ret = lttng_enable_event(handle, NULL, channel_name);
-                               if (ret == 0) {
-                                       MSG("All kernel events are enabled in channel %s", channel_name);
-                               }
-                               goto error;
+                               MSG("All kernel events are enabled in channel %s",
+                                               channel_name);
                        }
-                       /* TODO: User-space tracer */
                        break;
                case LTTNG_EVENT_SYSCALL:
                        if (opt_kernel) {
-                               ev.name[0] = '\0';
-                               ev.type = opt_event_type;
-
-                               ret = lttng_enable_event(handle, &ev, channel_name);
-                               if (ret == 0) {
-                                       MSG("All kernel system calls are enabled in channel %s", channel_name);
-                               }
-                               goto error;
+                               MSG("All kernel system calls are enabled in channel %s",
+                                               channel_name);
                        }
                        break;
                default:
-                       MSG("Enable all not supported for this instrumentation type.");
+                       /*
+                        * We should not be here since lttng_enable_event should had failed
+                        * on the event type.
+                        */
                        goto error;
+
                }
+
+               goto end;
        }
 
        /* Strip event list */
@@ -310,6 +315,7 @@ static int enable_events(char *session_name)
                event_name = strtok(NULL, ",");
        }
 
+end:
 error:
        if (opt_channel_name == NULL) {
                free(channel_name);
index 65a710e5a8d97418fddfadc9bf7d15154ebea19a..215fa6837e600be04ce5bcab4a1610494aaa7111 100644 (file)
@@ -33,11 +33,15 @@ int main(int argc, char **argv)
 {
     struct lttng_handle *handle = NULL;
     struct lttng_domain dom;
+       struct lttng_event event;
     char *channel_name = "mychan";
     int ret = 0;
 
     dom.type = LTTNG_DOMAIN_KERNEL;
 
+       memset(&event, 0, sizeof(struct lttng_event));
+       event.type = LTTNG_EVENT_TRACEPOINT;
+
        printf("\nTesting tracing all kernel events:\n");
        printf("-----------\n");
        /* Check if root */
@@ -66,7 +70,7 @@ int main(int argc, char **argv)
        PRINT_OK();
 
        printf("Enabling all kernel events: ");
-    if ((ret = lttng_enable_event(handle, NULL, channel_name)) < 0) {
+    if ((ret = lttng_enable_event(handle, &event, channel_name)) < 0) {
         printf("error enabling event: %s\n", lttng_get_readable_code(ret));
                goto enable_fail;
     }
This page took 0.044655 seconds and 4 git commands to generate.