Fix UST renaming and update ust headers
[lttng-tools.git] / ltt-sessiond / ust-ctl.c
index 7f70b8975b5d963dfd890b22d14c13c9817e9ef0..6f73bfc6659237c97e93c0729abb7422d48d65e0 100644 (file)
  */
 
 #define _GNU_SOURCE
-#include <config.h>
 #include <stdlib.h>
 #include <stdio.h>
 #include <string.h>
 #include <unistd.h>
 
-#include <ust/lttng-ust-comm.h>
+#include <lttng-sessiond-comm.h>
 #include <lttngerr.h>
 
 #include "ust-comm.h"
 #include "ust-ctl.h"
+#include "../hashtable/hash.h"
+
+/*
+ * Init command for tracer with cmd type and correct handle.
+ */
+static void init_command(int cmd, int handle, struct lttcomm_ust_msg *command)
+{
+       memset(command, 0, sizeof(struct lttcomm_ust_msg));
+
+       command->cmd = cmd;
+       command->handle = handle;
+}
+
+/*
+ * Generic send command to ust tracer. Caller must free reply.
+ */
+static struct lttcomm_ust_reply *send_command(int sock,
+               struct lttcomm_ust_msg *command)
+{
+       struct lttcomm_ust_reply *reply;
+
+       reply = ustcomm_send_command(sock, command);
+       if (reply == NULL) {
+               goto error;
+       }
+
+       if (reply->ret_code != LTTCOMM_OK) {
+               ERR("Return code (%d): %s", reply->ret_code,
+                               lttcomm_get_readable_code(reply->ret_code));
+               goto error;
+       }
+
+       return reply;
+
+error:
+       return NULL;
+}
 
 /*
  * Send registration done packet to the application.
@@ -47,8 +83,8 @@ int ustctl_register_done(int sock)
                goto error;
        }
 
-       if (reply->ret_code != USTCOMM_OK) {
-               DBG("Return code: %s", ustcomm_get_readable_code(reply->ret_code));
+       if (reply->ret_code != LTTCOMM_OK) {
+               DBG("Return code: %s", lttcomm_get_readable_code(reply->ret_code));
                goto error;
        }
 
@@ -60,9 +96,12 @@ error:
 
 /*
  * Create an UST session on the tracer.
+ *
+ * Return handle if success else negative value.
  */
 int ustctl_create_session(int sock, struct ltt_ust_session *session)
 {
+       int ret;
        struct lttcomm_ust_msg command;
        struct lttcomm_ust_reply *reply = NULL;
 
@@ -74,17 +113,13 @@ int ustctl_create_session(int sock, struct ltt_ust_session *session)
                goto error;
        }
 
-       if (reply->ret_code != USTCOMM_OK) {
-               DBG("Return code: %s", ustcomm_get_readable_code(reply->ret_code));
-               goto error;
-       }
-
        /* Save session handle */
-       session->handle = reply->ret_val;
+       ret = reply->ret_val;
        free(reply);
 
-       DBG2("ustctl create session command successful");
-       return 0;
+       DBG2("ustctl create session command successful with handle %d", ret);
+
+       return ret;
 
 error:
        free(reply);
@@ -93,47 +128,30 @@ error:
 
 /*
  * Create UST channel to the tracer.
+ *
+ * Return handle if success else negative value.
  */
 int ustctl_create_channel(int sock, struct ltt_ust_session *session,
-               struct lttng_channel *channel)
+               struct lttng_ust_channel *channel)
 {
+       int ret;
        struct lttcomm_ust_msg command;
        struct lttcomm_ust_reply *reply = NULL;
-       struct ltt_ust_channel *uchan;
-
-       uchan = trace_ust_create_channel(channel, session->path);
-       if (uchan == NULL) {
-               goto error;
-       }
-
-       memset(&command, 0, sizeof(command));
-
-       command.cmd = LTTNG_UST_CHANNEL;
-       command.handle = session->handle;
 
+       init_command(LTTNG_UST_CHANNEL, session->handle, &command);
        /* Copy channel attributes to command */
-       memcpy(&command.u.channel, &uchan->attr, sizeof(command.u.channel));
+       memcpy(&command.u.channel, channel, sizeof(command.u.channel));
 
-       reply = ustcomm_send_command(sock, &command);
+       /* Send command to tracer */
+       reply = send_command(sock, &command);
        if (reply == NULL) {
                goto error;
        }
 
-       if (reply->ret_code != USTCOMM_OK) {
-               DBG("Return code (%d): %s", reply->ret_code,
-                               ustcomm_get_readable_code(reply->ret_code));
-               goto error;
-       }
-
-       uchan->handle = reply->ret_val;
-
-       /* Add channel to session */
-       cds_list_add(&uchan->list, &session->channels.head);
-       session->channels.count++;
-
+       ret = reply->ret_val;
        free(reply);
 
-       return 0;
+       return ret;
 
 error:
        free(reply);
@@ -149,21 +167,14 @@ int ustctl_enable_channel(int sock, struct ltt_ust_session *session,
        struct lttcomm_ust_msg command;
        struct lttcomm_ust_reply *reply = NULL;
 
-       memset(&command, 0, sizeof(command));
-
-       command.cmd = LTTNG_UST_ENABLE;
-       command.handle = chan->handle;
+       init_command(LTTNG_UST_ENABLE, chan->handle, &command);
 
        reply = ustcomm_send_command(sock, &command);
        if (reply == NULL) {
                goto error;
        }
 
-       if (reply->ret_code != USTCOMM_OK) {
-               DBG("Return code (%d): %s", reply->ret_code,
-                               ustcomm_get_readable_code(reply->ret_code));
-               goto error;
-       } else if (reply->handle != chan->handle) {
+       if (reply->handle != chan->handle) {
                ERR("Receive wrong handle from UST reply on enable channel");
                goto error;
        }
@@ -198,11 +209,7 @@ int ustctl_disable_channel(int sock, struct ltt_ust_session *session,
                goto error;
        }
 
-       if (reply->ret_code != USTCOMM_OK) {
-               DBG("Return code (%d): %s", reply->ret_code,
-                               ustcomm_get_readable_code(reply->ret_code));
-               goto error;
-       } else if (reply->handle != chan->handle) {
+       if (reply->handle != chan->handle) {
                ERR("Receive wrong handle from UST reply on enable channel");
                goto error;
        }
This page took 0.02535 seconds and 4 git commands to generate.