From: Francis Deslauriers Date: Sun, 15 Oct 2017 21:06:49 +0000 (-0400) Subject: Add utils to send file descriptors to the sessiond X-Git-Tag: v2.11.0-rc1~98 X-Git-Url: https://git.lttng.org./?a=commitdiff_plain;h=a04d53fc9a0dd3a5d6f9be82d475dfec48205ac0;p=lttng-tools.git Add utils to send file descriptors to the sessiond Signed-off-by: Francis Deslauriers Signed-off-by: Jérémie Galarneau --- diff --git a/src/lib/lttng-ctl/lttng-ctl-helper.h b/src/lib/lttng-ctl/lttng-ctl-helper.h index 8e9786bc2..9b50aacf7 100644 --- a/src/lib/lttng-ctl/lttng-ctl-helper.h +++ b/src/lib/lttng-ctl/lttng-ctl-helper.h @@ -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. */ diff --git a/src/lib/lttng-ctl/lttng-ctl.c b/src/lib/lttng-ctl/lttng-ctl.c index 37b253102..eadb00eda 100644 --- a/src/lib/lttng-ctl/lttng-ctl.c +++ b/src/lib/lttng-ctl/lttng-ctl.c @@ -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; }