Remove connect/disconnect sessiond from lttng API
[lttng-tools.git] / liblttngctl / liblttngctl.c
index cad4d735eed17aff794aa5aae95892f505198ef0..c851ce6ad70bdf847cd2b8f26ae715b31d527c8e 100644 (file)
@@ -89,70 +89,9 @@ end:
 }
 
 /*
- *  ask_sessiond
- *
- *  Ask the session daemon a specific command and put the data into buf.
- *
- *  Return size of data (only payload, not header).
- */
-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 */
-       ret = send_data_sessiond();
-       if (ret < 0) {
-               goto end;
-       }
-
-       /* Get header from data transmission */
-       ret = recv_data_sessiond(&llm, sizeof(llm));
-       if (ret < 0) {
-               goto end;
-       }
-
-       /* Check error code if OK */
-       if (llm.ret_code != LTTCOMM_OK) {
-               ret = -llm.ret_code;
-               goto end;
-       }
-
-       size = llm.data_size;
-       if (size == 0) {
-               goto end;
-       }
-
-       data = (void*) malloc(size);
-
-       /* Get payload data */
-       ret = recv_data_sessiond(data, size);
-       if (ret < 0) {
-               free(data);
-               goto end;
-       }
-
-       *buf = data;
-       ret = size;
-
-end:
-       lttng_disconnect_sessiond();
-       return ret;
-}
-
-/*
- *  check_tracing_group
- *
  *  Check if the specified group name exist.
- *  If yes, 0, else -1
+ *
+ *  If yes return 0, else return -1.
  */
 static int check_tracing_group(const char *grp_name)
 {
@@ -201,10 +140,8 @@ end:
 }
 
 /*
- *  set_session_daemon_path
- *
- *  Set sessiond socket path by putting it in 
- *  the global sessiond_sock_path variable.
+ *  Set sessiond socket path by putting it in the global sessiond_sock_path
+ *  variable.
  */
 static int set_session_daemon_path(void)
 {
@@ -225,6 +162,108 @@ static int set_session_daemon_path(void)
        return 0;
 }
 
+/*
+ *  Connect to the LTTng session daemon.
+ *
+ *  On success, return 0. On error, return -1.
+ */
+static int connect_sessiond(void)
+{
+       int ret;
+
+       ret = set_session_daemon_path();
+       if (ret < 0) {
+               return ret;
+       }
+
+       /* Connect to the sesssion daemon */
+       ret = lttcomm_connect_unix_sock(sessiond_sock_path);
+       if (ret < 0) {
+               return ret;
+       }
+
+       sessiond_socket = ret;
+       connected = 1;
+
+       return 0;
+}
+
+/*
+ *  Clean disconnect the session daemon.
+ */
+static int disconnect_sessiond(void)
+{
+       int ret = 0;
+
+       if (connected) {
+               ret = lttcomm_close_unix_sock(sessiond_socket);
+               sessiond_socket = 0;
+               connected = 0;
+       }
+
+       return ret;
+}
+
+/*
+ *  ask_sessiond
+ *
+ *  Ask the session daemon a specific command and put the data into buf.
+ *
+ *  Return size of data (only payload, not header).
+ */
+static int ask_sessiond(enum lttcomm_sessiond_command lct, void **buf)
+{
+       int ret;
+       size_t size;
+       void *data = NULL;
+
+       ret = connect_sessiond();
+       if (ret < 0) {
+               goto end;
+       }
+
+       lsm.cmd_type = lct;
+
+       /* Send command to session daemon */
+       ret = send_data_sessiond();
+       if (ret < 0) {
+               goto end;
+       }
+
+       /* Get header from data transmission */
+       ret = recv_data_sessiond(&llm, sizeof(llm));
+       if (ret < 0) {
+               goto end;
+       }
+
+       /* Check error code if OK */
+       if (llm.ret_code != LTTCOMM_OK) {
+               ret = -llm.ret_code;
+               goto end;
+       }
+
+       size = llm.data_size;
+       if (size == 0) {
+               goto end;
+       }
+
+       data = (void*) malloc(size);
+
+       /* Get payload data */
+       ret = recv_data_sessiond(data, size);
+       if (ret < 0) {
+               free(data);
+               goto end;
+       }
+
+       *buf = data;
+       ret = size;
+
+end:
+       disconnect_sessiond();
+       return ret;
+}
+
 /*
  *  lttng_start_tracing
  *
@@ -251,6 +290,24 @@ int lttng_stop_tracing(char *session_name)
  * BEGIN Kernel control API
  */
 
+/*
+ *  lttng_kernel_add_context
+ */
+int lttng_kernel_add_context(struct lttng_kernel_context *ctx,
+               char *event_name, char *channel_name)
+{
+       if (channel_name != NULL) {
+               strncpy(lsm.u.context.channel_name, channel_name, NAME_MAX);
+       }
+
+       if (event_name != NULL) {
+               strncpy(lsm.u.context.event_name, event_name, NAME_MAX);
+       }
+
+       memcpy(&lsm.u.context.ctx, ctx, sizeof(struct lttng_kernel_context));
+       return ask_sessiond(LTTNG_KERNEL_ADD_CONTEXT, NULL);
+}
+
 /*
  *  lttng_kernel_enable_event
  */
@@ -258,7 +315,7 @@ int lttng_kernel_enable_event(struct lttng_event *ev, char *channel_name)
 {
        int ret;
 
-       if (strlen(channel_name) == 0) {
+       if (channel_name == NULL) {
                strncpy(lsm.u.enable.channel_name, DEFAULT_CHANNEL_NAME, NAME_MAX);
        } else {
                strncpy(lsm.u.enable.channel_name, channel_name, NAME_MAX);
@@ -283,7 +340,7 @@ int lttng_kernel_disable_event(char *name, char *channel_name)
 {
        int ret;
 
-       if (strlen(channel_name) == 0) {
+       if (channel_name == NULL) {
                strncpy(lsm.u.disable.channel_name, DEFAULT_CHANNEL_NAME, NAME_MAX);
        } else {
                strncpy(lsm.u.disable.channel_name, channel_name, NAME_MAX);
@@ -451,52 +508,6 @@ int lttng_list_sessions(struct lttng_session **sessions)
        return ret / sizeof(struct lttng_session);
 }
 
-/*
- *  lttng_connect_sessiond
- *
- *  Connect to the LTTng session daemon.
- *  On success, return 0
- *  On error, return a negative value
- */
-int lttng_connect_sessiond(void)
-{
-       int ret;
-
-       ret = set_session_daemon_path();
-       if (ret < 0) {
-               return ret;
-       }
-
-       /* Connect to the sesssion daemon */
-       ret = lttcomm_connect_unix_sock(sessiond_sock_path);
-       if (ret < 0) {
-               return ret;
-       }
-
-       sessiond_socket = ret;
-       connected = 1;
-
-       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;
-}
-
 void lttng_set_session_name(char *name)
 {
        strncpy(lsm.session_name, name, NAME_MAX);
This page took 0.025863 seconds and 4 git commands to generate.