Fix errors due to lttng.h cleanup
[lttng-tools.git] / liblttngctl / liblttngctl.c
index 9afd6fda3239e0085c24ec433383ac2755019bd8..c27ce092825595692b91e4552b250a190dcf486f 100644 (file)
@@ -24,7 +24,7 @@
 #include <string.h>
 #include <unistd.h>
 
-#include <lttng/liblttngctl.h>
+#include <lttng/lttng.h>
 
 #include "liblttsessiondcomm.h"
 #include "lttngerr.h"
@@ -39,7 +39,7 @@ static struct lttcomm_lttng_msg llm;
 
 /* Prototypes */
 static int check_tracing_group(const char *grp_name);
-static int ask_sessiond(enum lttcomm_command_type lct, void **buf);
+static int ask_sessiond(enum lttcomm_sessiond_command lct, void **buf);
 static int recv_data_sessiond(void *buf, size_t len);
 static int send_data_sessiond(void);
 static int set_session_daemon_path(void);
@@ -105,12 +105,17 @@ end:
  *
  *  Return size of data (only payload, not header).
  */
-static int ask_sessiond(enum lttcomm_command_type lct, void **buf)
+static int ask_sessiond(enum lttcomm_sessiond_command lct, void **buf)
 {
        int ret;
        size_t size;
        void *data = NULL;
 
+       ret = lttng_connect_sessiond();
+       if (ret < 0) {
+               goto end;
+       }
+
        lsm.cmd_type = lct;
 
        /* Send command to session daemon */
@@ -131,7 +136,7 @@ static int ask_sessiond(enum lttcomm_command_type lct, void **buf)
                goto end;
        }
 
-       size = llm.size_payload;
+       size = llm.trace_name_offset + llm.data_size;
        if (size == 0) {
                goto end;
        }
@@ -148,11 +153,100 @@ static int ask_sessiond(enum lttcomm_command_type lct, void **buf)
        ret = size;
 
 end:
-       /* Reset lsm data struct */
-       memset(&lsm, 0, sizeof(lsm));
+       lttng_disconnect_sessiond();
        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(void)
+{
+       return ask_sessiond(KERNEL_CREATE_CHANNEL, NULL);
+}
+
+/*
+ *  lttng_kernel_open_metadata
+ *
+ *  Open metadata in the kernel tracer.
+ */
+int lttng_kernel_open_metadata(void)
+{
+       return ask_sessiond(KERNEL_OPEN_METADATA, NULL);
+}
+
+/*
+ *  lttng_kernel_create_stream
+ *
+ *  Create stream in the kernel tracer.
+ */
+int lttng_kernel_create_stream(void)
+{
+       return ask_sessiond(KERNEL_CREATE_STREAM, 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
  *
@@ -167,6 +261,51 @@ const char *lttng_get_readable_code(int code)
        return lttcomm_get_readable_code(code);
 }
 
+/*
+ *  lttng_ust_start_trace
+ *
+ *  Request a trace start for pid.
+ */
+int lttng_ust_start_trace(pid_t pid)
+{
+       int ret;
+
+       lsm.pid = pid;
+       ret = ask_sessiond(UST_START_TRACE, NULL);
+
+       return ret;
+}
+
+/*
+ *  lttng_ust_stop_trace
+ *
+ *  Request a trace stop for pid.
+ */
+int lttng_ust_stop_trace(pid_t pid)
+{
+       int ret;
+
+       lsm.pid = pid;
+       ret = ask_sessiond(UST_STOP_TRACE, NULL);
+
+       return ret;
+}
+
+/*
+ *  lttng_ust_create_trace
+ *
+ *  Request a trace creation for pid.
+ */
+int lttng_ust_create_trace(pid_t pid)
+{
+       int ret;
+
+       lsm.pid = pid;
+       ret = ask_sessiond(UST_CREATE_TRACE, NULL);
+
+       return ret;
+}
+
 /*
  *  lttng_ust_list_apps
  *
@@ -188,16 +327,36 @@ int lttng_ust_list_apps(pid_t **pids)
        return ret / sizeof(pid_t);
 }
 
+/*
+ *  lttng_list_traces
+ *
+ *  Ask the session daemon for all traces (kernel and ust)
+ *  for the session identified by uuid.
+ *
+ *  Return the number of traces.
+ */
+int lttng_list_traces(uuid_t *uuid, struct lttng_trace **traces)
+{
+       int ret;
+
+       uuid_copy(lsm.session_uuid, *uuid);
+
+       ret = ask_sessiond(LTTNG_LIST_TRACES, (void **) traces);
+       if (ret < 0) {
+               return ret;
+       }
+
+       return ret / sizeof(struct lttng_trace);
+}
+
 /*
  *  lttng_create_session
  *
- *  Create a brand new session using name. Allocate
- *  the session_id param pointing to the UUID.
+ *  Create a brand new session using name.
  */
-int lttng_create_session(char *name, uuid_t *session_id)
+int lttng_create_session(char *name)
 {
        int ret;
-       char *uuid;
 
        strncpy(lsm.session_name, name, sizeof(lsm.session_name));
        lsm.session_name[sizeof(lsm.session_name) - 1] = '\0';
@@ -207,8 +366,6 @@ int lttng_create_session(char *name, uuid_t *session_id)
                goto end;
        }
 
-       uuid_copy(*session_id, llm.session_id);
-
 end:
        return ret;
 }
@@ -222,7 +379,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) {
@@ -281,6 +438,34 @@ int lttng_connect_sessiond(void)
        return 0;
 }
 
+/*
+ *  lttng_disconnect_sessiond
+ *
+ *  Clean disconnect the session daemon.
+ */
+int lttng_disconnect_sessiond(void)
+{
+       int ret = 0;
+
+       if (connected) {
+               ret = lttcomm_close_unix_sock(sessiond_socket);
+               sessiond_socket = 0;
+               connected = 0;
+       }
+
+       return ret;
+}
+
+/*
+ *  lttng_set_current_session_uuid
+ *
+ *  Set the session uuid for current lsm.
+ */
+void lttng_set_current_session_uuid(uuid_t *uuid)
+{
+       uuid_copy(lsm.session_uuid, *uuid);
+}
+
 /*
  *  lttng_set_tracing_group
  *
@@ -332,7 +517,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;
@@ -403,5 +588,5 @@ end:
 static void __attribute__((constructor)) init()
 {
        /* Set default session group */
-       lttng_set_tracing_group(DEFAULT_TRACING_GROUP);
+       lttng_set_tracing_group(LTTNG_DEFAULT_TRACING_GROUP);
 }
This page took 0.027433 seconds and 5 git commands to generate.