From ac497a37018f3c253d2e50397294f58d33f7f24f Mon Sep 17 00:00:00 2001 From: Simon Marchi Date: Fri, 3 Sep 2021 17:31:29 -0400 Subject: [PATCH] bin: compile lttng-relayd as a C++ MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Same as the previous commit, but change lttng-relayd to be a C++ program. In addition to what was mentioned in previous commits: - Test test_relayd_backward_compat_group_by_session uses an object file from the relayd binary, so it's simpler to change this test to be C++ as well. - There are some declarations related to fs_handle in fd-tracker.h. Remove them, as they are already in fs-handle.h. Change-Id: I72c5fdecd2e82c30633563a47bd641af1dcfa29c Signed-off-by: Simon Marchi Signed-off-by: Jérémie Galarneau --- src/bin/lttng-relayd/Makefile.am | 32 ++++++------- ....c => backward-compatibility-group-by.cpp} | 2 +- .../lttng-relayd/{cmd-2-1.c => cmd-2-1.cpp} | 0 .../lttng-relayd/{cmd-2-11.c => cmd-2-11.cpp} | 0 .../lttng-relayd/{cmd-2-2.c => cmd-2-2.cpp} | 0 .../lttng-relayd/{cmd-2-4.c => cmd-2-4.cpp} | 0 .../{connection.c => connection.cpp} | 2 +- .../{ctf-trace.c => ctf-trace.cpp} | 2 +- .../{health-relayd.c => health-relayd.cpp} | 2 +- src/bin/lttng-relayd/{index.c => index.cpp} | 18 +++---- src/bin/lttng-relayd/{live.c => live.cpp} | 20 ++++---- src/bin/lttng-relayd/{main.c => main.cpp} | 39 +++++++-------- .../lttng-relayd/{session.c => session.cpp} | 2 +- ...ace-chunks.c => sessiond-trace-chunks.cpp} | 4 +- src/bin/lttng-relayd/{stream.c => stream.cpp} | 12 ++--- .../{tcp_keep_alive.c => tcp_keep_alive.cpp} | 0 ...{tracefile-array.c => tracefile-array.cpp} | 4 +- src/bin/lttng-relayd/{utils.c => utils.cpp} | 0 .../{viewer-session.c => viewer-session.cpp} | 2 +- src/bin/lttng-relayd/viewer-session.h | 1 + .../{viewer-stream.c => viewer-stream.cpp} | 2 +- src/common/fd-tracker/fd-tracker.h | 48 +++---------------- src/common/fd-tracker/utils.h | 8 ++++ src/common/fs-handle.h | 8 ++++ src/common/index/index.h | 8 ++++ src/common/trace-chunk-registry.h | 8 ++++ src/common/trace-chunk.c | 1 + tests/unit/Makefile.am | 2 +- tests/unit/test_fd_tracker.c | 1 + ...layd_backward_compat_group_by_session.cpp} | 0 30 files changed, 114 insertions(+), 114 deletions(-) rename src/bin/lttng-relayd/{backward-compatibility-group-by.c => backward-compatibility-group-by.cpp} (99%) rename src/bin/lttng-relayd/{cmd-2-1.c => cmd-2-1.cpp} (100%) rename src/bin/lttng-relayd/{cmd-2-11.c => cmd-2-11.cpp} (100%) rename src/bin/lttng-relayd/{cmd-2-2.c => cmd-2-2.cpp} (100%) rename src/bin/lttng-relayd/{cmd-2-4.c => cmd-2-4.cpp} (100%) rename src/bin/lttng-relayd/{connection.c => connection.cpp} (98%) rename src/bin/lttng-relayd/{ctf-trace.c => ctf-trace.cpp} (98%) rename src/bin/lttng-relayd/{health-relayd.c => health-relayd.cpp} (99%) rename src/bin/lttng-relayd/{index.c => index.cpp} (96%) rename src/bin/lttng-relayd/{live.c => live.cpp} (99%) rename src/bin/lttng-relayd/{main.c => main.cpp} (99%) rename src/bin/lttng-relayd/{session.c => session.cpp} (99%) rename src/bin/lttng-relayd/{sessiond-trace-chunks.c => sessiond-trace-chunks.cpp} (98%) rename src/bin/lttng-relayd/{stream.c => stream.cpp} (99%) rename src/bin/lttng-relayd/{tcp_keep_alive.c => tcp_keep_alive.cpp} (100%) rename src/bin/lttng-relayd/{tracefile-array.c => tracefile-array.cpp} (97%) rename src/bin/lttng-relayd/{utils.c => utils.cpp} (100%) rename src/bin/lttng-relayd/{viewer-session.c => viewer-session.cpp} (98%) rename src/bin/lttng-relayd/{viewer-stream.c => viewer-stream.cpp} (99%) rename tests/unit/{test_relayd_backward_compat_group_by_session.c => test_relayd_backward_compat_group_by_session.cpp} (100%) diff --git a/src/bin/lttng-relayd/Makefile.am b/src/bin/lttng-relayd/Makefile.am index f6d5b2950..51b232968 100644 --- a/src/bin/lttng-relayd/Makefile.am +++ b/src/bin/lttng-relayd/Makefile.am @@ -9,23 +9,23 @@ endif bin_PROGRAMS = lttng-relayd -lttng_relayd_SOURCES = main.c lttng-relayd.h utils.h utils.c cmd.h \ - index.c index.h live.c live.h ctf-trace.c ctf-trace.h \ - cmd-2-1.c cmd-2-1.h \ - cmd-2-2.c cmd-2-2.h \ - cmd-2-4.c cmd-2-4.h \ - cmd-2-11.c cmd-2-11.h \ - health-relayd.c health-relayd.h \ +lttng_relayd_SOURCES = main.cpp lttng-relayd.h utils.h utils.cpp cmd.h \ + index.cpp index.h live.cpp live.h ctf-trace.cpp ctf-trace.h \ + cmd-2-1.cpp cmd-2-1.h \ + cmd-2-2.cpp cmd-2-2.h \ + cmd-2-4.cpp cmd-2-4.h \ + cmd-2-11.cpp cmd-2-11.h \ + health-relayd.cpp health-relayd.h \ lttng-viewer-abi.h testpoint.h \ - viewer-stream.h viewer-stream.c \ - session.c session.h \ - stream.c stream.h \ - connection.c connection.h \ - viewer-session.c viewer-session.h \ - tracefile-array.c tracefile-array.h \ - tcp_keep_alive.c tcp_keep_alive.h \ - sessiond-trace-chunks.c sessiond-trace-chunks.h \ - backward-compatibility-group-by.c backward-compatibility-group-by.h + viewer-stream.h viewer-stream.cpp \ + session.cpp session.h \ + stream.cpp stream.h \ + connection.cpp connection.h \ + viewer-session.cpp viewer-session.h \ + tracefile-array.cpp tracefile-array.h \ + tcp_keep_alive.cpp tcp_keep_alive.h \ + sessiond-trace-chunks.cpp sessiond-trace-chunks.h \ + backward-compatibility-group-by.cpp backward-compatibility-group-by.h # link on liblttngctl for check if relayd is already alive. lttng_relayd_LDADD = $(URCU_LIBS) \ diff --git a/src/bin/lttng-relayd/backward-compatibility-group-by.c b/src/bin/lttng-relayd/backward-compatibility-group-by.cpp similarity index 99% rename from src/bin/lttng-relayd/backward-compatibility-group-by.c rename to src/bin/lttng-relayd/backward-compatibility-group-by.cpp index 9e144f9f5..f0454a56b 100644 --- a/src/bin/lttng-relayd/backward-compatibility-group-by.c +++ b/src/bin/lttng-relayd/backward-compatibility-group-by.cpp @@ -172,7 +172,7 @@ char *backward_compat_group_by_session(const char *path, goto error_regex; } } else { - datetime = zmalloc(DATETIME_STR_LEN); + datetime = (char *) zmalloc(DATETIME_STR_LEN); if (!datetime) { PERROR("Failed to allocate DATETIME string"); goto error; diff --git a/src/bin/lttng-relayd/cmd-2-1.c b/src/bin/lttng-relayd/cmd-2-1.cpp similarity index 100% rename from src/bin/lttng-relayd/cmd-2-1.c rename to src/bin/lttng-relayd/cmd-2-1.cpp diff --git a/src/bin/lttng-relayd/cmd-2-11.c b/src/bin/lttng-relayd/cmd-2-11.cpp similarity index 100% rename from src/bin/lttng-relayd/cmd-2-11.c rename to src/bin/lttng-relayd/cmd-2-11.cpp diff --git a/src/bin/lttng-relayd/cmd-2-2.c b/src/bin/lttng-relayd/cmd-2-2.cpp similarity index 100% rename from src/bin/lttng-relayd/cmd-2-2.c rename to src/bin/lttng-relayd/cmd-2-2.cpp diff --git a/src/bin/lttng-relayd/cmd-2-4.c b/src/bin/lttng-relayd/cmd-2-4.cpp similarity index 100% rename from src/bin/lttng-relayd/cmd-2-4.c rename to src/bin/lttng-relayd/cmd-2-4.cpp diff --git a/src/bin/lttng-relayd/connection.c b/src/bin/lttng-relayd/connection.cpp similarity index 98% rename from src/bin/lttng-relayd/connection.c rename to src/bin/lttng-relayd/connection.cpp index e50784bf5..98ffad29f 100644 --- a/src/bin/lttng-relayd/connection.c +++ b/src/bin/lttng-relayd/connection.cpp @@ -90,7 +90,7 @@ struct relay_connection *connection_create(struct lttcomm_sock *sock, { struct relay_connection *conn; - conn = zmalloc(sizeof(*conn)); + conn = (relay_connection *) zmalloc(sizeof(*conn)); if (!conn) { PERROR("zmalloc relay connection"); goto end; diff --git a/src/bin/lttng-relayd/ctf-trace.c b/src/bin/lttng-relayd/ctf-trace.cpp similarity index 98% rename from src/bin/lttng-relayd/ctf-trace.c rename to src/bin/lttng-relayd/ctf-trace.cpp index f2af1a3d0..7a3cbdea0 100644 --- a/src/bin/lttng-relayd/ctf-trace.c +++ b/src/bin/lttng-relayd/ctf-trace.cpp @@ -80,7 +80,7 @@ static struct ctf_trace *ctf_trace_create(struct relay_session *session, { struct ctf_trace *trace; - trace = zmalloc(sizeof(*trace)); + trace = (ctf_trace *) zmalloc(sizeof(*trace)); if (!trace) { PERROR("Failed to allocate ctf_trace"); goto end; diff --git a/src/bin/lttng-relayd/health-relayd.c b/src/bin/lttng-relayd/health-relayd.cpp similarity index 99% rename from src/bin/lttng-relayd/health-relayd.c rename to src/bin/lttng-relayd/health-relayd.cpp index 57fa70f22..2e532bde4 100644 --- a/src/bin/lttng-relayd/health-relayd.c +++ b/src/bin/lttng-relayd/health-relayd.cpp @@ -243,7 +243,7 @@ static int open_unix_socket(void *data, int *out_fd) { int ret; - const char *path = data; + const char *path = (const char *) data; ret = lttcomm_create_unix_sock(path); if (ret < 0) { diff --git a/src/bin/lttng-relayd/index.c b/src/bin/lttng-relayd/index.cpp similarity index 96% rename from src/bin/lttng-relayd/index.c rename to src/bin/lttng-relayd/index.cpp index f7d22b3aa..ef00a6eca 100644 --- a/src/bin/lttng-relayd/index.c +++ b/src/bin/lttng-relayd/index.cpp @@ -34,7 +34,7 @@ static struct relay_index *relay_index_create(struct relay_stream *stream, DBG2("Creating relay index for stream id %" PRIu64 " and seqnum %" PRIu64, stream->stream_handle, net_seq_num); - index = zmalloc(sizeof(*index)); + index = (relay_index *) zmalloc(sizeof(*index)); if (!index) { PERROR("Relay index zmalloc"); goto end; @@ -407,14 +407,14 @@ int relay_index_set_control_data(struct relay_index *index, unsigned int minor_version) { /* The index on disk is encoded in big endian. */ - const struct ctf_packet_index index_data = { - .packet_size = htobe64(data->packet_size), - .content_size = htobe64(data->content_size), - .timestamp_begin = htobe64(data->timestamp_begin), - .timestamp_end = htobe64(data->timestamp_end), - .events_discarded = htobe64(data->events_discarded), - .stream_id = htobe64(data->stream_id), - }; + ctf_packet_index index_data {}; + + index_data.packet_size = htobe64(data->packet_size); + index_data.content_size = htobe64(data->content_size); + index_data.timestamp_begin = htobe64(data->timestamp_begin); + index_data.timestamp_end = htobe64(data->timestamp_end); + index_data.events_discarded = htobe64(data->events_discarded); + index_data.stream_id = htobe64(data->stream_id); if (minor_version >= 8) { index->index_data.stream_instance_id = htobe64(data->stream_instance_id); diff --git a/src/bin/lttng-relayd/live.c b/src/bin/lttng-relayd/live.cpp similarity index 99% rename from src/bin/lttng-relayd/live.c rename to src/bin/lttng-relayd/live.cpp index 962fe0fd1..92c3bf4a7 100644 --- a/src/bin/lttng-relayd/live.c +++ b/src/bin/lttng-relayd/live.cpp @@ -552,7 +552,7 @@ static int create_sock(void *data, int *out_fd) { int ret; - struct lttcomm_sock *sock = data; + struct lttcomm_sock *sock = (lttcomm_sock *) data; ret = lttcomm_create_sock(sock); if (ret < 0) { @@ -567,7 +567,7 @@ end: static int close_sock(void *data, int *in_fd) { - struct lttcomm_sock *sock = data; + struct lttcomm_sock *sock = (lttcomm_sock *) data; return sock->ops->close(sock); } @@ -576,7 +576,7 @@ static int accept_sock(void *data, int *out_fd) { int ret = 0; /* Socks is an array of in_sock, out_sock. */ - struct lttcomm_sock **socks = data; + struct lttcomm_sock **socks = (lttcomm_sock **) data; struct lttcomm_sock *in_sock = socks[0]; socks[1] = in_sock->ops->accept(in_sock); @@ -784,7 +784,9 @@ restart: newsock = NULL; /* Enqueue request for the dispatcher thread. */ - cds_wfcq_enqueue(&viewer_conn_queue.head, &viewer_conn_queue.tail, + cds_wfcq_head_ptr_t head; + head.h = &viewer_conn_queue.head; + cds_wfcq_enqueue(head, &viewer_conn_queue.tail, &new_conn->qnode); /* @@ -1024,7 +1026,7 @@ int viewer_list_sessions(struct relay_connection *conn) DBG("List sessions received"); - send_session_buf = zmalloc(SESSION_BUF_DEFAULT_COUNT * sizeof(*send_session_buf)); + send_session_buf = (lttng_viewer_session *) zmalloc(SESSION_BUF_DEFAULT_COUNT * sizeof(*send_session_buf)); if (!send_session_buf) { return -1; } @@ -1046,7 +1048,7 @@ int viewer_list_sessions(struct relay_connection *conn) struct lttng_viewer_session *newbuf; uint32_t new_buf_count = buf_count << 1; - newbuf = realloc(send_session_buf, + newbuf = (lttng_viewer_session *) realloc(send_session_buf, new_buf_count * sizeof(*send_session_buf)); if (!newbuf) { ret = -1; @@ -1296,7 +1298,7 @@ int viewer_attach_session(struct relay_connection *conn) case LTTNG_VIEWER_SEEK_BEGINNING: case LTTNG_VIEWER_SEEK_LAST: response.status = htobe32(LTTNG_VIEWER_ATTACH_OK); - seek_type = be32toh(request.seek); + seek_type = (lttng_viewer_seek) be32toh(request.seek); break; default: ERR("Wrong seek parameter"); @@ -1868,7 +1870,7 @@ int viewer_get_packet(struct relay_connection *conn) reply_size += packet_data_len; } - reply = zmalloc(reply_size); + reply = (char *) zmalloc(reply_size); if (!reply) { PERROR("packet reply zmalloc"); reply_size = sizeof(reply_header); @@ -2122,7 +2124,7 @@ int viewer_get_metadata(struct relay_connection *conn) } reply.len = htobe64(len); - data = zmalloc(len); + data = (char *) zmalloc(len); if (!data) { PERROR("viewer metadata zmalloc"); goto error; diff --git a/src/bin/lttng-relayd/main.c b/src/bin/lttng-relayd/main.cpp similarity index 99% rename from src/bin/lttng-relayd/main.c rename to src/bin/lttng-relayd/main.cpp index fb1817cd0..bc3c56f34 100644 --- a/src/bin/lttng-relayd/main.c +++ b/src/bin/lttng-relayd/main.cpp @@ -33,6 +33,7 @@ #include #include #include +#include #include #include @@ -954,7 +955,7 @@ static int check_thread_quit_pipe(int fd, uint32_t events) static int create_sock(void *data, int *out_fd) { int ret; - struct lttcomm_sock *sock = data; + struct lttcomm_sock *sock = (lttcomm_sock *) data; ret = lttcomm_create_sock(sock); if (ret < 0) { @@ -968,7 +969,7 @@ end: static int close_sock(void *data, int *in_fd) { - struct lttcomm_sock *sock = data; + struct lttcomm_sock *sock = (lttcomm_sock *) data; return sock->ops->close(sock); } @@ -977,7 +978,7 @@ static int accept_sock(void *data, int *out_fd) { int ret = 0; /* Socks is an array of in_sock, out_sock. */ - struct lttcomm_sock **socks = data; + struct lttcomm_sock **socks = (lttcomm_sock **) data; struct lttcomm_sock *in_sock = socks[0]; socks[1] = in_sock->ops->accept(in_sock); @@ -1215,7 +1216,9 @@ restart: } /* Enqueue request for the dispatcher thread. */ - cds_wfcq_enqueue(&relay_conn_queue.head, &relay_conn_queue.tail, + cds_wfcq_head_ptr_t head; + head.h = &relay_conn_queue.head; + cds_wfcq_enqueue(head, &relay_conn_queue.tail, &new_conn->qnode); /* @@ -2099,7 +2102,7 @@ static int relay_data_pending(const struct lttcomm_relayd_hdr *recv_hdr, * Ensure that both the index and stream data have been * flushed up to the requested point. */ - stream_seq = min(stream->prev_data_seq, stream->prev_index_seq); + stream_seq = std::min(stream->prev_data_seq, stream->prev_index_seq); } else { stream_seq = stream->prev_data_seq; } @@ -2337,7 +2340,7 @@ static int relay_end_data_pending(const struct lttcomm_relayd_hdr *recv_hdr, * Ensure that both the index and stream data have been * flushed up to the requested point. */ - stream_seq = min(stream->prev_data_seq, stream->prev_index_seq); + stream_seq = std::min(stream->prev_data_seq, stream->prev_index_seq); } else { stream_seq = stream->prev_data_seq; } @@ -2891,10 +2894,8 @@ static int relay_close_trace_chunk(const struct lttcomm_relayd_hdr *recv_hdr, msg = (typeof(msg)) header_view.data; chunk_id = be64toh(msg->chunk_id); close_timestamp = (time_t) be64toh(msg->close_timestamp); - close_command = (typeof(close_command)){ - .value = be32toh(msg->close_command.value), - .is_set = msg->close_command.is_set, - }; + close_command.value = (lttng_trace_chunk_command_type) be32toh(msg->close_command.value); + close_command.is_set = msg->close_command.is_set; chunk = sessiond_trace_chunk_registry_get_chunk( sessiond_trace_chunk_registry, @@ -3146,11 +3147,9 @@ static int relay_trace_chunk_exists(const struct lttcomm_relayd_hdr *recv_hdr, * It is a protocol (or internal) error and the session/connection * should be torn down. */ - reply = (typeof(reply)){ - .generic.ret_code = htobe32((uint32_t) - (ret == 0 ? LTTNG_OK : LTTNG_ERR_INVALID_PROTOCOL)), - .trace_chunk_exists = ret == 0 ? chunk_exists : 0, - }; + reply.generic.ret_code = htobe32((uint32_t) (ret == 0 ? LTTNG_OK : LTTNG_ERR_INVALID_PROTOCOL)); + reply.trace_chunk_exists = ret == 0 ? chunk_exists : 0; + send_ret = conn->sock->ops->sendmsg( conn->sock, &reply, sizeof(reply), 0); if (send_ret < (ssize_t) sizeof(reply)) { @@ -3197,11 +3196,9 @@ static int relay_get_configuration(const struct lttcomm_relayd_hdr *recv_hdr, } ret = 0; reply: - reply = (typeof(reply)){ - .generic.ret_code = htobe32((uint32_t) - (ret == 0 ? LTTNG_OK : LTTNG_ERR_INVALID_PROTOCOL)), - .relayd_configuration_flags = htobe64(result_flags), - }; + reply.generic.ret_code = htobe32((uint32_t) (ret == 0 ? LTTNG_OK : LTTNG_ERR_INVALID_PROTOCOL)); + reply.relayd_configuration_flags = htobe64(result_flags); + send_ret = conn->sock->ops->sendmsg( conn->sock, &reply, sizeof(reply), 0); if (send_ret < (ssize_t) sizeof(reply)) { @@ -3632,7 +3629,7 @@ static enum relay_connection_status relay_process_data_receive_payload( * - the on-stack data buffer */ while (left_to_receive > 0 && !partial_recv) { - size_t recv_size = min(left_to_receive, chunk_size); + size_t recv_size = std::min(left_to_receive, chunk_size); struct lttng_buffer_view packet_chunk; ret = conn->sock->ops->recvmsg(conn->sock, data_buffer, diff --git a/src/bin/lttng-relayd/session.c b/src/bin/lttng-relayd/session.cpp similarity index 99% rename from src/bin/lttng-relayd/session.c rename to src/bin/lttng-relayd/session.cpp index 0a535cf87..5fa39663a 100644 --- a/src/bin/lttng-relayd/session.c +++ b/src/bin/lttng-relayd/session.cpp @@ -310,7 +310,7 @@ struct relay_session *session_create(const char *session_name, goto error; } - session = zmalloc(sizeof(*session)); + session = (relay_session *) zmalloc(sizeof(*session)); if (!session) { PERROR("Failed to allocate session"); goto error; diff --git a/src/bin/lttng-relayd/sessiond-trace-chunks.c b/src/bin/lttng-relayd/sessiond-trace-chunks.cpp similarity index 98% rename from src/bin/lttng-relayd/sessiond-trace-chunks.c rename to src/bin/lttng-relayd/sessiond-trace-chunks.cpp index 2f98c3d63..e0c46e34a 100644 --- a/src/bin/lttng-relayd/sessiond-trace-chunks.c +++ b/src/bin/lttng-relayd/sessiond-trace-chunks.cpp @@ -197,7 +197,7 @@ int trace_chunk_registry_ht_element_create( goto end; } - new_element = zmalloc(sizeof(*new_element)); + new_element = (trace_chunk_registry_ht_element *) zmalloc(sizeof(*new_element)); if (!new_element) { ret = -1; goto end; @@ -263,7 +263,7 @@ end: struct sessiond_trace_chunk_registry *sessiond_trace_chunk_registry_create(void) { struct sessiond_trace_chunk_registry *sessiond_registry = - zmalloc(sizeof(*sessiond_registry)); + (sessiond_trace_chunk_registry *) zmalloc(sizeof(*sessiond_registry)); if (!sessiond_registry) { goto end; diff --git a/src/bin/lttng-relayd/stream.c b/src/bin/lttng-relayd/stream.cpp similarity index 99% rename from src/bin/lttng-relayd/stream.c rename to src/bin/lttng-relayd/stream.cpp index 1eaca14ec..158009295 100644 --- a/src/bin/lttng-relayd/stream.c +++ b/src/bin/lttng-relayd/stream.cpp @@ -9,6 +9,7 @@ */ #define _LGPL_SOURCE +#include #include #include #include @@ -103,7 +104,7 @@ static int stream_create_data_output_file_from_trace_chunk( * to be replaced is unlinked in order to not overwrite its * content. */ - status = lttng_trace_chunk_unlink_file(trace_chunk, + status = (lttng_trace_chunk_status) lttng_trace_chunk_unlink_file(trace_chunk, stream_path); if (status != LTTNG_TRACE_CHUNK_STATUS_OK) { PERROR("Failed to unlink stream file \"%s\" during trace file rotation", @@ -260,8 +261,7 @@ static int rotate_truncate_stream(struct relay_stream *stream) while (copy_bytes_left) { ssize_t io_ret; char copy_buffer[FILE_IO_STACK_BUFFER_SIZE]; - const off_t copy_size_this_pass = min_t( - off_t, copy_bytes_left, sizeof(copy_buffer)); + const off_t copy_size_this_pass = std::min(copy_bytes_left, sizeof(copy_buffer)); io_ret = fs_handle_read(previous_stream_file, copy_buffer, copy_size_this_pass); @@ -578,7 +578,7 @@ struct relay_stream *stream_create(struct ctf_trace *trace, bool acquired_reference = false; struct lttng_trace_chunk *current_trace_chunk; - stream = zmalloc(sizeof(struct relay_stream)); + stream = (relay_stream *) zmalloc(sizeof(struct relay_stream)); if (stream == NULL) { PERROR("relay stream zmalloc"); goto error_no_alloc; @@ -1063,7 +1063,7 @@ int stream_write(struct relay_stream *stream, ASSERT_LOCKED(stream->lock); memset(padding_buffer, 0, - min(sizeof(padding_buffer), padding_to_write)); + std::min(sizeof(padding_buffer), padding_to_write)); if (!stream->file || !stream->trace_chunk) { ERR("Protocol error: received a packet for a stream that doesn't have a current trace chunk: stream_id = %" PRIu64 ", channel_name = %s", @@ -1085,7 +1085,7 @@ int stream_write(struct relay_stream *stream, while (padding_to_write > 0) { const size_t padding_to_write_this_pass = - min(padding_to_write, sizeof(padding_buffer)); + std::min(padding_to_write, sizeof(padding_buffer)); write_ret = fs_handle_write(stream->file, padding_buffer, padding_to_write_this_pass); diff --git a/src/bin/lttng-relayd/tcp_keep_alive.c b/src/bin/lttng-relayd/tcp_keep_alive.cpp similarity index 100% rename from src/bin/lttng-relayd/tcp_keep_alive.c rename to src/bin/lttng-relayd/tcp_keep_alive.cpp diff --git a/src/bin/lttng-relayd/tracefile-array.c b/src/bin/lttng-relayd/tracefile-array.cpp similarity index 97% rename from src/bin/lttng-relayd/tracefile-array.c rename to src/bin/lttng-relayd/tracefile-array.cpp index 996c43e45..05012b642 100644 --- a/src/bin/lttng-relayd/tracefile-array.c +++ b/src/bin/lttng-relayd/tracefile-array.cpp @@ -17,11 +17,11 @@ struct tracefile_array *tracefile_array_create(size_t count) struct tracefile_array *tfa = NULL; int i; - tfa = zmalloc(sizeof(*tfa)); + tfa = (tracefile_array *) zmalloc(sizeof(*tfa)); if (!tfa) { goto error; } - tfa->tf = zmalloc(sizeof(*tfa->tf) * count); + tfa->tf = (tracefile *) zmalloc(sizeof(*tfa->tf) * count); if (!tfa->tf) { goto error; } diff --git a/src/bin/lttng-relayd/utils.c b/src/bin/lttng-relayd/utils.cpp similarity index 100% rename from src/bin/lttng-relayd/utils.c rename to src/bin/lttng-relayd/utils.cpp diff --git a/src/bin/lttng-relayd/viewer-session.c b/src/bin/lttng-relayd/viewer-session.cpp similarity index 98% rename from src/bin/lttng-relayd/viewer-session.c rename to src/bin/lttng-relayd/viewer-session.cpp index b2aba61bc..9bed097ab 100644 --- a/src/bin/lttng-relayd/viewer-session.c +++ b/src/bin/lttng-relayd/viewer-session.cpp @@ -22,7 +22,7 @@ struct relay_viewer_session *viewer_session_create(void) { struct relay_viewer_session *vsession; - vsession = zmalloc(sizeof(*vsession)); + vsession = (relay_viewer_session *) zmalloc(sizeof(*vsession)); if (!vsession) { goto end; } diff --git a/src/bin/lttng-relayd/viewer-session.h b/src/bin/lttng-relayd/viewer-session.h index cbf4aa157..2a685f948 100644 --- a/src/bin/lttng-relayd/viewer-session.h +++ b/src/bin/lttng-relayd/viewer-session.h @@ -20,6 +20,7 @@ #include #include "session.h" +#include "lttng-viewer-abi.h" struct relay_viewer_session { /* diff --git a/src/bin/lttng-relayd/viewer-stream.c b/src/bin/lttng-relayd/viewer-stream.cpp similarity index 99% rename from src/bin/lttng-relayd/viewer-stream.c rename to src/bin/lttng-relayd/viewer-stream.cpp index 494b0e621..7a66fde5b 100644 --- a/src/bin/lttng-relayd/viewer-stream.c +++ b/src/bin/lttng-relayd/viewer-stream.cpp @@ -44,7 +44,7 @@ struct relay_viewer_stream *viewer_stream_create(struct relay_stream *stream, ASSERT_LOCKED(stream->lock); - vstream = zmalloc(sizeof(*vstream)); + vstream = (relay_viewer_stream *) zmalloc(sizeof(*vstream)); if (!vstream) { PERROR("relay viewer stream zmalloc"); goto error; diff --git a/src/common/fd-tracker/fd-tracker.h b/src/common/fd-tracker/fd-tracker.h index ec859c085..5801622e2 100644 --- a/src/common/fd-tracker/fd-tracker.h +++ b/src/common/fd-tracker/fd-tracker.h @@ -13,6 +13,10 @@ #include #include +#ifdef __cplusplus +extern "C" { +#endif + struct fs_handle; struct fd_tracker; @@ -138,46 +142,8 @@ int fd_tracker_close_unsuspendable_fd(struct fd_tracker *tracker, */ void fd_tracker_log(struct fd_tracker *tracker); -/* - * Marks the handle as the most recently used and marks the 'fd' as - * "in-use". This prevents the tracker from recycling the underlying - * file descriptor while it is actively being used by a thread. - * - * Don't forget that the tracker may be initiating an fd 'suspension' - * from another thread as the need to free an fd slot may arise from any - * thread within the daemon. - * - * Note that a restorable fd should never be held for longer than - * strictly necessary (e.g. the duration of a syscall()). - * - * Returns the fd on success, otherwise a negative value may be returned - * if the restoration of the fd failed. - */ -int fs_handle_get_fd(struct fs_handle *handle); - -/* - * Used by the application to signify that it is no longer using the - * underlying fd and that it may be suspended. - */ -void fs_handle_put_fd(struct fs_handle *handle); - -/* - * Unlink the file associated to an fs_handle. Note that the unlink - * operation will not be performed immediately. It will only be performed - * once all references to the underlying file (through other fs_handle objects) - * have been released. - * - * However, note that the file will be renamed so as to provide the observable - * effect of an unlink(), that is removing a name from the filesystem. - * - * Returns 0 on success, otherwise a negative value will be returned - * if the operation failed. - */ -int fs_handle_unlink(struct fs_handle *handle); - -/* - * Frees the handle and discards the underlying fd. - */ -int fs_handle_close(struct fs_handle *handle); +#ifdef __cplusplus +} +#endif #endif /* FD_TRACKER_H */ diff --git a/src/common/fd-tracker/utils.h b/src/common/fd-tracker/utils.h index 829b56b6d..ac614c7b1 100644 --- a/src/common/fd-tracker/utils.h +++ b/src/common/fd-tracker/utils.h @@ -12,6 +12,10 @@ #include #include +#ifdef __cplusplus +extern "C" { +#endif + struct lttng_poll_event; /* @@ -46,4 +50,8 @@ struct lttng_directory_handle *fd_tracker_create_directory_handle_from_handle( struct lttng_directory_handle *handle, const char *path); +#ifdef __cplusplus +} +#endif + #endif /* FD_TRACKER_UTILS_H */ diff --git a/src/common/fs-handle.h b/src/common/fs-handle.h index be6419c88..afc5abc48 100644 --- a/src/common/fs-handle.h +++ b/src/common/fs-handle.h @@ -11,6 +11,10 @@ #include #include +#ifdef __cplusplus +extern "C" { +#endif + struct fs_handle; /* @@ -63,4 +67,8 @@ int fs_handle_truncate(struct fs_handle *handle, off_t offset); off_t fs_handle_seek(struct fs_handle *handle, off_t offset, int whence); +#ifdef __cplusplus +} +#endif + #endif /* FS_HANDLE_H */ diff --git a/src/common/index/index.h b/src/common/index/index.h index 25ecc1975..c7bc65682 100644 --- a/src/common/index/index.h +++ b/src/common/index/index.h @@ -17,6 +17,10 @@ #include #include +#ifdef __cplusplus +extern "C" { +#endif + struct lttng_index_file { struct fs_handle *file; uint32_t major; @@ -52,4 +56,8 @@ int lttng_index_file_read(const struct lttng_index_file *index_file, void lttng_index_file_get(struct lttng_index_file *index_file); void lttng_index_file_put(struct lttng_index_file *index_file); +#ifdef __cplusplus +} +#endif + #endif /* _INDEX_H */ diff --git a/src/common/trace-chunk-registry.h b/src/common/trace-chunk-registry.h index 0eee0c21c..f61e56080 100644 --- a/src/common/trace-chunk-registry.h +++ b/src/common/trace-chunk-registry.h @@ -14,6 +14,10 @@ #include #include +#ifdef __cplusplus +extern "C" { +#endif + struct lttng_trace_chunk_registry; /* @@ -92,4 +96,8 @@ lttng_trace_chunk_registry_find_anonymous_chunk( unsigned int lttng_trace_chunk_registry_put_each_chunk( const struct lttng_trace_chunk_registry *registry); +#ifdef __cplusplus +} +#endif + #endif /* LTTNG_TRACE_CHUNK_REGISTRY_H */ diff --git a/src/common/trace-chunk.c b/src/common/trace-chunk.c index 4bc3dbae0..d04d51637 100644 --- a/src/common/trace-chunk.c +++ b/src/common/trace-chunk.c @@ -12,6 +12,7 @@ #include #include #include +#include #include #include #include diff --git a/tests/unit/Makefile.am b/tests/unit/Makefile.am index c8deb2ec3..e1e538657 100644 --- a/tests/unit/Makefile.am +++ b/tests/unit/Makefile.am @@ -146,7 +146,7 @@ test_condition_SOURCES = test_condition.c test_condition_LDADD = $(LIBTAP) $(LIBCOMMON) $(LIBLTTNG_CTL) $(DL_LIBS) # relayd backward compat for groou-by-session utilities -test_relayd_backward_compat_group_by_session_SOURCES = test_relayd_backward_compat_group_by_session.c +test_relayd_backward_compat_group_by_session_SOURCES = test_relayd_backward_compat_group_by_session.cpp test_relayd_backward_compat_group_by_session_LDADD = $(LIBTAP) $(LIBCOMMON) $(RELAYD_OBJS) test_relayd_backward_compat_group_by_session_CPPFLAGS = $(AM_CPPFLAGS) -I$(top_srcdir)/src/bin/lttng-relayd diff --git a/tests/unit/test_fd_tracker.c b/tests/unit/test_fd_tracker.c index 73010c4c1..6df179f9d 100644 --- a/tests/unit/test_fd_tracker.c +++ b/tests/unit/test_fd_tracker.c @@ -24,6 +24,7 @@ #include #include #include +#include #include /* For error.h */ diff --git a/tests/unit/test_relayd_backward_compat_group_by_session.c b/tests/unit/test_relayd_backward_compat_group_by_session.cpp similarity index 100% rename from tests/unit/test_relayd_backward_compat_group_by_session.c rename to tests/unit/test_relayd_backward_compat_group_by_session.cpp -- 2.34.1