* 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.
*/
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.
*
/*
* 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;
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) {
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;
}