Add utils to send file descriptors to the sessiond
authorFrancis Deslauriers <francis.deslauriers@efficios.com>
Sun, 15 Oct 2017 21:06:49 +0000 (17:06 -0400)
committerJérémie Galarneau <jeremie.galarneau@efficios.com>
Fri, 24 Aug 2018 19:18:50 +0000 (15:18 -0400)
Signed-off-by: Francis Deslauriers <francis.deslauriers@efficios.com>
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
src/lib/lttng-ctl/lttng-ctl-helper.h
src/lib/lttng-ctl/lttng-ctl.c

index 8e9786bc244dd361081133c960d9bd785f0da3e8..9b50aacf75c85019b2dbef4635954193f6105f09 100644 (file)
@@ -41,22 +41,33 @@ void lttng_ctl_copy_lttng_domain(struct lttng_domain *dst,
  * Return the size of the received data on success or else a negative lttng
  * error code. If buf is NULL, 0 is returned on success.
  */
-int lttng_ctl_ask_sessiond_varlen(struct lttcomm_session_msg *lsm,
+int lttng_ctl_ask_sessiond_fds_varlen(struct lttcomm_session_msg *lsm,
+               const int *fds, size_t nb_fd,
                const void *vardata, size_t vardata_len,
                void **user_payload_buf, void **user_cmd_header_buf,
                size_t *user_cmd_header_len);
 
 /*
- * Calls lttng_ctl_ask_sessiond_varlen() with no expected command header.
+ * Calls lttng_ctl_ask_sessiond_fds_varlen() with no expected command header.
  */
 static inline
 int lttng_ctl_ask_sessiond_varlen_no_cmd_header(struct lttcomm_session_msg *lsm,
                void *vardata, size_t vardata_len, void **user_payload_buf)
 {
-       return lttng_ctl_ask_sessiond_varlen(lsm, vardata,
+       return lttng_ctl_ask_sessiond_fds_varlen(lsm, NULL, 0, vardata,
                vardata_len, user_payload_buf, NULL, NULL);
 }
 
+/*
+ * Calls lttng_ctl_ask_sessiond_fds_varlen() with fds and no expected command header.
+ */
+static inline
+int lttng_ctl_ask_sessiond_fds_no_cmd_header(struct lttcomm_session_msg *lsm,
+               const int *fds, size_t nb_fd, void **buf)
+{
+       return lttng_ctl_ask_sessiond_fds_varlen(lsm, fds, nb_fd, NULL,
+               0, NULL, NULL, NULL);
+}
 /*
  * Use this if no variable length data needs to be sent.
  */
index 37b2531028c83930537f796bdaca041b83df3bd4..eadb00eda37af2fb293723aab83aa237f9515144 100644 (file)
@@ -176,6 +176,35 @@ end:
        return ret;
 }
 
+/*
+ * Send file descriptors to the session daemon.
+ *
+ * On success, returns the number of bytes sent (>=0)
+ * On error, returns -1
+ */
+static int send_session_fds(const int *fds, size_t nb_fd)
+{
+       int ret;
+
+       if (!connected) {
+               ret = -LTTNG_ERR_NO_SESSIOND;
+               goto end;
+       }
+
+       if (!fds || !nb_fd) {
+               ret = 0;
+               goto end;
+       }
+
+       ret = lttcomm_send_fds_unix_sock(sessiond_socket, fds, nb_fd);
+       if (ret < 0) {
+               ret = -LTTNG_ERR_FATAL;
+       }
+
+end:
+       return ret;
+}
+
 /*
  * Receive data from the sessiond socket.
  *
@@ -445,15 +474,16 @@ end:
 
 /*
  * Ask the session daemon a specific command and put the data into buf.
- * Takes extra var. len. data as input to send to the session daemon.
+ * Takes extra var. len. data and file descriptors as input to send to the
+ * session daemon.
  *
  * Return size of data (only payload, not header) or a negative error code.
  */
 LTTNG_HIDDEN
-int lttng_ctl_ask_sessiond_varlen(struct lttcomm_session_msg *lsm,
-               const void *vardata, size_t vardata_len,
-               void **user_payload_buf, void **user_cmd_header_buf,
-               size_t *user_cmd_header_len)
+int lttng_ctl_ask_sessiond_fds_varlen(struct lttcomm_session_msg *lsm,
+               const int *fds, size_t nb_fd, const void *vardata,
+               size_t vardata_len, void **user_payload_buf,
+               void **user_cmd_header_buf, size_t *user_cmd_header_len)
 {
        int ret;
        size_t payload_len;
@@ -478,6 +508,13 @@ int lttng_ctl_ask_sessiond_varlen(struct lttcomm_session_msg *lsm,
                goto end;
        }
 
+       /* Send fds */
+       ret = send_session_fds(fds, nb_fd);
+       if (ret < 0) {
+               /* Ret value is a valid lttng error code. */
+               goto end;
+       }
+
        /* Get header from data transmission */
        ret = recv_data_sessiond(&llm, sizeof(llm));
        if (ret < 0) {
@@ -1873,8 +1910,8 @@ int lttng_list_events(struct lttng_handle *handle,
                        sizeof(lsm.u.list.channel_name));
        lttng_ctl_copy_lttng_domain(&lsm.domain, &handle->domain);
 
-       ret = lttng_ctl_ask_sessiond_varlen(&lsm, NULL, 0, (void **) events,
-               (void **) &cmd_header, &cmd_header_len);
+       ret = lttng_ctl_ask_sessiond_fds_varlen(&lsm, NULL, 0, NULL, 0,
+               (void **) events, (void **) &cmd_header, &cmd_header_len);
        if (ret < 0) {
                goto error;
        }
This page took 0.028777 seconds and 5 git commands to generate.