Use UST comm lib
[lttng-tools.git] / ltt-sessiond / ust-comm.c
index accd4276d27c48156bfebb3e0a92602f75b6c60f..4a54bf78429e0172a1c7ddfbaa385c0aa98f1a74 100644 (file)
  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
  */
 
+#include <config.h>
+#include <stdlib.h>
 #include <lttngerr.h>
-
+#include <ust/lttng-ust-comm.h>
 #include "ust-comm.h"
 
 /*
  * Send msg containing a command to an UST application via sock and wait for
- * the reply.
+ * the reply. Caller must free() the reply structure sent back.
  *
- * Return -1 on error or if reply fails else return 0.
+ * Return the replied structure or NULL.
  */
-int ustcomm_send_command(int sock, struct lttcomm_ust_msg *msg)
+struct lttcomm_ust_reply *ustcomm_send_command(int sock,
+               struct lttcomm_ust_msg *msg)
 {
        ssize_t len;
-       struct lttcomm_ust_reply reply;
+       struct lttcomm_ust_reply *reply;
 
-       DBG("Sending UST command %d to sock %d", msg->cmd, sock);
+       /* Extra safety */
+       if (msg == NULL || sock < 0) {
+               goto error;
+       }
+
+       DBG2("Sending UST command %d to sock %d", msg->cmd, sock);
 
        /* Send UST msg */
-       len = lttcomm_send_unix_sock(sock, msg, sizeof(*msg));
+       len = ustcomm_send_unix_sock(sock, msg, sizeof(*msg));
        if (len < 0) {
                goto error;
        }
 
-       DBG("Receiving UST reply on sock %d", sock);
-
-       /* Get UST reply */
-       len = lttcomm_recv_unix_sock(sock, &reply, sizeof(reply));
-       if (len < 0) {
+       reply = malloc(sizeof(struct lttcomm_ust_reply));
+       if (reply == NULL) {
+               perror("malloc ust reply");
                goto error;
        }
 
-       if (reply.ret_code != LTTCOMM_OK) {
+       DBG2("Receiving UST reply on sock %d", sock);
+
+       /* Get UST reply */
+       len = ustcomm_recv_unix_sock(sock, reply, sizeof(*reply));
+       if (len < 0 || len < sizeof(*reply)) {
                goto error;
        }
 
-       return 0;
+       return reply;
 
 error:
-       return -1;
+       return NULL;
 }
This page took 0.026593 seconds and 5 git commands to generate.