From 7966af5763c4aaca39df9bbfa9277ff15715c720 Mon Sep 17 00:00:00 2001 From: Simon Marchi Date: Wed, 6 Oct 2021 12:14:41 -0400 Subject: [PATCH] bin: compile lttng-sessiond as C++ MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Same as commit 48a400056134 ("bin: compile lttng as C++"), but change lttng-sessiond to be a C++ program. In addition to the categories of changes already mentioned in that commit's message, here are some interesting changes: - Add an include in trigger.h, an exported header, to fix: CXX notification-thread.lo In file included from /home/simark/src/lttng-tools/src/bin/lttng-sessiond/notification-thread.cpp:9: /home/simark/src/lttng-tools/include/lttng/trigger/trigger.h:142:13: error: use of enum ‘lttng_error_code’ without previous declaration 142 | extern enum lttng_error_code lttng_register_trigger_with_name( | ^~~~~~~~~~~~~~~~ - We get this with clang: CXX lttng-conf.o In file included from /home/simark/src/lttng-tools/src/bin/lttng/conf.cpp:18: In file included from /home/simark/src/lttng-tools/src/common/common.h:14: In file included from /home/simark/src/lttng-tools/src/common/runas.h:17: In file included from /home/simark/src/lttng-tools/src/common/sessiond-comm/sessiond-comm.h:38: In file included from /home/simark/src/lttng-tools/src/common/unix.h:17: /home/simark/src/lttng-tools/src/common/payload-view.h:82:27: error: 'lttng_payload_view_from_payload' has C-linkage specified, but returns user-defined type 'struct lttng_payload_view' which is incompatible with C [-Werror,-Wreturn-type-c-linkage] struct lttng_payload_view lttng_payload_view_from_payload( ^ Turns out that because of the "const" field in lttng_payload_view, clang doesn't consider that type incompatible with C. I don't really want to remove the "const" for C code using that API, so conditionally remove it if we are compiling with clang in C++. - clang gives: CXX event.lo In file included from /home/simark/src/lttng-tools/src/bin/lttng-sessiond/event.cpp:19: /home/simark/src/lttng-tools/src/common/bytecode/bytecode.h:50:1: error: struct has size 0 in C, size 1 in C++ [-Werror,-Wextern-c-compat] struct literal_string { ^ It looks like that type isn't even used? Remove it. - it's not possible to initialize some union members, for example with lttcomm_consumer_msg, in consumer.cpp. Initialize it in a separate statement. - It's not possible to use the transparent union trick when calling urcu function, for example in thread_application_registration, in register.cpp. We need to instantiate a cds_wfcq_head_ptr_t object, assign the appropriate field, and pass that object to the function. - the ALIGNED_CONST_PTR trick does not work in C++: CXX consumer.lo In file included from /home/simark/src/lttng-tools/src/common/error.h:19, from /home/simark/src/lttng-tools/src/common/common.h:12, from /home/simark/src/lttng-tools/src/bin/lttng-sessiond/consumer.cpp:19: /home/simark/src/lttng-tools/src/bin/lttng-sessiond/consumer.cpp: In function ‘int consumer_send_relayd_socket(consumer_socket*, lttcomm_relayd_sock*, consumer_output*, lttng_stream_type, uint64_t, const char*, const char*, const char*, int, const uint64_t*, time_t, bool)’: /home/simark/src/lttng-tools/src/common/macros.h:116:58: error: expected primary-expression before ‘]’ token 116 | #define ALIGNED_CONST_PTR(value) (((const typeof(value) []) { value })) | ^ /home/simark/src/lttng-tools/src/bin/lttng-sessiond/consumer.cpp:1192:48: note: in expansion of macro ‘ALIGNED_CONST_PTR’ 1192 | ret = consumer_send_fds(consumer_sock, ALIGNED_CONST_PTR(rsock->sock.fd), 1); | ^~~~~~~~~~~~~~~~~ Replace uses with copying the data in a local variable (which is properly aligned), and pass the address to that variable to the function. - In consumer.h, an array field in a structure is defined using the max macro. It can't be replaced with std::max, since std::max isn't constexpr in C++11. Define a max_constexpr function locally and use it. - g++ 7 doesn't support non-trivial designated initializers, leading to errors like: CXX globals.lo /home/smarchi/src/lttng-tools/src/bin/lttng-sessiond/globals.cpp:44:1: sorry, unimplemented: non-trivial designated initializers not supported }; ^ Change consumer_data to have a constructor instead. Change initializations of some structures, such as lttcomm_lttng_msg, to initialize the fields separate from the variable declaration. This requires making these variable non-const which is not ideal. But once everything is C++, these types could get a fancy constructor, and then they can be made const again. - When compiling without UST support the stub versions of functions ust_app_rotate_session & co, in ust-app.h, are used. Some of them have the return type "enum lttng_error_code", but return 0, an invalid value, causing: CXX main.o In file included from /home/smarchi/src/lttng-tools/src/bin/lttng-sessiond/lttng-sessiond.h:22:0, from /home/smarchi/src/lttng-tools/src/bin/lttng-sessiond/main.cpp:45: /home/smarchi/src/lttng-tools/src/bin/lttng-sessiond/ust-app.h: In function ‘lttng_error_code ust_app_snapshot_record(ltt_ust_session*, const consumer_output*, int, uint64_t)’: /home/smarchi/src/lttng-tools/src/bin/lttng-sessiond/ust-app.h:575:9: error: invalid conversion from ‘int’ to ‘lttng_error_code’ [-fpermissive] return 0; ^ Change these functions to return LTTNG_ERR_UNK. These functions are not supposed to be called if UST support is not included. But even if they were: all their callers check that the return value is not LTTNG_OK. The value 0 would be considered an error, so will be LTTNG_ERR_UNK. Change-Id: I2cdd34459a54b1943087b43843ef20b35b7bf7d8 Signed-off-by: Simon Marchi Signed-off-by: Jérémie Galarneau --- include/lttng/action/action-internal.h | 8 ++ include/lttng/action/list-internal.h | 8 ++ .../lttng/condition/buffer-usage-internal.h | 8 ++ .../condition/event-rule-matches-internal.h | 8 ++ .../session-consumed-size-internal.h | 8 ++ .../condition/session-rotation-internal.h | 8 ++ include/lttng/error-query-internal.h | 8 ++ include/lttng/event-internal.h | 8 ++ include/lttng/health-internal.h | 8 ++ include/lttng/location-internal.h | 8 ++ include/lttng/log-level-rule-internal.h | 8 ++ .../notification/notification-internal.h | 8 ++ include/lttng/session-descriptor-internal.h | 8 ++ include/lttng/trigger/trigger.h | 1 + include/lttng/userspace-probe-internal.h | 8 ++ src/bin/lttng-sessiond/Makefile.am | 96 +++++++-------- ...{action-executor.c => action-executor.cpp} | 67 +++++------ .../{agent-thread.c => agent-thread.cpp} | 10 +- src/bin/lttng-sessiond/{agent.c => agent.cpp} | 51 ++++---- ...{buffer-registry.c => buffer-registry.cpp} | 16 +-- .../lttng-sessiond/{channel.c => channel.cpp} | 4 +- src/bin/lttng-sessiond/{clear.c => clear.cpp} | 4 +- .../lttng-sessiond/{client.c => client.cpp} | 113 ++++++++++-------- src/bin/lttng-sessiond/{cmd.c => cmd.cpp} | 59 ++++----- ...tion-internal.c => condition-internal.cpp} | 0 src/bin/lttng-sessiond/condition-internal.h | 9 ++ .../{consumer.c => consumer.cpp} | 28 +++-- src/bin/lttng-sessiond/consumer.h | 41 +++++-- .../lttng-sessiond/{context.c => context.cpp} | 0 .../{dispatch.c => dispatch.cpp} | 8 +- ....c => event-notifier-error-accounting.cpp} | 32 ++--- src/bin/lttng-sessiond/{event.c => event.cpp} | 2 +- .../{fd-limit.c => fd-limit.cpp} | 2 +- .../lttng-sessiond/{globals.c => globals.cpp} | 29 +---- .../lttng-sessiond/{health.c => health.cpp} | 8 +- .../{ht-cleanup.c => ht-cleanup.cpp} | 0 ...{kernel-consumer.c => kernel-consumer.cpp} | 0 .../lttng-sessiond/{kernel.c => kernel.cpp} | 8 +- .../{lttng-syscall.c => lttng-syscall.cpp} | 14 +-- src/bin/lttng-sessiond/{main.c => main.cpp} | 2 +- .../{manage-apps.c => manage-apps.cpp} | 8 +- ...{manage-consumer.c => manage-consumer.cpp} | 14 +-- .../{manage-kernel.c => manage-kernel.cpp} | 8 +- .../{modprobe.c => modprobe.cpp} | 8 +- ...nds.c => notification-thread-commands.cpp} | 4 +- ...vents.c => notification-thread-events.cpp} | 42 +++---- ...ation-thread.c => notification-thread.cpp} | 8 +- .../{notify-apps.c => notify-apps.cpp} | 8 +- .../{process-utils.c => process-utils.cpp} | 0 .../{register.c => register.cpp} | 16 +-- .../lttng-sessiond/{rotate.c => rotate.cpp} | 0 ...{rotation-thread.c => rotation-thread.cpp} | 10 +- src/bin/lttng-sessiond/{save.c => save.cpp} | 4 +- .../lttng-sessiond/{session.c => session.cpp} | 8 +- ...{sessiond-config.c => sessiond-config.cpp} | 68 ++++++----- .../{snapshot.c => snapshot.cpp} | 2 +- .../{thread-utils.c => thread-utils.cpp} | 0 .../lttng-sessiond/{thread.c => thread.cpp} | 2 +- src/bin/lttng-sessiond/{timer.c => timer.cpp} | 2 +- .../{trace-kernel.c => trace-kernel.cpp} | 24 ++-- .../{trace-ust.c => trace-ust.cpp} | 20 ++-- .../lttng-sessiond/{tracker.c => tracker.cpp} | 6 +- ...-error-query.c => trigger-error-query.cpp} | 0 .../lttng-sessiond/{ust-app.c => ust-app.cpp} | 50 ++++---- src/bin/lttng-sessiond/ust-app.h | 10 +- .../{ust-consumer.c => ust-consumer.cpp} | 0 src/bin/lttng-sessiond/ust-ctl-internal.h | 8 ++ ...{ust-field-utils.c => ust-field-utils.cpp} | 0 .../{ust-metadata.c => ust-metadata.cpp} | 2 +- .../{ust-registry.c => ust-registry.cpp} | 18 +-- .../{ust-sigbus.c => ust-sigbus.cpp} | 0 src/bin/lttng-sessiond/{utils.c => utils.cpp} | 0 src/common/buffer-view.h | 8 ++ src/common/bytecode/bytecode.h | 12 +- src/common/compat/directory-handle.h | 9 ++ src/common/compat/poll.h | 24 ++++ src/common/config/session-config.h | 8 ++ src/common/context.h | 8 ++ src/common/credentials.h | 8 ++ src/common/daemonize.h | 8 ++ src/common/defaults.h | 8 ++ src/common/dynamic-buffer.h | 8 ++ src/common/fd-handle.h | 8 ++ src/common/filter.h | 8 ++ src/common/futex.h | 8 ++ src/common/hashtable/hashtable.h | 12 +- src/common/hashtable/utils.h | 8 ++ src/common/index-allocator.h | 8 ++ src/common/kernel-ctl/kernel-ctl.h | 8 ++ src/common/macros.h | 7 -- src/common/optional.h | 4 +- src/common/payload-view.h | 29 ++++- src/common/payload.h | 8 ++ src/common/pipe.h | 8 ++ src/common/readwrite.h | 8 ++ src/common/relayd/relayd.h | 8 ++ src/common/runas.h | 8 ++ src/common/sessiond-comm/inet.c | 21 ++-- src/common/sessiond-comm/inet.h | 8 ++ src/common/sessiond-comm/inet6.c | 19 ++- src/common/sessiond-comm/sessiond-comm.h | 8 ++ src/common/shm.h | 8 ++ src/common/testpoint/testpoint.h | 10 +- src/common/trace-chunk.h | 8 ++ src/common/unix.h | 8 ++ src/common/uuid.h | 8 ++ src/common/waiter.h | 8 ++ tests/unit/Makefile.am | 6 +- ...est_kernel_data.c => test_kernel_data.cpp} | 0 .../unit/{test_session.c => test_session.cpp} | 0 .../{test_ust_data.c => test_ust_data.cpp} | 6 +- tests/utils/tap/tap.h | 8 ++ 112 files changed, 928 insertions(+), 505 deletions(-) rename src/bin/lttng-sessiond/{action-executor.c => action-executor.cpp} (95%) rename src/bin/lttng-sessiond/{agent-thread.c => agent-thread.cpp} (97%) rename src/bin/lttng-sessiond/{agent.c => agent.cpp} (97%) rename src/bin/lttng-sessiond/{buffer-registry.c => buffer-registry.cpp} (97%) rename src/bin/lttng-sessiond/{channel.c => channel.cpp} (98%) rename src/bin/lttng-sessiond/{clear.c => clear.cpp} (97%) rename src/bin/lttng-sessiond/{client.c => client.cpp} (96%) rename src/bin/lttng-sessiond/{cmd.c => cmd.cpp} (98%) rename src/bin/lttng-sessiond/{condition-internal.c => condition-internal.cpp} (100%) rename src/bin/lttng-sessiond/{consumer.c => consumer.cpp} (98%) rename src/bin/lttng-sessiond/{context.c => context.cpp} (100%) rename src/bin/lttng-sessiond/{dispatch.c => dispatch.cpp} (98%) rename src/bin/lttng-sessiond/{event-notifier-error-accounting.c => event-notifier-error-accounting.cpp} (97%) rename src/bin/lttng-sessiond/{event.c => event.cpp} (99%) rename src/bin/lttng-sessiond/{fd-limit.c => fd-limit.cpp} (97%) rename src/bin/lttng-sessiond/{globals.c => globals.cpp} (64%) rename src/bin/lttng-sessiond/{health.c => health.cpp} (95%) rename src/bin/lttng-sessiond/{ht-cleanup.c => ht-cleanup.cpp} (100%) rename src/bin/lttng-sessiond/{kernel-consumer.c => kernel-consumer.cpp} (100%) rename src/bin/lttng-sessiond/{kernel.c => kernel.cpp} (99%) rename src/bin/lttng-sessiond/{lttng-syscall.c => lttng-syscall.cpp} (92%) rename src/bin/lttng-sessiond/{main.c => main.cpp} (99%) rename src/bin/lttng-sessiond/{manage-apps.c => manage-apps.cpp} (95%) rename src/bin/lttng-sessiond/{manage-consumer.c => manage-consumer.cpp} (96%) rename src/bin/lttng-sessiond/{manage-kernel.c => manage-kernel.cpp} (97%) rename src/bin/lttng-sessiond/{modprobe.c => modprobe.cpp} (98%) rename src/bin/lttng-sessiond/{notification-thread-commands.c => notification-thread-commands.cpp} (98%) rename src/bin/lttng-sessiond/{notification-thread-events.c => notification-thread-events.cpp} (98%) rename src/bin/lttng-sessiond/{notification-thread.c => notification-thread.cpp} (98%) rename src/bin/lttng-sessiond/{notify-apps.c => notify-apps.cpp} (95%) rename src/bin/lttng-sessiond/{process-utils.c => process-utils.cpp} (100%) rename src/bin/lttng-sessiond/{register.c => register.cpp} (95%) rename src/bin/lttng-sessiond/{rotate.c => rotate.cpp} (100%) rename src/bin/lttng-sessiond/{rotation-thread.c => rotation-thread.cpp} (98%) rename src/bin/lttng-sessiond/{save.c => save.cpp} (99%) rename src/bin/lttng-sessiond/{session.c => session.cpp} (99%) rename src/bin/lttng-sessiond/{sessiond-config.c => sessiond-config.cpp} (94%) rename src/bin/lttng-sessiond/{snapshot.c => snapshot.cpp} (99%) rename src/bin/lttng-sessiond/{thread-utils.c => thread-utils.cpp} (100%) rename src/bin/lttng-sessiond/{thread.c => thread.cpp} (98%) rename src/bin/lttng-sessiond/{timer.c => timer.cpp} (99%) rename src/bin/lttng-sessiond/{trace-kernel.c => trace-kernel.cpp} (96%) rename src/bin/lttng-sessiond/{trace-ust.c => trace-ust.cpp} (98%) rename src/bin/lttng-sessiond/{tracker.c => tracker.cpp} (97%) rename src/bin/lttng-sessiond/{trigger-error-query.c => trigger-error-query.cpp} (100%) rename src/bin/lttng-sessiond/{ust-app.c => ust-app.cpp} (99%) rename src/bin/lttng-sessiond/{ust-consumer.c => ust-consumer.cpp} (100%) rename src/bin/lttng-sessiond/{ust-field-utils.c => ust-field-utils.cpp} (100%) rename src/bin/lttng-sessiond/{ust-metadata.c => ust-metadata.cpp} (99%) rename src/bin/lttng-sessiond/{ust-registry.c => ust-registry.cpp} (98%) rename src/bin/lttng-sessiond/{ust-sigbus.c => ust-sigbus.cpp} (100%) rename src/bin/lttng-sessiond/{utils.c => utils.cpp} (100%) rename tests/unit/{test_kernel_data.c => test_kernel_data.cpp} (100%) rename tests/unit/{test_session.c => test_session.cpp} (100%) rename tests/unit/{test_ust_data.c => test_ust_data.cpp} (97%) diff --git a/include/lttng/action/action-internal.h b/include/lttng/action/action-internal.h index 71270a835..b55a6d59b 100644 --- a/include/lttng/action/action-internal.h +++ b/include/lttng/action/action-internal.h @@ -19,6 +19,10 @@ #include #include +#ifdef __cplusplus +extern "C" { +#endif + struct lttng_rate_policy; struct mi_writer; struct mi_lttng_error_query_callbacks; @@ -128,4 +132,8 @@ enum lttng_error_code lttng_action_mi_serialize(const struct lttng_trigger *trig *error_query_callbacks, struct lttng_dynamic_array *action_path_indexes); +#ifdef __cplusplus +} +#endif + #endif /* LTTNG_ACTION_INTERNAL_H */ diff --git a/include/lttng/action/list-internal.h b/include/lttng/action/list-internal.h index 231755fd6..3d7a5ba60 100644 --- a/include/lttng/action/list-internal.h +++ b/include/lttng/action/list-internal.h @@ -12,6 +12,10 @@ #include +#ifdef __cplusplus +extern "C" { +#endif + struct lttng_action; struct lttng_payload_view; struct mi_writer; @@ -39,4 +43,8 @@ enum lttng_error_code lttng_action_list_mi_serialize(const struct lttng_trigger *error_query_callbacks, struct lttng_dynamic_array *action_path_indexes); +#ifdef __cplusplus +} +#endif + #endif /* LTTNG_ACTION_LIST_INTERNAL_H */ diff --git a/include/lttng/condition/buffer-usage-internal.h b/include/lttng/condition/buffer-usage-internal.h index 1e6d5a509..6ea19e065 100644 --- a/include/lttng/condition/buffer-usage-internal.h +++ b/include/lttng/condition/buffer-usage-internal.h @@ -15,6 +15,10 @@ #include "common/buffer-view.h" #include +#ifdef __cplusplus +extern "C" { +#endif + struct lttng_condition_buffer_usage { struct lttng_condition parent; struct { @@ -77,4 +81,8 @@ ssize_t lttng_evaluation_buffer_usage_high_create_from_payload( struct lttng_payload_view *view, struct lttng_evaluation **evaluation); +#ifdef __cplusplus +} +#endif + #endif /* LTTNG_CONDITION_BUFFER_USAGE_INTERNAL_H */ diff --git a/include/lttng/condition/event-rule-matches-internal.h b/include/lttng/condition/event-rule-matches-internal.h index ef39f4f04..4aac9f991 100644 --- a/include/lttng/condition/event-rule-matches-internal.h +++ b/include/lttng/condition/event-rule-matches-internal.h @@ -16,6 +16,10 @@ #include #include +#ifdef __cplusplus +extern "C" { +#endif + struct lttng_capture_descriptor { struct lttng_event_expr *event_expression; struct lttng_bytecode *bytecode; @@ -86,4 +90,8 @@ const struct lttng_bytecode * lttng_condition_event_rule_matches_get_capture_bytecode_at_index( const struct lttng_condition *condition, unsigned int index); +#ifdef __cplusplus +} +#endif + #endif /* LTTNG_CONDITION_EVENT_RULE_MATCHES_INTERNAL_H */ diff --git a/include/lttng/condition/session-consumed-size-internal.h b/include/lttng/condition/session-consumed-size-internal.h index 9340a5f23..07c5953e1 100644 --- a/include/lttng/condition/session-consumed-size-internal.h +++ b/include/lttng/condition/session-consumed-size-internal.h @@ -14,6 +14,10 @@ #include #include +#ifdef __cplusplus +extern "C" { +#endif + struct lttng_payload; struct lttng_payload_view; @@ -53,4 +57,8 @@ ssize_t lttng_evaluation_session_consumed_size_create_from_payload( struct lttng_payload_view *view, struct lttng_evaluation **evaluation); +#ifdef __cplusplus +} +#endif + #endif /* LTTNG_CONDITION_SESSION_CONSUMED_SIZE_INTERNAL_H */ diff --git a/include/lttng/condition/session-rotation-internal.h b/include/lttng/condition/session-rotation-internal.h index c723c6d6a..e5993e960 100644 --- a/include/lttng/condition/session-rotation-internal.h +++ b/include/lttng/condition/session-rotation-internal.h @@ -15,6 +15,10 @@ #include #include +#ifdef __cplusplus +extern "C" { +#endif + struct lttng_condition_session_rotation { struct lttng_condition parent; char *session_name; @@ -61,4 +65,8 @@ ssize_t lttng_evaluation_session_rotation_completed_create_from_payload( struct lttng_payload_view *view, struct lttng_evaluation **evaluation); +#ifdef __cplusplus +} +#endif + #endif /* LTTNG_CONDITION_SESSION_ROTATION_INTERNAL_H */ diff --git a/include/lttng/error-query-internal.h b/include/lttng/error-query-internal.h index 07e2280d7..d3072f54b 100644 --- a/include/lttng/error-query-internal.h +++ b/include/lttng/error-query-internal.h @@ -15,6 +15,10 @@ #include #include +#ifdef __cplusplus +extern "C" { +#endif + struct mi_writer; enum lttng_error_query_target_type { @@ -78,4 +82,8 @@ enum lttng_error_code lttng_error_query_results_mi_serialize( const struct lttng_error_query_results *results, struct mi_writer *writer); +#ifdef __cplusplus +} +#endif + #endif /* LTTNG_ERROR_QUERY_INTERNAL_H */ diff --git a/include/lttng/event-internal.h b/include/lttng/event-internal.h index 8d03fbdec..7370d0510 100644 --- a/include/lttng/event-internal.h +++ b/include/lttng/event-internal.h @@ -15,6 +15,10 @@ #include #include +#ifdef __cplusplus +extern "C" { +#endif + struct lttng_userspace_probe_location; struct lttng_event_extended { @@ -35,4 +39,8 @@ struct lttng_event_extended { struct lttng_event *lttng_event_copy(const struct lttng_event *event); +#ifdef __cplusplus +} +#endif + #endif /* LTTNG_EVENT_INTERNAL_H */ diff --git a/include/lttng/health-internal.h b/include/lttng/health-internal.h index ceda0a8dd..875cc960b 100644 --- a/include/lttng/health-internal.h +++ b/include/lttng/health-internal.h @@ -17,6 +17,10 @@ #include #include +#ifdef __cplusplus +extern "C" { +#endif + /* * These are the value added to the current state depending of the position in * the thread where is either waiting on a poll() or running in the code. @@ -116,4 +120,8 @@ int health_check_state(struct health_app *ha, int type); void health_register(struct health_app *ha, int type); void health_unregister(struct health_app *ha); +#ifdef __cplusplus +} +#endif + #endif /* HEALTH_INTERNAL_H */ diff --git a/include/lttng/location-internal.h b/include/lttng/location-internal.h index 33498c90d..9eafd471a 100644 --- a/include/lttng/location-internal.h +++ b/include/lttng/location-internal.h @@ -15,6 +15,10 @@ #include #include +#ifdef __cplusplus +extern "C" { +#endif + /* * The public API assumes that trace archive locations are always * provided as "constant". This means that the user of liblttng-ctl never @@ -97,4 +101,8 @@ void lttng_trace_archive_location_get( void lttng_trace_archive_location_put( struct lttng_trace_archive_location *location); +#ifdef __cplusplus +} +#endif + #endif /* LTTNG_LOCATION_INTERNAL_H */ diff --git a/include/lttng/log-level-rule-internal.h b/include/lttng/log-level-rule-internal.h index c17e590b7..b02afafe0 100644 --- a/include/lttng/log-level-rule-internal.h +++ b/include/lttng/log-level-rule-internal.h @@ -18,6 +18,10 @@ #include #include +#ifdef __cplusplus +extern "C" { +#endif + struct mi_writer; /* @@ -60,4 +64,8 @@ enum lttng_error_code lttng_log_level_rule_mi_serialize( const struct lttng_log_level_rule *rule, struct mi_writer *writer); +#ifdef __cplusplus +} +#endif + #endif /* LTTNG_LOG_LEVEL_RULE_INTERNAL_H */ diff --git a/include/lttng/notification/notification-internal.h b/include/lttng/notification/notification-internal.h index 7e601b0c7..1d337e07d 100644 --- a/include/lttng/notification/notification-internal.h +++ b/include/lttng/notification/notification-internal.h @@ -14,6 +14,10 @@ #include #include +#ifdef __cplusplus +extern "C" { +#endif + struct lttng_payload; struct lttng_payload_view; @@ -40,4 +44,8 @@ ssize_t lttng_notification_create_from_payload( struct lttng_payload_view *view, struct lttng_notification **notification); +#ifdef __cplusplus +} +#endif + #endif /* LTTNG_NOTIFICATION_INTERNAL_H */ diff --git a/include/lttng/session-descriptor-internal.h b/include/lttng/session-descriptor-internal.h index f438d4812..97628bb88 100644 --- a/include/lttng/session-descriptor-internal.h +++ b/include/lttng/session-descriptor-internal.h @@ -15,6 +15,10 @@ #include #include +#ifdef __cplusplus +extern "C" { +#endif + /* Note that these enums are used as part of the lttnctl protocol. */ enum lttng_session_descriptor_type { LTTNG_SESSION_DESCRIPTOR_TYPE_UNKNOWN = -1, @@ -81,4 +85,8 @@ int lttng_session_descriptor_assign( struct lttng_session_descriptor *dst_descriptor, const struct lttng_session_descriptor *src_descriptor); +#ifdef __cplusplus +} +#endif + #endif /* LTTNG_SESSION_DESCRIPTOR_INTERNAL_H */ diff --git a/include/lttng/trigger/trigger.h b/include/lttng/trigger/trigger.h index c4899f936..842203ace 100644 --- a/include/lttng/trigger/trigger.h +++ b/include/lttng/trigger/trigger.h @@ -11,6 +11,7 @@ #include #include #include +#include struct lttng_action; struct lttng_condition; diff --git a/include/lttng/userspace-probe-internal.h b/include/lttng/userspace-probe-internal.h index 5e960c106..fe96a4ea3 100644 --- a/include/lttng/userspace-probe-internal.h +++ b/include/lttng/userspace-probe-internal.h @@ -14,6 +14,10 @@ #include #include +#ifdef __cplusplus +extern "C" { +#endif + struct lttng_payload; struct lttng_payload_view; struct lttng_dynamic_buffer; @@ -159,4 +163,8 @@ enum lttng_error_code lttng_userspace_probe_location_mi_serialize( const struct lttng_userspace_probe_location *location, struct mi_writer *writer); +#ifdef __cplusplus +} +#endif + #endif /* LTTNG_USERSPACE_PROBE_INTERNAL_H */ diff --git a/src/bin/lttng-sessiond/Makefile.am b/src/bin/lttng-sessiond/Makefile.am index 11fb85e0b..2de44a492 100644 --- a/src/bin/lttng-sessiond/Makefile.am +++ b/src/bin/lttng-sessiond/Makefile.am @@ -9,62 +9,62 @@ endif noinst_LTLIBRARIES = liblttng-sessiond-common.la -liblttng_sessiond_common_la_SOURCES = utils.c utils.h \ - trace-kernel.c trace-kernel.h \ - kernel.c kernel.h \ +liblttng_sessiond_common_la_SOURCES = utils.cpp utils.h \ + trace-kernel.cpp trace-kernel.h \ + kernel.cpp kernel.h \ ust-app.h ust-sigbus.h trace-ust.h notify-apps.h \ lttng-ust-ctl.h lttng-ust-abi.h lttng-ust-error.h \ ust-ctl-internal.h ust-abi-internal.h ust-error-internal.h \ ust-registry.h \ - condition-internal.c condition-internal.h \ - context.c context.h \ - channel.c channel.h \ - event.c event.h \ - consumer.c consumer.h \ - session.c session.h \ - modprobe.c modprobe.h kern-modules.h \ - fd-limit.c fd-limit.h \ - kernel-consumer.c kernel-consumer.h \ + condition-internal.cpp condition-internal.h \ + context.cpp context.h \ + channel.cpp channel.h \ + event.cpp event.h \ + consumer.cpp consumer.h \ + session.cpp session.h \ + modprobe.cpp modprobe.h kern-modules.h \ + fd-limit.cpp fd-limit.h \ + kernel-consumer.cpp kernel-consumer.h \ consumer.h \ health-sessiond.h \ - cmd.c cmd.h \ - buffer-registry.c buffer-registry.h \ - testpoint.h ht-cleanup.c ht-cleanup.h \ - snapshot.c snapshot.h \ - agent.c agent.h \ - save.h save.c \ - lttng-syscall.h lttng-syscall.c \ - notification-thread.h notification-thread.c \ + cmd.cpp cmd.h \ + buffer-registry.cpp buffer-registry.h \ + testpoint.h ht-cleanup.cpp ht-cleanup.h \ + snapshot.cpp snapshot.h \ + agent.cpp agent.h \ + save.h save.cpp \ + lttng-syscall.h lttng-syscall.cpp \ + notification-thread.h notification-thread.cpp \ notification-thread-internal.h \ - notification-thread-commands.h notification-thread-commands.c \ - notification-thread-events.h notification-thread-events.c \ - sessiond-config.h sessiond-config.c \ - rotate.h rotate.c \ - rotation-thread.h rotation-thread.c \ - timer.c timer.h \ - globals.c \ - thread-utils.c \ - process-utils.c \ - thread.c thread.h \ - health.c \ - client.c client.h \ - dispatch.c dispatch.h \ - register.c register.h \ - manage-apps.c manage-apps.h \ - manage-kernel.c manage-kernel.h \ - manage-consumer.c manage-consumer.h \ - clear.c clear.h \ - tracker.c tracker.h \ - event-notifier-error-accounting.c event-notifier-error-accounting.h \ - action-executor.c action-executor.h\ - trigger-error-query.c + notification-thread-commands.h notification-thread-commands.cpp \ + notification-thread-events.h notification-thread-events.cpp \ + sessiond-config.h sessiond-config.cpp \ + rotate.h rotate.cpp \ + rotation-thread.h rotation-thread.cpp \ + timer.cpp timer.h \ + globals.cpp \ + thread-utils.cpp \ + process-utils.cpp \ + thread.cpp thread.h \ + health.cpp \ + client.cpp client.h \ + dispatch.cpp dispatch.h \ + register.cpp register.h \ + manage-apps.cpp manage-apps.h \ + manage-kernel.cpp manage-kernel.h \ + manage-consumer.cpp manage-consumer.h \ + clear.cpp clear.h \ + tracker.cpp tracker.h \ + event-notifier-error-accounting.cpp event-notifier-error-accounting.h \ + action-executor.cpp action-executor.h\ + trigger-error-query.cpp if HAVE_LIBLTTNG_UST_CTL -liblttng_sessiond_common_la_SOURCES += trace-ust.c ust-registry.c ust-app.c \ - ust-consumer.c ust-consumer.h notify-apps.c \ - ust-metadata.c ust-clock.h agent-thread.c agent-thread.h \ - ust-field-utils.h ust-field-utils.c \ - ust-sigbus.c +liblttng_sessiond_common_la_SOURCES += trace-ust.cpp ust-registry.cpp ust-app.cpp \ + ust-consumer.cpp ust-consumer.h notify-apps.cpp \ + ust-metadata.cpp ust-clock.h agent-thread.cpp agent-thread.h \ + ust-field-utils.h ust-field-utils.cpp \ + ust-sigbus.cpp endif # link on liblttngctl for check if sessiond is already alive. @@ -88,7 +88,7 @@ endif bin_PROGRAMS = lttng-sessiond -lttng_sessiond_SOURCES = lttng-sessiond.h main.c +lttng_sessiond_SOURCES = lttng-sessiond.h main.cpp lttng_sessiond_LDFLAGS = -rdynamic diff --git a/src/bin/lttng-sessiond/action-executor.c b/src/bin/lttng-sessiond/action-executor.cpp similarity index 95% rename from src/bin/lttng-sessiond/action-executor.c rename to src/bin/lttng-sessiond/action-executor.cpp index 94b819c46..cc7834f27 100644 --- a/src/bin/lttng-sessiond/action-executor.c +++ b/src/bin/lttng-sessiond/action-executor.cpp @@ -143,12 +143,12 @@ static int action_executor_generic_handler(struct action_executor *executor, struct action_work_subitem *); static const action_executor_handler action_executors[] = { - [LTTNG_ACTION_TYPE_NOTIFY] = action_executor_notify_handler, - [LTTNG_ACTION_TYPE_START_SESSION] = action_executor_start_session_handler, - [LTTNG_ACTION_TYPE_STOP_SESSION] = action_executor_stop_session_handler, - [LTTNG_ACTION_TYPE_ROTATE_SESSION] = action_executor_rotate_session_handler, - [LTTNG_ACTION_TYPE_SNAPSHOT_SESSION] = action_executor_snapshot_session_handler, - [LTTNG_ACTION_TYPE_LIST] = action_executor_list_handler, + action_executor_notify_handler, + action_executor_start_session_handler, + action_executor_stop_session_handler, + action_executor_rotate_session_handler, + action_executor_snapshot_session_handler, + action_executor_list_handler, }; /* Forward declaration */ @@ -160,7 +160,7 @@ static int populate_subitem_array_from_trigger(struct lttng_trigger *trigger, static void action_work_subitem_destructor(void *element) { - struct action_work_subitem *subitem = element; + struct action_work_subitem *subitem = (action_work_subitem *) element; lttng_action_put(subitem->action); } @@ -226,7 +226,7 @@ static int client_handle_transmission_status( void *user_data) { int ret = 0; - struct action_executor *executor = user_data; + struct action_executor *executor = (action_executor *) user_data; bool update_communication = true; switch (status) { @@ -339,7 +339,7 @@ static int action_executor_start_session_handler( goto error_dispose_session; } - cmd_ret = cmd_start_trace(session); + cmd_ret = (lttng_error_code) cmd_start_trace(session); switch (cmd_ret) { case LTTNG_OK: DBG("Successfully started session `%s` on behalf of trigger `%s`", @@ -431,7 +431,7 @@ static int action_executor_stop_session_handler( goto error_dispose_session; } - cmd_ret = cmd_stop_trace(session); + cmd_ret = (lttng_error_code) cmd_stop_trace(session); switch (cmd_ret) { case LTTNG_OK: DBG("Successfully stopped session `%s` on behalf of trigger `%s`", @@ -523,7 +523,7 @@ static int action_executor_rotate_session_handler( goto error_dispose_session; } - cmd_ret = cmd_rotate_session(session, NULL, false, + cmd_ret = (lttng_error_code) cmd_rotate_session(session, NULL, false, LTTNG_TRACE_CHUNK_COMMAND_TYPE_MOVE_TO_COMPLETED); switch (cmd_ret) { case LTTNG_OK: @@ -566,14 +566,14 @@ static int action_executor_snapshot_session_handler( const char *session_name; enum lttng_action_status action_status; struct ltt_session *session; - const struct lttng_snapshot_output default_snapshot_output = { - .max_size = UINT64_MAX, - }; + lttng_snapshot_output default_snapshot_output; const struct lttng_snapshot_output *snapshot_output = &default_snapshot_output; enum lttng_error_code cmd_ret; struct lttng_action *action = item->action; + default_snapshot_output.max_size = UINT64_MAX; + /* * Validate if, at the moment the action was queued, the target session * existed. If not, skip the action altogether. @@ -637,7 +637,7 @@ static int action_executor_snapshot_session_handler( goto error_dispose_session; } - cmd_ret = cmd_snapshot_record(session, snapshot_output, 0); + cmd_ret = (lttng_error_code) cmd_snapshot_record(session, snapshot_output, 0); switch (cmd_ret) { case LTTNG_OK: DBG("Successfully recorded snapshot of session `%s` on behalf of trigger `%s`", @@ -711,7 +711,7 @@ static int action_work_item_execute(struct action_executor *executor, for (i = 0; i < count; i++) { struct action_work_subitem *item; - item = lttng_dynamic_array_get_element(&work_item->subitems, i); + item = (action_work_subitem *) lttng_dynamic_array_get_element(&work_item->subitems, i); ret = action_executor_generic_handler( executor, work_item, item); if (ret) { @@ -735,7 +735,7 @@ static void action_work_item_destroy(struct action_work_item *work_item) static void *action_executor_thread(void *_data) { - struct action_executor *executor = _data; + struct action_executor *executor = (action_executor *) _data; LTTNG_ASSERT(executor); @@ -824,7 +824,7 @@ static void *action_executor_thread(void *_data) static bool shutdown_action_executor_thread(void *_data) { - struct action_executor *executor = _data; + struct action_executor *executor = (action_executor *) _data; pthread_mutex_lock(&executor->work.lock); executor->should_quit = true; @@ -835,7 +835,7 @@ static bool shutdown_action_executor_thread(void *_data) static void clean_up_action_executor_thread(void *_data) { - struct action_executor *executor = _data; + struct action_executor *executor = (action_executor *) _data; LTTNG_ASSERT(cds_list_empty(&executor->work.list)); @@ -847,7 +847,7 @@ static void clean_up_action_executor_thread(void *_data) struct action_executor *action_executor_create( struct notification_thread_handle *handle) { - struct action_executor *executor = zmalloc(sizeof(*executor)); + struct action_executor *executor = (action_executor *) zmalloc(sizeof(*executor)); if (!executor) { goto end; @@ -918,7 +918,7 @@ enum action_executor_status action_executor_enqueue_trigger( goto error_unlock; } - work_item = zmalloc(sizeof(*work_item)); + work_item = (action_work_item *) zmalloc(sizeof(*work_item)); if (!work_item) { PERROR("Failed to allocate action executor work item: trigger name = '%s'", get_trigger_name(trigger)); @@ -934,22 +934,21 @@ enum action_executor_status action_executor_enqueue_trigger( LTTNG_ASSERT(reference_acquired); } - *work_item = (typeof(*work_item)){ - .id = work_item_id, - .trigger = trigger, - /* Ownership transferred to the work item. */ - .evaluation = evaluation, - .object_creds = { - .is_set = !!object_creds, - .value = object_creds ? *object_creds : - (typeof(work_item->object_creds.value)) {}, - }, - .client_list = client_list, - .list_node = CDS_LIST_HEAD_INIT(work_item->list_node), - }; + work_item->id = work_item_id; + work_item->trigger = trigger; + /* Ownership transferred to the work item. */ + work_item->evaluation = evaluation; evaluation = NULL; + work_item->client_list = client_list; + work_item->object_creds.is_set = !!object_creds; + if (object_creds) { + work_item->object_creds.value = *object_creds; + } + + CDS_INIT_LIST_HEAD(&work_item->list_node); + /* Build the array of action work subitems for the passed trigger. */ lttng_dynamic_array_init(&work_item->subitems, sizeof(struct action_work_subitem), diff --git a/src/bin/lttng-sessiond/agent-thread.c b/src/bin/lttng-sessiond/agent-thread.cpp similarity index 97% rename from src/bin/lttng-sessiond/agent-thread.c rename to src/bin/lttng-sessiond/agent-thread.cpp index f2ee4c041..5e158b49b 100644 --- a/src/bin/lttng-sessiond/agent-thread.c +++ b/src/bin/lttng-sessiond/agent-thread.cpp @@ -296,8 +296,8 @@ static int accept_agent_connection( } *agent_app_id = (struct agent_app_id) { - .domain = (enum lttng_domain_type) be32toh(msg.domain), .pid = (pid_t) be32toh(msg.pid), + .domain = (lttng_domain_type) be32toh(msg.domain), }; DBG2("New registration for agent application: pid = %ld, domain = %s, socket fd = %d", @@ -358,7 +358,7 @@ static void *thread_agent_management(void *data) uint32_t revents, nb_fd; struct lttng_poll_event events; struct lttcomm_sock *reg_sock; - struct thread_notifiers *notifiers = data; + struct thread_notifiers *notifiers = (thread_notifiers *) data; const int quit_pipe_read_fd = lttng_pipe_get_readfd( notifiers->quit_pipe); @@ -550,7 +550,7 @@ error_poll_create: static bool shutdown_agent_management_thread(void *data) { - struct thread_notifiers *notifiers = data; + struct thread_notifiers *notifiers = (thread_notifiers *) data; const int write_fd = lttng_pipe_get_writefd(notifiers->quit_pipe); return notify_thread_pipe(write_fd) == 1; @@ -558,7 +558,7 @@ static bool shutdown_agent_management_thread(void *data) static void cleanup_agent_management_thread(void *data) { - struct thread_notifiers *notifiers = data; + struct thread_notifiers *notifiers = (thread_notifiers *) data; lttng_pipe_destroy(notifiers->quit_pipe); sem_destroy(¬ifiers->ready); @@ -570,7 +570,7 @@ bool launch_agent_management_thread(void) struct thread_notifiers *notifiers; struct lttng_thread *thread; - notifiers = zmalloc(sizeof(*notifiers)); + notifiers = (thread_notifiers *) zmalloc(sizeof(*notifiers)); if (!notifiers) { goto error_alloc; } diff --git a/src/bin/lttng-sessiond/agent.c b/src/bin/lttng-sessiond/agent.cpp similarity index 97% rename from src/bin/lttng-sessiond/agent.c rename to src/bin/lttng-sessiond/agent.cpp index 77846b4f2..5be61dc36 100644 --- a/src/bin/lttng-sessiond/agent.c +++ b/src/bin/lttng-sessiond/agent.cpp @@ -30,8 +30,6 @@ #include "utils.h" #include "common/error.h" -#define AGENT_RET_CODE_INDEX(code) (code - AGENT_RET_CODE_SUCCESS) - typedef enum lttng_event_rule_status (*event_rule_logging_get_name_pattern)( const struct lttng_event_rule *rule, const char **pattern); typedef enum lttng_event_rule_status (*event_rule_logging_get_log_level_rule)( @@ -55,13 +53,19 @@ struct agent_app_ctx { /* * Human readable agent return code. */ -static const char *error_string_array[] = { - [ AGENT_RET_CODE_INDEX(AGENT_RET_CODE_SUCCESS) ] = "Success", - [ AGENT_RET_CODE_INDEX(AGENT_RET_CODE_INVALID) ] = "Invalid command", - [ AGENT_RET_CODE_INDEX(AGENT_RET_CODE_UNKNOWN_NAME) ] = "Unknown logger name", - - /* Last element */ - [ AGENT_RET_CODE_INDEX(AGENT_RET_CODE_NR) ] = "Unknown code", +static +const char *lttcomm_agent_ret_code_str(lttcomm_agent_ret_code code) +{ + switch (code) { + case AGENT_RET_CODE_SUCCESS: + return "Success"; + case AGENT_RET_CODE_INVALID: + return "Invalid command"; + case AGENT_RET_CODE_UNKNOWN_NAME: + return "Unknown logger name"; + default: + return "Unknown code"; + } }; static @@ -81,9 +85,8 @@ void log_reply_code(uint32_t in_reply_ret_code) level = PRINT_ERR; } - LOG(level, "Agent replied with retcode: %s (%"PRIu32")", - error_string_array[AGENT_RET_CODE_INDEX( - reply_ret_code)], + LOG(level, "Agent replied with retcode: %s (%" PRIu32 ")", + lttcomm_agent_ret_code_str((lttcomm_agent_ret_code) reply_ret_code), in_reply_ret_code); } @@ -100,7 +103,7 @@ static int ht_match_event_by_name(struct cds_lfht_node *node, LTTNG_ASSERT(_key); event = caa_container_of(node, struct agent_event, node.node); - key = _key; + key = (agent_ht_key *) _key; /* Match 1 elements of the key: name. */ @@ -130,7 +133,7 @@ static int ht_match_event(struct cds_lfht_node *node, LTTNG_ASSERT(_key); event = caa_container_of(node, struct agent_event, node.node); - key = _key; + key = (agent_ht_key *) _key; /* Match 2 elements of the key: name and loglevel. */ @@ -345,7 +348,7 @@ static ssize_t list_events(struct agent_app *app, struct lttng_event **events) goto error; } - reply = zmalloc(data_size); + reply = (lttcomm_agent_list_reply *) zmalloc(data_size); if (!reply) { ret = LTTNG_ERR_NOMEM; goto error; @@ -358,7 +361,7 @@ static ssize_t list_events(struct agent_app *app, struct lttng_event **events) } nb_event = be32toh(reply->nb_event); - tmp_events = zmalloc(sizeof(*tmp_events) * nb_event); + tmp_events = (lttng_event *) zmalloc(sizeof(*tmp_events) * nb_event); if (!tmp_events) { ret = LTTNG_ERR_NOMEM; goto error; @@ -438,7 +441,7 @@ static int enable_event(const struct agent_app *app, struct agent_event *event) goto error_io; } - bytes_to_send = zmalloc(data_size); + bytes_to_send = (char *) zmalloc(data_size); if (!bytes_to_send) { ret = LTTNG_ERR_NOMEM; goto error; @@ -723,7 +726,7 @@ struct agent_app_ctx *create_app_ctx(const struct lttng_event_context *ctx) } LTTNG_ASSERT(ctx->ctx == LTTNG_EVENT_CONTEXT_APP_CONTEXT); - agent_ctx = zmalloc(sizeof(*ctx)); + agent_ctx = (agent_app_ctx *) zmalloc(sizeof(*ctx)); if (!agent_ctx) { goto end; } @@ -895,7 +898,7 @@ int agent_list_events(struct lttng_event **events, DBG2("Agent listing events for domain %d", domain); nbmem = UST_APP_EVENT_LIST_SIZE; - tmp_events = zmalloc(nbmem * sizeof(*tmp_events)); + tmp_events = (lttng_event *) zmalloc(nbmem * sizeof(*tmp_events)); if (!tmp_events) { PERROR("zmalloc agent list events"); ret = -ENOMEM; @@ -924,10 +927,10 @@ int agent_list_events(struct lttng_event **events, struct lttng_event *new_tmp_events; size_t new_nbmem; - new_nbmem = max_t(size_t, count + nb_ev, nbmem << 1); + new_nbmem = std::max(count + nb_ev, nbmem << 1); DBG2("Reallocating agent event list from %zu to %zu entries", nbmem, new_nbmem); - new_tmp_events = realloc(tmp_events, + new_tmp_events = (lttng_event *) realloc(tmp_events, new_nbmem * sizeof(*new_tmp_events)); if (!new_tmp_events) { PERROR("realloc agent events"); @@ -971,7 +974,7 @@ struct agent_app *agent_create_app(pid_t pid, enum lttng_domain_type domain, LTTNG_ASSERT(sock); - app = zmalloc(sizeof(*app)); + app = (agent_app *) zmalloc(sizeof(*app)); if (!app) { PERROR("Failed to allocate agent application instance"); goto error; @@ -1112,7 +1115,7 @@ struct agent *agent_create(enum lttng_domain_type domain) int ret; struct agent *agt; - agt = zmalloc(sizeof(struct agent)); + agt = (agent *) zmalloc(sizeof(struct agent)); if (!agt) { goto error; } @@ -1151,7 +1154,7 @@ struct agent_event *agent_create_event(const char *name, goto error; } - event = zmalloc(sizeof(*event)); + event = (agent_event *) zmalloc(sizeof(*event)); if (!event) { goto error; } diff --git a/src/bin/lttng-sessiond/buffer-registry.c b/src/bin/lttng-sessiond/buffer-registry.cpp similarity index 97% rename from src/bin/lttng-sessiond/buffer-registry.c rename to src/bin/lttng-sessiond/buffer-registry.cpp index 3390f870a..aca8ec1f2 100644 --- a/src/bin/lttng-sessiond/buffer-registry.c +++ b/src/bin/lttng-sessiond/buffer-registry.cpp @@ -46,7 +46,7 @@ static int ht_match_reg_uid(struct cds_lfht_node *node, const void *_key) reg = caa_container_of(node, struct buffer_reg_uid, node.node); LTTNG_ASSERT(reg); - key = _key; + key = (buffer_reg_uid *) _key; if (key->session_id != reg->session_id || key->bits_per_long != reg->bits_per_long || @@ -67,7 +67,7 @@ no_match: static unsigned long ht_hash_reg_uid(const void *_key, unsigned long seed) { uint64_t xored_key; - const struct buffer_reg_uid *key = _key; + const struct buffer_reg_uid *key = (buffer_reg_uid *) _key; LTTNG_ASSERT(key); @@ -104,14 +104,14 @@ int buffer_reg_uid_create(uint64_t session_id, uint32_t bits_per_long, uid_t uid LTTNG_ASSERT(regp); - reg = zmalloc(sizeof(*reg)); + reg = (buffer_reg_uid *) zmalloc(sizeof(*reg)); if (!reg) { PERROR("zmalloc buffer registry uid"); ret = -ENOMEM; goto error; } - reg->registry = zmalloc(sizeof(struct buffer_reg_session)); + reg->registry = (buffer_reg_session *) zmalloc(sizeof(struct buffer_reg_session)); if (!reg->registry) { PERROR("zmalloc buffer registry uid session"); ret = -ENOMEM; @@ -232,14 +232,14 @@ int buffer_reg_pid_create(uint64_t session_id, struct buffer_reg_pid **regp, LTTNG_ASSERT(regp); - reg = zmalloc(sizeof(*reg)); + reg = (buffer_reg_pid *) zmalloc(sizeof(*reg)); if (!reg) { PERROR("zmalloc buffer registry pid"); ret = -ENOMEM; goto error; } - reg->registry = zmalloc(sizeof(struct buffer_reg_session)); + reg->registry = (buffer_reg_session *) zmalloc(sizeof(struct buffer_reg_session)); if (!reg->registry) { PERROR("zmalloc buffer registry pid session"); ret = -ENOMEM; @@ -369,7 +369,7 @@ int buffer_reg_channel_create(uint64_t key, struct buffer_reg_channel **regp) DBG3("Buffer registry channel create with key: %" PRIu64, key); - reg = zmalloc(sizeof(*reg)); + reg = (buffer_reg_channel *) zmalloc(sizeof(*reg)); if (!reg) { PERROR("zmalloc buffer registry channel"); return -ENOMEM; @@ -399,7 +399,7 @@ int buffer_reg_stream_create(struct buffer_reg_stream **regp) DBG3("Buffer registry creating stream"); - reg = zmalloc(sizeof(*reg)); + reg = (buffer_reg_stream *) zmalloc(sizeof(*reg)); if (!reg) { PERROR("zmalloc buffer registry stream"); return -ENOMEM; diff --git a/src/bin/lttng-sessiond/channel.c b/src/bin/lttng-sessiond/channel.cpp similarity index 98% rename from src/bin/lttng-sessiond/channel.c rename to src/bin/lttng-sessiond/channel.cpp index e84da039a..0f150972c 100644 --- a/src/bin/lttng-sessiond/channel.c +++ b/src/bin/lttng-sessiond/channel.cpp @@ -34,13 +34,13 @@ struct lttng_channel *channel_new_default_attr(int dom, const char *channel_name = DEFAULT_CHANNEL_NAME; struct lttng_channel_extended *extended_attr = NULL; - chan = zmalloc(sizeof(struct lttng_channel)); + chan = (lttng_channel *) zmalloc(sizeof(struct lttng_channel)); if (chan == NULL) { PERROR("zmalloc channel init"); goto error_alloc; } - extended_attr = zmalloc(sizeof(struct lttng_channel_extended)); + extended_attr = (lttng_channel_extended *) zmalloc(sizeof(struct lttng_channel_extended)); if (!extended_attr) { PERROR("zmalloc channel extended init"); goto error; diff --git a/src/bin/lttng-sessiond/clear.c b/src/bin/lttng-sessiond/clear.cpp similarity index 97% rename from src/bin/lttng-sessiond/clear.c rename to src/bin/lttng-sessiond/clear.cpp index e699caffc..1239c5f24 100644 --- a/src/bin/lttng-sessiond/clear.c +++ b/src/bin/lttng-sessiond/clear.cpp @@ -31,7 +31,7 @@ void cmd_clear_session_reply(const struct ltt_session *session, int ret; ssize_t comm_ret; const struct cmd_clear_session_reply_context *reply_context = - _reply_context; + (cmd_clear_session_reply_context *) _reply_context; struct lttcomm_lttng_msg llm = { .cmd_type = LTTNG_CLEAR_SESSION, .ret_code = LTTNG_OK, @@ -66,7 +66,7 @@ int cmd_clear_session(struct ltt_session *session, int *sock_fd) usess = session->ust_session; if (sock_fd) { - reply_context = zmalloc(sizeof(*reply_context)); + reply_context = (cmd_clear_session_reply_context *) zmalloc(sizeof(*reply_context)); if (!reply_context) { ret = LTTNG_ERR_NOMEM; goto end; diff --git a/src/bin/lttng-sessiond/client.c b/src/bin/lttng-sessiond/client.cpp similarity index 96% rename from src/bin/lttng-sessiond/client.c rename to src/bin/lttng-sessiond/client.cpp index ed9f2af3e..154fa4a36 100644 --- a/src/bin/lttng-sessiond/client.c +++ b/src/bin/lttng-sessiond/client.cpp @@ -86,12 +86,12 @@ static int setup_lttng_msg(struct command_ctx *cmd_ctx, int ret = 0; const size_t header_len = sizeof(struct lttcomm_lttng_msg); const size_t total_msg_size = header_len + cmd_header_len + payload_len; - const struct lttcomm_lttng_msg llm = { - .cmd_type = cmd_ctx->lsm.cmd_type, - .pid = cmd_ctx->lsm.domain.attr.pid, - .cmd_header_size = cmd_header_len, - .data_size = payload_len, - }; + lttcomm_lttng_msg llm {}; + + llm.cmd_type = cmd_ctx->lsm.cmd_type; + llm.pid = (uint32_t) cmd_ctx->lsm.domain.attr.pid; + llm.cmd_header_size = (uint32_t) cmd_header_len; + llm.data_size = (uint32_t) payload_len; ret = lttng_dynamic_buffer_set_size(&cmd_ctx->reply_payload.buffer, 0); if (ret) { @@ -160,13 +160,13 @@ static void update_lttng_msg(struct command_ctx *cmd_ctx, size_t cmd_header_len, { const size_t header_len = sizeof(struct lttcomm_lttng_msg); const size_t total_msg_size = header_len + cmd_header_len + payload_len; - const struct lttcomm_lttng_msg llm = { - .cmd_type = cmd_ctx->lsm.cmd_type, - .pid = cmd_ctx->lsm.domain.attr.pid, - .cmd_header_size = cmd_header_len, - .data_size = payload_len, - }; struct lttcomm_lttng_msg *p_llm; + lttcomm_lttng_msg llm {}; + + llm.cmd_type = cmd_ctx->lsm.cmd_type; + llm.pid = (uint32_t) cmd_ctx->lsm.domain.attr.pid; + llm.cmd_header_size = (uint32_t) cmd_header_len; + llm.data_size = (uint32_t) payload_len; LTTNG_ASSERT(cmd_ctx->reply_payload.buffer.size >= sizeof(llm)); @@ -263,7 +263,7 @@ static pid_t spawn_consumerd(struct consumer_data *consumer_data) tmp = ""; } tmplen = strlen(the_config.consumerd64_lib_dir.value) + 1 /* : */ + strlen(tmp); - tmpnew = zmalloc(tmplen + 1 /* \0 */); + tmpnew = (char *) zmalloc(tmplen + 1 /* \0 */); if (!tmpnew) { ret = -ENOMEM; goto error; @@ -305,7 +305,7 @@ static pid_t spawn_consumerd(struct consumer_data *consumer_data) tmp = ""; } tmplen = strlen(the_config.consumerd32_lib_dir.value) + 1 /* : */ + strlen(tmp); - tmpnew = zmalloc(tmplen + 1 /* \0 */); + tmpnew = (char *) zmalloc(tmplen + 1 /* \0 */); if (!tmpnew) { ret = -ENOMEM; goto error; @@ -931,7 +931,7 @@ static int process_client_msg(struct command_ctx *cmd_ctx, int *sock, bool need_consumerd; DBG("Processing client command '%s\' (%d)", - lttcomm_sessiond_command_str(cmd_ctx->lsm.cmd_type), + lttcomm_sessiond_command_str((lttcomm_sessiond_command) cmd_ctx->lsm.cmd_type), cmd_ctx->lsm.cmd_type); LTTNG_ASSERT(!rcu_read_ongoing()); @@ -1191,8 +1191,8 @@ static int process_client_msg(struct command_ctx *cmd_ctx, int *sock, if (need_tracing_session) { /* Create UST session if none exist. */ if (cmd_ctx->session->ust_session == NULL) { - ret = create_ust_session(cmd_ctx->session, - ALIGNED_CONST_PTR(cmd_ctx->lsm.domain)); + lttng_domain domain = cmd_ctx->lsm.domain; + ret = create_ust_session(cmd_ctx->session, &domain); if (ret != LTTNG_OK) { goto error; } @@ -1323,6 +1323,8 @@ skip_domain: switch (cmd_ctx->lsm.cmd_type) { case LTTNG_ADD_CONTEXT: { + lttng_event_context ctx; + /* * An LTTNG_ADD_CONTEXT command might have a supplementary * payload if the context being added is an application context. @@ -1344,7 +1346,7 @@ skip_domain: goto error; } - provider_name = zmalloc(provider_name_len + 1); + provider_name = (char *) zmalloc(provider_name_len + 1); if (!provider_name) { ret = -LTTNG_ERR_NOMEM; goto error; @@ -1352,7 +1354,7 @@ skip_domain: cmd_ctx->lsm.u.context.ctx.u.app_ctx.provider_name = provider_name; - context_name = zmalloc(context_name_len + 1); + context_name = (char *) zmalloc(context_name_len + 1); if (!context_name) { ret = -LTTNG_ERR_NOMEM; goto error_add_context; @@ -1377,10 +1379,11 @@ skip_domain: * cmd_add_context assumes ownership of the provider and context * names. */ + ctx = cmd_ctx->lsm.u.context.ctx; ret = cmd_add_context(cmd_ctx->session, cmd_ctx->lsm.domain.type, cmd_ctx->lsm.u.context.channel_name, - ALIGNED_CONST_PTR(cmd_ctx->lsm.u.context.ctx), + &ctx, the_kernel_poll_pipe[1]); cmd_ctx->lsm.u.context.ctx.u.app_ctx.provider_name = NULL; @@ -1401,6 +1404,7 @@ error_add_context: } case LTTNG_DISABLE_EVENT: { + lttng_event event; /* * FIXME: handle filter; for now we just receive the filter's @@ -1428,18 +1432,21 @@ error_add_context: count -= (size_t) ret; } } + event = cmd_ctx->lsm.u.disable.event; ret = cmd_disable_event(cmd_ctx->session, cmd_ctx->lsm.domain.type, cmd_ctx->lsm.u.disable.channel_name, - ALIGNED_CONST_PTR(cmd_ctx->lsm.u.disable.event)); + &event); break; } case LTTNG_ENABLE_CHANNEL: { cmd_ctx->lsm.u.channel.chan.attr.extended.ptr = (struct lttng_channel_extended *) &cmd_ctx->lsm.u.channel.extended; + lttng_domain domain = cmd_ctx->lsm.domain; + lttng_channel chan = cmd_ctx->lsm.u.channel.chan; ret = cmd_enable_channel(cmd_ctx->session, - ALIGNED_CONST_PTR(cmd_ctx->lsm.domain), - ALIGNED_CONST_PTR(cmd_ctx->lsm.u.channel.chan), + &domain, + &chan, the_kernel_poll_pipe[1]); break; } @@ -1572,8 +1579,9 @@ error_add_context: goto error; } + uint32_t tracking_policy_u32 = tracking_policy; ret = setup_lttng_msg_no_cmd_header(cmd_ctx, - &(uint32_t){tracking_policy}, sizeof(uint32_t)); + &tracking_policy_u32, sizeof(uint32_t)); if (ret < 0) { ret = LTTNG_ERR_NOMEM; goto error; @@ -1647,12 +1655,14 @@ error_add_context: struct lttng_event_exclusion *exclusion = NULL; struct lttng_bytecode *bytecode = NULL; char *filter_expression = NULL; + lttng_event event; + lttng_domain domain; /* Handle exclusion events and receive it from the client. */ if (cmd_ctx->lsm.u.enable.exclusion_count > 0) { size_t count = cmd_ctx->lsm.u.enable.exclusion_count; - exclusion = zmalloc(sizeof(struct lttng_event_exclusion) + + exclusion = (lttng_event_exclusion *) zmalloc(sizeof(struct lttng_event_exclusion) + (count * LTTNG_SYMBOL_NAME_LEN)); if (!exclusion) { ret = LTTNG_ERR_EXCLUSION_NOMEM; @@ -1683,7 +1693,7 @@ error_add_context: goto error; } - filter_expression = zmalloc(expression_len); + filter_expression = (char *) zmalloc(expression_len); if (!filter_expression) { free(exclusion); ret = LTTNG_ERR_FILTER_NOMEM; @@ -1715,7 +1725,7 @@ error_add_context: goto error; } - bytecode = zmalloc(bytecode_len); + bytecode = (lttng_bytecode *) zmalloc(bytecode_len); if (!bytecode) { free(filter_expression); free(exclusion); @@ -1745,7 +1755,8 @@ error_add_context: } } - ev = lttng_event_copy(ALIGNED_CONST_PTR(cmd_ctx->lsm.u.enable.event)); + event = cmd_ctx->lsm.u.enable.event; + ev = lttng_event_copy(&event); if (!ev) { DBG("Failed to copy event: %s", cmd_ctx->lsm.u.enable.event.name); @@ -1769,8 +1780,9 @@ error_add_context: } } + domain = cmd_ctx->lsm.domain; ret = cmd_enable_event(cmd_ctx->session, - ALIGNED_CONST_PTR(cmd_ctx->lsm.domain), + &domain, cmd_ctx->lsm.u.enable.channel_name, ev, filter_expression, bytecode, exclusion, @@ -1877,7 +1889,7 @@ error_add_context: goto error; } - uris = zmalloc(len); + uris = (lttng_uri *) zmalloc(len); if (uris == NULL) { ret = LTTNG_ERR_FATAL; goto error; @@ -2016,7 +2028,7 @@ error_add_context: case LTTNG_LIST_SESSIONS: { unsigned int nr_sessions; - void *sessions_payload; + lttng_session *sessions_payload; size_t payload_len; session_lock_list(); @@ -2026,7 +2038,7 @@ error_add_context: payload_len = (sizeof(struct lttng_session) * nr_sessions) + (sizeof(struct lttng_session_extended) * nr_sessions); - sessions_payload = zmalloc(payload_len); + sessions_payload = (lttng_session *) zmalloc(payload_len); if (!sessions_payload) { session_unlock_list(); @@ -2113,9 +2125,10 @@ error_add_context: { uint32_t snapshot_id; struct lttcomm_lttng_output_id reply; + lttng_snapshot_output output = cmd_ctx->lsm.u.snapshot_output.output; ret = cmd_snapshot_add_output(cmd_ctx->session, - ALIGNED_CONST_PTR(cmd_ctx->lsm.u.snapshot_output.output), + &output, &snapshot_id); if (ret != LTTNG_OK) { goto error; @@ -2134,8 +2147,8 @@ error_add_context: } case LTTNG_SNAPSHOT_DEL_OUTPUT: { - ret = cmd_snapshot_del_output(cmd_ctx->session, - ALIGNED_CONST_PTR(cmd_ctx->lsm.u.snapshot_output.output)); + lttng_snapshot_output output = cmd_ctx->lsm.u.snapshot_output.output; + ret = cmd_snapshot_del_output(cmd_ctx->session, &output); break; } case LTTNG_SNAPSHOT_LIST_OUTPUT: @@ -2163,8 +2176,9 @@ error_add_context: } case LTTNG_SNAPSHOT_RECORD: { + lttng_snapshot_output output = cmd_ctx->lsm.u.snapshot_record.output; ret = cmd_snapshot_record(cmd_ctx->session, - ALIGNED_CONST_PTR(cmd_ctx->lsm.u.snapshot_record.output), + &output, cmd_ctx->lsm.u.snapshot_record.wait); break; } @@ -2371,12 +2385,12 @@ error_add_context: } case LTTNG_SESSION_LIST_ROTATION_SCHEDULES: { - struct lttng_session_list_schedules_return schedules = { - .periodic.set = !!cmd_ctx->session->rotate_timer_period, - .periodic.value = cmd_ctx->session->rotate_timer_period, - .size.set = !!cmd_ctx->session->rotate_size, - .size.value = cmd_ctx->session->rotate_size, - }; + lttng_session_list_schedules_return schedules; + + schedules.periodic.set = !!cmd_ctx->session->rotate_timer_period; + schedules.periodic.value = cmd_ctx->session->rotate_timer_period; + schedules.size.set = !!cmd_ctx->session->rotate_size; + schedules.size.value = cmd_ctx->session->rotate_size; ret = setup_lttng_msg_no_cmd_header(cmd_ctx, &schedules, sizeof(schedules)); @@ -2553,7 +2567,7 @@ end: static void cleanup_client_thread(void *data) { - struct lttng_pipe *quit_pipe = data; + struct lttng_pipe *quit_pipe = (lttng_pipe *) data; lttng_pipe_destroy(quit_pipe); } @@ -2574,7 +2588,7 @@ static void *thread_manage_clients(void *data) uint32_t revents, nb_fd; struct lttng_poll_event events; const int client_sock = thread_state.client_sock; - struct lttng_pipe *quit_pipe = data; + struct lttng_pipe *quit_pipe = (lttng_pipe *) data; const int thread_quit_pipe_fd = lttng_pipe_get_readfd(quit_pipe); struct command_ctx cmd_ctx = {}; @@ -2636,10 +2650,9 @@ static void *thread_manage_clients(void *data) while (1) { const struct cmd_completion_handler *cmd_completion_handler; - cmd_ctx.creds = (lttng_sock_cred) { - .uid = UINT32_MAX, - .gid = UINT32_MAX, - }; + cmd_ctx.creds.uid = UINT32_MAX; + cmd_ctx.creds.gid = UINT32_MAX; + cmd_ctx.creds.pid = 0; cmd_ctx.session = NULL; lttng_payload_clear(&cmd_ctx.reply_payload); cmd_ctx.lttng_msg_size = 0; @@ -2762,7 +2775,7 @@ static void *thread_manage_clients(void *data) if (ret < LTTNG_OK || ret >= LTTNG_ERR_NR) { WARN("Command returned an invalid status code, returning unknown error: " "command type = %s (%d), ret = %d", - lttcomm_sessiond_command_str(cmd_ctx.lsm.cmd_type), + lttcomm_sessiond_command_str((lttcomm_sessiond_command) cmd_ctx.lsm.cmd_type), cmd_ctx.lsm.cmd_type, ret); ret = LTTNG_ERR_UNK; } @@ -2848,7 +2861,7 @@ error_create_poll: static bool shutdown_client_thread(void *thread_data) { - struct lttng_pipe *client_quit_pipe = thread_data; + struct lttng_pipe *client_quit_pipe = (lttng_pipe *) thread_data; const int write_fd = lttng_pipe_get_writefd(client_quit_pipe); return notify_thread_pipe(write_fd) == 1; diff --git a/src/bin/lttng-sessiond/cmd.c b/src/bin/lttng-sessiond/cmd.cpp similarity index 98% rename from src/bin/lttng-sessiond/cmd.c rename to src/bin/lttng-sessiond/cmd.cpp index 2c0fa462d..4ddff45b4 100644 --- a/src/bin/lttng-sessiond/cmd.c +++ b/src/bin/lttng-sessiond/cmd.cpp @@ -8,6 +8,7 @@ #define _LGPL_SOURCE +#include #include #include #include @@ -489,11 +490,11 @@ static int list_lttng_agent_events(struct agent *agt, rcu_read_lock(); cds_lfht_for_each_entry ( agt->events->ht, &iter.iter, agent_event, node.node) { - struct lttng_event event = { - .enabled = AGENT_EVENT_IS_ENABLED(agent_event), - .loglevel = agent_event->loglevel_value, - .loglevel_type = agent_event->loglevel_type, - }; + struct lttng_event event {}; + + event.loglevel_type = agent_event->loglevel_type; + event.loglevel = agent_event->loglevel_value; + event.enabled = AGENT_EVENT_IS_ENABLED(agent_event); ret = lttng_strncpy(event.name, agent_event->name, sizeof(event.name)); if (ret) { @@ -807,7 +808,7 @@ static enum lttng_error_code add_uri_to_consumer( /* Set URI into consumer output object */ ret = consumer_set_network_uri(session, consumer, uri); if (ret < 0) { - ret_code = -ret; + ret_code = (lttng_error_code) -ret; goto error; } else if (ret == 1) { /* @@ -2055,7 +2056,7 @@ end: static inline bool name_starts_with(const char *name, const char *prefix) { - const size_t max_cmp_len = min(strlen(prefix), LTTNG_SYMBOL_NAME_LEN); + const size_t max_cmp_len = std::min(strlen(prefix), (size_t) LTTNG_SYMBOL_NAME_LEN); return !strncmp(name, prefix, max_cmp_len); } @@ -2192,7 +2193,7 @@ static int _cmd_enable_event(struct ltt_session *session, } } if (filter) { - filter_a = zmalloc(sizeof(*filter_a) + filter->len); + filter_a = (lttng_bytecode *) zmalloc(sizeof(*filter_a) + filter->len); if (!filter_a) { free(filter_expression_a); ret = LTTNG_ERR_FATAL; @@ -2419,7 +2420,7 @@ static int _cmd_enable_event(struct ltt_session *session, struct lttng_bytecode) + filter->len; - filter_copy = zmalloc(filter_size); + filter_copy = (lttng_bytecode *) zmalloc(filter_size); if (!filter_copy) { ret = LTTNG_ERR_NOMEM; goto error; @@ -2673,7 +2674,7 @@ int cmd_start_trace(struct ltt_session *session) goto error; } LTTNG_ASSERT(!session->current_trace_chunk); - ret = session_set_trace_chunk(session, trace_chunk, + ret = (lttng_error_code) session_set_trace_chunk(session, trace_chunk, NULL); lttng_trace_chunk_put(trace_chunk); if (ret) { @@ -2693,7 +2694,7 @@ int cmd_start_trace(struct ltt_session *session) * was produced as the session was stopped, so the * rotation should happen on reception of the command. */ - ret = cmd_rotate_session(session, NULL, true, + ret = (lttng_error_code) cmd_rotate_session(session, NULL, true, LTTNG_TRACE_CHUNK_COMMAND_TYPE_NO_OPERATION); if (ret != LTTNG_OK) { goto error; @@ -2704,7 +2705,7 @@ int cmd_start_trace(struct ltt_session *session) /* Kernel tracing */ if (ksession != NULL) { DBG("Start kernel tracing session %s", session->name); - ret = start_kernel_session(ksession); + ret = (lttng_error_code) start_kernel_session(ksession); if (ret != LTTNG_OK) { goto error; } @@ -2991,7 +2992,7 @@ enum lttng_error_code set_session_output_from_descriptor( case LTTNG_SESSION_DESCRIPTOR_TYPE_REGULAR: case LTTNG_SESSION_DESCRIPTOR_TYPE_LIVE: { - ret_code = cmd_set_consumer_uri(session, uri_count, uris); + ret_code = (lttng_error_code) cmd_set_consumer_uri(session, uri_count, uris); break; } default: @@ -3195,7 +3196,7 @@ void cmd_destroy_session_reply(const struct ltt_session *session, int ret; ssize_t comm_ret; const struct cmd_destroy_session_reply_context *reply_context = - _reply_context; + (cmd_destroy_session_reply_context *) _reply_context; struct lttng_dynamic_buffer payload; struct lttcomm_session_destroy_command_header cmd_header; struct lttng_trace_archive_location *location = NULL; @@ -3288,7 +3289,7 @@ int cmd_destroy_session(struct ltt_session *session, struct cmd_destroy_session_reply_context *reply_context = NULL; if (sock_fd) { - reply_context = zmalloc(sizeof(*reply_context)); + reply_context = (cmd_destroy_session_reply_context *) zmalloc(sizeof(*reply_context)); if (!reply_context) { ret = LTTNG_ERR_NOMEM; goto end; @@ -3309,7 +3310,7 @@ int cmd_destroy_session(struct ltt_session *session, /* Carry on with the destruction of the session. */ ERR("Failed to stop session \"%s\" as part of its destruction: %s", session->name, lttng_strerror(-ret)); - destruction_last_error = ret; + destruction_last_error = (lttng_error_code) ret; } } @@ -3337,7 +3338,7 @@ int cmd_destroy_session(struct ltt_session *session, if (ret != LTTNG_OK) { ERR("Failed to perform an implicit rotation as part of the destruction of session \"%s\": %s", session->name, lttng_strerror(-ret)); - destruction_last_error = -ret; + destruction_last_error = (lttng_error_code) -ret; } if (reply_context) { reply_context->implicit_rotation_on_destroy = true; @@ -3365,7 +3366,7 @@ int cmd_destroy_session(struct ltt_session *session, ret != -LTTNG_ERR_ROTATION_NOT_AVAILABLE_KERNEL) { ERR("Failed to perform a quiet rotation as part of the destruction of session \"%s\": %s", session->name, lttng_strerror(ret)); - destruction_last_error = -ret; + destruction_last_error = (lttng_error_code) -ret; } } @@ -3491,7 +3492,7 @@ int cmd_register_consumer(struct ltt_session *session, goto error; } - socket->lock = zmalloc(sizeof(pthread_mutex_t)); + socket->lock = (pthread_mutex_t *) zmalloc(sizeof(pthread_mutex_t)); if (socket->lock == NULL) { PERROR("zmalloc pthread mutex"); ret = LTTNG_ERR_FATAL; @@ -3559,7 +3560,7 @@ ssize_t cmd_list_domains(struct ltt_session *session, goto end; } - *domains = zmalloc(nb_dom * sizeof(struct lttng_domain)); + *domains = (lttng_domain *) zmalloc(nb_dom * sizeof(struct lttng_domain)); if (*domains == NULL) { ret = LTTNG_ERR_FATAL; goto error; @@ -3642,14 +3643,14 @@ ssize_t cmd_list_channels(enum lttng_domain_type domain, struct lttng_channel_extended *channel_exts; payload_size = nb_chan * channel_size; - *channels = zmalloc(payload_size); + *channels = (lttng_channel *) zmalloc(payload_size); if (*channels == NULL) { ret = -LTTNG_ERR_FATAL; goto end; } - channel_exts = ((void *) *channels) + - (nb_chan * sizeof(struct lttng_channel)); + channel_exts = (lttng_channel_extended *) + (((char *) *channels) + (nb_chan * sizeof(struct lttng_channel))); ret = list_lttng_channels(domain, session, *channels, channel_exts); if (ret != LTTNG_OK) { free(*channels); @@ -4015,7 +4016,7 @@ ssize_t cmd_snapshot_list_outputs(struct ltt_session *session, goto end; } - list = zmalloc(session->snapshot.nb_output * sizeof(*list)); + list = (lttng_snapshot_output *) zmalloc(session->snapshot.nb_output * sizeof(*list)); if (!list) { ret = -LTTNG_ERR_NOMEM; goto end; @@ -4374,7 +4375,7 @@ enum lttng_error_code synchronize_tracer_notifier_register( agent_add(agt, the_trigger_agents_ht_by_domain); } - ret_code = trigger_agent_enable(trigger, agt); + ret_code = (lttng_error_code) trigger_agent_enable(trigger, agt); if (ret_code != LTTNG_OK) { goto end_unlock_session_list; } @@ -4535,7 +4536,7 @@ enum lttng_error_code synchronize_tracer_notifier_unregister( * this function under those circumstances is an internal error. */ LTTNG_ASSERT(agt); - ret_code = trigger_agent_disable(trigger, agt); + ret_code = (lttng_error_code) trigger_agent_disable(trigger, agt); if (ret_code != LTTNG_OK) { goto end_unlock_session_list; } @@ -4870,7 +4871,7 @@ static enum lttng_error_code set_relayd_for_snapshot( cds_lfht_for_each_entry(output->socks->ht, &iter.iter, socket, node.node) { pthread_mutex_lock(socket->lock); - status = send_consumer_relayd_sockets(0, session->id, + status = send_consumer_relayd_sockets(LTTNG_DOMAIN_NONE, session->id, output, socket, session->name, session->hostname, base_path, @@ -5521,7 +5522,7 @@ int cmd_rotate_session(struct ltt_session *session, if (ret != LTTNG_OK) { ERR("Failed to notify notification thread that a session rotation is ongoing for session %s", session->name); - cmd_ret = ret; + cmd_ret = (lttng_error_code) ret; } } @@ -5836,7 +5837,7 @@ end: /* Wait for a given path to be removed before continuing. */ static enum lttng_error_code wait_on_path(void *path_data) { - const char *shm_path = path_data; + const char *shm_path = (const char *) path_data; DBG("Waiting for the shm path at %s to be removed before completing session destruction", shm_path); diff --git a/src/bin/lttng-sessiond/condition-internal.c b/src/bin/lttng-sessiond/condition-internal.cpp similarity index 100% rename from src/bin/lttng-sessiond/condition-internal.c rename to src/bin/lttng-sessiond/condition-internal.cpp diff --git a/src/bin/lttng-sessiond/condition-internal.h b/src/bin/lttng-sessiond/condition-internal.h index 270a8b1af..fa8f7be04 100644 --- a/src/bin/lttng-sessiond/condition-internal.h +++ b/src/bin/lttng-sessiond/condition-internal.h @@ -10,6 +10,10 @@ #include +#ifdef __cplusplus +extern "C" { +#endif + /* * The lttng_condition hashing code is kept in this file (rather than * condition.c) since it makes use of GPLv2 code (hashtable utils), which we @@ -19,4 +23,9 @@ unsigned long lttng_condition_hash(const struct lttng_condition *condition); struct lttng_condition *lttng_condition_copy( const struct lttng_condition *condition); + +#ifdef __cplusplus +} +#endif + #endif /* LTTNG_SESSIOND_CONDITION_INTERNAL_H */ diff --git a/src/bin/lttng-sessiond/consumer.c b/src/bin/lttng-sessiond/consumer.cpp similarity index 98% rename from src/bin/lttng-sessiond/consumer.c rename to src/bin/lttng-sessiond/consumer.cpp index 7c36d61be..f7a92cb3d 100644 --- a/src/bin/lttng-sessiond/consumer.c +++ b/src/bin/lttng-sessiond/consumer.cpp @@ -49,7 +49,7 @@ char *setup_channel_trace_path(struct consumer_output *consumer, * Allocate the string ourself to make sure we never exceed * LTTNG_PATH_MAX. */ - pathname = zmalloc(LTTNG_PATH_MAX); + pathname = (char *) zmalloc(LTTNG_PATH_MAX); if (!pathname) { goto error; } @@ -425,7 +425,7 @@ struct consumer_socket *consumer_allocate_socket(int *fd) LTTNG_ASSERT(fd); - socket = zmalloc(sizeof(struct consumer_socket)); + socket = (consumer_socket *) zmalloc(sizeof(struct consumer_socket)); if (socket == NULL) { PERROR("zmalloc consumer socket"); goto error; @@ -512,7 +512,7 @@ struct consumer_output *consumer_create_output(enum consumer_dst_type type) { struct consumer_output *output = NULL; - output = zmalloc(sizeof(struct consumer_output)); + output = (consumer_output *) zmalloc(sizeof(struct consumer_output)); if (output == NULL) { PERROR("zmalloc consumer_output"); goto error; @@ -1134,6 +1134,7 @@ int consumer_send_relayd_socket(struct consumer_socket *consumer_sock, bool session_name_contains_creation_time) { int ret; + int fd; struct lttcomm_consumer_msg msg; /* Code flow error. Safety net. */ @@ -1187,7 +1188,8 @@ int consumer_send_relayd_socket(struct consumer_socket *consumer_sock, } DBG3("Sending relayd socket file descriptor to consumer"); - ret = consumer_send_fds(consumer_sock, ALIGNED_CONST_PTR(rsock->sock.fd), 1); + fd = rsock->sock.fd; + ret = consumer_send_fds(consumer_sock, &fd, 1); if (ret < 0) { goto error; } @@ -1724,10 +1726,10 @@ error: int consumer_open_channel_packets(struct consumer_socket *socket, uint64_t key) { int ret; - const struct lttcomm_consumer_msg msg = { + lttcomm_consumer_msg msg = { .cmd_type = LTTNG_CONSUMER_OPEN_CHANNEL_PACKETS, - .u.open_channel_packets.key = key, }; + msg.u.open_channel_packets.key = key; LTTNG_ASSERT(socket); @@ -1825,8 +1827,8 @@ int consumer_create_trace_chunk(struct consumer_socket *socket, enum lttng_trace_chunk_status tc_status; struct lttcomm_consumer_msg msg = { .cmd_type = LTTNG_CONSUMER_CREATE_TRACE_CHUNK, - .u.create_trace_chunk.session_id = session_id, }; + msg.u.create_trace_chunk.session_id = session_id; LTTNG_ASSERT(socket); LTTNG_ASSERT(chunk); @@ -1977,10 +1979,11 @@ int consumer_close_trace_chunk(struct consumer_socket *socket, { int ret; enum lttng_trace_chunk_status chunk_status; - struct lttcomm_consumer_msg msg = { - .cmd_type = LTTNG_CONSUMER_CLOSE_TRACE_CHUNK, - .u.close_trace_chunk.session_id = session_id, + lttcomm_consumer_msg msg = { + .cmd_type = LTTNG_CONSUMER_CLOSE_TRACE_CHUNK, }; + msg.u.close_trace_chunk.session_id = session_id; + struct lttcomm_consumer_close_trace_chunk_reply reply; uint64_t chunk_id; time_t close_timestamp; @@ -2102,10 +2105,11 @@ int consumer_trace_chunk_exists(struct consumer_socket *socket, { int ret; enum lttng_trace_chunk_status chunk_status; - struct lttcomm_consumer_msg msg = { + lttcomm_consumer_msg msg = { .cmd_type = LTTNG_CONSUMER_TRACE_CHUNK_EXISTS, - .u.trace_chunk_exists.session_id = session_id, }; + msg.u.trace_chunk_exists.session_id = session_id; + uint64_t chunk_id; const char *consumer_reply_str; diff --git a/src/bin/lttng-sessiond/consumer.h b/src/bin/lttng-sessiond/consumer.h index eaa04d302..ffba198a8 100644 --- a/src/bin/lttng-sessiond/consumer.h +++ b/src/bin/lttng-sessiond/consumer.h @@ -12,6 +12,7 @@ #include #include #include +#include #include "snapshot.h" @@ -19,6 +20,19 @@ struct snapshot; struct snapshot_output; struct ltt_session; +/* + * Needed until we use C++14, where std::max is constexpr. + * + * Use a static_assert so we remember to remove it when we upgrade to a newer + * C++. + */ +static_assert(__cplusplus == 201103L, ""); +template +constexpr T max_constexpr(T l, T r) +{ + return l > r ? l : r; +} + enum consumer_dst_type { CONSUMER_DST_LOCAL, CONSUMER_DST_NET, @@ -61,39 +75,43 @@ struct consumer_socket { }; struct consumer_data { + consumer_data (lttng_consumer_type type_) + : type(type_) + {} + enum lttng_consumer_type type; /* Mutex to control consumerd pid assignation */ - pthread_mutex_t pid_mutex; - pid_t pid; + pthread_mutex_t pid_mutex = PTHREAD_MUTEX_INITIALIZER; + pid_t pid = 0; - int err_sock; + int err_sock = -1; /* These two sockets uses the cmd_unix_sock_path. */ - int cmd_sock; + int cmd_sock = -1; /* * Write-end of the channel monitoring pipe to be passed to the * consumer. */ - int channel_monitor_pipe; + int channel_monitor_pipe = -1; /* * The metadata socket object is handled differently and only created * locally in this object thus it's the only reference available in the * session daemon. For that reason, a variable for the fd is required and * the metadata socket fd points to it. */ - int metadata_fd; - struct consumer_socket metadata_sock; + int metadata_fd = 0; + struct consumer_socket metadata_sock {}; /* consumer error and command Unix socket path */ - const char *err_unix_sock_path; - const char *cmd_unix_sock_path; + const char *err_unix_sock_path = nullptr; + const char *cmd_unix_sock_path = nullptr; /* * This lock has two purposes. It protects any change to the consumer * socket and make sure only one thread uses this object for read/write * operations. */ - pthread_mutex_t lock; + pthread_mutex_t lock = PTHREAD_MUTEX_INITIALIZER; }; /* @@ -149,7 +167,8 @@ struct consumer_output { * Subdirectory path name used for both local and network * consumer ("kernel", "ust", or empty). */ - char domain_subdir[max(sizeof(DEFAULT_KERNEL_TRACE_DIR), + char domain_subdir[ + max_constexpr(sizeof(DEFAULT_KERNEL_TRACE_DIR), sizeof(DEFAULT_UST_TRACE_DIR))]; /* diff --git a/src/bin/lttng-sessiond/context.c b/src/bin/lttng-sessiond/context.cpp similarity index 100% rename from src/bin/lttng-sessiond/context.c rename to src/bin/lttng-sessiond/context.cpp diff --git a/src/bin/lttng-sessiond/dispatch.c b/src/bin/lttng-sessiond/dispatch.cpp similarity index 98% rename from src/bin/lttng-sessiond/dispatch.c rename to src/bin/lttng-sessiond/dispatch.cpp index a767ccbdd..b4092eb44 100644 --- a/src/bin/lttng-sessiond/dispatch.c +++ b/src/bin/lttng-sessiond/dispatch.cpp @@ -232,7 +232,7 @@ static void *thread_dispatch_ust_registration(void *data) struct ust_reg_wait_queue wait_queue = { .count = 0, }; - struct thread_notifiers *notifiers = data; + struct thread_notifiers *notifiers = (thread_notifiers *) data; rcu_register_thread(); @@ -291,7 +291,7 @@ static void *thread_dispatch_ust_registration(void *data) ust_cmd->reg_msg.major, ust_cmd->reg_msg.minor); if (ust_cmd->reg_msg.type == LTTNG_UST_CTL_SOCKET_CMD) { - wait_node = zmalloc(sizeof(*wait_node)); + wait_node = (ust_reg_wait_node *) zmalloc(sizeof(*wait_node)); if (!wait_node) { PERROR("zmalloc wait_node dispatch"); ret = close(ust_cmd->sock); @@ -495,7 +495,7 @@ error_testpoint: static bool shutdown_ust_dispatch_thread(void *data) { - struct thread_notifiers *notifiers = data; + struct thread_notifiers *notifiers = (thread_notifiers *) data; CMM_STORE_SHARED(notifiers->dispatch_thread_exit, 1); futex_nto1_wake(¬ifiers->ust_cmd_queue->futex); @@ -509,7 +509,7 @@ bool launch_ust_dispatch_thread(struct ust_cmd_queue *cmd_queue, struct lttng_thread *thread; struct thread_notifiers *notifiers; - notifiers = zmalloc(sizeof(*notifiers)); + notifiers = (thread_notifiers *) zmalloc(sizeof(*notifiers)); if (!notifiers) { goto error; } diff --git a/src/bin/lttng-sessiond/event-notifier-error-accounting.c b/src/bin/lttng-sessiond/event-notifier-error-accounting.cpp similarity index 97% rename from src/bin/lttng-sessiond/event-notifier-error-accounting.c rename to src/bin/lttng-sessiond/event-notifier-error-accounting.cpp index 1488d801c..c99c39338 100644 --- a/src/bin/lttng-sessiond/event-notifier-error-accounting.c +++ b/src/bin/lttng-sessiond/event-notifier-error-accounting.cpp @@ -375,11 +375,11 @@ struct ust_error_accounting_entry *ust_error_accounting_entry_create( struct lttng_ust_ctl_daemon_counter *daemon_counter; struct lttng_ust_abi_object_data *counter, **cpu_counters; struct ust_error_accounting_entry *entry = NULL; - const struct lttng_ust_ctl_counter_dimension dimension = { - .size = ust_state.number_indices, - .has_underflow = false, - .has_overflow = false, - }; + lttng_ust_ctl_counter_dimension dimension; + + dimension.size = ust_state.number_indices; + dimension.has_underflow = false; + dimension.has_overflow = false; if (!ust_app_supports_counters(app)) { DBG("Refusing to create accounting entry for application (unsupported feature): app name = '%s', app ppid = %d", @@ -387,7 +387,7 @@ struct ust_error_accounting_entry *ust_error_accounting_entry_create( goto error; } - entry = zmalloc(sizeof(struct ust_error_accounting_entry)); + entry = (ust_error_accounting_entry *) zmalloc(sizeof(struct ust_error_accounting_entry)); if (!entry) { PERROR("Failed to allocate event notifier error acounting entry") goto error; @@ -397,7 +397,7 @@ struct ust_error_accounting_entry *ust_error_accounting_entry_create( entry->uid = app->uid; entry->nr_counter_cpu_fds = lttng_ust_ctl_get_nr_cpu_per_counter(); - cpu_counter_fds = zmalloc(entry->nr_counter_cpu_fds * sizeof(*cpu_counter_fds)); + cpu_counter_fds = (int *) zmalloc(entry->nr_counter_cpu_fds * sizeof(*cpu_counter_fds)); if (!cpu_counter_fds) { PERROR("Failed to allocate event notifier error counter file descriptors array: application uid = %d, application name = '%s', pid = %d, allocation size = %zu", (int) app->uid, app->name, (int) app->pid, @@ -410,7 +410,7 @@ struct ust_error_accounting_entry *ust_error_accounting_entry_create( cpu_counter_fds[i] = -1; } - cpu_counters = zmalloc(entry->nr_counter_cpu_fds * sizeof(struct lttng_ust_abi_object_data *)); + cpu_counters = (lttng_ust_abi_object_data **) zmalloc(entry->nr_counter_cpu_fds * sizeof(struct lttng_ust_abi_object_data *)); if (!cpu_counters) { PERROR("Failed to allocate event notifier error counter lttng_ust_abi_object_data array: application uid = %d, application name = '%s', pid = %d, allocation size = %zu", (int) app->uid, app->name, (int) app->pid, @@ -654,7 +654,7 @@ event_notifier_error_accounting_register_app(struct ust_app *app) goto error_send_counter_data; } - cpu_counters = zmalloc(entry->nr_counter_cpu_fds * sizeof(struct lttng_ust_abi_object_data *)); + cpu_counters = (lttng_ust_abi_object_data **) zmalloc(entry->nr_counter_cpu_fds * sizeof(struct lttng_ust_abi_object_data *)); if (!cpu_counters) { PERROR("Failed to allocate event notifier error counter lttng_ust_abi_object_data array: application uid = %d, application name = '%s', pid = %d, allocation size = %zu", (int) app->uid, app->name, (int) app->pid, @@ -975,17 +975,17 @@ event_notifier_error_accounting_register_kernel( { int error_counter_fd = -1, ret; enum event_notifier_error_accounting_status status; - const struct lttng_kernel_abi_counter_conf error_counter_conf = { + lttng_kernel_abi_counter_conf error_counter_conf = { .arithmetic = LTTNG_KERNEL_ABI_COUNTER_ARITHMETIC_MODULAR, .bitness = sizeof(void *) == sizeof(uint32_t) ? LTTNG_KERNEL_ABI_COUNTER_BITNESS_32 : LTTNG_KERNEL_ABI_COUNTER_BITNESS_64, - .global_sum_step = 0, .number_dimensions = 1, - .dimensions[0].size = kernel_state.number_indices, - .dimensions[0].has_underflow = false, - .dimensions[0].has_overflow = false, + .global_sum_step = 0, }; + error_counter_conf.dimensions[0].size = kernel_state.number_indices; + error_counter_conf.dimensions[0].has_underflow = false; + error_counter_conf.dimensions[0].has_overflow = false; ret = kernctl_create_event_notifier_group_error_counter( kernel_event_notifier_group_fd, &error_counter_conf); @@ -1036,7 +1036,7 @@ enum event_notifier_error_accounting_status create_error_counter_index_for_token switch (index_alloc_status) { case LTTNG_INDEX_ALLOCATOR_STATUS_EMPTY: DBG("No indices left in the configured event notifier error counter: " - "number-of-indices = %"PRIu64, + "number-of-indices = %" PRIu64, lttng_index_allocator_get_index_count( state->index_allocator)); status = EVENT_NOTIFIER_ERROR_ACCOUNTING_STATUS_NO_INDEX_AVAILABLE; @@ -1048,7 +1048,7 @@ enum event_notifier_error_accounting_status create_error_counter_index_for_token goto end; } - index_entry = zmalloc(sizeof(*index_entry)); + index_entry = (index_ht_entry *) zmalloc(sizeof(*index_entry)); if (index_entry == NULL) { PERROR("Failed to allocate event notifier error counter hash table entry"); status = EVENT_NOTIFIER_ERROR_ACCOUNTING_STATUS_NOMEM; diff --git a/src/bin/lttng-sessiond/event.c b/src/bin/lttng-sessiond/event.cpp similarity index 99% rename from src/bin/lttng-sessiond/event.c rename to src/bin/lttng-sessiond/event.cpp index 97bb69ba8..284a8c472 100644 --- a/src/bin/lttng-sessiond/event.c +++ b/src/bin/lttng-sessiond/event.cpp @@ -49,7 +49,7 @@ static void add_unique_ust_event(struct lttng_ht *ht, key.name = event->attr.name; key.filter = (struct lttng_bytecode *) event->filter; - key.loglevel_type = event->attr.loglevel_type; + key.loglevel_type = (lttng_ust_abi_loglevel_type) event->attr.loglevel_type; key.loglevel_value = event->attr.loglevel; key.exclusion = event->exclusion; diff --git a/src/bin/lttng-sessiond/fd-limit.c b/src/bin/lttng-sessiond/fd-limit.cpp similarity index 97% rename from src/bin/lttng-sessiond/fd-limit.c rename to src/bin/lttng-sessiond/fd-limit.cpp index 973f7d74a..833b64714 100644 --- a/src/bin/lttng-sessiond/fd-limit.c +++ b/src/bin/lttng-sessiond/fd-limit.cpp @@ -21,7 +21,7 @@ static long fd_count; * threshold in % of number of fd allowed. */ static long fd_threshold[LTTNG_FD_NR_TYPES] = { - [LTTNG_FD_APPS] = 75, + 75, /* LTTNG_FD_APPS */ }; static rlim_t max_nr_fd; diff --git a/src/bin/lttng-sessiond/globals.c b/src/bin/lttng-sessiond/globals.cpp similarity index 64% rename from src/bin/lttng-sessiond/globals.c rename to src/bin/lttng-sessiond/globals.cpp index ee08ef1b0..b4cedf337 100644 --- a/src/bin/lttng-sessiond/globals.c +++ b/src/bin/lttng-sessiond/globals.cpp @@ -34,32 +34,9 @@ pid_t the_child_ppid; struct sessiond_config the_config; -struct consumer_data the_kconsumer_data = { - .type = LTTNG_CONSUMER_KERNEL, - .err_sock = -1, - .cmd_sock = -1, - .channel_monitor_pipe = -1, - .pid_mutex = PTHREAD_MUTEX_INITIALIZER, - .lock = PTHREAD_MUTEX_INITIALIZER, -}; - -struct consumer_data the_ustconsumer64_data = { - .type = LTTNG_CONSUMER64_UST, - .err_sock = -1, - .cmd_sock = -1, - .channel_monitor_pipe = -1, - .pid_mutex = PTHREAD_MUTEX_INITIALIZER, - .lock = PTHREAD_MUTEX_INITIALIZER, -}; - -struct consumer_data the_ustconsumer32_data = { - .type = LTTNG_CONSUMER32_UST, - .err_sock = -1, - .cmd_sock = -1, - .channel_monitor_pipe = -1, - .pid_mutex = PTHREAD_MUTEX_INITIALIZER, - .lock = PTHREAD_MUTEX_INITIALIZER, -}; +consumer_data the_kconsumer_data(LTTNG_CONSUMER_KERNEL); +consumer_data the_ustconsumer64_data(LTTNG_CONSUMER64_UST); +consumer_data the_ustconsumer32_data(LTTNG_CONSUMER32_UST); enum consumerd_state the_ust_consumerd_state; enum consumerd_state the_kernel_consumerd_state; diff --git a/src/bin/lttng-sessiond/health.c b/src/bin/lttng-sessiond/health.cpp similarity index 95% rename from src/bin/lttng-sessiond/health.c rename to src/bin/lttng-sessiond/health.cpp index 7fc557da5..53b9ee01f 100644 --- a/src/bin/lttng-sessiond/health.c +++ b/src/bin/lttng-sessiond/health.cpp @@ -39,7 +39,7 @@ void wait_until_thread_is_ready(struct thread_notifiers *notifiers) static void cleanup_health_management_thread(void *data) { - struct thread_notifiers *notifiers = data; + struct thread_notifiers *notifiers = (thread_notifiers *) data; lttng_pipe_destroy(notifiers->quit_pipe); sem_destroy(¬ifiers->ready); @@ -58,7 +58,7 @@ static void *thread_manage_health(void *data) struct health_comm_msg msg; struct health_comm_reply reply; /* Thread-specific quit pipe. */ - struct thread_notifiers *notifiers = data; + struct thread_notifiers *notifiers = (thread_notifiers *) data; const int quit_pipe_read_fd = lttng_pipe_get_readfd( notifiers->quit_pipe); @@ -244,7 +244,7 @@ error: static bool shutdown_health_management_thread(void *data) { - struct thread_notifiers *notifiers = data; + struct thread_notifiers *notifiers = ( thread_notifiers *) data; const int write_fd = lttng_pipe_get_writefd(notifiers->quit_pipe); return notify_thread_pipe(write_fd) == 1; @@ -255,7 +255,7 @@ bool launch_health_management_thread(void) struct thread_notifiers *notifiers; struct lttng_thread *thread; - notifiers = zmalloc(sizeof(*notifiers)); + notifiers = (thread_notifiers *) zmalloc(sizeof(*notifiers)); if (!notifiers) { goto error_alloc; } diff --git a/src/bin/lttng-sessiond/ht-cleanup.c b/src/bin/lttng-sessiond/ht-cleanup.cpp similarity index 100% rename from src/bin/lttng-sessiond/ht-cleanup.c rename to src/bin/lttng-sessiond/ht-cleanup.cpp diff --git a/src/bin/lttng-sessiond/kernel-consumer.c b/src/bin/lttng-sessiond/kernel-consumer.cpp similarity index 100% rename from src/bin/lttng-sessiond/kernel-consumer.c rename to src/bin/lttng-sessiond/kernel-consumer.cpp diff --git a/src/bin/lttng-sessiond/kernel.c b/src/bin/lttng-sessiond/kernel.cpp similarity index 99% rename from src/bin/lttng-sessiond/kernel.c rename to src/bin/lttng-sessiond/kernel.cpp index ffbde695e..22ce819b5 100644 --- a/src/bin/lttng-sessiond/kernel.c +++ b/src/bin/lttng-sessiond/kernel.cpp @@ -631,7 +631,7 @@ int kernel_create_event(struct lttng_event *ev, } if (ev->type == LTTNG_EVENT_USERSPACE_PROBE) { - ret = userspace_probe_event_add_callsites(ev, channel->session, + ret = (lttng_error_code) userspace_probe_event_add_callsites(ev, channel->session, event->fd); if (ret) { goto add_callsite_error; @@ -1436,7 +1436,7 @@ ssize_t kernel_list_events(struct lttng_event **events) * See kernel-ctl.h for explanation of this value */ nbmem = KERNEL_EVENT_INIT_LIST_SIZE; - elist = zmalloc(sizeof(struct lttng_event) * nbmem); + elist = (lttng_event *) zmalloc(sizeof(struct lttng_event) * nbmem); if (elist == NULL) { PERROR("alloc list events"); count = -ENOMEM; @@ -1451,7 +1451,7 @@ ssize_t kernel_list_events(struct lttng_event **events) new_nbmem = nbmem << 1; DBG("Reallocating event list from %zu to %zu bytes", nbmem, new_nbmem); - new_elist = realloc(elist, new_nbmem * sizeof(struct lttng_event)); + new_elist = (lttng_event *) realloc(elist, new_nbmem * sizeof(struct lttng_event)); if (new_elist == NULL) { PERROR("realloc list events"); free(event); @@ -2280,7 +2280,7 @@ static int match_trigger(struct cds_lfht_node *node, const void *key) { const struct ltt_kernel_event_notifier_rule *event_notifier_rule; - const struct lttng_trigger *trigger = key; + const struct lttng_trigger *trigger = (lttng_trigger *) key; event_notifier_rule = caa_container_of(node, const struct ltt_kernel_event_notifier_rule, ht_node); diff --git a/src/bin/lttng-sessiond/lttng-syscall.c b/src/bin/lttng-sessiond/lttng-syscall.cpp similarity index 92% rename from src/bin/lttng-sessiond/lttng-syscall.c rename to src/bin/lttng-sessiond/lttng-syscall.cpp index 06021bcf5..f14563457 100644 --- a/src/bin/lttng-sessiond/lttng-syscall.c +++ b/src/bin/lttng-sessiond/lttng-syscall.cpp @@ -60,7 +60,7 @@ int syscall_init_table(int tracer_fd) } nbmem = SYSCALL_TABLE_INIT_SIZE; - syscall_table = zmalloc(sizeof(struct syscall) * nbmem); + syscall_table = (struct syscall *) zmalloc(sizeof(struct syscall) * nbmem); if (!syscall_table) { ret = -errno; PERROR("syscall list zmalloc"); @@ -78,7 +78,7 @@ int syscall_init_table(int tracer_fd) size_t new_nbmem; /* Double memory size. */ - new_nbmem = max(index + 1, nbmem << 1); + new_nbmem = std::max(index + 1, nbmem << 1); if (new_nbmem > (SIZE_MAX / sizeof(*new_list))) { /* Overflow, stop everything, something went really wrong. */ ERR("Syscall listing memory size overflow. Stopping"); @@ -90,7 +90,7 @@ int syscall_init_table(int tracer_fd) DBG("Reallocating syscall table from %zu to %zu entries", nbmem, new_nbmem); - new_list = realloc(syscall_table, new_nbmem * sizeof(*new_list)); + new_list = (struct syscall *) realloc(syscall_table, new_nbmem * sizeof(*new_list)); if (!new_list) { ret = -errno; PERROR("syscall list realloc"); @@ -224,9 +224,9 @@ static void update_event_syscall_bitness(struct lttng_event *events, LTTNG_ASSERT(events); if (syscall_table[index].bitness == 32) { - events[syscall_index].flags |= LTTNG_EVENT_FLAG_SYSCALL_32; + events[syscall_index].flags = (lttng_event_flag) (events[syscall_index].flags | LTTNG_EVENT_FLAG_SYSCALL_32); } else { - events[syscall_index].flags |= LTTNG_EVENT_FLAG_SYSCALL_64; + events[syscall_index].flags = (lttng_event_flag) (events[syscall_index].flags | LTTNG_EVENT_FLAG_SYSCALL_64); } } @@ -243,7 +243,7 @@ static int add_syscall_to_ht(struct lttng_ht *ht, unsigned int index, LTTNG_ASSERT(ht); - ksyscall = zmalloc(sizeof(*ksyscall)); + ksyscall = (struct syscall *) zmalloc(sizeof(*ksyscall)); if (!ksyscall) { ret = -LTTNG_ERR_NOMEM; goto error; @@ -286,7 +286,7 @@ ssize_t syscall_table_list(struct lttng_event **_events) * them might not be valid. The count below will make sure to return the * right size of the events array. */ - events = zmalloc(syscall_table_nb_entry * sizeof(*events)); + events = (lttng_event *) zmalloc(syscall_table_nb_entry * sizeof(*events)); if (!events) { PERROR("syscall table list zmalloc"); ret = -LTTNG_ERR_NOMEM; diff --git a/src/bin/lttng-sessiond/main.c b/src/bin/lttng-sessiond/main.cpp similarity index 99% rename from src/bin/lttng-sessiond/main.c rename to src/bin/lttng-sessiond/main.cpp index 4effb3ce9..e5e718891 100644 --- a/src/bin/lttng-sessiond/main.c +++ b/src/bin/lttng-sessiond/main.cpp @@ -1410,7 +1410,7 @@ end: static int run_as_worker_post_fork_cleanup(void *data) { - struct sessiond_config *sessiond_config = data; + struct sessiond_config *sessiond_config = (struct sessiond_config *) data; sessiond_config_fini(sessiond_config); return 0; diff --git a/src/bin/lttng-sessiond/manage-apps.c b/src/bin/lttng-sessiond/manage-apps.cpp similarity index 95% rename from src/bin/lttng-sessiond/manage-apps.c rename to src/bin/lttng-sessiond/manage-apps.cpp index e2f3ed26a..cff56cbad 100644 --- a/src/bin/lttng-sessiond/manage-apps.c +++ b/src/bin/lttng-sessiond/manage-apps.cpp @@ -20,7 +20,7 @@ struct thread_notifiers { static void cleanup_application_management_thread(void *data) { - struct thread_notifiers *notifiers = data; + struct thread_notifiers *notifiers = (thread_notifiers *) data; lttng_pipe_destroy(notifiers->quit_pipe); free(notifiers); @@ -45,7 +45,7 @@ static void *thread_application_management(void *data) ssize_t size_ret; uint32_t revents, nb_fd; struct lttng_poll_event events; - struct thread_notifiers *notifiers = data; + struct thread_notifiers *notifiers = (thread_notifiers *) data; const int quit_pipe_read_fd = lttng_pipe_get_readfd( notifiers->quit_pipe); @@ -199,7 +199,7 @@ error_testpoint: static bool shutdown_application_management_thread(void *data) { - struct thread_notifiers *notifiers = data; + struct thread_notifiers *notifiers = (thread_notifiers *) data; const int write_fd = lttng_pipe_get_writefd(notifiers->quit_pipe); return notify_thread_pipe(write_fd) == 1; @@ -211,7 +211,7 @@ bool launch_application_management_thread(int apps_cmd_pipe_read_fd) struct thread_notifiers *notifiers = NULL; struct lttng_thread *thread; - notifiers = zmalloc(sizeof(*notifiers)); + notifiers = (thread_notifiers *) zmalloc(sizeof(*notifiers)); if (!notifiers) { goto error_alloc; } diff --git a/src/bin/lttng-sessiond/manage-consumer.c b/src/bin/lttng-sessiond/manage-consumer.cpp similarity index 96% rename from src/bin/lttng-sessiond/manage-consumer.c rename to src/bin/lttng-sessiond/manage-consumer.cpp index 719d42b18..d7df6ce8f 100644 --- a/src/bin/lttng-sessiond/manage-consumer.c +++ b/src/bin/lttng-sessiond/manage-consumer.cpp @@ -57,7 +57,7 @@ static void *thread_consumer_management(void *data) uint32_t revents, nb_fd; enum lttcomm_return_code code; struct lttng_poll_event events; - struct thread_notifiers *notifiers = data; + struct thread_notifiers *notifiers = (thread_notifiers *) data; struct consumer_data *consumer_data = notifiers->consumer_data; const int quit_pipe_read_fd = lttng_pipe_get_readfd(notifiers->quit_pipe); struct consumer_socket *cmd_socket_wrapper = NULL; @@ -172,7 +172,7 @@ static void *thread_consumer_management(void *data) health_code_update(); if (code != LTTCOMM_CONSUMERD_COMMAND_SOCK_READY) { ERR("consumer error when waiting for SOCK_READY : %s", - lttcomm_get_readable_code(-code)); + lttcomm_get_readable_code((lttcomm_return_code) -code)); mark_thread_intialization_as_failed(notifiers); goto error; } @@ -193,7 +193,7 @@ static void *thread_consumer_management(void *data) consumer_data->metadata_sock.fd_ptr = &consumer_data->metadata_fd; /* Create metadata socket lock. */ - consumer_data->metadata_sock.lock = zmalloc(sizeof(pthread_mutex_t)); + consumer_data->metadata_sock.lock = (pthread_mutex_t *) zmalloc(sizeof(pthread_mutex_t)); if (consumer_data->metadata_sock.lock == NULL) { PERROR("zmalloc pthread mutex"); mark_thread_intialization_as_failed(notifiers); @@ -317,7 +317,7 @@ static void *thread_consumer_management(void *data) } ERR("consumer return code : %s", - lttcomm_get_readable_code(-code)); + lttcomm_get_readable_code((lttcomm_return_code) -code)); goto exit; } else if (pollfd == consumer_data->metadata_fd) { @@ -417,7 +417,7 @@ error_poll: static bool shutdown_consumer_management_thread(void *data) { - struct thread_notifiers *notifiers = data; + struct thread_notifiers *notifiers = (thread_notifiers *) data; const int write_fd = lttng_pipe_get_writefd(notifiers->quit_pipe); return notify_thread_pipe(write_fd) == 1; @@ -425,7 +425,7 @@ static bool shutdown_consumer_management_thread(void *data) static void cleanup_consumer_management_thread(void *data) { - struct thread_notifiers *notifiers = data; + struct thread_notifiers *notifiers = (thread_notifiers *) data; lttng_pipe_destroy(notifiers->quit_pipe); free(notifiers); @@ -437,7 +437,7 @@ bool launch_consumer_management_thread(struct consumer_data *consumer_data) struct thread_notifiers *notifiers = NULL; struct lttng_thread *thread; - notifiers = zmalloc(sizeof(*notifiers)); + notifiers = (thread_notifiers *) zmalloc(sizeof(*notifiers)); if (!notifiers) { goto error_alloc; } diff --git a/src/bin/lttng-sessiond/manage-kernel.c b/src/bin/lttng-sessiond/manage-kernel.cpp similarity index 97% rename from src/bin/lttng-sessiond/manage-kernel.c rename to src/bin/lttng-sessiond/manage-kernel.cpp index 55ecbf8b3..2ffe60919 100644 --- a/src/bin/lttng-sessiond/manage-kernel.c +++ b/src/bin/lttng-sessiond/manage-kernel.cpp @@ -167,7 +167,7 @@ static void *thread_kernel_management(void *data) uint32_t revents, nb_fd; char tmp; struct lttng_poll_event events; - struct thread_notifiers *notifiers = data; + struct thread_notifiers *notifiers = (thread_notifiers *) data; const int quit_pipe_read_fd = lttng_pipe_get_readfd(notifiers->quit_pipe); DBG("[thread] Thread manage kernel started"); @@ -312,7 +312,7 @@ error_testpoint: static bool shutdown_kernel_management_thread(void *data) { - struct thread_notifiers *notifiers = data; + struct thread_notifiers *notifiers = (thread_notifiers *) data; const int write_fd = lttng_pipe_get_writefd(notifiers->quit_pipe); return notify_thread_pipe(write_fd) == 1; @@ -320,7 +320,7 @@ static bool shutdown_kernel_management_thread(void *data) static void cleanup_kernel_management_thread(void *data) { - struct thread_notifiers *notifiers = data; + struct thread_notifiers *notifiers = (thread_notifiers *) data; lttng_pipe_destroy(notifiers->quit_pipe); free(notifiers); @@ -332,7 +332,7 @@ bool launch_kernel_management_thread(int kernel_poll_pipe_read_fd) struct thread_notifiers *notifiers = NULL; struct lttng_thread *thread; - notifiers = zmalloc(sizeof(*notifiers)); + notifiers = (thread_notifiers *) zmalloc(sizeof(*notifiers)); if (!notifiers) { goto error_alloc; } diff --git a/src/bin/lttng-sessiond/modprobe.c b/src/bin/lttng-sessiond/modprobe.cpp similarity index 98% rename from src/bin/lttng-sessiond/modprobe.c rename to src/bin/lttng-sessiond/modprobe.cpp index 24b34d094..7e27a02eb 100644 --- a/src/bin/lttng-sessiond/modprobe.c +++ b/src/bin/lttng-sessiond/modprobe.cpp @@ -602,7 +602,7 @@ static int grow_probes(void) /* Initialize capacity to 1 if 0. */ if (probes_capacity == 0) { - probes = zmalloc(sizeof(*probes)); + probes = (kern_modules_param *) zmalloc(sizeof(*probes)); if (!probes) { PERROR("malloc probe list"); return -ENOMEM; @@ -615,7 +615,7 @@ static int grow_probes(void) /* Double size. */ probes_capacity *= 2; - tmp_probes = zmalloc(sizeof(*tmp_probes) * probes_capacity); + tmp_probes = (kern_modules_param *) zmalloc(sizeof(*tmp_probes) * probes_capacity); if (!tmp_probes) { PERROR("malloc probe list"); return -ENOMEM; @@ -677,7 +677,7 @@ static int append_list_to_probes(const char *list) name_len = strlen(next) + 13; cur_mod = &probes[nr_probes]; - cur_mod->name = zmalloc(name_len); + cur_mod->name = (char *) zmalloc(name_len); if (!cur_mod->name) { PERROR("malloc probe list"); ret = -ENOMEM; @@ -728,7 +728,7 @@ int modprobe_lttng_data(void) /* Default probes. */ int def_len = ARRAY_SIZE(kern_modules_probes_default); - probes = zmalloc(sizeof(*probes) * def_len); + probes = (kern_modules_param *) zmalloc(sizeof(*probes) * def_len); if (!probes) { PERROR("malloc probe list"); return -ENOMEM; diff --git a/src/bin/lttng-sessiond/notification-thread-commands.c b/src/bin/lttng-sessiond/notification-thread-commands.cpp similarity index 98% rename from src/bin/lttng-sessiond/notification-thread-commands.c rename to src/bin/lttng-sessiond/notification-thread-commands.cpp index 2908ccb76..600951159 100644 --- a/src/bin/lttng-sessiond/notification-thread-commands.c +++ b/src/bin/lttng-sessiond/notification-thread-commands.cpp @@ -59,7 +59,7 @@ struct notification_thread_command *notification_thread_command_copy( { struct notification_thread_command *new_cmd; - new_cmd = zmalloc(sizeof(*new_cmd)); + new_cmd = (notification_thread_command *) zmalloc(sizeof(*new_cmd)); if (!new_cmd) { goto end; } @@ -425,7 +425,7 @@ struct lttng_event_notifier_notification *lttng_event_notifier_notification_crea LTTNG_ASSERT(domain != LTTNG_DOMAIN_NONE); LTTNG_ASSERT((payload && payload_size) || (!payload && !payload_size)); - notification = zmalloc(sizeof(struct lttng_event_notifier_notification)); + notification = (lttng_event_notifier_notification *) zmalloc(sizeof(struct lttng_event_notifier_notification)); if (notification == NULL) { ERR("Error allocating notification"); goto end; diff --git a/src/bin/lttng-sessiond/notification-thread-events.c b/src/bin/lttng-sessiond/notification-thread-events.cpp similarity index 98% rename from src/bin/lttng-sessiond/notification-thread-events.c rename to src/bin/lttng-sessiond/notification-thread-events.cpp index a295739f2..6f449fc63 100644 --- a/src/bin/lttng-sessiond/notification-thread-events.c +++ b/src/bin/lttng-sessiond/notification-thread-events.cpp @@ -295,7 +295,7 @@ int match_trigger(struct cds_lfht_node *node, const void *key) static int match_trigger_token(struct cds_lfht_node *node, const void *key) { - const uint64_t *_key = key; + const uint64_t *_key = (uint64_t *) key; struct notification_trigger_tokens_ht_element *element; element = caa_container_of(node, @@ -322,7 +322,7 @@ int match_client_list_condition(struct cds_lfht_node *node, const void *key) static int match_session(struct cds_lfht_node *node, const void *key) { - const char *name = key; + const char *name = (const char *) key; struct session_info *session_info = caa_container_of( node, struct session_info, sessions_ht_node); @@ -522,7 +522,7 @@ void free_session_info_rcu(struct rcu_head *node) static void session_info_destroy(void *_data) { - struct session_info *session_info = _data; + struct session_info *session_info = (struct session_info *) _data; int ret; LTTNG_ASSERT(session_info); @@ -569,7 +569,7 @@ struct session_info *session_info_create(const char *name, uid_t uid, gid_t gid, LTTNG_ASSERT(name); - session_info = zmalloc(sizeof(*session_info)); + session_info = (struct session_info *) zmalloc(sizeof(*session_info)); if (!session_info) { goto end; } @@ -623,7 +623,7 @@ struct channel_info *channel_info_create(const char *channel_name, struct channel_key *channel_key, uint64_t channel_capacity, struct session_info *session_info) { - struct channel_info *channel_info = zmalloc(sizeof(*channel_info)); + struct channel_info *channel_info = (struct channel_info *) zmalloc(sizeof(*channel_info)); if (!channel_info) { goto end; @@ -723,7 +723,7 @@ struct notification_client_list *notification_client_list_create( struct cds_lfht_iter iter; struct notification_client_list *client_list; - client_list = zmalloc(sizeof(*client_list)); + client_list = (notification_client_list *) zmalloc(sizeof(*client_list)); if (!client_list) { PERROR("Failed to allocate notification client list"); goto end; @@ -755,7 +755,7 @@ struct notification_client_list *notification_client_list_create( continue; } - client_list_element = zmalloc(sizeof(*client_list_element)); + client_list_element = (notification_client_list_element *) zmalloc(sizeof(*client_list_element)); if (!client_list_element) { goto error_put_client_list; } @@ -1116,12 +1116,12 @@ int notification_thread_client_subscribe(struct notification_client *client, } } - condition_list_element = zmalloc(sizeof(*condition_list_element)); + condition_list_element = (lttng_condition_list_element *) zmalloc(sizeof(*condition_list_element)); if (!condition_list_element) { ret = -1; goto error; } - client_list_element = zmalloc(sizeof(*client_list_element)); + client_list_element = (notification_client_list_element *) zmalloc(sizeof(*client_list_element)); if (!client_list_element) { ret = -1; goto error; @@ -1494,7 +1494,7 @@ struct lttng_session_trigger_list *lttng_session_trigger_list_create( { struct lttng_session_trigger_list *list; - list = zmalloc(sizeof(*list)); + list = (lttng_session_trigger_list *) zmalloc(sizeof(*list)); if (!list) { goto end; } @@ -1545,7 +1545,7 @@ int lttng_session_trigger_list_add(struct lttng_session_trigger_list *list, { int ret = 0; struct lttng_trigger_list_element *new_element = - zmalloc(sizeof(*new_element)); + (lttng_trigger_list_element *) zmalloc(sizeof(*new_element)); if (!new_element) { ret = -1; @@ -1743,7 +1743,7 @@ int handle_notification_thread_command_add_channel( continue; } - new_element = zmalloc(sizeof(*new_element)); + new_element = (lttng_trigger_list_element *) zmalloc(sizeof(*new_element)); if (!new_element) { rcu_read_unlock(); goto error; @@ -1757,7 +1757,7 @@ int handle_notification_thread_command_add_channel( DBG("Found %i triggers that apply to newly added channel", trigger_count); - channel_trigger_list = zmalloc(sizeof(*channel_trigger_list)); + channel_trigger_list = (lttng_channel_trigger_list *) zmalloc(sizeof(*channel_trigger_list)); if (!channel_trigger_list) { goto error; } @@ -2020,7 +2020,7 @@ int handle_notification_thread_command_add_tracer_event_source( enum lttng_error_code cmd_result = LTTNG_OK; struct notification_event_tracer_event_source_element *element = NULL; - element = zmalloc(sizeof(*element)); + element = (notification_event_tracer_event_source_element *) zmalloc(sizeof(*element)); if (!element) { cmd_result = LTTNG_ERR_NOMEM; ret = -1; @@ -2485,7 +2485,7 @@ int bind_trigger_to_matching_channels(struct lttng_trigger *trigger, struct lttng_channel_trigger_list, channel_triggers_ht_node); - trigger_list_element = zmalloc(sizeof(*trigger_list_element)); + trigger_list_element = (lttng_trigger_list_element *) zmalloc(sizeof(*trigger_list_element)); if (!trigger_list_element) { ret = -1; goto end; @@ -2606,7 +2606,7 @@ enum lttng_error_code setup_tracer_notifier( struct lttng_condition *condition = lttng_trigger_get_condition(trigger); struct notification_trigger_tokens_ht_element *trigger_tokens_ht_element = NULL; - trigger_tokens_ht_element = zmalloc(sizeof(*trigger_tokens_ht_element)); + trigger_tokens_ht_element = (notification_trigger_tokens_ht_element *) zmalloc(sizeof(*trigger_tokens_ht_element)); if (!trigger_tokens_ht_element) { ret = LTTNG_ERR_NOMEM; goto end; @@ -2729,7 +2729,7 @@ int handle_notification_thread_command_register_trigger( goto error; } - trigger_ht_element = zmalloc(sizeof(*trigger_ht_element)); + trigger_ht_element = (lttng_trigger_ht_element *) zmalloc(sizeof(*trigger_ht_element)); if (!trigger_ht_element) { ret = -1; goto error; @@ -3320,7 +3320,7 @@ int handle_notification_thread_client_connect( DBG("Handling new notification channel client connection"); - client = zmalloc(sizeof(*client)); + client = (notification_client *) zmalloc(sizeof(*client)); if (!client) { /* Fatal error. */ ret = -1; @@ -3581,7 +3581,7 @@ enum client_transmission_status client_flush_outgoing_queue( if ((ret >= 0 && ret < to_send_count)) { DBG("Client (socket fd = %i) outgoing queue could not be completely flushed", client->socket); - to_send_count -= max(ret, 0); + to_send_count -= std::max(ret, (ssize_t) 0); memmove(client->communication.outbound.payload.buffer.data, pv.buffer.data + @@ -4562,7 +4562,7 @@ struct lttng_event_notifier_notification *recv_one_event_notifier_notification( goto end; } - capture_buffer = zmalloc(capture_buffer_size); + capture_buffer = (char *) zmalloc(capture_buffer_size); if (!capture_buffer) { ERR("Failed to allocate capture buffer"); goto end; @@ -4865,7 +4865,7 @@ int handle_notification_thread_channel_sample( */ struct channel_state_sample *stored_sample; - stored_sample = zmalloc(sizeof(*stored_sample)); + stored_sample = (channel_state_sample *) zmalloc(sizeof(*stored_sample)); if (!stored_sample) { ret = -1; goto end_unlock; diff --git a/src/bin/lttng-sessiond/notification-thread.c b/src/bin/lttng-sessiond/notification-thread.cpp similarity index 98% rename from src/bin/lttng-sessiond/notification-thread.c rename to src/bin/lttng-sessiond/notification-thread.cpp index c15e356ad..e8a2adec9 100644 --- a/src/bin/lttng-sessiond/notification-thread.c +++ b/src/bin/lttng-sessiond/notification-thread.cpp @@ -89,7 +89,7 @@ struct notification_thread_handle *notification_thread_handle_create( struct notification_thread_handle *handle; struct lttng_pipe *event_pipe = NULL; - handle = zmalloc(sizeof(*handle)); + handle = (notification_thread_handle *) zmalloc(sizeof(*handle)); if (!handle) { goto end; } @@ -157,7 +157,7 @@ char *get_notification_channel_sock_path(void) bool is_root = !getuid(); char *sock_path; - sock_path = zmalloc(LTTNG_PATH_MAX); + sock_path = (char *) zmalloc(LTTNG_PATH_MAX); if (!sock_path) { goto error; } @@ -633,7 +633,7 @@ static void *thread_notification(void *data) { int ret; - struct notification_thread_handle *handle = data; + struct notification_thread_handle *handle = (notification_thread_handle *) data; struct notification_thread_state state; enum lttng_domain_type domain; @@ -785,7 +785,7 @@ end: static bool shutdown_notification_thread(void *thread_data) { - struct notification_thread_handle *handle = thread_data; + struct notification_thread_handle *handle = (notification_thread_handle *) thread_data; notification_thread_command_quit(handle); return true; diff --git a/src/bin/lttng-sessiond/notify-apps.c b/src/bin/lttng-sessiond/notify-apps.cpp similarity index 95% rename from src/bin/lttng-sessiond/notify-apps.c rename to src/bin/lttng-sessiond/notify-apps.cpp index 7c86b57c8..0e799ff26 100644 --- a/src/bin/lttng-sessiond/notify-apps.c +++ b/src/bin/lttng-sessiond/notify-apps.cpp @@ -32,7 +32,7 @@ static void *thread_application_notification(void *data) ssize_t size_ret; uint32_t revents, nb_fd; struct lttng_poll_event events; - struct thread_notifiers *notifiers = data; + struct thread_notifiers *notifiers = (thread_notifiers *) data; const int quit_pipe_read_fd = lttng_pipe_get_readfd(notifiers->quit_pipe); DBG("[ust-thread] Manage application notify command"); @@ -192,7 +192,7 @@ error_testpoint: static bool shutdown_application_notification_thread(void *data) { - struct thread_notifiers *notifiers = data; + struct thread_notifiers *notifiers = (thread_notifiers *) data; const int write_fd = lttng_pipe_get_writefd(notifiers->quit_pipe); return notify_thread_pipe(write_fd) == 1; @@ -200,7 +200,7 @@ static bool shutdown_application_notification_thread(void *data) static void cleanup_application_notification_thread(void *data) { - struct thread_notifiers *notifiers = data; + struct thread_notifiers *notifiers = (thread_notifiers *) data; lttng_pipe_destroy(notifiers->quit_pipe); free(notifiers); @@ -212,7 +212,7 @@ bool launch_application_notification_thread(int apps_cmd_notify_pipe_read_fd) struct thread_notifiers *notifiers; struct lttng_pipe *quit_pipe; - notifiers = zmalloc(sizeof(*notifiers)); + notifiers = (thread_notifiers *) zmalloc(sizeof(*notifiers)); if (!notifiers) { goto error_alloc; } diff --git a/src/bin/lttng-sessiond/process-utils.c b/src/bin/lttng-sessiond/process-utils.cpp similarity index 100% rename from src/bin/lttng-sessiond/process-utils.c rename to src/bin/lttng-sessiond/process-utils.cpp diff --git a/src/bin/lttng-sessiond/register.c b/src/bin/lttng-sessiond/register.cpp similarity index 95% rename from src/bin/lttng-sessiond/register.c rename to src/bin/lttng-sessiond/register.cpp index bd6cd52dd..5bcc637b0 100644 --- a/src/bin/lttng-sessiond/register.c +++ b/src/bin/lttng-sessiond/register.cpp @@ -111,7 +111,7 @@ error: static void cleanup_application_registration_thread(void *data) { - struct thread_state *thread_state = data; + struct thread_state *thread_state = (struct thread_state *) data; if (!data) { return; @@ -143,7 +143,7 @@ static bool wait_thread_status(struct thread_state *thread_state) static void thread_init_cleanup(void *data) { - struct thread_state *thread_state = data; + struct thread_state *thread_state = (struct thread_state *) data; set_thread_status(thread_state, false); } @@ -162,7 +162,7 @@ static void *thread_application_registration(void *data) */ struct ust_command *ust_cmd = NULL; const bool is_root = (getuid() == 0); - struct thread_state *thread_state = data; + struct thread_state *thread_state = (struct thread_state *) data; const int application_socket = thread_state->application_socket; const int quit_pipe_read_fd = lttng_pipe_get_readfd( thread_state->quit_pipe); @@ -265,7 +265,7 @@ static void *thread_application_registration(void *data) (void) utils_set_fd_cloexec(sock); /* Create UST registration command for enqueuing */ - ust_cmd = zmalloc(sizeof(struct ust_command)); + ust_cmd = (ust_command *) zmalloc(sizeof(struct ust_command)); if (ust_cmd == NULL) { PERROR("ust command zmalloc"); ret = close(sock); @@ -321,7 +321,9 @@ static void *thread_application_registration(void *data) * Lock free enqueue the registration request. The red pill * has been taken! This apps will be part of the *system*. */ - cds_wfcq_enqueue(&thread_state->ust_cmd_queue->head, + cds_wfcq_head_ptr_t head; + head.h = &thread_state->ust_cmd_queue->head; + cds_wfcq_enqueue(head, &thread_state->ust_cmd_queue->tail, &ust_cmd->node); @@ -374,7 +376,7 @@ error_create_poll: static bool shutdown_application_registration_thread(void *data) { - struct thread_state *thread_state = data; + struct thread_state *thread_state = (struct thread_state *) data; const int write_fd = lttng_pipe_get_writefd(thread_state->quit_pipe); return notify_thread_pipe(write_fd) == 1; @@ -390,7 +392,7 @@ struct lttng_thread *launch_application_registration_thread( const bool is_root = (getuid() == 0); int application_socket = -1; - thread_state = zmalloc(sizeof(*thread_state)); + thread_state = (struct thread_state *) zmalloc(sizeof(*thread_state)); if (!thread_state) { goto error_alloc; } diff --git a/src/bin/lttng-sessiond/rotate.c b/src/bin/lttng-sessiond/rotate.cpp similarity index 100% rename from src/bin/lttng-sessiond/rotate.c rename to src/bin/lttng-sessiond/rotate.cpp diff --git a/src/bin/lttng-sessiond/rotation-thread.c b/src/bin/lttng-sessiond/rotation-thread.cpp similarity index 98% rename from src/bin/lttng-sessiond/rotation-thread.c rename to src/bin/lttng-sessiond/rotation-thread.cpp index 3373443f0..8754d48a1 100644 --- a/src/bin/lttng-sessiond/rotation-thread.c +++ b/src/bin/lttng-sessiond/rotation-thread.cpp @@ -88,7 +88,7 @@ struct rotation_thread_timer_queue *rotation_thread_timer_queue_create(void) { struct rotation_thread_timer_queue *queue = NULL; - queue = zmalloc(sizeof(*queue)); + queue = (rotation_thread_timer_queue *) zmalloc(sizeof(*queue)); if (!queue) { PERROR("Failed to allocate timer rotate queue"); goto end; @@ -133,7 +133,7 @@ struct rotation_thread_handle *rotation_thread_handle_create( { struct rotation_thread_handle *handle; - handle = zmalloc(sizeof(*handle)); + handle = (rotation_thread_handle *) zmalloc(sizeof(*handle)); if (!handle) { goto end; } @@ -192,7 +192,7 @@ void rotation_thread_enqueue_job(struct rotation_thread_timer_queue *queue, goto end; } - job = zmalloc(sizeof(struct rotation_thread_job)); + job = (rotation_thread_job *) zmalloc(sizeof(struct rotation_thread_job)); if (!job) { PERROR("Failed to allocate rotation thread job of type \"%s\" for session \"%s\"", job_type_str, session->name); @@ -763,7 +763,7 @@ static void *thread_rotation(void *data) { int ret; - struct rotation_thread_handle *handle = data; + struct rotation_thread_handle *handle = (rotation_thread_handle *) data; struct rotation_thread thread; int queue_pipe_fd; @@ -871,7 +871,7 @@ end: static bool shutdown_rotation_thread(void *thread_data) { - struct rotation_thread_handle *handle = thread_data; + struct rotation_thread_handle *handle = (rotation_thread_handle *) thread_data; const int write_fd = lttng_pipe_get_writefd(handle->quit_pipe); return notify_thread_pipe(write_fd) == 1; diff --git a/src/bin/lttng-sessiond/save.c b/src/bin/lttng-sessiond/save.cpp similarity index 99% rename from src/bin/lttng-sessiond/save.c rename to src/bin/lttng-sessiond/save.cpp index f0a6e43d5..2055e867d 100644 --- a/src/bin/lttng-sessiond/save.c +++ b/src/bin/lttng-sessiond/save.cpp @@ -1063,7 +1063,7 @@ int save_ust_event(struct config_writer *writer, } loglevel_type_string = get_loglevel_type_string( - event->attr.loglevel_type); + (lttng_ust_abi_loglevel_type) event->attr.loglevel_type); if (!loglevel_type_string) { ERR("Unsupported UST loglevel type."); ret = LTTNG_ERR_INVALID; @@ -2322,7 +2322,7 @@ int save_consumer_output(struct config_writer *writer, { char *uri; - uri = zmalloc(PATH_MAX); + uri = (char *) zmalloc(PATH_MAX); if (!uri) { ret = LTTNG_ERR_NOMEM; goto end; diff --git a/src/bin/lttng-sessiond/session.c b/src/bin/lttng-sessiond/session.cpp similarity index 99% rename from src/bin/lttng-sessiond/session.c rename to src/bin/lttng-sessiond/session.cpp index dc6dea443..0d19042b5 100644 --- a/src/bin/lttng-sessiond/session.c +++ b/src/bin/lttng-sessiond/session.cpp @@ -56,10 +56,10 @@ struct ltt_session_clear_notifier_element { * Please see session.h for more explanation and correct usage of the list. */ static struct ltt_session_list ltt_session_list = { - .head = CDS_LIST_HEAD_INIT(ltt_session_list.head), .lock = PTHREAD_MUTEX_INITIALIZER, .removal_cond = PTHREAD_COND_INITIALIZER, .next_uuid = 0, + .head = CDS_LIST_HEAD_INIT(ltt_session_list.head), }; /* These characters are forbidden in a session name. Used by validate_name. */ @@ -924,7 +924,7 @@ void session_notify_destruction(const struct ltt_session *session) for (i = 0; i < count; i++) { const struct ltt_session_destroy_notifier_element *element = - lttng_dynamic_array_get_element( + (ltt_session_destroy_notifier_element *) lttng_dynamic_array_get_element( &session->destroy_notifiers, i); element->notifier(session, element->user_data); @@ -942,7 +942,7 @@ void session_notify_clear(struct ltt_session *session) for (i = 0; i < count; i++) { const struct ltt_session_clear_notifier_element *element = - lttng_dynamic_array_get_element( + (ltt_session_clear_notifier_element *) lttng_dynamic_array_get_element( &session->clear_notifiers, i); element->notifier(session, element->user_data); @@ -1175,7 +1175,7 @@ enum lttng_error_code session_create(const char *name, uid_t uid, gid_t gid, goto error; } } - new_session = zmalloc(sizeof(struct ltt_session)); + new_session = (ltt_session *) zmalloc(sizeof(struct ltt_session)); if (!new_session) { PERROR("Failed to allocate an ltt_session structure"); ret_code = LTTNG_ERR_NOMEM; diff --git a/src/bin/lttng-sessiond/sessiond-config.c b/src/bin/lttng-sessiond/sessiond-config.cpp similarity index 94% rename from src/bin/lttng-sessiond/sessiond-config.c rename to src/bin/lttng-sessiond/sessiond-config.cpp index 707e57950..05b77e69c 100644 --- a/src/bin/lttng-sessiond/sessiond-config.c +++ b/src/bin/lttng-sessiond/sessiond-config.cpp @@ -18,51 +18,53 @@ static struct sessiond_config sessiond_config_build_defaults = { - .quiet = false, .verbose = 0, .verbose_consumer = 0, - .agent_tcp_port = { .begin = DEFAULT_AGENT_TCP_PORT_RANGE_BEGIN, .end = DEFAULT_AGENT_TCP_PORT_RANGE_END }, + .event_notifier_buffer_size_kernel = DEFAULT_EVENT_NOTIFIER_ERROR_COUNT_MAP_SIZE, .event_notifier_buffer_size_userspace = DEFAULT_EVENT_NOTIFIER_ERROR_COUNT_MAP_SIZE, .app_socket_timeout = DEFAULT_APP_SOCKET_RW_TIMEOUT, + .quiet = false, + + .no_kernel = false, .background = false, .daemonize = false, .sig_parent = false, - .tracing_group_name.value = (char *) DEFAULT_TRACING_GROUP, - .kmod_probes_list.value = NULL, - .kmod_extra_probes_list.value = NULL, - - .rundir.value = NULL, - - .apps_unix_sock_path.value = NULL, - .client_unix_sock_path.value = NULL, - .wait_shm_path.value = NULL, - .health_unix_sock_path.value = NULL, - .lttng_ust_clock_plugin.value = NULL, - .pid_file_path.value = NULL, - .lock_file_path.value = NULL, - .agent_port_file_path.value = NULL, - .load_session_path.value = NULL, - - .consumerd32_path.value = NULL, - .consumerd32_bin_path.value = NULL, - .consumerd32_lib_dir.value = NULL, - .consumerd32_err_unix_sock_path.value = NULL, - .consumerd32_cmd_unix_sock_path.value = NULL, - - .consumerd64_path.value = NULL, - .consumerd64_bin_path.value = NULL, - .consumerd64_lib_dir.value = NULL, - .consumerd64_err_unix_sock_path.value = NULL, - .consumerd64_cmd_unix_sock_path.value = NULL, - - .kconsumerd_path.value = NULL, - .kconsumerd_err_unix_sock_path.value = NULL, - .kconsumerd_cmd_unix_sock_path.value = NULL, + .tracing_group_name = { (char *) DEFAULT_TRACING_GROUP }, + .kmod_probes_list = { nullptr }, + .kmod_extra_probes_list = { nullptr }, + + .rundir = { nullptr }, + + .apps_unix_sock_path = { nullptr }, + .client_unix_sock_path = { nullptr }, + .wait_shm_path = { nullptr }, + .health_unix_sock_path = { nullptr }, + .lttng_ust_clock_plugin = { nullptr }, + .pid_file_path = { nullptr }, + .lock_file_path = { nullptr }, + .load_session_path = { nullptr }, + .agent_port_file_path = { nullptr }, + + .consumerd32_path = { nullptr }, + .consumerd32_bin_path = { nullptr }, + .consumerd32_lib_dir = { nullptr }, + .consumerd32_err_unix_sock_path = { nullptr }, + .consumerd32_cmd_unix_sock_path = { nullptr }, + + .consumerd64_path = { nullptr }, + .consumerd64_bin_path = { nullptr }, + .consumerd64_lib_dir = { nullptr }, + .consumerd64_err_unix_sock_path = { nullptr }, + .consumerd64_cmd_unix_sock_path = { nullptr }, + + .kconsumerd_path = { nullptr }, + .kconsumerd_err_unix_sock_path = { nullptr }, + .kconsumerd_cmd_unix_sock_path = { nullptr }, }; static diff --git a/src/bin/lttng-sessiond/snapshot.c b/src/bin/lttng-sessiond/snapshot.cpp similarity index 99% rename from src/bin/lttng-sessiond/snapshot.c rename to src/bin/lttng-sessiond/snapshot.cpp index 6e4a0c3f1..03472201a 100644 --- a/src/bin/lttng-sessiond/snapshot.c +++ b/src/bin/lttng-sessiond/snapshot.cpp @@ -165,7 +165,7 @@ error: struct snapshot_output *snapshot_output_alloc(void) { - return zmalloc(sizeof(struct snapshot_output)); + return (snapshot_output *) zmalloc(sizeof(struct snapshot_output)); } /* diff --git a/src/bin/lttng-sessiond/thread-utils.c b/src/bin/lttng-sessiond/thread-utils.cpp similarity index 100% rename from src/bin/lttng-sessiond/thread-utils.c rename to src/bin/lttng-sessiond/thread-utils.cpp diff --git a/src/bin/lttng-sessiond/thread.c b/src/bin/lttng-sessiond/thread.cpp similarity index 98% rename from src/bin/lttng-sessiond/thread.c rename to src/bin/lttng-sessiond/thread.cpp index a4e3cb86e..446a8c9d2 100644 --- a/src/bin/lttng-sessiond/thread.c +++ b/src/bin/lttng-sessiond/thread.cpp @@ -77,7 +77,7 @@ struct lttng_thread *lttng_thread_create(const char *name, int ret; struct lttng_thread *thread; - thread = zmalloc(sizeof(*thread)); + thread = (lttng_thread *) zmalloc(sizeof(*thread)); if (!thread) { goto error_alloc; } diff --git a/src/bin/lttng-sessiond/timer.c b/src/bin/lttng-sessiond/timer.cpp similarity index 99% rename from src/bin/lttng-sessiond/timer.c rename to src/bin/lttng-sessiond/timer.cpp index 4e522a7fc..5a1f35dfa 100644 --- a/src/bin/lttng-sessiond/timer.c +++ b/src/bin/lttng-sessiond/timer.cpp @@ -340,7 +340,7 @@ void *thread_timer(void *data) int signr; sigset_t mask; siginfo_t info; - struct timer_thread_parameters *ctx = data; + struct timer_thread_parameters *ctx = (timer_thread_parameters *) data; rcu_register_thread(); rcu_thread_online(); diff --git a/src/bin/lttng-sessiond/trace-kernel.c b/src/bin/lttng-sessiond/trace-kernel.cpp similarity index 96% rename from src/bin/lttng-sessiond/trace-kernel.c rename to src/bin/lttng-sessiond/trace-kernel.cpp index cbafd12bd..cf1455ee6 100644 --- a/src/bin/lttng-sessiond/trace-kernel.c +++ b/src/bin/lttng-sessiond/trace-kernel.cpp @@ -151,7 +151,7 @@ struct ltt_kernel_session *trace_kernel_create_session(void) struct ltt_kernel_session *lks = NULL; /* Allocate a new ltt kernel session */ - lks = zmalloc(sizeof(struct ltt_kernel_session)); + lks = (ltt_kernel_session *) zmalloc(sizeof(struct ltt_kernel_session)); if (lks == NULL) { PERROR("create kernel session zmalloc"); goto alloc_error; @@ -222,19 +222,19 @@ struct ltt_kernel_channel *trace_kernel_create_channel( LTTNG_ASSERT(chan); - lkc = zmalloc(sizeof(struct ltt_kernel_channel)); + lkc = (ltt_kernel_channel *) zmalloc(sizeof(struct ltt_kernel_channel)); if (lkc == NULL) { PERROR("ltt_kernel_channel zmalloc"); goto error; } - lkc->channel = zmalloc(sizeof(struct lttng_channel)); + lkc->channel = (lttng_channel *) zmalloc(sizeof(struct lttng_channel)); if (lkc->channel == NULL) { PERROR("lttng_channel zmalloc"); goto error; } - extended = zmalloc(sizeof(struct lttng_channel_extended)); + extended = (lttng_channel_extended *) zmalloc(sizeof(struct lttng_channel_extended)); if (!extended) { PERROR("lttng_channel_channel zmalloc"); goto error; @@ -285,7 +285,7 @@ struct ltt_kernel_context *trace_kernel_create_context( { struct ltt_kernel_context *kctx; - kctx = zmalloc(sizeof(*kctx)); + kctx = (ltt_kernel_context *) zmalloc(sizeof(*kctx)); if (!kctx) { PERROR("zmalloc kernel context"); goto error; @@ -310,7 +310,7 @@ struct ltt_kernel_context *trace_kernel_copy_context( struct ltt_kernel_context *kctx_copy; LTTNG_ASSERT(kctx); - kctx_copy = zmalloc(sizeof(*kctx_copy)); + kctx_copy = (ltt_kernel_context *) zmalloc(sizeof(*kctx_copy)); if (!kctx_copy) { PERROR("zmalloc ltt_kernel_context"); goto error; @@ -341,8 +341,8 @@ enum lttng_error_code trace_kernel_create_event( LTTNG_ASSERT(ev); - local_kernel_event = zmalloc(sizeof(struct ltt_kernel_event)); - attr = zmalloc(sizeof(struct lttng_kernel_abi_event)); + local_kernel_event = (ltt_kernel_event *) zmalloc(sizeof(struct ltt_kernel_event)); + attr = (lttng_kernel_abi_event *) zmalloc(sizeof(struct lttng_kernel_abi_event)); if (local_kernel_event == NULL || attr == NULL) { PERROR("kernel event zmalloc"); ret = LTTNG_ERR_NOMEM; @@ -514,7 +514,7 @@ enum lttng_error_code trace_kernel_create_event_notifier_rule( LTTNG_ASSERT(event_rule_type != LTTNG_EVENT_RULE_TYPE_UNKNOWN); local_kernel_token_event_rule = - zmalloc(sizeof(struct ltt_kernel_event_notifier_rule)); + (ltt_kernel_event_notifier_rule *) zmalloc(sizeof(struct ltt_kernel_event_notifier_rule)); if (local_kernel_token_event_rule == NULL) { PERROR("Failed to allocate ltt_kernel_token_event_rule structure"); ret = LTTNG_ERR_NOMEM; @@ -734,8 +734,8 @@ struct ltt_kernel_metadata *trace_kernel_create_metadata(void) struct ltt_kernel_metadata *lkm; struct lttng_channel *chan; - lkm = zmalloc(sizeof(struct ltt_kernel_metadata)); - chan = zmalloc(sizeof(struct lttng_channel)); + lkm = (ltt_kernel_metadata *) zmalloc(sizeof(struct ltt_kernel_metadata)); + chan = (lttng_channel *) zmalloc(sizeof(struct lttng_channel)); if (lkm == NULL || chan == NULL) { PERROR("kernel metadata zmalloc"); goto error; @@ -800,7 +800,7 @@ struct ltt_kernel_stream *trace_kernel_create_stream(const char *name, LTTNG_ASSERT(name); - lks = zmalloc(sizeof(struct ltt_kernel_stream)); + lks = (ltt_kernel_stream *) zmalloc(sizeof(struct ltt_kernel_stream)); if (lks == NULL) { PERROR("kernel stream zmalloc"); goto error; diff --git a/src/bin/lttng-sessiond/trace-ust.c b/src/bin/lttng-sessiond/trace-ust.cpp similarity index 98% rename from src/bin/lttng-sessiond/trace-ust.c rename to src/bin/lttng-sessiond/trace-ust.cpp index 47e98cc78..0f303bf03 100644 --- a/src/bin/lttng-sessiond/trace-ust.c +++ b/src/bin/lttng-sessiond/trace-ust.cpp @@ -39,7 +39,7 @@ int trace_ust_ht_match_event_by_name(struct cds_lfht_node *node, LTTNG_ASSERT(_key); event = caa_container_of(node, struct ltt_ust_event, node.node); - name = _key; + name = (const char *) _key; /* Event name */ if (strncmp(event->attr.name, name, sizeof(event->attr.name)) != 0) { @@ -70,7 +70,7 @@ int trace_ust_ht_match_event(struct cds_lfht_node *node, const void *_key) LTTNG_ASSERT(_key); event = caa_container_of(node, struct ltt_ust_event, node.node); - key = _key; + key = (ltt_ust_ht_key *) _key; ev_loglevel_value = event->attr.loglevel; /* Match the 4 elements of the key: name, filter, loglevel, exclusions. */ @@ -269,7 +269,7 @@ struct ltt_ust_session *trace_ust_create_session(uint64_t session_id) struct ltt_ust_session *lus; /* Allocate a new ltt ust session */ - lus = zmalloc(sizeof(struct ltt_ust_session)); + lus = (ltt_ust_session *) zmalloc(sizeof(struct ltt_ust_session)); if (lus == NULL) { PERROR("create ust session zmalloc"); goto error_alloc; @@ -348,7 +348,7 @@ struct ltt_ust_channel *trace_ust_create_channel(struct lttng_channel *chan, LTTNG_ASSERT(chan); - luc = zmalloc(sizeof(struct ltt_ust_channel)); + luc = (ltt_ust_channel *) zmalloc(sizeof(struct ltt_ust_channel)); if (luc == NULL) { PERROR("ltt_ust_channel zmalloc"); goto error; @@ -461,7 +461,7 @@ enum lttng_error_code trace_ust_create_event(struct lttng_event *ev, goto error; } - local_ust_event = zmalloc(sizeof(struct ltt_ust_event)); + local_ust_event = (ltt_ust_event *) zmalloc(sizeof(struct ltt_ust_event)); if (local_ust_event == NULL) { PERROR("ust event zmalloc"); ret = LTTNG_ERR_NOMEM; @@ -685,7 +685,7 @@ struct ltt_ust_context *trace_ust_create_context( goto end; } - uctx = zmalloc(sizeof(struct ltt_ust_context)); + uctx = (ltt_ust_context *) zmalloc(sizeof(struct ltt_ust_context)); if (!uctx) { PERROR("zmalloc ltt_ust_context"); goto end; @@ -811,7 +811,7 @@ static int id_tracker_add_id(struct ust_id_tracker *id_tracker, int id) retval = LTTNG_ERR_PROCESS_ATTR_EXISTS; goto end; } - tracker_node = zmalloc(sizeof(*tracker_node)); + tracker_node = (ust_id_tracker_node *) zmalloc(sizeof(*tracker_node)); if (!tracker_node) { retval = LTTNG_ERR_NOMEM; goto end; @@ -956,7 +956,7 @@ enum lttng_error_code trace_ust_process_attr_tracker_set_tracking_policy( case LTTNG_TRACKING_POLICY_INCLUDE_SET: /* fall-through. */ fini_id_tracker(id_tracker); - ret_code = init_id_tracker(id_tracker); + ret_code = (lttng_error_code) init_id_tracker(id_tracker); if (ret_code != LTTNG_OK) { ERR("Error initializing ID tracker"); goto end; @@ -1060,7 +1060,7 @@ enum lttng_error_code trace_ust_process_attr_tracker_inclusion_set_add_value( lttng_process_attr_to_string(process_attr), integral_value, session->id); - ret_code = id_tracker_add_id(id_tracker, integral_value); + ret_code = (lttng_error_code) id_tracker_add_id(id_tracker, integral_value); if (ret_code != LTTNG_OK) { goto end; } @@ -1170,7 +1170,7 @@ enum lttng_error_code trace_ust_process_attr_tracker_inclusion_set_remove_value( lttng_process_attr_to_string(process_attr), integral_value, session->id); - ret_code = id_tracker_del_id(id_tracker, integral_value); + ret_code = (lttng_error_code) id_tracker_del_id(id_tracker, integral_value); if (ret_code != LTTNG_OK) { goto end; } diff --git a/src/bin/lttng-sessiond/tracker.c b/src/bin/lttng-sessiond/tracker.cpp similarity index 97% rename from src/bin/lttng-sessiond/tracker.c rename to src/bin/lttng-sessiond/tracker.cpp index 8293904fb..1cae40350 100644 --- a/src/bin/lttng-sessiond/tracker.c +++ b/src/bin/lttng-sessiond/tracker.cpp @@ -49,7 +49,7 @@ struct process_attr_tracker *process_attr_tracker_create(void) { struct process_attr_tracker *tracker; - tracker = zmalloc(sizeof(*tracker)); + tracker = (process_attr_tracker *) zmalloc(sizeof(*tracker)); if (!tracker) { return NULL; } @@ -150,7 +150,7 @@ end: static int match_inclusion_set_value( struct cds_lfht_node *node, const void *key) { - const struct process_attr_value *value_key = key; + const struct process_attr_value *value_key = (process_attr_value *) key; const struct process_attr_tracker_value_node *value_node = caa_container_of(node, struct process_attr_tracker_value_node, @@ -201,7 +201,7 @@ enum process_attr_tracker_status process_attr_tracker_inclusion_set_add_value( goto end; } - value_node = zmalloc(sizeof(*value_node)); + value_node = (process_attr_tracker_value_node *) zmalloc(sizeof(*value_node)); if (!value_node) { status = PROCESS_ATTR_TRACKER_STATUS_ERROR; goto end; diff --git a/src/bin/lttng-sessiond/trigger-error-query.c b/src/bin/lttng-sessiond/trigger-error-query.cpp similarity index 100% rename from src/bin/lttng-sessiond/trigger-error-query.c rename to src/bin/lttng-sessiond/trigger-error-query.cpp diff --git a/src/bin/lttng-sessiond/ust-app.c b/src/bin/lttng-sessiond/ust-app.cpp similarity index 99% rename from src/bin/lttng-sessiond/ust-app.c rename to src/bin/lttng-sessiond/ust-app.cpp index d303e8b66..a848d474c 100644 --- a/src/bin/lttng-sessiond/ust-app.c +++ b/src/bin/lttng-sessiond/ust-app.cpp @@ -102,7 +102,7 @@ static void copy_channel_attr_to_ustctl( attr->overwrite = uattr->overwrite; attr->switch_timer_interval = uattr->switch_timer_interval; attr->read_timer_interval = uattr->read_timer_interval; - attr->output = uattr->output; + attr->output = (lttng_ust_abi_output) uattr->output; attr->blocking_timeout = uattr->u.s.blocking_timeout; } @@ -122,7 +122,7 @@ static int ht_match_ust_app_event(struct cds_lfht_node *node, const void *_key) LTTNG_ASSERT(_key); event = caa_container_of(node, struct ust_app_event, node.node); - key = _key; + key = (ust_app_ht_key *) _key; ev_loglevel_value = event->attr.loglevel; /* Match the 4 elements of the key: name, filter, loglevel, exclusions */ @@ -202,7 +202,7 @@ static void add_unique_ust_app_event(struct ust_app_channel *ua_chan, ht = ua_chan->events; key.name = event->attr.name; key.filter = event->filter; - key.loglevel_type = event->attr.loglevel; + key.loglevel_type = (lttng_ust_abi_loglevel_type) event->attr.loglevel; key.exclusion = event->exclusion; node_ptr = cds_lfht_add_unique(ht->ht, @@ -697,7 +697,7 @@ ssize_t ust_app_push_metadata(struct ust_registry_session *registry, } /* Allocate only what we have to send. */ - metadata_str = zmalloc(len); + metadata_str = (char *) zmalloc(len); if (!metadata_str) { PERROR("zmalloc ust app metadata string"); ret_val = -ENOMEM; @@ -760,7 +760,7 @@ push_data: * send. */ registry->metadata_len_sent = - max_t(size_t, registry->metadata_len_sent, + std::max(registry->metadata_len_sent, new_metadata_len_sent); } free(metadata_str); @@ -1167,7 +1167,7 @@ struct ust_app_session *alloc_ust_app_session(void) struct ust_app_session *ua_sess; /* Init most of the default value by allocating and zeroing */ - ua_sess = zmalloc(sizeof(struct ust_app_session)); + ua_sess = (ust_app_session *) zmalloc(sizeof(struct ust_app_session)); if (ua_sess == NULL) { PERROR("malloc"); goto error_free; @@ -1195,7 +1195,7 @@ struct ust_app_channel *alloc_ust_app_channel(const char *name, struct ust_app_channel *ua_chan; /* Init most of the default value by allocating and zeroing */ - ua_chan = zmalloc(sizeof(struct ust_app_channel)); + ua_chan = (ust_app_channel *) zmalloc(sizeof(struct ust_app_channel)); if (ua_chan == NULL) { PERROR("malloc"); goto error; @@ -1224,7 +1224,7 @@ struct ust_app_channel *alloc_ust_app_channel(const char *name, ua_chan->attr.overwrite = attr->overwrite; ua_chan->attr.switch_timer_interval = attr->switch_timer_interval; ua_chan->attr.read_timer_interval = attr->read_timer_interval; - ua_chan->attr.output = attr->output; + ua_chan->attr.output = (lttng_ust_abi_output) attr->output; ua_chan->attr.blocking_timeout = attr->u.s.blocking_timeout; } /* By default, the channel is a per cpu channel. */ @@ -1247,7 +1247,7 @@ struct ust_app_stream *ust_app_alloc_stream(void) { struct ust_app_stream *stream = NULL; - stream = zmalloc(sizeof(*stream)); + stream = (ust_app_stream *) zmalloc(sizeof(*stream)); if (stream == NULL) { PERROR("zmalloc ust app stream"); goto error; @@ -1270,7 +1270,7 @@ struct ust_app_event *alloc_ust_app_event(char *name, struct ust_app_event *ua_event; /* Init most of the default value by allocating and zeroing */ - ua_event = zmalloc(sizeof(struct ust_app_event)); + ua_event = (ust_app_event *) zmalloc(sizeof(struct ust_app_event)); if (ua_event == NULL) { PERROR("Failed to allocate ust_app_event structure"); goto error; @@ -1307,7 +1307,7 @@ static struct ust_app_event_notifier_rule *alloc_ust_app_event_notifier_rule( struct lttng_condition *condition = NULL; const struct lttng_event_rule *event_rule = NULL; - ua_event_notifier_rule = zmalloc(sizeof(struct ust_app_event_notifier_rule)); + ua_event_notifier_rule = (ust_app_event_notifier_rule *) zmalloc(sizeof(struct ust_app_event_notifier_rule)); if (ua_event_notifier_rule == NULL) { PERROR("Failed to allocate ust_app_event_notifier_rule structure"); goto error; @@ -1367,7 +1367,7 @@ struct ust_app_ctx *alloc_ust_app_ctx(struct lttng_ust_context_attr *uctx) { struct ust_app_ctx *ua_ctx; - ua_ctx = zmalloc(sizeof(struct ust_app_ctx)); + ua_ctx = (ust_app_ctx *) zmalloc(sizeof(struct ust_app_ctx)); if (ua_ctx == NULL) { goto error; } @@ -1410,7 +1410,7 @@ static struct lttng_ust_abi_filter_bytecode *create_ust_filter_bytecode_from_byt struct lttng_ust_abi_filter_bytecode *filter = NULL; /* Copy filter bytecode. */ - filter = zmalloc(sizeof(*filter) + orig_f->len); + filter = (lttng_ust_abi_filter_bytecode *) zmalloc(sizeof(*filter) + orig_f->len); if (!filter) { PERROR("Failed to allocate lttng_ust_filter_bytecode: bytecode len = %" PRIu32 " bytes", orig_f->len); goto error; @@ -1434,7 +1434,7 @@ create_ust_capture_bytecode_from_bytecode(const struct lttng_bytecode *orig_f) struct lttng_ust_abi_capture_bytecode *capture = NULL; /* Copy capture bytecode. */ - capture = zmalloc(sizeof(*capture) + orig_f->len); + capture = (lttng_ust_abi_capture_bytecode *) zmalloc(sizeof(*capture) + orig_f->len); if (!capture) { PERROR("Failed to allocate lttng_ust_abi_capture_bytecode: bytecode len = %" PRIu32 " bytes", orig_f->len); goto error; @@ -1514,7 +1514,7 @@ static struct ust_app_event *find_ust_app_event(struct lttng_ht *ht, /* Setup key for event lookup. */ key.name = name; key.filter = filter; - key.loglevel_type = loglevel_value; + key.loglevel_type = (lttng_ust_abi_loglevel_type) loglevel_value; /* lttng_event_exclusion and lttng_ust_event_exclusion structures are similar */ key.exclusion = exclusion; @@ -1713,7 +1713,7 @@ struct lttng_ust_abi_event_exclusion *create_ust_exclusion_from_exclusion( size_t exclusion_alloc_size = sizeof(struct lttng_ust_abi_event_exclusion) + LTTNG_UST_ABI_SYM_NAME_LEN * exclusion->count; - ust_exclusion = zmalloc(exclusion_alloc_size); + ust_exclusion = (lttng_ust_abi_event_exclusion *) zmalloc(exclusion_alloc_size); if (!ust_exclusion) { PERROR("malloc"); goto end; @@ -2333,7 +2333,7 @@ static void shadow_copy_event(struct ust_app_event *ua_event, if (uevent->exclusion) { exclusion_alloc_size = sizeof(struct lttng_event_exclusion) + LTTNG_UST_ABI_SYM_NAME_LEN * uevent->exclusion->count; - ua_event->exclusion = zmalloc(exclusion_alloc_size); + ua_event->exclusion = (lttng_event_exclusion *) zmalloc(exclusion_alloc_size); if (ua_event->exclusion == NULL) { PERROR("malloc"); } else { @@ -2364,7 +2364,7 @@ static void shadow_copy_channel(struct ust_app_channel *ua_chan, ua_chan->attr.switch_timer_interval = uchan->attr.switch_timer_interval; ua_chan->attr.read_timer_interval = uchan->attr.read_timer_interval; ua_chan->monitor_timer_interval = uchan->monitor_timer_interval; - ua_chan->attr.output = uchan->attr.output; + ua_chan->attr.output = (lttng_ust_abi_output) uchan->attr.output; ua_chan->attr.blocking_timeout = uchan->attr.u.s.blocking_timeout; /* @@ -2773,7 +2773,7 @@ static int ht_match_ust_app_ctx(struct cds_lfht_node *node, const void *_key) LTTNG_ASSERT(_key); ctx = caa_container_of(node, struct ust_app_ctx, node.node); - key = _key; + key = (lttng_ust_context_attr *) _key; /* Context type */ if (ctx->ctx.ctx != key->ctx) { @@ -3983,7 +3983,7 @@ struct ust_app *ust_app_create(struct ust_register_msg *msg, int sock) goto error; } - lta = zmalloc(sizeof(struct ust_app)); + lta = (ust_app *) zmalloc(sizeof(struct ust_app)); if (lta == NULL) { PERROR("malloc"); goto error_free_pipe; @@ -4359,7 +4359,7 @@ int ust_app_list_events(struct lttng_event **events) struct lttng_event *tmp_event; nbmem = UST_APP_EVENT_LIST_SIZE; - tmp_event = zmalloc(nbmem * sizeof(struct lttng_event)); + tmp_event = (lttng_event *) zmalloc(nbmem * sizeof(struct lttng_event)); if (tmp_event == NULL) { PERROR("zmalloc ust app events"); ret = -ENOMEM; @@ -4424,7 +4424,7 @@ int ust_app_list_events(struct lttng_event **events) new_nbmem = nbmem << 1; DBG2("Reallocating event list from %zu to %zu entries", nbmem, new_nbmem); - new_tmp_event = realloc(tmp_event, + new_tmp_event = (lttng_event *) realloc(tmp_event, new_nbmem * sizeof(struct lttng_event)); if (new_tmp_event == NULL) { int release_ret; @@ -4494,7 +4494,7 @@ int ust_app_list_event_fields(struct lttng_event_field **fields) struct lttng_event_field *tmp_event; nbmem = UST_APP_EVENT_LIST_SIZE; - tmp_event = zmalloc(nbmem * sizeof(struct lttng_event_field)); + tmp_event = (lttng_event_field *) zmalloc(nbmem * sizeof(struct lttng_event_field)); if (tmp_event == NULL) { PERROR("zmalloc ust app event fields"); ret = -ENOMEM; @@ -4559,7 +4559,7 @@ int ust_app_list_event_fields(struct lttng_event_field **fields) new_nbmem = nbmem << 1; DBG2("Reallocating event field list from %zu to %zu entries", nbmem, new_nbmem); - new_tmp_event = realloc(tmp_event, + new_tmp_event = (lttng_event_field *) realloc(tmp_event, new_nbmem * sizeof(struct lttng_event_field)); if (new_tmp_event == NULL) { int release_ret; @@ -6810,7 +6810,7 @@ void ust_app_notify_sock_unregister(int sock) rcu_read_lock(); - obj = zmalloc(sizeof(*obj)); + obj = (ust_app_notify_sock_obj *) zmalloc(sizeof(*obj)); if (!obj) { /* * An ENOMEM is kind of uncool. If this strikes we continue the diff --git a/src/bin/lttng-sessiond/ust-app.h b/src/bin/lttng-sessiond/ust-app.h index 77a365409..8d2d28986 100644 --- a/src/bin/lttng-sessiond/ust-app.h +++ b/src/bin/lttng-sessiond/ust-app.h @@ -572,7 +572,7 @@ static inline enum lttng_error_code ust_app_snapshot_record(struct ltt_ust_session *usess, const struct consumer_output *output, int wait, uint64_t max_stream_size) { - return 0; + return LTTNG_ERR_UNK; } static inline unsigned int ust_app_get_nb_stream(struct ltt_ust_session *usess) @@ -642,14 +642,14 @@ int ust_app_regenerate_statedump_all(struct ltt_ust_session *usess) static inline enum lttng_error_code ust_app_rotate_session(struct ltt_session *session) { - return 0; + return LTTNG_ERR_UNK; } static inline enum lttng_error_code ust_app_create_channel_subdirectories( const struct ltt_ust_session *session) { - return 0; + return LTTNG_ERR_UNK; } static inline @@ -661,13 +661,13 @@ int ust_app_release_object(struct ust_app *app, struct lttng_ust_abi_object_data static inline enum lttng_error_code ust_app_clear_session(struct ltt_session *session) { - return 0; + return LTTNG_ERR_UNK; } static inline enum lttng_error_code ust_app_open_packets(struct ltt_session *session) { - return 0; + return LTTNG_ERR_UNK; } #endif /* HAVE_LIBLTTNG_UST_CTL */ diff --git a/src/bin/lttng-sessiond/ust-consumer.c b/src/bin/lttng-sessiond/ust-consumer.cpp similarity index 100% rename from src/bin/lttng-sessiond/ust-consumer.c rename to src/bin/lttng-sessiond/ust-consumer.cpp diff --git a/src/bin/lttng-sessiond/ust-ctl-internal.h b/src/bin/lttng-sessiond/ust-ctl-internal.h index 610aa7f36..d85af2868 100644 --- a/src/bin/lttng-sessiond/ust-ctl-internal.h +++ b/src/bin/lttng-sessiond/ust-ctl-internal.h @@ -14,6 +14,10 @@ #include "lttng-ust-abi.h" +#ifdef __cplusplus +extern "C" { +#endif + #ifndef LTTNG_UST_UUID_LEN #define LTTNG_UST_UUID_LEN 16 #endif @@ -655,4 +659,8 @@ int lttng_ust_ctl_counter_clear(struct lttng_ust_ctl_daemon_counter *counter, void lttng_ust_ctl_sigbus_handle(void *addr); +#ifdef __cplusplus +} +#endif + #endif /* LTTNG_UST_CTL_INTERNAL_H */ diff --git a/src/bin/lttng-sessiond/ust-field-utils.c b/src/bin/lttng-sessiond/ust-field-utils.cpp similarity index 100% rename from src/bin/lttng-sessiond/ust-field-utils.c rename to src/bin/lttng-sessiond/ust-field-utils.cpp diff --git a/src/bin/lttng-sessiond/ust-metadata.c b/src/bin/lttng-sessiond/ust-metadata.cpp similarity index 99% rename from src/bin/lttng-sessiond/ust-metadata.c rename to src/bin/lttng-sessiond/ust-metadata.cpp index 7110662c7..abe473f27 100644 --- a/src/bin/lttng-sessiond/ust-metadata.c +++ b/src/bin/lttng-sessiond/ust-metadata.cpp @@ -70,7 +70,7 @@ ssize_t metadata_reserve(struct ust_registry_session *session, size_t len) new_alloc_len = max_t(size_t, 1U << get_count_order(new_alloc_len), old_alloc_len << 1); - newptr = realloc(session->metadata, new_alloc_len); + newptr = (char *) realloc(session->metadata, new_alloc_len); if (!newptr) return -ENOMEM; session->metadata = newptr; diff --git a/src/bin/lttng-sessiond/ust-registry.c b/src/bin/lttng-sessiond/ust-registry.cpp similarity index 98% rename from src/bin/lttng-sessiond/ust-registry.c rename to src/bin/lttng-sessiond/ust-registry.cpp index 93131abaa..173465203 100644 --- a/src/bin/lttng-sessiond/ust-registry.c +++ b/src/bin/lttng-sessiond/ust-registry.cpp @@ -34,7 +34,7 @@ static int ht_match_event(struct cds_lfht_node *node, const void *_key) event = caa_container_of(node, struct ust_registry_event, node.node); LTTNG_ASSERT(event); - key = _key; + key = (ust_registry_event *) _key; /* It has to be a perfect match. First, compare the event names. */ if (strncmp(event->name, key->name, sizeof(event->name))) { @@ -79,7 +79,7 @@ no_match: static unsigned long ht_hash_event(const void *_key, unsigned long seed) { uint64_t hashed_key; - const struct ust_registry_event *key = _key; + const struct ust_registry_event *key = (ust_registry_event *) _key; LTTNG_ASSERT(key); @@ -146,7 +146,7 @@ static int ht_match_enum(struct cds_lfht_node *node, const void *_key) _enum = caa_container_of(node, struct ust_registry_enum, node.node); LTTNG_ASSERT(_enum); - key = _key; + key = (ust_registry_enum *) _key; if (strncmp(_enum->name, key->name, LTTNG_UST_ABI_SYM_NAME_LEN)) { goto no_match; @@ -169,7 +169,7 @@ no_match: static int ht_match_enum_id(struct cds_lfht_node *node, const void *_key) { struct ust_registry_enum *_enum; - const struct ust_registry_enum *key = _key; + const struct ust_registry_enum *key = (ust_registry_enum *) _key; LTTNG_ASSERT(node); LTTNG_ASSERT(_key); @@ -194,7 +194,7 @@ no_match: */ static unsigned long ht_hash_enum(void *_key, unsigned long seed) { - struct ust_registry_enum *key = _key; + struct ust_registry_enum *key = (ust_registry_enum *) _key; LTTNG_ASSERT(key); return hash_key_str(key->name, seed); @@ -296,7 +296,7 @@ static struct ust_registry_event *alloc_event(int session_objd, return NULL; } - event = zmalloc(sizeof(*event)); + event = (ust_registry_event *) zmalloc(sizeof(*event)); if (!event) { PERROR("zmalloc ust registry event"); goto error; @@ -632,7 +632,7 @@ int ust_registry_create_or_find_enum(struct ust_registry_session *session, } /* Check if the enumeration was already dumped */ - reg_enum = zmalloc(sizeof(*reg_enum)); + reg_enum = (ust_registry_enum *) zmalloc(sizeof(*reg_enum)); if (!reg_enum) { PERROR("zmalloc ust registry enumeration"); ret = -ENOMEM; @@ -762,7 +762,7 @@ int ust_registry_channel_add(struct ust_registry_session *session, LTTNG_ASSERT(session); - chan = zmalloc(sizeof(*chan)); + chan = (ust_registry_channel *) zmalloc(sizeof(*chan)); if (!chan) { PERROR("zmalloc ust registry channel"); ret = -ENOMEM; @@ -892,7 +892,7 @@ int ust_registry_session_init(struct ust_registry_session **sessionp, LTTNG_ASSERT(sessionp); - session = zmalloc(sizeof(*session)); + session = (ust_registry_session *) zmalloc(sizeof(*session)); if (!session) { PERROR("zmalloc ust registry session"); goto error_alloc; diff --git a/src/bin/lttng-sessiond/ust-sigbus.c b/src/bin/lttng-sessiond/ust-sigbus.cpp similarity index 100% rename from src/bin/lttng-sessiond/ust-sigbus.c rename to src/bin/lttng-sessiond/ust-sigbus.cpp diff --git a/src/bin/lttng-sessiond/utils.c b/src/bin/lttng-sessiond/utils.cpp similarity index 100% rename from src/bin/lttng-sessiond/utils.c rename to src/bin/lttng-sessiond/utils.cpp diff --git a/src/common/buffer-view.h b/src/common/buffer-view.h index 58f1ede2e..ecd764d7c 100644 --- a/src/common/buffer-view.h +++ b/src/common/buffer-view.h @@ -13,6 +13,10 @@ #include #include +#ifdef __cplusplus +extern "C" { +#endif + struct lttng_dynamic_buffer; struct lttng_buffer_view { @@ -92,4 +96,8 @@ bool lttng_buffer_view_contains_string(const struct lttng_buffer_view *buf, const char *str, size_t len_with_null_terminator); +#ifdef __cplusplus +} +#endif + #endif /* LTTNG_BUFFER_VIEW_H */ diff --git a/src/common/bytecode/bytecode.h b/src/common/bytecode/bytecode.h index d7ef4aedd..54ed7363e 100644 --- a/src/common/bytecode/bytecode.h +++ b/src/common/bytecode/bytecode.h @@ -13,6 +13,10 @@ #include "common/macros.h" #include "common/sessiond-comm/sessiond-comm.h" +#ifdef __cplusplus +extern "C" { +#endif + /* * offsets are absolute from start of bytecode. */ @@ -43,10 +47,6 @@ struct literal_double { double v; } LTTNG_PACKED; -struct literal_string { - char string[0]; -} LTTNG_PACKED; - enum bytecode_op { BYTECODE_OP_UNKNOWN = 0, @@ -262,4 +262,8 @@ unsigned int bytecode_get_len(struct lttng_bytecode *bytecode) return bytecode->len; } +#ifdef __cplusplus +} +#endif + #endif /* LTTNG_COMMON_BYTECODE_H */ diff --git a/src/common/compat/directory-handle.h b/src/common/compat/directory-handle.h index 50185a526..9a1072019 100644 --- a/src/common/compat/directory-handle.h +++ b/src/common/compat/directory-handle.h @@ -13,6 +13,10 @@ #include #include +#ifdef __cplusplus +extern "C" { +#endif + enum lttng_directory_handle_rmdir_recursive_flags { LTTNG_DIRECTORY_HANDLE_FAIL_NON_EMPTY_FLAG = (1U << 0), LTTNG_DIRECTORY_HANDLE_SKIP_NON_EMPTY_FLAG = (1U << 1), @@ -259,4 +263,9 @@ bool lttng_directory_handle_uses_fd( bool lttng_directory_handle_equals(const struct lttng_directory_handle *lhs, const struct lttng_directory_handle *rhs); + +#ifdef __cplusplus +} +#endif + #endif /* _COMPAT_PATH_HANDLE_H */ diff --git a/src/common/compat/poll.h b/src/common/compat/poll.h index e2a424abe..75de9ba5f 100644 --- a/src/common/compat/poll.h +++ b/src/common/compat/poll.h @@ -13,6 +13,10 @@ #include +#ifdef __cplusplus +extern "C" { +#endif + /* * Used by lttng_poll_clean to free the events structure in a lttng_poll_event. */ @@ -21,6 +25,10 @@ static inline void __lttng_poll_free(void *events) free(events); } +#ifdef __cplusplus +} +#endif + /* * epoll(7) implementation. */ @@ -30,6 +38,10 @@ static inline void __lttng_poll_free(void *events) #include #include +#ifdef __cplusplus +extern "C" { +#endif + /* See man epoll(7) for this define path */ #define COMPAT_EPOLL_PROC_PATH "/proc/sys/fs/epoll/max_user_watches" @@ -208,6 +220,10 @@ static inline void lttng_poll_clean(struct lttng_poll_event *events) __lttng_poll_free((void *) events->events); } +#ifdef __cplusplus +} +#endif + #else /* HAVE_EPOLL */ /* * Fallback on poll(2) API @@ -226,6 +242,10 @@ static inline void lttng_poll_clean(struct lttng_poll_event *events) #include #include +#ifdef __cplusplus +extern "C" { +#endif + enum { /* Polling variables compatibility for poll */ LPOLLIN = POLLIN, @@ -377,6 +397,10 @@ static inline void lttng_poll_clean(struct lttng_poll_event *events) } } +#ifdef __cplusplus +} +#endif + #endif /* HAVE_EPOLL */ #endif /* _LTT_POLL_H */ diff --git a/src/common/config/session-config.h b/src/common/config/session-config.h index a6955b0b9..ff74eb099 100644 --- a/src/common/config/session-config.h +++ b/src/common/config/session-config.h @@ -13,6 +13,10 @@ #include #include +#ifdef __cplusplus +extern "C" { +#endif + struct config_entry { /* section is NULL if the entry is not in a section */ const char *section; @@ -229,4 +233,8 @@ int config_load_session(const char *path, const char *session_name, int overwrite, unsigned int autoload, const struct config_load_session_override_attr *overrides); +#ifdef __cplusplus +} +#endif + #endif /* _CONFIG_H */ diff --git a/src/common/context.h b/src/common/context.h index f4abd8417..b6755adda 100644 --- a/src/common/context.h +++ b/src/common/context.h @@ -10,6 +10,10 @@ #include +#ifdef __cplusplus +extern "C" { +#endif + /* * Parse string as an application context of the form * "$app.provider_name:context_name" and return the provider name and context @@ -24,4 +28,8 @@ int parse_application_context(const char *str, char **provider_name, char **ctx_name); +#ifdef __cplusplus +} +#endif + #endif /* LTTNG_COMMON_CONTEXT_H */ diff --git a/src/common/credentials.h b/src/common/credentials.h index b1576a757..21aa33416 100644 --- a/src/common/credentials.h +++ b/src/common/credentials.h @@ -14,6 +14,10 @@ #include "optional.h" +#ifdef __cplusplus +extern "C" { +#endif + struct lttng_credentials { LTTNG_OPTIONAL(uid_t) uid; LTTNG_OPTIONAL(gid_t) gid; @@ -32,4 +36,8 @@ bool lttng_credentials_is_equal_gid(const struct lttng_credentials *a, bool lttng_credentials_is_equal(const struct lttng_credentials *a, const struct lttng_credentials *b); +#ifdef __cplusplus +} +#endif + #endif /* LTTNG_CREDENTIALS_H */ diff --git a/src/common/daemonize.h b/src/common/daemonize.h index 2c88f06b7..8590779c2 100644 --- a/src/common/daemonize.h +++ b/src/common/daemonize.h @@ -12,6 +12,10 @@ #include #include +#ifdef __cplusplus +extern "C" { +#endif + /* * Daemonize this process by forking and making the parent wait for the child * to signal it indicating readiness. Once received, the parent successfully @@ -25,4 +29,8 @@ int lttng_daemonize(pid_t *child_ppid, int *completion_flag, int close_fds); +#ifdef __cplusplus +} +#endif + #endif /* LTTNG_DAEMONIZE_H */ diff --git a/src/common/defaults.h b/src/common/defaults.h index 39b77470d..95b1dc29b 100644 --- a/src/common/defaults.h +++ b/src/common/defaults.h @@ -13,6 +13,10 @@ #include #include +#ifdef __cplusplus +extern "C" { +#endif + /* Default unix group name for tracing. */ #define DEFAULT_TRACING_GROUP "tracing" @@ -424,4 +428,8 @@ size_t default_get_ust_uid_channel_subbuf_size(void); */ pthread_attr_t *default_pthread_attr(void); +#ifdef __cplusplus +} +#endif + #endif /* _DEFAULTS_H */ diff --git a/src/common/dynamic-buffer.h b/src/common/dynamic-buffer.h index 0e0dedc9b..d4813fa39 100644 --- a/src/common/dynamic-buffer.h +++ b/src/common/dynamic-buffer.h @@ -12,6 +12,10 @@ #include #include +#ifdef __cplusplus +extern "C" { +#endif + struct lttng_buffer_view; struct lttng_dynamic_buffer { @@ -92,4 +96,8 @@ void lttng_dynamic_buffer_reset(struct lttng_dynamic_buffer *buffer); size_t lttng_dynamic_buffer_get_capacity_left( struct lttng_dynamic_buffer *buffer); +#ifdef __cplusplus +} +#endif + #endif /* LTTNG_DYNAMIC_BUFFER_H */ diff --git a/src/common/fd-handle.h b/src/common/fd-handle.h index dab9e2bfa..36a92473a 100644 --- a/src/common/fd-handle.h +++ b/src/common/fd-handle.h @@ -10,6 +10,10 @@ #include +#ifdef __cplusplus +extern "C" { +#endif + /* * Wrapper around a file descriptor providing reference counting semantics. * @@ -44,4 +48,8 @@ int fd_handle_get_fd(struct fd_handle *handle); */ struct fd_handle *fd_handle_copy(const struct fd_handle *handle); +#ifdef __cplusplus +} +#endif + #endif /* FS_HANDLE_H */ diff --git a/src/common/filter.h b/src/common/filter.h index 305434bf6..f5dcdf319 100644 --- a/src/common/filter.h +++ b/src/common/filter.h @@ -10,6 +10,10 @@ #include +#ifdef __cplusplus +extern "C" { +#endif + struct bytecode_symbol_iterator; /* @@ -33,4 +37,8 @@ const char *bytecode_symbol_iterator_get_name( void bytecode_symbol_iterator_destroy(struct bytecode_symbol_iterator *it); +#ifdef __cplusplus +} +#endif + #endif /* LTTNG_COMMON_FILTER_H */ diff --git a/src/common/futex.h b/src/common/futex.h index 602be3186..92a844674 100644 --- a/src/common/futex.h +++ b/src/common/futex.h @@ -9,9 +9,17 @@ #ifndef _LTT_FUTEX_H #define _LTT_FUTEX_H +#ifdef __cplusplus +extern "C" { +#endif + void futex_wait_update(int32_t *futex, int active); void futex_nto1_prepare(int32_t *futex); void futex_nto1_wait(int32_t *futex); void futex_nto1_wake(int32_t *futex); +#ifdef __cplusplus +} +#endif + #endif /* _LTT_FUTEX_H */ diff --git a/src/common/hashtable/hashtable.h b/src/common/hashtable/hashtable.h index 2c77f0afc..e2dae968d 100644 --- a/src/common/hashtable/hashtable.h +++ b/src/common/hashtable/hashtable.h @@ -14,9 +14,13 @@ #include #include +#ifdef __cplusplus +extern "C" { +#endif + extern unsigned long lttng_ht_seed; -typedef unsigned long (*hash_fct)(const void *_key, unsigned long seed); +typedef unsigned long (*hash_fct_type)(const void *_key, unsigned long seed); typedef cds_lfht_match_fct hash_match_fct; enum lttng_ht_type { @@ -29,7 +33,7 @@ enum lttng_ht_type { struct lttng_ht { struct cds_lfht *ht; cds_lfht_match_fct match_fct; - hash_fct hash_fct; + hash_fct_type hash_fct; }; struct lttng_ht_iter { @@ -122,4 +126,8 @@ struct lttng_ht_node_u64 *lttng_ht_iter_get_node_u64( struct lttng_ht_node_two_u64 *lttng_ht_iter_get_node_two_u64( struct lttng_ht_iter *iter); +#ifdef __cplusplus +} +#endif + #endif /* _LTT_HT_H */ diff --git a/src/common/hashtable/utils.h b/src/common/hashtable/utils.h index 992643931..44f80ce4f 100644 --- a/src/common/hashtable/utils.h +++ b/src/common/hashtable/utils.h @@ -10,6 +10,10 @@ #include +#ifdef __cplusplus +extern "C" { +#endif + unsigned long hash_key_ulong(const void *_key, unsigned long seed); unsigned long hash_key_u64(const void *_key, unsigned long seed); unsigned long hash_key_str(const void *key, unsigned long seed); @@ -19,4 +23,8 @@ int hash_match_key_u64(const void *key1, const void *key2); int hash_match_key_str(const void *key1, const void *key2); int hash_match_key_two_u64(const void *key1, const void *key2); +#ifdef __cplusplus +} +#endif + #endif /* _LTT_HT_UTILS_H */ diff --git a/src/common/index-allocator.h b/src/common/index-allocator.h index 3da733e9e..9dbd745e6 100644 --- a/src/common/index-allocator.h +++ b/src/common/index-allocator.h @@ -10,6 +10,10 @@ #include +#ifdef __cplusplus +extern "C" { +#endif + struct lttng_index_allocator; enum lttng_index_allocator_status { @@ -49,4 +53,8 @@ enum lttng_index_allocator_status lttng_index_allocator_release( */ void lttng_index_allocator_destroy(struct lttng_index_allocator *allocator); +#ifdef __cplusplus +} +#endif + #endif /* _COMMON_INDEX_ALLOCATOR_H */ diff --git a/src/common/kernel-ctl/kernel-ctl.h b/src/common/kernel-ctl/kernel-ctl.h index e6805a983..c2fa6408b 100644 --- a/src/common/kernel-ctl/kernel-ctl.h +++ b/src/common/kernel-ctl/kernel-ctl.h @@ -16,6 +16,10 @@ #include #include /* for struct lttng_filter_bytecode */ +#ifdef __cplusplus +extern "C" { +#endif + int kernctl_create_session(int fd); int kernctl_open_metadata(int fd, struct lttng_channel_attr *chops); int kernctl_create_channel(int fd, struct lttng_channel_attr *chops); @@ -125,4 +129,8 @@ int kernctl_get_current_timestamp(int fd, uint64_t *ts); int kernctl_get_sequence_number(int fd, uint64_t *seq); int kernctl_get_instance_id(int fd, uint64_t *seq); +#ifdef __cplusplus +} +#endif + #endif /* _LTTNG_KERNEL_CTL_H */ diff --git a/src/common/macros.h b/src/common/macros.h index 874501ef1..7530c912a 100644 --- a/src/common/macros.h +++ b/src/common/macros.h @@ -101,13 +101,6 @@ void *zmalloc(size_t len) #define ASSERT_LOCKED(lock) LTTNG_ASSERT(pthread_mutex_trylock(&lock)) -/* - * Get an aligned pointer to a value. This is meant - * as a helper to pass an aligned pointer to a member in a packed structure - * to a function. - */ -#define ALIGNED_CONST_PTR(value) (((const typeof(value) []) { value })) - /* * lttng_strncpy returns 0 on success, or nonzero on failure. * It checks that the @src string fits into @dst_len before performing diff --git a/src/common/optional.h b/src/common/optional.h index dcb7ca863..0501904cb 100644 --- a/src/common/optional.h +++ b/src/common/optional.h @@ -88,13 +88,13 @@ /* * Initialize an optional field as 'set' with a given value. */ -#define LTTNG_OPTIONAL_INIT_VALUE(val) { .value = val, .is_set = 1 } +#define LTTNG_OPTIONAL_INIT_VALUE(val) { .is_set = 1, .value = val } /* Set the value of an optional field. */ #define LTTNG_OPTIONAL_SET(field_ptr, val) \ do { \ - (field_ptr)->value = (val); \ (field_ptr)->is_set = 1; \ + (field_ptr)->value = (val); \ } while (0) /* Put an optional field in the "unset" (NULL-ed) state. */ diff --git a/src/common/payload-view.h b/src/common/payload-view.h index 57a8342d7..af8519ab3 100644 --- a/src/common/payload-view.h +++ b/src/common/payload-view.h @@ -11,6 +11,10 @@ #include #include +#ifdef __cplusplus +extern "C" { +#endif + struct lttng_payload; struct fd_handle; @@ -46,7 +50,26 @@ struct fd_handle; struct lttng_payload_view { struct lttng_buffer_view buffer; /* private */ - const struct lttng_dynamic_pointer_array _fd_handles; + + /* + * Avoid a -Wreturn-type-c-linkage warning with clang. + * gcc is more permissive with regards to this warning, but + * clang is right that a structure containing a _const_ structure is not + * a trivial type in the eyes of the C++ standard, theoritically affecting its + * compatibility with C from an ABI standpoint: + * A trivial class is a class that is trivially copyable and has one or + * more default constructors, all of which are either trivial or deleted and + * at least one of which is not deleted. + * + * A const member implicitly deletes lttng_payload_view's constructor, + * making it non-trivial. This is not a problem for the moment as we are + * transitioning all code to C++11. + */ +#if !defined(__cplusplus) + const +#endif + struct lttng_dynamic_pointer_array _fd_handles; + struct { size_t *p_fd_handles_position; size_t fd_handles_position; @@ -159,4 +182,8 @@ int lttng_payload_view_get_fd_handle_count( struct fd_handle *lttng_payload_view_pop_fd_handle( struct lttng_payload_view *payload_view); +#ifdef __cplusplus +} +#endif + #endif /* LTTNG_PAYLOAD_VIEW_H */ diff --git a/src/common/payload.h b/src/common/payload.h index d6c0cc19e..e9bd8be9d 100644 --- a/src/common/payload.h +++ b/src/common/payload.h @@ -12,6 +12,10 @@ #include #include +#ifdef __cplusplus +extern "C" { +#endif + /* * An lttng_payload encompasses the 'data' (bytes) and any passed file * descriptors as part of a message between liblttng-ctl and the session @@ -57,4 +61,8 @@ void lttng_payload_clear(struct lttng_payload *payload); int lttng_payload_push_fd_handle(struct lttng_payload *payload, struct fd_handle *fd_handle); +#ifdef __cplusplus +} +#endif + #endif /* LTTNG_PAYLOAD_H */ diff --git a/src/common/pipe.h b/src/common/pipe.h index d9f43d66e..b94d871e4 100644 --- a/src/common/pipe.h +++ b/src/common/pipe.h @@ -12,6 +12,10 @@ #include #include +#ifdef __cplusplus +extern "C" { +#endif + enum lttng_pipe_state { LTTNG_PIPE_STATE_OPENED = 1, LTTNG_PIPE_STATE_CLOSED = 2, @@ -81,4 +85,8 @@ int lttng_pipe_release_readfd(struct lttng_pipe *pipe); /* Returns and releases the write end of the pipe. */ int lttng_pipe_release_writefd(struct lttng_pipe *pipe); +#ifdef __cplusplus +} +#endif + #endif /* LTTNG_PIPE_H */ diff --git a/src/common/readwrite.h b/src/common/readwrite.h index ac3668a5a..9923e8128 100644 --- a/src/common/readwrite.h +++ b/src/common/readwrite.h @@ -11,6 +11,10 @@ #include #include +#ifdef __cplusplus +extern "C" { +#endif + /* * lttng_read and lttng_write take care of EINTR and partial read/write. * Upon success, they return the "count" received as parameter. @@ -22,4 +26,8 @@ ssize_t lttng_read(int fd, void *buf, size_t count); ssize_t lttng_write(int fd, const void *buf, size_t count); +#ifdef __cplusplus +} +#endif + #endif /* LTTNG_COMMON_READWRITE_H */ diff --git a/src/common/relayd/relayd.h b/src/common/relayd/relayd.h index 1fbe22676..6053be796 100644 --- a/src/common/relayd/relayd.h +++ b/src/common/relayd/relayd.h @@ -16,6 +16,10 @@ #include #include +#ifdef __cplusplus +extern "C" { +#endif + struct relayd_stream_rotation_position { uint64_t stream_id; /* @@ -77,4 +81,8 @@ int relayd_get_configuration(struct lttcomm_relayd_sock *sock, uint64_t query_flags, uint64_t *result_flags); +#ifdef __cplusplus +} +#endif + #endif /* _RELAYD_H */ diff --git a/src/common/runas.h b/src/common/runas.h index 406dfca22..ca084102e 100644 --- a/src/common/runas.h +++ b/src/common/runas.h @@ -16,6 +16,10 @@ #include #include +#ifdef __cplusplus +extern "C" { +#endif + /* * The run-as process is launched by forking without an exec*() call. This means * that any resource allocated before the run-as worker is launched should be @@ -61,4 +65,8 @@ int run_as_create_worker(const char *procname, post_fork_cleanup_cb clean_up_func, void *clean_up_user_data); void run_as_destroy_worker(void); +#ifdef __cplusplus +} +#endif + #endif /* _RUNAS_H */ diff --git a/src/common/sessiond-comm/inet.c b/src/common/sessiond-comm/inet.c index 357e10b08..93fb19bb5 100644 --- a/src/common/sessiond-comm/inet.c +++ b/src/common/sessiond-comm/inet.c @@ -87,19 +87,17 @@ error: */ int lttcomm_bind_inet_sock(struct lttcomm_sock *sock) { - return bind(sock->fd, - (const struct sockaddr *) ALIGNED_CONST_PTR( - sock->sockaddr.addr.sin), - sizeof(sock->sockaddr.addr.sin)); + struct sockaddr_in sockaddr = sock->sockaddr.addr.sin; + + return bind(sock->fd, &sockaddr, sizeof(sockaddr)); } static int connect_no_timeout(struct lttcomm_sock *sock) { - return connect(sock->fd, - (const struct sockaddr *) ALIGNED_CONST_PTR( - sock->sockaddr.addr.sin), - sizeof(sock->sockaddr.addr.sin)); + struct sockaddr_in sockaddr = sock->sockaddr.addr.sin; + + return connect(sock->fd, &sockaddr, sizeof(sockaddr)); } static @@ -109,6 +107,7 @@ int connect_with_timeout(struct lttcomm_sock *sock) int ret, flags, connect_ret; struct timespec orig_time, cur_time; unsigned long diff_ms; + struct sockaddr_in sockaddr; ret = fcntl(sock->fd, F_GETFL, 0); if (ret == -1) { @@ -130,10 +129,8 @@ int connect_with_timeout(struct lttcomm_sock *sock) return -1; } - connect_ret = connect(sock->fd, - (const struct sockaddr *) ALIGNED_CONST_PTR( - sock->sockaddr.addr.sin), - sizeof(sock->sockaddr.addr.sin)); + sockaddr = sock->sockaddr.addr.sin; + connect_ret = connect(sock->fd, &sockaddr, sizeof(sockaddr)); if (connect_ret == -1 && errno != EAGAIN && errno != EWOULDBLOCK && errno != EINPROGRESS) { goto error; diff --git a/src/common/sessiond-comm/inet.h b/src/common/sessiond-comm/inet.h index 2db8c0890..5c0828b2b 100644 --- a/src/common/sessiond-comm/inet.h +++ b/src/common/sessiond-comm/inet.h @@ -12,6 +12,10 @@ #include "sessiond-comm.h" +#ifdef __cplusplus +extern "C" { +#endif + /* See man tcp(7) for more detail about this value. */ #define LTTCOMM_INET_PROC_SYN_RETRIES_PATH "/proc/sys/net/ipv4/tcp_syn_retries" #define LTTCOMM_INET_PROC_FIN_TIMEOUT_PATH "/proc/sys/net/ipv4/tcp_fin_timeout" @@ -53,4 +57,8 @@ extern ssize_t lttcomm_sendmsg_inet_sock(struct lttcomm_sock *sock, /* Initialize inet communication layer. */ extern void lttcomm_inet_init(void); +#ifdef __cplusplus +} +#endif + #endif /* _LTTCOMM_INET_H */ diff --git a/src/common/sessiond-comm/inet6.c b/src/common/sessiond-comm/inet6.c index f705bc0c0..8c0d0b795 100644 --- a/src/common/sessiond-comm/inet6.c +++ b/src/common/sessiond-comm/inet6.c @@ -85,19 +85,15 @@ error: */ int lttcomm_bind_inet6_sock(struct lttcomm_sock *sock) { - return bind(sock->fd, - (const struct sockaddr *) ALIGNED_CONST_PTR( - sock->sockaddr.addr.sin6), - sizeof(sock->sockaddr.addr.sin6)); + struct sockaddr_in6 sockaddr = sock->sockaddr.addr.sin6; + return bind(sock->fd, &sockaddr, sizeof(sockaddr)); } static int connect_no_timeout(struct lttcomm_sock *sock) { - return connect(sock->fd, - (const struct sockaddr *) ALIGNED_CONST_PTR( - sock->sockaddr.addr.sin6), - sizeof(sock->sockaddr.addr.sin6)); + struct sockaddr_in6 sockaddr = sock->sockaddr.addr.sin6; + return connect(sock->fd, &sockaddr, sizeof(sockaddr)); } static @@ -107,6 +103,7 @@ int connect_with_timeout(struct lttcomm_sock *sock) int ret, flags, connect_ret; struct timespec orig_time, cur_time; unsigned long diff_ms; + struct sockaddr_in6 sockaddr; ret = fcntl(sock->fd, F_GETFL, 0); if (ret == -1) { @@ -128,10 +125,8 @@ int connect_with_timeout(struct lttcomm_sock *sock) return -1; } - connect_ret = connect(sock->fd, - (const struct sockaddr *) ALIGNED_CONST_PTR( - sock->sockaddr.addr.sin6), - sizeof(sock->sockaddr.addr.sin6)); + sockaddr = sock->sockaddr.addr.sin6; + connect_ret = connect(sock->fd, &sockaddr, sizeof(sockaddr)); if (connect_ret == -1 && errno != EAGAIN && errno != EWOULDBLOCK && errno != EINPROGRESS) { goto error; diff --git a/src/common/sessiond-comm/sessiond-comm.h b/src/common/sessiond-comm/sessiond-comm.h index c8e1e1ae1..65020bbfc 100644 --- a/src/common/sessiond-comm/sessiond-comm.h +++ b/src/common/sessiond-comm/sessiond-comm.h @@ -37,6 +37,10 @@ #include "inet6.h" #include +#ifdef __cplusplus +extern "C" { +#endif + /* Queue size of listen(2) */ #define LTTNG_SESSIOND_COMM_MAX_LISTEN 64 @@ -931,4 +935,8 @@ void lttcomm_init(void); /* Get network timeout, in milliseconds */ unsigned long lttcomm_get_network_timeout(void); +#ifdef __cplusplus +} +#endif + #endif /* _LTTNG_SESSIOND_COMM_H */ diff --git a/src/common/shm.h b/src/common/shm.h index d714506b8..530507c35 100644 --- a/src/common/shm.h +++ b/src/common/shm.h @@ -9,8 +9,16 @@ #ifndef _LTT_SHM_H #define _LTT_SHM_H +#ifdef __cplusplus +extern "C" { +#endif + char *shm_ust_get_mmap(char *shm_path, int global); int shm_create_anonymous(const char *owner_name); +#ifdef __cplusplus +} +#endif + #endif /* _LTT_SHM_H */ diff --git a/src/common/testpoint/testpoint.h b/src/common/testpoint/testpoint.h index 1f856f397..b613b1749 100644 --- a/src/common/testpoint/testpoint.h +++ b/src/common/testpoint/testpoint.h @@ -14,6 +14,10 @@ #include /* for caa_likely/unlikely */ +#ifdef __cplusplus +extern "C" { +#endif + extern int lttng_testpoint_activated; void *lttng_testpoint_lookup(const char *name); @@ -43,7 +47,7 @@ void *lttng_testpoint_lookup(const char *name); ret = tp(); \ } else { \ if (!found) { \ - tp = lttng_testpoint_lookup(tp_name); \ + tp = (int (*)(void)) lttng_testpoint_lookup(tp_name); \ if (tp) { \ found = 1; \ ret = tp(); \ @@ -59,4 +63,8 @@ void *lttng_testpoint_lookup(const char *name); #define TESTPOINT_DECL(name) \ _TESTPOINT_DECL(name) +#ifdef __cplusplus +} +#endif + #endif /* NTESTPOINT */ diff --git a/src/common/trace-chunk.h b/src/common/trace-chunk.h index 4e4440b6a..9bb4f3708 100644 --- a/src/common/trace-chunk.h +++ b/src/common/trace-chunk.h @@ -16,6 +16,10 @@ #include #include +#ifdef __cplusplus +extern "C" { +#endif + /* * A trace chunk is a group of directories and files forming a (or a set of) * complete and independant trace(s). For instance, a trace archive chunk, @@ -182,4 +186,8 @@ bool lttng_trace_chunk_get(struct lttng_trace_chunk *chunk); void lttng_trace_chunk_put(struct lttng_trace_chunk *chunk); +#ifdef __cplusplus +} +#endif + #endif /* LTTNG_TRACE_CHUNK_H */ diff --git a/src/common/unix.h b/src/common/unix.h index 820dff0b5..e5c7435e3 100644 --- a/src/common/unix.h +++ b/src/common/unix.h @@ -16,6 +16,10 @@ #include #include +#ifdef __cplusplus +extern "C" { +#endif + int lttcomm_create_unix_sock(const char *pathname); int lttcomm_create_anon_unix_socketpair(int *fds); int lttcomm_connect_unix_sock(const char *pathname); @@ -51,4 +55,8 @@ ssize_t lttcomm_recv_creds_unix_sock(int sock, void *buf, size_t len, int lttcomm_setsockopt_creds_unix_sock(int sock); +#ifdef __cplusplus +} +#endif + #endif /* _LTTCOMM_UNIX_H */ diff --git a/src/common/uuid.h b/src/common/uuid.h index 0d3e79aee..d95ea062e 100644 --- a/src/common/uuid.h +++ b/src/common/uuid.h @@ -13,6 +13,10 @@ #include #include +#ifdef __cplusplus +extern "C" { +#endif + /* * Includes final \0. */ @@ -59,4 +63,8 @@ void lttng_uuid_copy(lttng_uuid dst, const lttng_uuid src); */ int lttng_uuid_generate(lttng_uuid uuid_out); +#ifdef __cplusplus +} +#endif + #endif /* LTTNG_UUID_H */ diff --git a/src/common/waiter.h b/src/common/waiter.h index ed870aeb0..30b51ee80 100644 --- a/src/common/waiter.h +++ b/src/common/waiter.h @@ -17,6 +17,10 @@ #include #include "macros.h" +#ifdef __cplusplus +extern "C" { +#endif + struct lttng_waiter { struct cds_wfs_node wait_queue_node; int32_t state; @@ -33,4 +37,8 @@ void lttng_waiter_wait(struct lttng_waiter *waiter); */ void lttng_waiter_wake_up(struct lttng_waiter *waiter); +#ifdef __cplusplus +} +#endif + #endif /* LTTNG_WAITER_H */ diff --git a/tests/unit/Makefile.am b/tests/unit/Makefile.am index 7ff30d266..c8deb2ec3 100644 --- a/tests/unit/Makefile.am +++ b/tests/unit/Makefile.am @@ -83,7 +83,7 @@ test_uri_LDADD = $(LIBTAP) $(LIBCOMMON) $(LIBHASHTABLE) $(DL_LIBS) RELAYD_OBJS = $(top_builddir)/src/bin/lttng-relayd/backward-compatibility-group-by.$(OBJEXT) -test_session_SOURCES = test_session.c +test_session_SOURCES = test_session.cpp test_session_LDADD = $(LIBTAP) $(LIBLTTNG_SESSIOND_COMMON) $(DL_LIBS) if HAVE_LIBLTTNG_UST_CTL @@ -93,11 +93,11 @@ endif # UST data structures unit test if HAVE_LIBLTTNG_UST_CTL -test_ust_data_SOURCES = test_ust_data.c +test_ust_data_SOURCES = test_ust_data.cpp test_ust_data_LDADD = $(LIBTAP) $(LIBLTTNG_SESSIOND_COMMON) $(DL_LIBS) endif -test_kernel_data_SOURCES = test_kernel_data.c +test_kernel_data_SOURCES = test_kernel_data.cpp test_kernel_data_LDADD = $(LIBTAP) $(LIBLTTNG_SESSIOND_COMMON) $(DL_LIBS) # utils suffix for unit test diff --git a/tests/unit/test_kernel_data.c b/tests/unit/test_kernel_data.cpp similarity index 100% rename from tests/unit/test_kernel_data.c rename to tests/unit/test_kernel_data.cpp diff --git a/tests/unit/test_session.c b/tests/unit/test_session.cpp similarity index 100% rename from tests/unit/test_session.c rename to tests/unit/test_session.cpp diff --git a/tests/unit/test_ust_data.c b/tests/unit/test_ust_data.cpp similarity index 97% rename from tests/unit/test_ust_data.c rename to tests/unit/test_ust_data.cpp index 95c6fe12d..a6dfba429 100644 --- a/tests/unit/test_ust_data.c +++ b/tests/unit/test_ust_data.cpp @@ -164,7 +164,7 @@ static void test_create_ust_event_exclusion(void) ev.loglevel_type = LTTNG_EVENT_LOGLEVEL_ALL; /* set up an exclusion set */ - exclusion = zmalloc(sizeof(*exclusion) + + exclusion = (lttng_event_exclusion *) zmalloc(sizeof(*exclusion) + LTTNG_SYMBOL_NAME_LEN * exclusion_count); ok(exclusion != NULL, "Create UST exclusion"); if (!exclusion) { @@ -184,7 +184,7 @@ static void test_create_ust_event_exclusion(void) ok(ret != LTTNG_OK, "Create UST event with identical exclusion names fails"); - exclusion = zmalloc(sizeof(*exclusion) + + exclusion = (lttng_event_exclusion *) zmalloc(sizeof(*exclusion) + LTTNG_SYMBOL_NAME_LEN * exclusion_count); ok(exclusion != NULL, "Create UST exclusion"); if (!exclusion) { @@ -192,7 +192,7 @@ static void test_create_ust_event_exclusion(void) goto end; } - exclusion_copy = zmalloc(sizeof(*exclusion) + + exclusion_copy = (lttng_event_exclusion *) zmalloc(sizeof(*exclusion) + LTTNG_SYMBOL_NAME_LEN * exclusion_count); if (!exclusion_copy) { skip(2, "zmalloc failed"); diff --git a/tests/utils/tap/tap.h b/tests/utils/tap/tap.h index c15909d89..84288f038 100644 --- a/tests/utils/tap/tap.h +++ b/tests/utils/tap/tap.h @@ -26,6 +26,10 @@ * SUCH DAMAGE. */ +#ifdef __cplusplus +extern "C" { +#endif + /* '## __VA_ARGS__' is a gcc'ism. C99 doesn't allow the token pasting and requires the caller to add the final comma if they've ommitted the optional arguments */ @@ -89,3 +93,7 @@ void todo_start(char *, ...); void todo_end(void); int exit_status(void); + +#ifdef __cplusplus +} +#endif -- 2.34.1