Add enable channel support for UST
[lttng-tools.git] / ltt-sessiond / ust-ctl.c
index 5f4e8a9fcefe09dda5fecef4335de708b35b85a2..2753b6f5ab639b593692c62292a5740cd08c653f 100644 (file)
@@ -60,17 +60,15 @@ error:
 /*
  * Create an UST session on the tracer.
  */
-int ustctl_create_session(struct ltt_ust_session *session)
+int ustctl_create_session(int sock, struct ltt_ust_session *session)
 {
        struct lttcomm_ust_msg command;
-       struct lttcomm_ust_reply *reply;
-
-       DBG("Creating UST session for app pid:%d", session->app->pid);
+       struct lttcomm_ust_reply *reply = NULL;
 
        command.cmd = LTTNG_UST_SESSION;
        command.handle = LTTNG_UST_ROOT_HANDLE;
 
-       reply = ustcomm_send_command(session->app->sock, &command);
+       reply = ustcomm_send_command(sock, &command);
        if (reply == NULL) {
                goto error;
        }
@@ -81,10 +79,140 @@ int ustctl_create_session(struct ltt_ust_session *session)
        }
 
        /* Save session handle */
-       session->handle = reply->handle;
+       session->handle = reply->ret_val;
+       free(reply);
+
+       DBG2("ustctl create session command successful");
+       return 0;
+
+error:
+       free(reply);
+       return -1;
+}
+
+/*
+ * Create UST channel to the tracer.
+ */
+int ustctl_create_channel(int sock, struct ltt_ust_session *session,
+               struct lttng_channel *channel)
+{
+       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;
+
+       /* Copy channel attributes to command */
+       memcpy(&command.u.channel, &uchan->attr, sizeof(command.u.channel));
+
+       reply = ustcomm_send_command(sock, &command);
+       if (reply == NULL) {
+               goto error;
+       }
+
+       if (reply->ret_code != LTTCOMM_OK) {
+               DBG("Return code (%d): %s", reply->ret_code,
+                               lttcomm_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++;
+
+       free(reply);
+
+       return 0;
+
+error:
+       free(reply);
+       return -1;
+}
+
+/*
+ * Enable UST channel.
+ */
+int ustctl_enable_channel(int sock, struct ltt_ust_session *session,
+               struct ltt_ust_channel *chan)
+{
+       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;
+
+       reply = ustcomm_send_command(sock, &command);
+       if (reply == NULL) {
+               goto error;
+       }
+
+       if (reply->ret_code != LTTCOMM_OK) {
+               DBG("Return code (%d): %s", reply->ret_code,
+                               lttcomm_get_readable_code(reply->ret_code));
+               goto error;
+       } else if (reply->handle != chan->handle) {
+               ERR("Receive wrong handle from UST reply on enable channel");
+               goto error;
+       }
+
+       chan->enabled = 1;
+       free(reply);
+
+       DBG2("ustctl enable channel successful for sock %d", sock);
+       return 0;
+
+error:
+       free(reply);
+       return -1;
+}
+
+/*
+ * Disable UST channel.
+ */
+int ustctl_disable_channel(int sock, struct ltt_ust_session *session,
+               struct ltt_ust_channel *chan)
+{
+       struct lttcomm_ust_msg command;
+       struct lttcomm_ust_reply *reply = NULL;
+
+       memset(&command, 0, sizeof(command));
+
+       command.cmd = LTTNG_UST_DISABLE;
+       command.handle = chan->handle;
+
+       reply = ustcomm_send_command(sock, &command);
+       if (reply == NULL) {
+               goto error;
+       }
+
+       if (reply->ret_code != LTTCOMM_OK) {
+               DBG("Return code (%d): %s", reply->ret_code,
+                               lttcomm_get_readable_code(reply->ret_code));
+               goto error;
+       } else if (reply->handle != chan->handle) {
+               ERR("Receive wrong handle from UST reply on enable channel");
+               goto error;
+       }
+
+       chan->enabled = 1;
+       free(reply);
 
+       DBG2("ustctl disable channel successful for sock %d", sock);
        return 0;
 
 error:
+       free(reply);
        return -1;
 }
This page took 0.024073 seconds and 4 git commands to generate.