From 97535efaa975ca52bf02c2d5e76351bfd2e3defa Mon Sep 17 00:00:00 2001 From: Simon Marchi Date: Fri, 3 Sep 2021 17:31:29 -0400 Subject: [PATCH] common: compile libconsumer, libust-consumer, libkernel-consumer as C++ MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Change-Id: I6d51a069b360121152286a674d551fd5e80bfe2f Signed-off-by: Simon Marchi Signed-off-by: Jérémie Galarneau --- src/common/consumer/Makefile.am | 12 +++++-- ...ta-cache.c => consumer-metadata-cache.cpp} | 2 +- src/common/consumer/consumer-metadata-cache.h | 8 +++++ ...{consumer-stream.c => consumer-stream.cpp} | 8 +++-- src/common/consumer/consumer-stream.h | 8 +++++ .../{consumer-timer.c => consumer-timer.cpp} | 12 +++---- .../consumer/{consumer.c => consumer.cpp} | 32 ++++++++----------- src/common/consumer/consumer.h | 20 ++++++------ ...{metadata-bucket.c => metadata-bucket.cpp} | 18 +++++++---- src/common/consumer/metadata-bucket.h | 9 +++++- src/common/kernel-consumer/Makefile.am | 4 ++- ...{kernel-consumer.c => kernel-consumer.cpp} | 8 ++--- src/common/kernel-consumer/kernel-consumer.h | 8 +++++ src/common/ust-consumer/Makefile.am | 4 ++- .../{ust-consumer.c => ust-consumer.cpp} | 19 +++++------ src/common/ust-consumer/ust-consumer.h | 8 +++++ .../regression/tools/notification/Makefile.am | 8 ++--- ...r_testpoints.c => consumer_testpoints.cpp} | 8 ++--- ...d_testpoints.c => sessiond_testpoints.cpp} | 6 ++-- 19 files changed, 128 insertions(+), 74 deletions(-) rename src/common/consumer/{consumer-metadata-cache.c => consumer-metadata-cache.cpp} (99%) rename src/common/consumer/{consumer-stream.c => consumer-stream.cpp} (99%) rename src/common/consumer/{consumer-timer.c => consumer-timer.cpp} (98%) rename src/common/consumer/{consumer.c => consumer.cpp} (99%) rename src/common/consumer/{metadata-bucket.c => metadata-bucket.cpp} (92%) rename src/common/kernel-consumer/{kernel-consumer.c => kernel-consumer.cpp} (99%) rename src/common/ust-consumer/{ust-consumer.c => ust-consumer.cpp} (99%) rename tests/regression/tools/notification/{consumer_testpoints.c => consumer_testpoints.cpp} (90%) rename tests/regression/tools/notification/{sessiond_testpoints.c => sessiond_testpoints.cpp} (90%) diff --git a/src/common/consumer/Makefile.am b/src/common/consumer/Makefile.am index 55e47b210..ba3ecf1da 100644 --- a/src/common/consumer/Makefile.am +++ b/src/common/consumer/Makefile.am @@ -5,9 +5,15 @@ noinst_LTLIBRARIES = libconsumer.la noinst_HEADERS = consumer-metadata-cache.h consumer-timer.h \ consumer-testpoint.h -libconsumer_la_SOURCES = consumer.c consumer.h consumer-metadata-cache.c \ - consumer-timer.c consumer-stream.c consumer-stream.h \ - metadata-bucket.c metadata-bucket.h +libconsumer_la_SOURCES = \ + consumer.cpp \ + consumer.h \ + consumer-metadata-cache.cpp \ + consumer-stream.cpp \ + consumer-stream.h \ + consumer-timer.cpp \ + metadata-bucket.cpp \ + metadata-bucket.h libconsumer_la_LIBADD = \ $(top_builddir)/src/common/sessiond-comm/libsessiond-comm.la \ diff --git a/src/common/consumer/consumer-metadata-cache.c b/src/common/consumer/consumer-metadata-cache.cpp similarity index 99% rename from src/common/consumer/consumer-metadata-cache.c rename to src/common/consumer/consumer-metadata-cache.cpp index 8ef284840..fdda6be8b 100644 --- a/src/common/consumer/consumer-metadata-cache.c +++ b/src/common/consumer/consumer-metadata-cache.cpp @@ -129,7 +129,7 @@ int consumer_metadata_cache_allocate(struct lttng_consumer_channel *channel) LTTNG_ASSERT(channel); - channel->metadata_cache = zmalloc( + channel->metadata_cache = (consumer_metadata_cache *) zmalloc( sizeof(struct consumer_metadata_cache)); if (!channel->metadata_cache) { PERROR("zmalloc metadata cache struct"); diff --git a/src/common/consumer/consumer-metadata-cache.h b/src/common/consumer/consumer-metadata-cache.h index b8f4efadc..4f8bb763f 100644 --- a/src/common/consumer/consumer-metadata-cache.h +++ b/src/common/consumer/consumer-metadata-cache.h @@ -12,6 +12,10 @@ #include #include +#ifdef __cplusplus +extern "C" { +#endif + enum consumer_metadata_cache_write_status { CONSUMER_METADATA_CACHE_WRITE_STATUS_ERROR = -1, /* @@ -59,4 +63,8 @@ void consumer_metadata_cache_destroy(struct lttng_consumer_channel *channel); int consumer_metadata_cache_flushed(struct lttng_consumer_channel *channel, uint64_t offset, int timer); +#ifdef __cplusplus +} +#endif + #endif /* CONSUMER_METADATA_CACHE_H */ diff --git a/src/common/consumer/consumer-stream.c b/src/common/consumer/consumer-stream.cpp similarity index 99% rename from src/common/consumer/consumer-stream.c rename to src/common/consumer/consumer-stream.cpp index be19c1bfd..fbaf4aef5 100644 --- a/src/common/consumer/consumer-stream.c +++ b/src/common/consumer/consumer-stream.cpp @@ -621,7 +621,7 @@ struct lttng_consumer_stream *consumer_stream_create( int ret; struct lttng_consumer_stream *stream; - stream = zmalloc(sizeof(*stream)); + stream = (lttng_consumer_stream *) zmalloc(sizeof(*stream)); if (stream == NULL) { PERROR("malloc struct lttng_consumer_stream"); ret = -ENOMEM; @@ -717,6 +717,8 @@ struct lttng_consumer_stream *consumer_stream_create( const post_consume_cb post_consume_index_op = channel->is_live ? consumer_stream_sync_metadata_index : consumer_stream_send_index; + const post_consume_cb post_consume_open_new_packet_ = + post_consume_open_new_packet; ret = lttng_dynamic_array_add_element( &stream->read_subbuffer_ops.post_consume_cbs, @@ -728,7 +730,7 @@ struct lttng_consumer_stream *consumer_stream_create( ret = lttng_dynamic_array_add_element( &stream->read_subbuffer_ops.post_consume_cbs, - &(post_consume_cb) { post_consume_open_new_packet }); + &post_consume_open_new_packet_); if (ret) { PERROR("Failed to add `open new packet` callback to stream's post consumption callbacks"); goto error; @@ -1220,7 +1222,7 @@ static ssize_t metadata_bucket_flush( const struct stream_subbuffer *buffer, void *data) { ssize_t ret; - struct lttng_consumer_stream *stream = data; + struct lttng_consumer_stream *stream = (lttng_consumer_stream *) data; ret = consumer_stream_consume_mmap(NULL, stream, buffer); if (ret < 0) { diff --git a/src/common/consumer/consumer-stream.h b/src/common/consumer/consumer-stream.h index c9af63cd8..af0690a25 100644 --- a/src/common/consumer/consumer-stream.h +++ b/src/common/consumer/consumer-stream.h @@ -10,6 +10,10 @@ #include "consumer.h" +#ifdef __cplusplus +extern "C" { +#endif + enum consumer_stream_open_packet_status { CONSUMER_STREAM_OPEN_PACKET_STATUS_OPENED, CONSUMER_STREAM_OPEN_PACKET_STATUS_NO_SPACE, @@ -166,4 +170,8 @@ enum consumer_stream_open_packet_status consumer_stream_open_packet( int consumer_stream_flush_buffer(struct lttng_consumer_stream *stream, bool producer_active); +#ifdef __cplusplus +} +#endif + #endif /* LTTNG_CONSUMER_STREAM_H */ diff --git a/src/common/consumer/consumer-timer.c b/src/common/consumer/consumer-timer.cpp similarity index 98% rename from src/common/consumer/consumer-timer.c rename to src/common/consumer/consumer-timer.cpp index 6d2e6b2b2..f6cb60c3b 100644 --- a/src/common/consumer/consumer-timer.c +++ b/src/common/consumer/consumer-timer.cpp @@ -82,7 +82,7 @@ static void metadata_switch_timer(struct lttng_consumer_local_data *ctx, int ret; struct lttng_consumer_channel *channel; - channel = si->si_value.sival_ptr; + channel = (lttng_consumer_channel *) si->si_value.sival_ptr; LTTNG_ASSERT(channel); if (channel->switch_timer_error) { @@ -280,7 +280,7 @@ static void live_timer(struct lttng_consumer_local_data *ctx, consumer_flush_kernel_index : consumer_flush_ust_index; - channel = si->si_value.sival_ptr; + channel = (lttng_consumer_channel *) si->si_value.sival_ptr; LTTNG_ASSERT(channel); if (channel->switch_timer_error) { @@ -697,14 +697,14 @@ void monitor_timer(struct lttng_consumer_channel *channel) if (ret == -1) { if (errno == EAGAIN) { /* Not an error, the sample is merely dropped. */ - DBG("Channel monitor pipe is full; dropping sample for channel key = %"PRIu64, + DBG("Channel monitor pipe is full; dropping sample for channel key = %" PRIu64, channel->key); } else { PERROR("write to the channel monitor pipe"); } } else { DBG("Sent channel monitoring sample for channel key %" PRIu64 - ", (highest = %" PRIu64 ", lowest = %"PRIu64")", + ", (highest = %" PRIu64 ", lowest = %" PRIu64 ")", channel->key, msg.highest, msg.lowest); } } @@ -738,7 +738,7 @@ void *consumer_timer_thread(void *data) int signr; sigset_t mask; siginfo_t info; - struct lttng_consumer_local_data *ctx = data; + struct lttng_consumer_local_data *ctx = (lttng_consumer_local_data *) data; rcu_register_thread(); @@ -783,7 +783,7 @@ void *consumer_timer_thread(void *data) } else if (signr == LTTNG_CONSUMER_SIG_MONITOR) { struct lttng_consumer_channel *channel; - channel = info.si_value.sival_ptr; + channel = (lttng_consumer_channel *) info.si_value.sival_ptr; monitor_timer(channel); } else if (signr == LTTNG_CONSUMER_SIG_EXIT) { LTTNG_ASSERT(CMM_LOAD_SHARED(consumer_quit)); diff --git a/src/common/consumer/consumer.c b/src/common/consumer/consumer.cpp similarity index 99% rename from src/common/consumer/consumer.c rename to src/common/consumer/consumer.cpp index 84fdbcaaa..47bb5bd98 100644 --- a/src/common/consumer/consumer.c +++ b/src/common/consumer/consumer.cpp @@ -44,11 +44,7 @@ #include #include -struct lttng_consumer_global_data the_consumer_data = { - .stream_count = 0, - .need_update = 1, - .type = LTTNG_CONSUMER_UNKNOWN, -}; +lttng_consumer_global_data the_consumer_data; enum consumer_channel_action { CONSUMER_CHANNEL_ADD, @@ -492,7 +488,7 @@ void lttng_consumer_cleanup_relayd(struct consumer_relayd_sock_pair *relayd) LTTNG_ASSERT(relayd); - DBG("Cleaning up relayd object ID %"PRIu64, relayd->net_seq_idx); + DBG("Cleaning up relayd object ID %" PRIu64, relayd->net_seq_idx); /* Save the net sequence index before destroying the object */ netidx = relayd->net_seq_idx; @@ -663,7 +659,7 @@ static struct consumer_relayd_sock_pair *consumer_allocate_relayd_sock_pair( goto error; } - obj = zmalloc(sizeof(struct consumer_relayd_sock_pair)); + obj = (consumer_relayd_sock_pair *) zmalloc(sizeof(struct consumer_relayd_sock_pair)); if (obj == NULL) { PERROR("zmalloc relayd sock"); goto error; @@ -1028,7 +1024,7 @@ struct lttng_consumer_channel *consumer_allocate_channel(uint64_t key, } } - channel = zmalloc(sizeof(*channel)); + channel = (lttng_consumer_channel *) zmalloc(sizeof(*channel)); if (channel == NULL) { PERROR("malloc struct lttng_consumer_channel"); goto end; @@ -1424,7 +1420,7 @@ struct lttng_consumer_local_data *lttng_consumer_create( the_consumer_data.type == type); the_consumer_data.type = type; - ctx = zmalloc(sizeof(struct lttng_consumer_local_data)); + ctx = (lttng_consumer_local_data *) zmalloc(sizeof(struct lttng_consumer_local_data)); if (ctx == NULL) { PERROR("allocating context"); goto error; @@ -2327,7 +2323,7 @@ void *consumer_thread_metadata_poll(void *data) struct lttng_ht_iter iter; struct lttng_ht_node_u64 *node; struct lttng_poll_event events; - struct lttng_consumer_local_data *ctx = data; + struct lttng_consumer_local_data *ctx = (lttng_consumer_local_data *) data; ssize_t len; rcu_register_thread(); @@ -2547,7 +2543,7 @@ void *consumer_thread_data_poll(void *data) const int nb_pipes_fd = 2; /* Number of FDs with CONSUMER_ENDPOINT_INACTIVE but still open. */ int nb_inactive_fd = 0; - struct lttng_consumer_local_data *ctx = data; + struct lttng_consumer_local_data *ctx = (lttng_consumer_local_data *) data; ssize_t len; rcu_register_thread(); @@ -2560,7 +2556,7 @@ void *consumer_thread_data_poll(void *data) health_code_update(); - local_stream = zmalloc(sizeof(struct lttng_consumer_stream *)); + local_stream = (lttng_consumer_stream **) zmalloc(sizeof(struct lttng_consumer_stream *)); if (local_stream == NULL) { PERROR("local_stream malloc"); goto end; @@ -2585,7 +2581,7 @@ void *consumer_thread_data_poll(void *data) local_stream = NULL; /* Allocate for all fds */ - pollfd = zmalloc((the_consumer_data.stream_count + + pollfd = (struct pollfd *) zmalloc((the_consumer_data.stream_count + nb_pipes_fd) * sizeof(struct pollfd)); if (pollfd == NULL) { @@ -2594,7 +2590,7 @@ void *consumer_thread_data_poll(void *data) goto end; } - local_stream = zmalloc((the_consumer_data.stream_count + + local_stream = (lttng_consumer_stream **) zmalloc((the_consumer_data.stream_count + nb_pipes_fd) * sizeof(struct lttng_consumer_stream *)); if (local_stream == NULL) { @@ -2915,7 +2911,7 @@ void *consumer_thread_channel_poll(void *data) struct lttng_ht_iter iter; struct lttng_ht_node_u64 *node; struct lttng_poll_event events; - struct lttng_consumer_local_data *ctx = data; + struct lttng_consumer_local_data *ctx = (lttng_consumer_local_data *) data; struct lttng_ht *channel_ht; rcu_register_thread(); @@ -3185,7 +3181,7 @@ void *consumer_thread_sessiond_poll(void *data) * making blocking sockets. */ struct pollfd consumer_sockpoll[2]; - struct lttng_consumer_local_data *ctx = data; + struct lttng_consumer_local_data *ctx = (lttng_consumer_local_data *) data; rcu_register_thread(); @@ -3912,7 +3908,7 @@ int consumer_send_status_msg(int sock, int ret_code) struct lttcomm_consumer_status_msg msg; memset(&msg, 0, sizeof(msg)); - msg.ret_code = ret_code; + msg.ret_code = (lttcomm_return_code) ret_code; return lttcomm_send_unix_sock(sock, &msg, sizeof(msg)); } @@ -4322,7 +4318,7 @@ int lttng_consumer_rotate_channel(struct lttng_consumer_channel *channel, stream_idx++) { enum consumer_stream_open_packet_status status; - stream = lttng_dynamic_pointer_array_get_pointer( + stream = (lttng_consumer_stream *) lttng_dynamic_pointer_array_get_pointer( &streams_packet_to_open, stream_idx); pthread_mutex_lock(&stream->lock); diff --git a/src/common/consumer/consumer.h b/src/common/consumer/consumer.h index 1b0ee000b..582385c82 100644 --- a/src/common/consumer/consumer.h +++ b/src/common/consumer/consumer.h @@ -802,30 +802,30 @@ struct lttng_consumer_global_data { * This is nested OUTSIDE the stream lock. * This is nested OUTSIDE the consumer_relayd_sock_pair lock. */ - pthread_mutex_t lock; + pthread_mutex_t lock {}; /* * Number of streams in the data stream hash table declared outside. * Protected by consumer_data.lock. */ - int stream_count; + int stream_count = 0; /* Channel hash table protected by consumer_data.lock. */ - struct lttng_ht *channel_ht; + struct lttng_ht *channel_ht = nullptr; /* Channel hash table indexed by session id. */ - struct lttng_ht *channels_by_session_id_ht; + struct lttng_ht *channels_by_session_id_ht = nullptr; /* * Flag specifying if the local array of FDs needs update in the * poll function. Protected by consumer_data.lock. */ - unsigned int need_update; - enum lttng_consumer_type type; + unsigned int need_update = 1; + enum lttng_consumer_type type = LTTNG_CONSUMER_UNKNOWN; /* * Relayd socket(s) hashtable indexed by network sequence number. Each * stream has an index which associate the right relayd socket to use. */ - struct lttng_ht *relayd_ht; + struct lttng_ht *relayd_ht = nullptr; /* * This hash table contains all streams (metadata and data) indexed by @@ -834,17 +834,17 @@ struct lttng_consumer_global_data { * * This HT uses the "node_session_id" of the consumer stream. */ - struct lttng_ht *stream_list_ht; + struct lttng_ht *stream_list_ht = nullptr; /* * This HT uses the "node_channel_id" of the consumer stream. */ - struct lttng_ht *stream_per_chan_id_ht; + struct lttng_ht *stream_per_chan_id_ht = nullptr; /* * Trace chunk registry indexed by (session_id, chunk_id). */ - struct lttng_trace_chunk_registry *chunk_registry; + struct lttng_trace_chunk_registry *chunk_registry = nullptr; }; /* diff --git a/src/common/consumer/metadata-bucket.c b/src/common/consumer/metadata-bucket.cpp similarity index 92% rename from src/common/consumer/metadata-bucket.c rename to src/common/consumer/metadata-bucket.cpp index 1ee5022e5..160185def 100644 --- a/src/common/consumer/metadata-bucket.c +++ b/src/common/consumer/metadata-bucket.cpp @@ -27,7 +27,7 @@ struct metadata_bucket *metadata_bucket_create( { struct metadata_bucket *bucket; - bucket = zmalloc(sizeof(typeof(*bucket))); + bucket = (metadata_bucket *) zmalloc(sizeof(typeof(*bucket))); if (!bucket) { PERROR("Failed to allocate buffer bucket"); goto end; @@ -126,11 +126,17 @@ enum metadata_bucket_status metadata_bucket_fill(struct metadata_bucket *bucket, flush_size = flushed_view.size - padding_this_buffer; flushed_subbuffer = (typeof(flushed_subbuffer)) { - .buffer.buffer = flushed_view, - .info.metadata.subbuf_size = flush_size, - .info.metadata.padded_subbuf_size = flushed_view.size, - .info.metadata.version = buffer->info.metadata.version, - .info.metadata.coherent = buffer->info.metadata.coherent, + .buffer = { + .buffer = flushed_view, + }, + .info = { + .metadata = { + .subbuf_size = flush_size, + .padded_subbuf_size = flushed_view.size, + .version = buffer->info.metadata.version, + .coherent = buffer->info.metadata.coherent, + }, + }, }; DBG("Metadata bucket flushing %zu bytes (%u sub-buffer%s)", diff --git a/src/common/consumer/metadata-bucket.h b/src/common/consumer/metadata-bucket.h index 0355eb3c0..8868811ef 100644 --- a/src/common/consumer/metadata-bucket.h +++ b/src/common/consumer/metadata-bucket.h @@ -10,6 +10,10 @@ #include +#ifdef __cplusplus +extern "C" { +#endif + struct metadata_bucket; typedef ssize_t (*metadata_bucket_flush_cb)( @@ -30,5 +34,8 @@ enum metadata_bucket_status metadata_bucket_fill(struct metadata_bucket *bucket, void metadata_bucket_reset(struct metadata_bucket *bucket); -#endif /* METADATA_BUCKET_H */ +#ifdef __cplusplus +} +#endif +#endif /* METADATA_BUCKET_H */ diff --git a/src/common/kernel-consumer/Makefile.am b/src/common/kernel-consumer/Makefile.am index cf86e2a63..b1184130e 100644 --- a/src/common/kernel-consumer/Makefile.am +++ b/src/common/kernel-consumer/Makefile.am @@ -2,7 +2,9 @@ noinst_LTLIBRARIES = libkernel-consumer.la -libkernel_consumer_la_SOURCES = kernel-consumer.c kernel-consumer.h +libkernel_consumer_la_SOURCES = \ + kernel-consumer.cpp \ + kernel-consumer.h libkernel_consumer_la_LIBADD = \ $(top_builddir)/src/common/kernel-ctl/libkernel-ctl.la \ diff --git a/src/common/kernel-consumer/kernel-consumer.c b/src/common/kernel-consumer/kernel-consumer.cpp similarity index 99% rename from src/common/kernel-consumer/kernel-consumer.c rename to src/common/kernel-consumer/kernel-consumer.cpp index 236c2c98f..aa443027e 100644 --- a/src/common/kernel-consumer/kernel-consumer.c +++ b/src/common/kernel-consumer/kernel-consumer.cpp @@ -122,7 +122,7 @@ int get_current_subbuf_addr(struct lttng_consumer_stream *stream, { int ret; unsigned long mmap_offset; - const char *mmap_base = stream->mmap_base; + const char *mmap_base = (const char *) stream->mmap_base; ret = kernctl_get_mmap_read_offset(stream->wait_fd, &mmap_offset); if (ret < 0) { @@ -538,7 +538,7 @@ int lttng_kconsumer_recv_cmd(struct lttng_consumer_local_data *ctx, switch (msg.u.channel.type) { case CONSUMER_CHANNEL_TYPE_DATA: case CONSUMER_CHANNEL_TYPE_METADATA: - new_channel->type = msg.u.channel.type; + new_channel->type = (consumer_channel_type) msg.u.channel.type; break; default: abort(); @@ -1223,7 +1223,7 @@ error_rotate_channel: lttng_consumer_clear_channel(channel); if (ret_clear_channel) { ERR("Clear channel failed"); - ret_code = ret_clear_channel; + ret_code = (lttcomm_return_code) ret_clear_channel; } health_code_update(); @@ -1321,7 +1321,7 @@ error_rotate_channel: case LTTNG_CONSUMER_CLOSE_TRACE_CHUNK: { enum lttng_trace_chunk_command_type close_command = - msg.u.close_trace_chunk.close_command.value; + (lttng_trace_chunk_command_type) msg.u.close_trace_chunk.close_command.value; const uint64_t relayd_id = msg.u.close_trace_chunk.relayd_id.value; struct lttcomm_consumer_close_trace_chunk_reply reply; diff --git a/src/common/kernel-consumer/kernel-consumer.h b/src/common/kernel-consumer/kernel-consumer.h index 004becb0f..71a33b73f 100644 --- a/src/common/kernel-consumer/kernel-consumer.h +++ b/src/common/kernel-consumer/kernel-consumer.h @@ -13,6 +13,10 @@ #include #include +#ifdef __cplusplus +extern "C" { +#endif + int lttng_kconsumer_take_snapshot(struct lttng_consumer_stream *stream); int lttng_kconsumer_sample_snapshot_positions( struct lttng_consumer_stream *stream); @@ -27,4 +31,8 @@ int lttng_kconsumer_data_pending(struct lttng_consumer_stream *stream); enum sync_metadata_status lttng_kconsumer_sync_metadata( struct lttng_consumer_stream *metadata); +#ifdef __cplusplus +} +#endif + #endif /* _LTTNG_KCONSUMER_H */ diff --git a/src/common/ust-consumer/Makefile.am b/src/common/ust-consumer/Makefile.am index 5ab0fe602..26f166785 100644 --- a/src/common/ust-consumer/Makefile.am +++ b/src/common/ust-consumer/Makefile.am @@ -4,7 +4,9 @@ if HAVE_LIBLTTNG_UST_CTL noinst_LTLIBRARIES = libust-consumer.la -libust_consumer_la_SOURCES = ust-consumer.c ust-consumer.h +libust_consumer_la_SOURCES = \ + ust-consumer.cpp \ + ust-consumer.h libust_consumer_la_LIBADD = \ $(UST_CTL_LIBS) \ diff --git a/src/common/ust-consumer/ust-consumer.c b/src/common/ust-consumer/ust-consumer.cpp similarity index 99% rename from src/common/ust-consumer/ust-consumer.c rename to src/common/ust-consumer/ust-consumer.cpp index 310b670b1..c9ec3c557 100644 --- a/src/common/ust-consumer/ust-consumer.c +++ b/src/common/ust-consumer/ust-consumer.cpp @@ -407,7 +407,7 @@ static int create_ust_channel(struct lttng_consumer_channel *channel, nr_stream_fds = 1; else nr_stream_fds = lttng_ust_ctl_get_nr_stream_per_channel(); - stream_fds = zmalloc(nr_stream_fds * sizeof(*stream_fds)); + stream_fds = (int *) zmalloc(nr_stream_fds * sizeof(*stream_fds)); if (!stream_fds) { ret = -1; goto error_alloc; @@ -1048,7 +1048,7 @@ int get_current_subbuf_addr(struct lttng_consumer_stream *stream, unsigned long mmap_offset; const char *mmap_base; - mmap_base = lttng_ust_ctl_get_mmap_base(stream->ustream); + mmap_base = (const char *) lttng_ust_ctl_get_mmap_base(stream->ustream); if (!mmap_base) { ERR("Failed to get mmap base for stream `%s`", stream->name); @@ -1285,7 +1285,7 @@ int lttng_ustconsumer_recv_metadata(int sock, uint64_t key, uint64_t offset, DBG("UST consumer push metadata key %" PRIu64 " of len %" PRIu64, key, len); - metadata_str = zmalloc(len * sizeof(char)); + metadata_str = (char *) zmalloc(len * sizeof(char)); if (!metadata_str) { PERROR("zmalloc metadata string"); ret_code = LTTCOMM_CONSUMERD_ENOMEM; @@ -1720,7 +1720,7 @@ end_get_channel_nosignal: ret = close_metadata(msg.u.close_metadata.key); if (ret != 0) { - ret_code = ret; + ret_code = (lttcomm_return_code) ret; } goto end_msg_sessiond; @@ -1731,7 +1731,7 @@ end_get_channel_nosignal: ret = flush_channel(msg.u.flush_channel.key); if (ret != 0) { - ret_code = ret; + ret_code = (lttcomm_return_code) ret; } goto end_msg_sessiond; @@ -1743,7 +1743,7 @@ end_get_channel_nosignal: ret = clear_quiescent_channel( msg.u.clear_quiescent_channel.key); if (ret != 0) { - ret_code = ret; + ret_code = (lttcomm_return_code) ret; } goto end_msg_sessiond; @@ -1810,7 +1810,7 @@ end_get_channel_nosignal: /* error receiving from sessiond */ goto error_push_metadata_fatal; } else { - ret_code = ret; + ret_code = (lttcomm_return_code) ret; goto end_push_metadata_msg_sessiond; } end_push_metadata_msg_sessiond: @@ -1824,7 +1824,7 @@ error_push_metadata_fatal: ret = setup_metadata(ctx, msg.u.setup_metadata.key); if (ret) { - ret_code = ret; + ret_code = (lttcomm_return_code) ret; } goto end_msg_sessiond; } @@ -2101,7 +2101,7 @@ end_rotate_channel_nosignal: found_channel); if (ret_clear_channel) { ERR("Clear channel failed key %" PRIu64, key); - ret_code = ret_clear_channel; + ret_code = (lttcomm_return_code) ret_clear_channel; } health_code_update(); @@ -2200,6 +2200,7 @@ end_rotate_channel_nosignal: case LTTNG_CONSUMER_CLOSE_TRACE_CHUNK: { enum lttng_trace_chunk_command_type close_command = + (lttng_trace_chunk_command_type) msg.u.close_trace_chunk.close_command.value; const uint64_t relayd_id = msg.u.close_trace_chunk.relayd_id.value; diff --git a/src/common/ust-consumer/ust-consumer.h b/src/common/ust-consumer/ust-consumer.h index e2507a7f4..29ae853da 100644 --- a/src/common/ust-consumer/ust-consumer.h +++ b/src/common/ust-consumer/ust-consumer.h @@ -13,6 +13,10 @@ #include #include +#ifdef __cplusplus +extern "C" { +#endif + #ifdef HAVE_LIBLTTNG_UST_CTL int lttng_ustconsumer_take_snapshot(struct lttng_consumer_stream *stream); @@ -240,4 +244,8 @@ void lttng_ustconsumer_sigbus_handle(void *addr) } #endif /* HAVE_LIBLTTNG_UST_CTL */ +#ifdef __cplusplus +} +#endif + #endif /* _LTTNG_USTCONSUMER_H */ diff --git a/tests/regression/tools/notification/Makefile.am b/tests/regression/tools/notification/Makefile.am index b9e4b8ac2..eaab5314a 100644 --- a/tests/regression/tools/notification/Makefile.am +++ b/tests/regression/tools/notification/Makefile.am @@ -12,8 +12,8 @@ if NO_SHARED CLEANFILES = libpause_consumer.so libpause_consumer.so.debug libpause_sessiond.so libpause_sessiond.so.debug EXTRA_DIST = \ base_client.c \ - consumer_testpoints.c \ - sessiond_testpoints.c \ + consumer_testpoints.cpp \ + sessiond_testpoints.cpp \ notification.c \ test_notification_kernel_buffer_usage \ test_notification_kernel_capture \ @@ -35,7 +35,7 @@ else FORCE_SHARED_LIB_OPTIONS = -module -shared -avoid-version \ -rpath $(abs_builddir) -libpause_consumer_la_SOURCES = consumer_testpoints.c +libpause_consumer_la_SOURCES = consumer_testpoints.cpp libpause_consumer_la_LIBADD = \ $(top_builddir)/src/common/sessiond-comm/libsessiond-comm.la \ $(top_builddir)/src/common/libcommon.la \ @@ -43,7 +43,7 @@ libpause_consumer_la_LIBADD = \ $(DL_LIBS) libpause_consumer_la_LDFLAGS = $(FORCE_SHARED_LIB_OPTIONS) -libpause_sessiond_la_SOURCES = sessiond_testpoints.c +libpause_sessiond_la_SOURCES = sessiond_testpoints.cpp libpause_sessiond_la_LIBADD = \ $(top_builddir)/src/common/libcommon.la \ $(top_builddir)/src/lib/lttng-ctl/liblttng-ctl.la \ diff --git a/tests/regression/tools/notification/consumer_testpoints.c b/tests/regression/tools/notification/consumer_testpoints.cpp similarity index 90% rename from tests/regression/tools/notification/consumer_testpoints.c rename to tests/regression/tools/notification/consumer_testpoints.cpp index 6294683f9..07c855c9c 100644 --- a/tests/regression/tools/notification/consumer_testpoints.c +++ b/tests/regression/tools/notification/consumer_testpoints.cpp @@ -47,7 +47,7 @@ void __attribute__((destructor)) pause_pipe_fini(void) * thread to create a named pipe/FIFO which a test application can use to either * pause or resume the consumption of data. */ -LTTNG_EXPORT int __testpoint_consumerd_thread_data(void); +extern "C" LTTNG_EXPORT int __testpoint_consumerd_thread_data(void); int __testpoint_consumerd_thread_data(void) { int ret = 0; @@ -66,9 +66,9 @@ int __testpoint_consumerd_thread_data(void) * dynamically would not allow this shared object to be LD_PRELOAD-ed * when launching the session daemon. */ - data_consumption_state = dlsym(NULL, "data_consumption_paused"); + data_consumption_state = (int *) dlsym(NULL, "data_consumption_paused"); LTTNG_ASSERT(data_consumption_state); - lttng_consumer_get_type = dlsym(NULL, "lttng_consumer_get_type"); + lttng_consumer_get_type = (lttng_consumer_type (*)()) dlsym(NULL, "lttng_consumer_get_type"); LTTNG_ASSERT(lttng_consumer_get_type); switch (lttng_consumer_get_type()) { @@ -107,7 +107,7 @@ end: return ret; } -LTTNG_EXPORT int __testpoint_consumerd_thread_data_poll(void); +extern "C" LTTNG_EXPORT int __testpoint_consumerd_thread_data_poll(void); int __testpoint_consumerd_thread_data_poll(void) { int ret = 0; diff --git a/tests/regression/tools/notification/sessiond_testpoints.c b/tests/regression/tools/notification/sessiond_testpoints.cpp similarity index 90% rename from tests/regression/tools/notification/sessiond_testpoints.c rename to tests/regression/tools/notification/sessiond_testpoints.cpp index 2bfd7cab7..fa3fe7f41 100644 --- a/tests/regression/tools/notification/sessiond_testpoints.c +++ b/tests/regression/tools/notification/sessiond_testpoints.cpp @@ -43,7 +43,7 @@ void __attribute__((destructor)) pause_pipe_fini(void) lttng_pipe_destroy(pause_pipe); } -LTTNG_EXPORT int __testpoint_sessiond_thread_notification(void); +extern "C" LTTNG_EXPORT int __testpoint_sessiond_thread_notification(void); int __testpoint_sessiond_thread_notification(void) { int ret = 0; @@ -56,7 +56,7 @@ int __testpoint_sessiond_thread_notification(void) goto end; } - notifier_notif_consumption_state = dlsym(NULL, "notifier_consumption_paused"); + notifier_notif_consumption_state = (int *) dlsym(NULL, "notifier_consumption_paused"); LTTNG_ASSERT(notifier_notif_consumption_state); ret = asprintf(&pause_pipe_path, "%s", pause_pipe_path_prefix); @@ -80,7 +80,7 @@ end: return ret; } -LTTNG_EXPORT int __testpoint_sessiond_handle_notifier_event_pipe(void); +extern "C" LTTNG_EXPORT int __testpoint_sessiond_handle_notifier_event_pipe(void); int __testpoint_sessiond_handle_notifier_event_pipe(void) { int ret = 0; -- 2.34.1