Import kernel control interface
[lttng-tools.git] / liblttngctl / liblttngctl.c
index 3ff1529a1857434202ac7acbd7f1d71fe1a3607b..a2934e63c9644e3e70ae3b7309880b4857e9b2bd 100644 (file)
@@ -35,7 +35,7 @@ static char sessiond_sock_path[PATH_MAX];
 
 /* Communication structure to ltt-sessiond */
 static struct lttcomm_session_msg lsm;
-static struct lttcomm_lttng_header llh;
+static struct lttcomm_lttng_msg llm;
 
 /* Prototypes */
 static int check_tracing_group(const char *grp_name);
@@ -125,18 +125,18 @@ static int ask_sessiond(enum lttcomm_sessiond_command lct, void **buf)
        }
 
        /* Get header from data transmission */
-       ret = recv_data_sessiond(&llh, sizeof(llh));
+       ret = recv_data_sessiond(&llm, sizeof(llm));
        if (ret < 0) {
                goto end;
        }
 
        /* Check error code if OK */
-       if (llh.ret_code != LTTCOMM_OK) {
-               ret = -llh.ret_code;
+       if (llm.ret_code != LTTCOMM_OK) {
+               ret = -llm.ret_code;
                goto end;
        }
 
-       size = llh.payload_size;
+       size = llm.trace_name_offset + llm.data_size;
        if (size == 0) {
                goto end;
        }
@@ -158,6 +158,86 @@ end:
        return ret;
 }
 
+/*
+ * BEGIN KERNEL CONTROL
+ */
+
+/*
+ *  lttng_kernel_enable_event
+ *
+ *  Enable an event in the kernel tracer.
+ */
+int lttng_kernel_enable_event(char *event_name)
+{
+       strncpy(lsm.u.event.event_name, event_name, NAME_MAX);
+       return ask_sessiond(KERNEL_ENABLE_EVENT, NULL);
+}
+
+/*
+ *  lttng_kernel_disable_event
+ *
+ *  Disable an event in the kernel tracer.
+ */
+int lttng_kernel_disable_event(char *event_name)
+{
+       strncpy(lsm.u.event.event_name, event_name, NAME_MAX);
+       return ask_sessiond(KERNEL_DISABLE_EVENT, NULL);
+}
+
+/*
+ *  lttng_kernel_create_session
+ *
+ *  Create a session in the kernel tracer.
+ */
+int lttng_kernel_create_session(void)
+{
+       return ask_sessiond(KERNEL_CREATE_SESSION, NULL);
+}
+
+/*
+ *  lttng_kernel_create_channel
+ *
+ *  Create a channel in the kernel tracer.
+ */
+int lttng_kernel_create_channel(int overwrite,
+               u64 subbuf_size, u64 num_subbuf,
+               unsigned int switch_timer_interval,
+               unsigned int read_timer_interval)
+{
+       /* Write setting to the session message */
+       lsm.u.create_channel.overwrite = overwrite;
+       lsm.u.create_channel.subbuf_size = subbuf_size;
+       lsm.u.create_channel.num_subbuf = num_subbuf;
+       lsm.u.create_channel.switch_timer_interval = switch_timer_interval;
+       lsm.u.create_channel.read_timer_interval = read_timer_interval;
+
+       return ask_sessiond(KERNEL_CREATE_CHANNEL, NULL);
+}
+
+/*
+ *  lttng_kernel_start_tracing
+ *
+ *  Start kernel tracing.
+ */
+int lttng_kernel_start_tracing(void)
+{
+       return ask_sessiond(KERNEL_START_TRACE, NULL);
+}
+
+/*
+ *  lttng_kernel_stop_tracing
+ *
+ *  Stop kernel tracing.
+ */
+int lttng_kernel_stop_tracing(void)
+{
+       return ask_sessiond(KERNEL_STOP_TRACE, NULL);
+}
+
+/*
+ * END KERNEL CONTROL
+ */
+
 /*
  *  lttng_get_readable_code
  *
@@ -250,7 +330,7 @@ int lttng_list_traces(uuid_t *uuid, struct lttng_trace **traces)
 {
        int ret;
 
-       uuid_copy(lsm.session_id, *uuid);
+       uuid_copy(lsm.session_uuid, *uuid);
 
        ret = ask_sessiond(LTTNG_LIST_TRACES, (void **) traces);
        if (ret < 0) {
@@ -278,7 +358,7 @@ int lttng_create_session(char *name, uuid_t *session_id)
                goto end;
        }
 
-       uuid_copy(*session_id, llh.session_id);
+       uuid_copy(*session_id, llm.session_uuid);
 
 end:
        return ret;
@@ -293,7 +373,7 @@ int lttng_destroy_session(uuid_t *uuid)
 {
        int ret;
 
-       uuid_copy(lsm.session_id, *uuid);
+       uuid_copy(lsm.session_uuid, *uuid);
 
        ret = ask_sessiond(LTTNG_DESTROY_SESSION, NULL);
        if (ret < 0) {
@@ -377,7 +457,7 @@ int lttng_disconnect_sessiond(void)
  */
 void lttng_set_current_session_uuid(uuid_t *uuid)
 {
-       uuid_copy(lsm.session_id, *uuid);
+       uuid_copy(lsm.session_uuid, *uuid);
 }
 
 /*
@@ -431,7 +511,7 @@ static int set_session_daemon_path(void)
 
        /* Are we in the tracing group ? */
        ret = check_tracing_group(tracing_group);
-       if (ret < 0) {
+       if (ret < 0 && getuid() != 0) {
                if (sprintf(sessiond_sock_path, DEFAULT_HOME_CLIENT_UNIX_SOCK,
                                        getenv("HOME")) < 0) {
                        return -ENOMEM;
This page took 0.025295 seconds and 4 git commands to generate.