*/
#define _LGPL_SOURCE
+#include "unix.hpp"
+
+#include <common/common.hpp>
+#include <common/compat/errno.hpp>
+#include <common/fd-handle.hpp>
+#include <common/sessiond-comm/sessiond-comm.hpp>
+
#include <limits.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <unistd.h>
-#include <common/common.hpp>
-#include <common/compat/errno.hpp>
-#include <common/sessiond-comm/sessiond-comm.hpp>
-#include <common/fd-handle.hpp>
-
-#include "unix.hpp"
-
/*
* Connect to unix socket using the path name.
*/
if (strlen(pathname) >= sizeof(s_un.sun_path)) {
ERR("unix socket address (\"%s\") is longer than the platform's limit (%zu > %zu).",
- pathname, strlen(pathname) + 1,
- sizeof(s_un.sun_path));
+ pathname,
+ strlen(pathname) + 1,
+ sizeof(s_un.sun_path));
ret = -ENAMETOOLONG;
goto error;
}
if (strlen(pathname) >= sizeof(s_un.sun_path)) {
ERR("unix socket address (\"%s\") is longer than the platform's limit (%zu > %zu).",
- pathname, strlen(pathname) + 1,
- sizeof(s_un.sun_path));
+ pathname,
+ strlen(pathname) + 1,
+ sizeof(s_un.sun_path));
ret = -ENAMETOOLONG;
goto error;
}
*/
DIAGNOSTIC_PUSH
DIAGNOSTIC_IGNORE_LOGICAL_OP
- if (errno == EAGAIN || errno == EWOULDBLOCK ||
- errno == EPIPE) {
- DIAGNOSTIC_POP
+ if (errno == EAGAIN || errno == EWOULDBLOCK || errno == EPIPE) {
+ DIAGNOSTIC_POP
/*
* Nothing was recv.
*/
*/
DIAGNOSTIC_PUSH
DIAGNOSTIC_IGNORE_LOGICAL_OP
- if (errno == EAGAIN || errno == EWOULDBLOCK ||
- errno == EPIPE) {
- DIAGNOSTIC_POP
+ if (errno == EAGAIN || errno == EWOULDBLOCK || errno == EPIPE) {
+ DIAGNOSTIC_POP
/*
* This can happen in non blocking mode.
* Nothing was sent.
if (nb_fd > LTTCOMM_MAX_SEND_FDS)
return -EINVAL;
- msg.msg_control = (caddr_t)tmp;
+ msg.msg_control = (caddr_t) tmp;
msg.msg_controllen = CMSG_LEN(sizeof_fds);
cmptr = CMSG_FIRSTHDR(&msg);
*
* Returns the size of data sent, or negative error value.
*/
-static
-ssize_t _lttcomm_send_payload_view_fds_unix_sock(int sock,
- struct lttng_payload_view *view,
- bool blocking)
+static ssize_t
+_lttcomm_send_payload_view_fds_unix_sock(int sock, struct lttng_payload_view *view, bool blocking)
{
int i;
ssize_t ret;
struct lttng_dynamic_array raw_fds;
const int fd_count = lttng_payload_view_get_fd_handle_count(view);
- lttng_dynamic_array_init(&raw_fds, sizeof(int), NULL);
+ lttng_dynamic_array_init(&raw_fds, sizeof(int), nullptr);
if (fd_count < 0) {
ret = -LTTNG_ERR_INVALID;
* owns a reference to the fd_handles.
*/
for (i = 0; i < fd_count; i++) {
- struct fd_handle *handle =
- lttng_payload_view_pop_fd_handle(view);
+ struct fd_handle *handle = lttng_payload_view_pop_fd_handle(view);
const int raw_fd = fd_handle_get_fd(handle);
- const int add_ret = lttng_dynamic_array_add_element(
- &raw_fds, &raw_fd);
+ const int add_ret = lttng_dynamic_array_add_element(&raw_fds, &raw_fd);
fd_handle_put(handle);
if (add_ret) {
}
if (blocking) {
- ret = lttcomm_send_fds_unix_sock(sock,
- (const int *) raw_fds.buffer.data, fd_count);
+ ret = lttcomm_send_fds_unix_sock(sock, (const int *) raw_fds.buffer.data, fd_count);
} else {
- ret = lttcomm_send_fds_unix_sock_non_block(sock,
- (const int *) raw_fds.buffer.data, fd_count);
+ ret = lttcomm_send_fds_unix_sock_non_block(
+ sock, (const int *) raw_fds.buffer.data, fd_count);
}
end:
return ret;
}
-ssize_t lttcomm_send_payload_view_fds_unix_sock(int sock,
- struct lttng_payload_view *view)
+ssize_t lttcomm_send_payload_view_fds_unix_sock(int sock, struct lttng_payload_view *view)
{
return _lttcomm_send_payload_view_fds_unix_sock(sock, view, true);
}
-ssize_t lttcomm_send_payload_view_fds_unix_sock_non_block(int sock,
- struct lttng_payload_view *view)
+ssize_t lttcomm_send_payload_view_fds_unix_sock_non_block(int sock, struct lttng_payload_view *view)
{
return _lttcomm_send_payload_view_fds_unix_sock(sock, view, false);
}
if (nb_fd > LTTCOMM_MAX_SEND_FDS)
return -EINVAL;
- msg.msg_control = (caddr_t)tmp;
+ msg.msg_control = (caddr_t) tmp;
msg.msg_controllen = CMSG_LEN(sizeof_fds);
cmptr = CMSG_FIRSTHDR(&msg);
DIAGNOSTIC_PUSH
DIAGNOSTIC_IGNORE_LOGICAL_OP
if (errno == EAGAIN || errno == EWOULDBLOCK) {
- DIAGNOSTIC_POP
+ DIAGNOSTIC_POP
/*
* This can happen in non blocking mode.
* Nothing was sent.
goto retry;
} else {
/* We consider EPIPE and EAGAIN as expected. */
- if (!lttng_opt_quiet &&
- (errno != EPIPE && errno != EAGAIN)) {
+ if (!lttng_opt_quiet && (errno != EPIPE && errno != EAGAIN)) {
PERROR("recvmsg");
}
goto end;
}
if (ret != 1) {
- fprintf(stderr, "Error: Received %zd bytes, expected %d\n",
- ret, 1);
+ fprintf(stderr, "Error: Received %zd bytes, expected %d\n", ret, 1);
goto end;
}
* need to expect a cmsg of the SCM_CREDENTIALS as the first control
* message.
*/
- for (cmsg = CMSG_FIRSTHDR(&msg); cmsg != NULL; cmsg = CMSG_NXTHDR(&msg, cmsg)) {
+ for (cmsg = CMSG_FIRSTHDR(&msg); cmsg != nullptr; cmsg = CMSG_NXTHDR(&msg, cmsg)) {
if (cmsg->cmsg_level != SOL_SOCKET) {
fprintf(stderr, "Error: The socket needs to be of type SOL_SOCKET\n");
ret = -1;
* now copy the fds to the fds ptr and return success.
*/
if (cmsg->cmsg_len != CMSG_LEN(sizeof_fds)) {
- fprintf(stderr, "Error: Received %zu bytes of"
+ fprintf(stderr,
+ "Error: Received %zu bytes of"
"ancillary data for FDs, expected %zu\n",
(size_t) cmsg->cmsg_len,
(size_t) CMSG_LEN(sizeof_fds));
return ret;
}
-static
-void close_raw_fd(void *ptr)
+static void close_raw_fd(void *ptr)
{
const int raw_fd = *((const int *) ptr);
}
}
-static
-enum lttng_error_code add_fds_to_payload(struct lttng_dynamic_array *raw_fds,
- struct lttng_payload *payload)
+static enum lttng_error_code add_fds_to_payload(struct lttng_dynamic_array *raw_fds,
+ struct lttng_payload *payload)
{
int i;
enum lttng_error_code ret_code = LTTNG_OK;
for (i = 0; i < fd_count; i++) {
int ret;
struct fd_handle *handle;
- int *raw_fd = (int *) lttng_dynamic_array_get_element(
- raw_fds, i);
+ int *raw_fd = (int *) lttng_dynamic_array_get_element(raw_fds, i);
LTTNG_ASSERT(*raw_fd != -1);
return ret_code;
}
-static
-ssize_t _lttcomm_recv_payload_fds_unix_sock(int sock, size_t nb_fd,
- struct lttng_payload *payload, bool blocking)
+static ssize_t _lttcomm_recv_payload_fds_unix_sock(int sock,
+ size_t nb_fd,
+ struct lttng_payload *payload,
+ bool blocking)
{
int i = 0;
enum lttng_error_code add_ret;
}
if (blocking) {
- ret = lttcomm_recv_fds_unix_sock(
- sock, (int *) raw_fds.buffer.data, nb_fd);
+ ret = lttcomm_recv_fds_unix_sock(sock, (int *) raw_fds.buffer.data, nb_fd);
} else {
ret = lttcomm_recv_fds_unix_sock_non_block(
- sock, (int *) raw_fds.buffer.data, nb_fd);
+ sock, (int *) raw_fds.buffer.data, nb_fd);
}
if (ret <= 0) {
add_ret = add_fds_to_payload(&raw_fds, payload);
if (add_ret != LTTNG_OK) {
- ret = - (int) add_ret;
+ ret = -(int) add_ret;
goto end;
}
return ret;
}
-ssize_t lttcomm_recv_payload_fds_unix_sock(int sock, size_t nb_fd,
- struct lttng_payload *payload)
+ssize_t lttcomm_recv_payload_fds_unix_sock(int sock, size_t nb_fd, struct lttng_payload *payload)
{
return _lttcomm_recv_payload_fds_unix_sock(sock, nb_fd, payload, true);
}
-ssize_t lttcomm_recv_payload_fds_unix_sock_non_block(int sock, size_t nb_fd,
- struct lttng_payload *payload)
+ssize_t
+lttcomm_recv_payload_fds_unix_sock_non_block(int sock, size_t nb_fd, struct lttng_payload *payload)
{
return _lttcomm_recv_payload_fds_unix_sock(sock, nb_fd, payload, false);
}
DIAGNOSTIC_PUSH
DIAGNOSTIC_IGNORE_LOGICAL_OP
if (errno == EAGAIN || errno == EWOULDBLOCK) {
- DIAGNOSTIC_POP
+ DIAGNOSTIC_POP
/*
* This can happen in non blocking mode.
* Nothing was recv.
}
if (ret != 1) {
- fprintf(stderr, "Error: Received %zd bytes, expected %d\n",
- ret, 1);
+ fprintf(stderr, "Error: Received %zd bytes, expected %d\n", ret, 1);
goto end;
}
* need to expect a cmsg of the SCM_CREDENTIALS as the first control
* message.
*/
- for (cmsg = CMSG_FIRSTHDR(&msg); cmsg != NULL; cmsg = CMSG_NXTHDR(&msg, cmsg)) {
+ for (cmsg = CMSG_FIRSTHDR(&msg); cmsg != nullptr; cmsg = CMSG_NXTHDR(&msg, cmsg)) {
if (cmsg->cmsg_level != SOL_SOCKET) {
fprintf(stderr, "Error: The socket needs to be of type SOL_SOCKET\n");
ret = -1;
* now copy the fds to the fds ptr and return success.
*/
if (cmsg->cmsg_len != CMSG_LEN(sizeof_fds)) {
- fprintf(stderr, "Error: Received %zu bytes of"
+ fprintf(stderr,
+ "Error: Received %zu bytes of"
"ancillary data for FDs, expected %zu\n",
(size_t) cmsg->cmsg_len,
(size_t) CMSG_LEN(sizeof_fds));
cmptr->cmsg_type = LTTNG_SOCK_CREDS;
cmptr->cmsg_len = CMSG_LEN(sizeof_cred);
- creds = (lttng_sock_cred*) CMSG_DATA(cmptr);
+ creds = (lttng_sock_cred *) CMSG_DATA(cmptr);
LTTNG_SOCK_SET_UID_CRED(creds, geteuid());
LTTNG_SOCK_SET_GID_CRED(creds, getegid());
*
* Returns the size of received data, or negative error value.
*/
-ssize_t lttcomm_recv_creds_unix_sock(int sock, void *buf, size_t len,
- lttng_sock_cred *creds)
+ssize_t lttcomm_recv_creds_unix_sock(int sock, void *buf, size_t len, lttng_sock_cred *creds)
{
struct msghdr msg;
struct iovec iov[1];
struct cmsghdr *cmptr;
size_t sizeof_cred = sizeof(lttng_sock_cred);
char anc_buf[CMSG_SPACE(sizeof_cred)];
-#endif /* __linux__, __CYGWIN__ */
+#endif /* __linux__, __CYGWIN__ */
LTTNG_ASSERT(sock);
LTTNG_ASSERT(buf);
}
cmptr = CMSG_FIRSTHDR(&msg);
- if (cmptr == NULL) {
+ if (cmptr == nullptr) {
fprintf(stderr, "Error: Invalid control message header\n");
ret = -1;
goto end;
}
- if (cmptr->cmsg_level != SOL_SOCKET ||
- cmptr->cmsg_type != LTTNG_SOCK_CREDS) {
+ if (cmptr->cmsg_level != SOL_SOCKET || cmptr->cmsg_type != LTTNG_SOCK_CREDS) {
fprintf(stderr, "Didn't received any credentials\n");
ret = -1;
goto end;
}
if (cmptr->cmsg_len != CMSG_LEN(sizeof_cred)) {
- fprintf(stderr, "Error: Received %zu bytes of ancillary data, expected %zu\n",
- (size_t) cmptr->cmsg_len, (size_t) CMSG_LEN(sizeof_cred));
+ fprintf(stderr,
+ "Error: Received %zu bytes of ancillary data, expected %zu\n",
+ (size_t) cmptr->cmsg_len,
+ (size_t) CMSG_LEN(sizeof_cred));
ret = -1;
goto end;
}
}
#else
#error "Please implement credential support for your OS."
-#endif /* __linux__, __CYGWIN__ */
+#endif /* __linux__, __CYGWIN__ */
end:
return ret;