From a6bc4ca9d659caf016ef932fcd944029737ac57c Mon Sep 17 00:00:00 2001 From: Simon Marchi Date: Wed, 22 Sep 2021 08:21:14 -0400 Subject: [PATCH] common: compile libcommon as C++ MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Change-Id: I5160ef36932d71a4d925018fe0763bbc78b88009 Signed-off-by: Simon Marchi Signed-off-by: Jérémie Galarneau --- src/common/Makefile.am | 138 +++--- src/common/actions/{action.c => action.cpp} | 4 +- src/common/actions/{list.c => list.cpp} | 8 +- src/common/actions/{notify.c => notify.cpp} | 2 +- src/common/actions/{path.c => path.cpp} | 10 +- .../{rate-policy.c => rate-policy.cpp} | 14 +- .../{rotate-session.c => rotate-session.cpp} | 2 +- ...napshot-session.c => snapshot-session.cpp} | 2 +- .../{start-session.c => start-session.cpp} | 2 +- .../{stop-session.c => stop-session.cpp} | 2 +- src/common/{buffer-view.c => buffer-view.cpp} | 2 +- .../{buffer-usage.c => buffer-usage.cpp} | 4 +- .../conditions/{condition.c => condition.cpp} | 0 ...-rule-matches.c => event-rule-matches.cpp} | 15 +- ...sumed-size.c => session-consumed-size.cpp} | 4 +- ...ession-rotation.c => session-rotation.cpp} | 23 +- src/common/{context.c => context.cpp} | 4 +- src/common/{credentials.c => credentials.cpp} | 0 src/common/{daemonize.c => daemonize.cpp} | 0 src/common/{defaults.c => defaults.cpp} | 13 +- src/common/{domain.c => domain.cpp} | 0 .../{dynamic-array.c => dynamic-array.cpp} | 0 .../{dynamic-buffer.c => dynamic-buffer.cpp} | 2 +- src/common/{endpoint.c => endpoint.cpp} | 0 src/common/{error-query.c => error-query.cpp} | 18 +- src/common/error.c | 283 ----------- src/common/error.cpp | 447 ++++++++++++++++++ src/common/{evaluation.c => evaluation.cpp} | 0 .../{event-expr.c => event-expr.cpp} | 2 +- ...nt-field-value.c => event-field-value.cpp} | 8 +- .../{event-rule.c => event-rule.cpp} | 0 .../{jul-logging.c => jul-logging.cpp} | 4 +- .../{kernel-kprobe.c => kernel-kprobe.cpp} | 2 +- .../{kernel-syscall.c => kernel-syscall.cpp} | 4 +- ...nel-tracepoint.c => kernel-tracepoint.cpp} | 2 +- .../{kernel-uprobe.c => kernel-uprobe.cpp} | 2 +- .../{log4j-logging.c => log4j-logging.cpp} | 4 +- .../{python-logging.c => python-logging.cpp} | 4 +- ...{user-tracepoint.c => user-tracepoint.cpp} | 6 +- src/common/{event.c => event.cpp} | 4 +- src/common/{fd-handle.c => fd-handle.cpp} | 2 +- src/common/{filter.c => filter.cpp} | 2 +- src/common/{fs-handle.c => fs-handle.cpp} | 0 src/common/{futex.c => futex.cpp} | 0 ...{index-allocator.c => index-allocator.cpp} | 4 +- .../{kernel-probe.c => kernel-probe.cpp} | 4 +- src/common/{location.c => location.cpp} | 2 +- .../{log-level-rule.c => log-level-rule.cpp} | 6 +- src/common/{lttng-elf.c => lttng-elf.cpp} | 15 +- src/common/lttng-elf.h | 6 +- src/common/{mi-lttng.c => mi-lttng.cpp} | 20 +- .../{notification.c => notification.cpp} | 2 +- .../{payload-view.c => payload-view.cpp} | 8 +- src/common/{payload.c => payload.cpp} | 4 +- src/common/{pipe.c => pipe.cpp} | 2 +- src/common/{readwrite.c => readwrite.cpp} | 4 +- src/common/{runas.c => runas.cpp} | 104 ++-- ...on-descriptor.c => session-descriptor.cpp} | 28 +- src/common/{shm.c => shm.cpp} | 2 +- src/common/{snapshot.c => snapshot.cpp} | 0 .../{spawn-viewer.c => spawn-viewer.cpp} | 4 +- src/common/{thread.c => thread.cpp} | 0 src/common/{time.c => time.cpp} | 3 +- src/common/{trace-chunk.c => trace-chunk.cpp} | 121 +++-- src/common/{tracker.c => tracker.cpp} | 8 +- src/common/{trigger.c => trigger.cpp} | 6 +- src/common/{unix.c => unix.cpp} | 6 +- src/common/{uri.c => uri.cpp} | 12 +- src/common/uri.h | 1 + ...{userspace-probe.c => userspace-probe.cpp} | 14 +- src/common/{utils.c => utils.cpp} | 32 +- src/common/{uuid.c => uuid.cpp} | 2 +- src/common/{waiter.c => waiter.cpp} | 0 .../regression/tools/notification/Makefile.am | 2 +- ..._getter.c => default_pipe_size_getter.cpp} | 0 75 files changed, 832 insertions(+), 635 deletions(-) rename src/common/actions/{action.c => action.cpp} (98%) rename src/common/actions/{list.c => list.cpp} (97%) rename src/common/actions/{notify.c => notify.cpp} (98%) rename src/common/actions/{path.c => path.cpp} (96%) rename src/common/actions/{rate-policy.c => rate-policy.cpp} (97%) rename src/common/actions/{rotate-session.c => rotate-session.cpp} (99%) rename src/common/actions/{snapshot-session.c => snapshot-session.cpp} (99%) rename src/common/actions/{start-session.c => start-session.cpp} (99%) rename src/common/actions/{stop-session.c => stop-session.cpp} (99%) rename src/common/{buffer-view.c => buffer-view.cpp} (99%) rename src/common/conditions/{buffer-usage.c => buffer-usage.cpp} (99%) rename src/common/conditions/{condition.c => condition.cpp} (100%) rename src/common/conditions/{event-rule-matches.c => event-rule-matches.cpp} (98%) rename src/common/conditions/{session-consumed-size.c => session-consumed-size.cpp} (98%) rename src/common/conditions/{session-rotation.c => session-rotation.cpp} (96%) rename src/common/{context.c => context.cpp} (94%) rename src/common/{credentials.c => credentials.cpp} (100%) rename src/common/{daemonize.c => daemonize.cpp} (100%) rename src/common/{defaults.c => defaults.cpp} (87%) rename src/common/{domain.c => domain.cpp} (100%) rename src/common/{dynamic-array.c => dynamic-array.cpp} (100%) rename src/common/{dynamic-buffer.c => dynamic-buffer.cpp} (99%) rename src/common/{endpoint.c => endpoint.cpp} (100%) rename src/common/{error-query.c => error-query.cpp} (98%) delete mode 100644 src/common/error.c create mode 100644 src/common/error.cpp rename src/common/{evaluation.c => evaluation.cpp} (100%) rename src/common/event-expr/{event-expr.c => event-expr.cpp} (99%) rename src/common/{event-field-value.c => event-field-value.cpp} (97%) rename src/common/event-rule/{event-rule.c => event-rule.cpp} (100%) rename src/common/event-rule/{jul-logging.c => jul-logging.cpp} (99%) rename src/common/event-rule/{kernel-kprobe.c => kernel-kprobe.cpp} (99%) rename src/common/event-rule/{kernel-syscall.c => kernel-syscall.cpp} (98%) rename src/common/event-rule/{kernel-tracepoint.c => kernel-tracepoint.cpp} (99%) rename src/common/event-rule/{kernel-uprobe.c => kernel-uprobe.cpp} (99%) rename src/common/event-rule/{log4j-logging.c => log4j-logging.cpp} (99%) rename src/common/event-rule/{python-logging.c => python-logging.cpp} (99%) rename src/common/event-rule/{user-tracepoint.c => user-tracepoint.cpp} (99%) rename src/common/{event.c => event.cpp} (85%) rename src/common/{fd-handle.c => fd-handle.cpp} (97%) rename src/common/{filter.c => filter.cpp} (96%) rename src/common/{fs-handle.c => fs-handle.cpp} (100%) rename src/common/{futex.c => futex.cpp} (100%) rename src/common/{index-allocator.c => index-allocator.cpp} (95%) rename src/common/{kernel-probe.c => kernel-probe.cpp} (99%) rename src/common/{location.c => location.cpp} (99%) rename src/common/{log-level-rule.c => log-level-rule.cpp} (96%) rename src/common/{lttng-elf.c => lttng-elf.cpp} (98%) rename src/common/{mi-lttng.c => mi-lttng.cpp} (99%) rename src/common/{notification.c => notification.cpp} (98%) rename src/common/{payload-view.c => payload-view.cpp} (93%) rename src/common/{payload.c => payload.cpp} (94%) rename src/common/{pipe.c => pipe.cpp} (99%) rename src/common/{readwrite.c => readwrite.cpp} (94%) rename src/common/{runas.c => runas.cpp} (97%) rename src/common/{session-descriptor.c => session-descriptor.cpp} (97%) rename src/common/{shm.c => shm.cpp} (98%) rename src/common/{snapshot.c => snapshot.cpp} (100%) rename src/common/{spawn-viewer.c => spawn-viewer.cpp} (98%) rename src/common/{thread.c => thread.cpp} (100%) rename src/common/{time.c => time.cpp} (97%) rename src/common/{trace-chunk.c => trace-chunk.cpp} (95%) rename src/common/{tracker.c => tracker.cpp} (97%) rename src/common/{trigger.c => trigger.cpp} (99%) rename src/common/{unix.c => unix.cpp} (99%) rename src/common/{uri.c => uri.cpp} (98%) rename src/common/{userspace-probe.c => userspace-probe.cpp} (99%) rename src/common/{utils.c => utils.cpp} (97%) rename src/common/{uuid.c => uuid.cpp} (98%) rename src/common/{waiter.c => waiter.cpp} (100%) rename tests/regression/tools/notification/{default_pipe_size_getter.c => default_pipe_size_getter.cpp} (100%) diff --git a/src/common/Makefile.am b/src/common/Makefile.am index cb8ac7b10..48e18f311 100644 --- a/src/common/Makefile.am +++ b/src/common/Makefile.am @@ -38,81 +38,81 @@ noinst_LTLIBRARIES = libcommon.la EXTRA_DIST = mi-lttng-4.1.xsd libcommon_la_SOURCES = \ - actions/action.c \ - actions/list.c \ - actions/notify.c \ - actions/path.c \ - actions/rotate-session.c \ - actions/snapshot-session.c \ - actions/start-session.c \ - actions/stop-session.c \ - actions/rate-policy.c \ - buffer-view.h buffer-view.c \ + actions/action.cpp \ + actions/list.cpp \ + actions/notify.cpp \ + actions/path.cpp \ + actions/rotate-session.cpp \ + actions/snapshot-session.cpp \ + actions/start-session.cpp \ + actions/stop-session.cpp \ + actions/rate-policy.cpp \ + buffer-view.h buffer-view.cpp \ common.h \ - conditions/buffer-usage.c \ - conditions/condition.c \ - conditions/event-rule-matches.c \ - conditions/session-consumed-size.c \ - conditions/session-rotation.c \ - context.c context.h \ - credentials.c credentials.h \ - daemonize.c daemonize.h \ - defaults.c \ - domain.c \ - dynamic-array.c dynamic-array.h \ - dynamic-buffer.c dynamic-buffer.h \ - endpoint.c \ - error.c error.h \ - error-query.c \ - evaluation.c \ - event.c \ - event-expr/event-expr.c \ - event-field-value.c \ - event-rule/event-rule.c \ - event-rule/kernel-kprobe.c \ - event-rule/kernel-syscall.c \ - event-rule/kernel-uprobe.c \ - event-rule/kernel-tracepoint.c \ - event-rule/user-tracepoint.c \ - event-rule/log4j-logging.c \ - event-rule/jul-logging.c \ - event-rule/python-logging.c \ - filter.c filter.h \ - fd-handle.c fd-handle.h \ - fs-handle.c fs-handle.h fs-handle-internal.h \ - futex.c futex.h \ - kernel-probe.c \ - index-allocator.c index-allocator.h \ - location.c \ - log-level-rule.c \ - mi-lttng.c mi-lttng.h \ - notification.c \ + conditions/buffer-usage.cpp \ + conditions/condition.cpp \ + conditions/event-rule-matches.cpp \ + conditions/session-consumed-size.cpp \ + conditions/session-rotation.cpp \ + context.cpp context.h \ + credentials.cpp credentials.h \ + daemonize.cpp daemonize.h \ + defaults.cpp \ + domain.cpp \ + dynamic-array.cpp dynamic-array.h \ + dynamic-buffer.cpp dynamic-buffer.h \ + endpoint.cpp \ + error.cpp error.h \ + error-query.cpp \ + evaluation.cpp \ + event.cpp \ + event-expr/event-expr.cpp \ + event-field-value.cpp \ + event-rule/event-rule.cpp \ + event-rule/kernel-kprobe.cpp \ + event-rule/kernel-syscall.cpp \ + event-rule/kernel-uprobe.cpp \ + event-rule/kernel-tracepoint.cpp \ + event-rule/user-tracepoint.cpp \ + event-rule/log4j-logging.cpp \ + event-rule/jul-logging.cpp \ + event-rule/python-logging.cpp \ + filter.cpp filter.h \ + fd-handle.cpp fd-handle.h \ + fs-handle.cpp fs-handle.h fs-handle-internal.h \ + futex.cpp futex.h \ + kernel-probe.cpp \ + index-allocator.cpp index-allocator.h \ + location.cpp \ + log-level-rule.cpp \ + mi-lttng.cpp mi-lttng.h \ + notification.cpp \ optional.h \ - payload.c payload.h \ - payload-view.c payload-view.h \ - pipe.c pipe.h \ - readwrite.c readwrite.h \ - runas.c runas.h \ - shm.c shm.h \ - session-descriptor.c \ - snapshot.c snapshot.h \ - spawn-viewer.c spawn-viewer.h \ - time.c \ - trace-chunk.c trace-chunk.h \ + payload.cpp payload.h \ + payload-view.cpp payload-view.h \ + pipe.cpp pipe.h \ + readwrite.cpp readwrite.h \ + runas.cpp runas.h \ + shm.cpp shm.h \ + session-descriptor.cpp \ + snapshot.cpp snapshot.h \ + spawn-viewer.cpp spawn-viewer.h \ + time.cpp \ + trace-chunk.cpp trace-chunk.h \ trace-chunk-registry.h \ - trigger.c \ - unix.c unix.h \ - uri.c uri.h \ - userspace-probe.c \ - utils.c utils.h \ - uuid.c uuid.h \ - thread.c thread.h \ - tracker.c tracker.h \ - waiter.c waiter.h + trigger.cpp \ + unix.cpp unix.h \ + uri.cpp uri.h \ + userspace-probe.cpp \ + utils.cpp utils.h \ + uuid.cpp uuid.h \ + thread.cpp thread.h \ + tracker.cpp tracker.h \ + waiter.cpp waiter.h if HAVE_ELF_H libcommon_la_SOURCES += \ - lttng-elf.c lttng-elf.h + lttng-elf.cpp lttng-elf.h endif libcommon_la_LIBADD = \ diff --git a/src/common/actions/action.c b/src/common/actions/action.cpp similarity index 98% rename from src/common/actions/action.c rename to src/common/actions/action.cpp index 21dee73fa..b71538b3f 100644 --- a/src/common/actions/action.c +++ b/src/common/actions/action.cpp @@ -164,7 +164,7 @@ ssize_t lttng_action_create_from_payload(struct lttng_payload_view *view, action_comm = (const struct lttng_action_comm *) action_comm_view.buffer.data; DBG("Create action from payload: action-type=%s", - lttng_action_type_string(action_comm->action_type)); + lttng_action_type_string((lttng_action_type) action_comm->action_type)); switch (action_comm->action_type) { case LTTNG_ACTION_TYPE_NOTIFY: @@ -193,7 +193,7 @@ ssize_t lttng_action_create_from_payload(struct lttng_payload_view *view, ERR("Failed to create action from payload, unhandled action type: action-type=%u (%s)", action_comm->action_type, lttng_action_type_string( - action_comm->action_type)); + (lttng_action_type) action_comm->action_type)); consumed_len = -1; goto end; } diff --git a/src/common/actions/list.c b/src/common/actions/list.cpp similarity index 97% rename from src/common/actions/list.c rename to src/common/actions/list.cpp index 86eabda8a..42d3d653e 100644 --- a/src/common/actions/list.c +++ b/src/common/actions/list.cpp @@ -71,7 +71,7 @@ static bool lttng_action_list_validate(struct lttng_action *action) for (i = 0; i < count; i++) { struct lttng_action *child = - lttng_dynamic_pointer_array_get_pointer( + (lttng_action *) lttng_dynamic_pointer_array_get_pointer( &action_list->actions, i); LTTNG_ASSERT(child); @@ -157,7 +157,7 @@ static int lttng_action_list_serialize( for (i = 0; i < count; i++) { struct lttng_action *child = - lttng_dynamic_pointer_array_get_pointer( + (lttng_action *) lttng_dynamic_pointer_array_get_pointer( &action_list->actions, i); LTTNG_ASSERT(child); @@ -362,7 +362,7 @@ struct lttng_action *lttng_action_list_create(void) struct lttng_action_list *action_list; struct lttng_action *action; - action_list = zmalloc(sizeof(struct lttng_action_list)); + action_list = (lttng_action_list *) zmalloc(sizeof(struct lttng_action_list)); if (!action_list) { action = NULL; goto end; @@ -464,7 +464,7 @@ struct lttng_action *lttng_action_list_borrow_mutable_at_index( } action_list = action_list_from_action_const(list); - action = lttng_dynamic_pointer_array_get_pointer(&action_list->actions, + action = (lttng_action *) lttng_dynamic_pointer_array_get_pointer(&action_list->actions, index); end: return action; diff --git a/src/common/actions/notify.c b/src/common/actions/notify.cpp similarity index 98% rename from src/common/actions/notify.c rename to src/common/actions/notify.cpp index c34f3845f..e3f837ade 100644 --- a/src/common/actions/notify.c +++ b/src/common/actions/notify.cpp @@ -132,7 +132,7 @@ struct lttng_action *lttng_action_notify_create(void) struct lttng_action_notify *notify = NULL; struct lttng_action *action = NULL; - notify = zmalloc(sizeof(struct lttng_action_notify)); + notify = (lttng_action_notify *) zmalloc(sizeof(struct lttng_action_notify)); if (!notify) { goto end; } diff --git a/src/common/actions/path.c b/src/common/actions/path.cpp similarity index 96% rename from src/common/actions/path.c rename to src/common/actions/path.cpp index 09cf08a48..816f2cd21 100644 --- a/src/common/actions/path.c +++ b/src/common/actions/path.cpp @@ -23,7 +23,7 @@ struct lttng_action_path *lttng_action_path_create( goto error; } - path = zmalloc(sizeof(*path)); + path = (lttng_action_path *) zmalloc(sizeof(*path)); if (!path) { goto error; } @@ -185,6 +185,7 @@ int lttng_action_path_serialize(const struct lttng_action_path *action_path, int ret; size_t index_count, i; enum lttng_action_path_status status; + lttng_action_path_comm comm; status = lttng_action_path_get_index_count(action_path, &index_count); if (status != LTTNG_ACTION_PATH_STATUS_OK) { @@ -192,10 +193,11 @@ int lttng_action_path_serialize(const struct lttng_action_path *action_path, goto end; } + comm = { + .index_count = (uint32_t) index_count, + }; ret = lttng_dynamic_buffer_append(&payload->buffer, - &((struct lttng_action_path_comm) { - .index_count = index_count - }), + &comm, sizeof(struct lttng_action_path_comm)); for (i = 0; i < index_count; i++) { diff --git a/src/common/actions/rate-policy.c b/src/common/actions/rate-policy.cpp similarity index 97% rename from src/common/actions/rate-policy.c rename to src/common/actions/rate-policy.cpp index c47e17018..d0834dd73 100644 --- a/src/common/actions/rate-policy.c +++ b/src/common/actions/rate-policy.cpp @@ -235,8 +235,8 @@ ssize_t lttng_rate_policy_create_from_payload(struct lttng_payload_view *view, rate_policy_create_from_payload_cb create_from_payload_cb; const struct lttng_rate_policy_comm *rate_policy_comm; const struct lttng_payload_view rate_policy_comm_view = - lttng_payload_view_from_view( - view, 0, sizeof(*rate_policy_comm)); + lttng_payload_view_from_view( + view, 0, sizeof(*rate_policy_comm)); if (!view || !rate_policy) { consumed_len = -1; @@ -253,8 +253,8 @@ ssize_t lttng_rate_policy_create_from_payload(struct lttng_payload_view *view, rate_policy_comm_view.buffer.data; DBG("Create rate_policy from payload: rate-policy-type=%s", - lttng_rate_policy_type_string( - rate_policy_comm->rate_policy_type)); + lttng_rate_policy_type_string( + (lttng_rate_policy_type) rate_policy_comm->rate_policy_type)); switch (rate_policy_comm->rate_policy_type) { case LTTNG_RATE_POLICY_TYPE_EVERY_N: @@ -269,7 +269,7 @@ ssize_t lttng_rate_policy_create_from_payload(struct lttng_payload_view *view, ERR("Failed to create rate-policy from payload, unhandled rate-policy type: rate-policy-type=%u (%s)", rate_policy_comm->rate_policy_type, lttng_rate_policy_type_string( - rate_policy_comm->rate_policy_type)); + (lttng_rate_policy_type) rate_policy_comm->rate_policy_type)); consumed_len = -1; goto end; } @@ -487,7 +487,7 @@ struct lttng_rate_policy *lttng_rate_policy_every_n_create(uint64_t interval) goto end; } - policy = zmalloc(sizeof(struct lttng_rate_policy_every_n)); + policy = (lttng_rate_policy_every_n *) zmalloc(sizeof(struct lttng_rate_policy_every_n)); if (!policy) { goto end; } @@ -702,7 +702,7 @@ struct lttng_rate_policy *lttng_rate_policy_once_after_n_create( goto end; } - policy = zmalloc(sizeof(struct lttng_rate_policy_once_after_n)); + policy = (lttng_rate_policy_once_after_n *) zmalloc(sizeof(struct lttng_rate_policy_once_after_n)); if (!policy) { goto end; } diff --git a/src/common/actions/rotate-session.c b/src/common/actions/rotate-session.cpp similarity index 99% rename from src/common/actions/rotate-session.c rename to src/common/actions/rotate-session.cpp index e519d45d8..985036acc 100644 --- a/src/common/actions/rotate-session.c +++ b/src/common/actions/rotate-session.cpp @@ -298,7 +298,7 @@ struct lttng_action *lttng_action_rotate_session_create(void) goto end; } - action = zmalloc(sizeof(struct lttng_action_rotate_session)); + action = (lttng_action *) zmalloc(sizeof(struct lttng_action_rotate_session)); if (!action) { goto end; } diff --git a/src/common/actions/snapshot-session.c b/src/common/actions/snapshot-session.cpp similarity index 99% rename from src/common/actions/snapshot-session.c rename to src/common/actions/snapshot-session.cpp index 26ddd1ba6..0f3da782f 100644 --- a/src/common/actions/snapshot-session.c +++ b/src/common/actions/snapshot-session.cpp @@ -455,7 +455,7 @@ struct lttng_action *lttng_action_snapshot_session_create(void) goto end; } - action = zmalloc(sizeof(struct lttng_action_snapshot_session)); + action = (lttng_action *) zmalloc(sizeof(struct lttng_action_snapshot_session)); if (!action) { goto end; } diff --git a/src/common/actions/start-session.c b/src/common/actions/start-session.cpp similarity index 99% rename from src/common/actions/start-session.c rename to src/common/actions/start-session.cpp index da7aad81f..1312e5ec5 100644 --- a/src/common/actions/start-session.c +++ b/src/common/actions/start-session.cpp @@ -301,7 +301,7 @@ struct lttng_action *lttng_action_start_session_create(void) goto end; } - action = zmalloc(sizeof(struct lttng_action_start_session)); + action = (lttng_action *) zmalloc(sizeof(struct lttng_action_start_session)); if (!action) { goto end; } diff --git a/src/common/actions/stop-session.c b/src/common/actions/stop-session.cpp similarity index 99% rename from src/common/actions/stop-session.c rename to src/common/actions/stop-session.cpp index fa2c77b13..55f1a55ed 100644 --- a/src/common/actions/stop-session.c +++ b/src/common/actions/stop-session.cpp @@ -301,7 +301,7 @@ struct lttng_action *lttng_action_stop_session_create(void) goto end; } - action = zmalloc(sizeof(struct lttng_action_stop_session)); + action = (lttng_action *) zmalloc(sizeof(struct lttng_action_stop_session)); if (!action) { goto end; } diff --git a/src/common/buffer-view.c b/src/common/buffer-view.cpp similarity index 99% rename from src/common/buffer-view.c rename to src/common/buffer-view.cpp index bfd5ac6d7..ebe686985 100644 --- a/src/common/buffer-view.c +++ b/src/common/buffer-view.cpp @@ -12,7 +12,7 @@ struct lttng_buffer_view lttng_buffer_view_init( const char *src, size_t offset, ptrdiff_t len) { - struct lttng_buffer_view view = { .data = src + offset, .size = len }; + struct lttng_buffer_view view = { .data = src + offset, .size = (size_t) len }; return view; } diff --git a/src/common/conditions/buffer-usage.c b/src/common/conditions/buffer-usage.cpp similarity index 99% rename from src/common/conditions/buffer-usage.c rename to src/common/conditions/buffer-usage.cpp index 714ba582c..fa28db65b 100644 --- a/src/common/conditions/buffer-usage.c +++ b/src/common/conditions/buffer-usage.cpp @@ -321,7 +321,7 @@ struct lttng_condition *lttng_condition_buffer_usage_create( { struct lttng_condition_buffer_usage *condition; - condition = zmalloc(sizeof(struct lttng_condition_buffer_usage)); + condition = (lttng_condition_buffer_usage *) zmalloc(sizeof(struct lttng_condition_buffer_usage)); if (!condition) { return NULL; } @@ -864,7 +864,7 @@ struct lttng_evaluation *lttng_evaluation_buffer_usage_create( { struct lttng_evaluation_buffer_usage *usage; - usage = zmalloc(sizeof(struct lttng_evaluation_buffer_usage)); + usage = (lttng_evaluation_buffer_usage *) zmalloc(sizeof(struct lttng_evaluation_buffer_usage)); if (!usage) { goto end; } diff --git a/src/common/conditions/condition.c b/src/common/conditions/condition.cpp similarity index 100% rename from src/common/conditions/condition.c rename to src/common/conditions/condition.cpp diff --git a/src/common/conditions/event-rule-matches.c b/src/common/conditions/event-rule-matches.cpp similarity index 98% rename from src/common/conditions/event-rule-matches.c rename to src/common/conditions/event-rule-matches.cpp index d91a2c3e7..3e7776f46 100644 --- a/src/common/conditions/event-rule-matches.c +++ b/src/common/conditions/event-rule-matches.cpp @@ -268,7 +268,7 @@ lttng_condition_event_rule_matches_get_internal_capture_descriptor_at_index( goto end; } - desc = lttng_dynamic_pointer_array_get_pointer( + desc = (lttng_capture_descriptor *) lttng_dynamic_pointer_array_get_pointer( &event_rule_matches_cond->capture_descriptors, index); end: return desc; @@ -518,7 +518,7 @@ struct lttng_condition *lttng_condition_event_rule_matches_create( goto end; } - condition = zmalloc(sizeof(struct lttng_condition_event_rule_matches)); + condition = (lttng_condition_event_rule_matches *) zmalloc(sizeof(struct lttng_condition_event_rule_matches)); if (!condition) { return NULL; } @@ -889,7 +889,7 @@ lttng_condition_event_rule_matches_append_capture_descriptor( goto end; } - descriptor = malloc(sizeof(*descriptor)); + descriptor = (lttng_capture_descriptor *) malloc(sizeof(*descriptor)); if (descriptor == NULL) { status = LTTNG_CONDITION_STATUS_ERROR; goto end; @@ -1385,7 +1385,7 @@ struct lttng_evaluation *lttng_evaluation_event_rule_matches_create( struct lttng_evaluation_event_rule_matches *hit; struct lttng_evaluation *evaluation = NULL; - hit = zmalloc(sizeof(struct lttng_evaluation_event_rule_matches)); + hit = (lttng_evaluation_event_rule_matches *) zmalloc(sizeof(struct lttng_evaluation_event_rule_matches)); if (!hit) { goto error; } @@ -1482,6 +1482,7 @@ lttng_condition_event_rule_matches_generate_capture_descriptor_bytecode( struct lttng_capture_descriptor *local_capture_desc = lttng_condition_event_rule_matches_get_internal_capture_descriptor_at_index( condition, i); + int bytecode_ret; if (local_capture_desc == NULL) { ret = LTTNG_ERR_FATAL; @@ -1489,10 +1490,10 @@ lttng_condition_event_rule_matches_generate_capture_descriptor_bytecode( } /* Generate the bytecode. */ - status = lttng_event_expr_to_bytecode( + bytecode_ret = lttng_event_expr_to_bytecode( local_capture_desc->event_expression, &local_capture_desc->bytecode); - if (status < 0 || local_capture_desc->bytecode == NULL) { + if (bytecode_ret < 0 || local_capture_desc->bytecode == NULL) { ret = LTTNG_ERR_INVALID_CAPTURE_EXPRESSION; goto end; } @@ -1532,7 +1533,7 @@ lttng_condition_event_rule_matches_get_capture_bytecode_at_index( goto end; } - desc = lttng_dynamic_pointer_array_get_pointer( + desc = (lttng_capture_descriptor *) lttng_dynamic_pointer_array_get_pointer( &event_rule_matches_cond->capture_descriptors, index); if (desc == NULL) { goto end; diff --git a/src/common/conditions/session-consumed-size.c b/src/common/conditions/session-consumed-size.cpp similarity index 98% rename from src/common/conditions/session-consumed-size.c rename to src/common/conditions/session-consumed-size.cpp index 2f95bd82a..86a7f332a 100644 --- a/src/common/conditions/session-consumed-size.c +++ b/src/common/conditions/session-consumed-size.cpp @@ -203,7 +203,7 @@ struct lttng_condition *lttng_condition_session_consumed_size_create(void) { struct lttng_condition_session_consumed_size *condition; - condition = zmalloc(sizeof(struct lttng_condition_session_consumed_size)); + condition = (lttng_condition_session_consumed_size *) zmalloc(sizeof(struct lttng_condition_session_consumed_size)); if (!condition) { return NULL; } @@ -484,7 +484,7 @@ struct lttng_evaluation *lttng_evaluation_session_consumed_size_create( { struct lttng_evaluation_session_consumed_size *consumed_eval; - consumed_eval = zmalloc(sizeof(struct lttng_evaluation_session_consumed_size)); + consumed_eval = (lttng_evaluation_session_consumed_size *) zmalloc(sizeof(struct lttng_evaluation_session_consumed_size)); if (!consumed_eval) { goto end; } diff --git a/src/common/conditions/session-rotation.c b/src/common/conditions/session-rotation.cpp similarity index 96% rename from src/common/conditions/session-rotation.c rename to src/common/conditions/session-rotation.cpp index d352718e1..7e59895f9 100644 --- a/src/common/conditions/session-rotation.c +++ b/src/common/conditions/session-rotation.cpp @@ -34,12 +34,13 @@ enum lttng_error_code lttng_condition_session_rotation_mi_serialize( static const struct lttng_condition rotation_condition_template = { - /* .type omitted; shall be set on creation. */ - .validate = lttng_condition_session_rotation_validate, - .serialize = lttng_condition_session_rotation_serialize, - .equal = lttng_condition_session_rotation_is_equal, - .destroy = lttng_condition_session_rotation_destroy, - .mi_serialize = lttng_condition_session_rotation_mi_serialize, + {}, + LTTNG_CONDITION_TYPE_UNKNOWN, /* type unset, shall be set on creation. */ + lttng_condition_session_rotation_validate, + lttng_condition_session_rotation_serialize, + lttng_condition_session_rotation_is_equal, + lttng_condition_session_rotation_destroy, + lttng_condition_session_rotation_mi_serialize, }; static @@ -52,9 +53,9 @@ void lttng_evaluation_session_rotation_destroy( static const struct lttng_evaluation rotation_evaluation_template = { - /* .type omitted; shall be set on creation. */ - .serialize = lttng_evaluation_session_rotation_serialize, - .destroy = lttng_evaluation_session_rotation_destroy, + LTTNG_CONDITION_TYPE_UNKNOWN, /* type unset, shall be set on creation. */ + lttng_evaluation_session_rotation_serialize, + lttng_evaluation_session_rotation_destroy, }; static @@ -184,7 +185,7 @@ struct lttng_condition *lttng_condition_session_rotation_create( { struct lttng_condition_session_rotation *condition; - condition = zmalloc(sizeof(struct lttng_condition_session_rotation)); + condition = (lttng_condition_session_rotation *) zmalloc(sizeof(struct lttng_condition_session_rotation)); if (!condition) { return NULL; } @@ -332,7 +333,7 @@ struct lttng_evaluation *lttng_evaluation_session_rotation_create( { struct lttng_evaluation_session_rotation *evaluation; - evaluation = zmalloc(sizeof(struct lttng_evaluation_session_rotation)); + evaluation = (lttng_evaluation_session_rotation *) zmalloc(sizeof(struct lttng_evaluation_session_rotation)); if (!evaluation) { return NULL; } diff --git a/src/common/context.c b/src/common/context.cpp similarity index 94% rename from src/common/context.c rename to src/common/context.cpp index e2e2b60d6..ab61a8133 100644 --- a/src/common/context.c +++ b/src/common/context.cpp @@ -52,7 +52,7 @@ int parse_application_context(const char *str, char **out_provider_name, } provider_name_len = colon_pos - sizeof(app_ctx_prefix) + 2; - provider_name = zmalloc(provider_name_len); + provider_name = (char *) zmalloc(provider_name_len); if (!provider_name) { PERROR("malloc provider_name"); goto not_found; @@ -61,7 +61,7 @@ int parse_application_context(const char *str, char **out_provider_name, provider_name_len - 1); ctx_name_len = len - colon_pos; - ctx_name = zmalloc(ctx_name_len); + ctx_name = (char *) zmalloc(ctx_name_len); if (!ctx_name) { PERROR("malloc ctx_name"); goto not_found; diff --git a/src/common/credentials.c b/src/common/credentials.cpp similarity index 100% rename from src/common/credentials.c rename to src/common/credentials.cpp diff --git a/src/common/daemonize.c b/src/common/daemonize.cpp similarity index 100% rename from src/common/daemonize.c rename to src/common/daemonize.cpp diff --git a/src/common/defaults.c b/src/common/defaults.cpp similarity index 87% rename from src/common/defaults.c rename to src/common/defaults.cpp index 2550784cf..5ecb435bb 100644 --- a/src/common/defaults.c +++ b/src/common/defaults.cpp @@ -11,6 +11,7 @@ #include #include #include +#include #include "defaults.h" #include "macros.h" @@ -36,27 +37,27 @@ static size_t get_page_size(void) size_t default_get_channel_subbuf_size(void) { - return max(_DEFAULT_CHANNEL_SUBBUF_SIZE, get_page_size()); + return std::max(_DEFAULT_CHANNEL_SUBBUF_SIZE, get_page_size()); } size_t default_get_metadata_subbuf_size(void) { - return max(DEFAULT_METADATA_SUBBUF_SIZE, get_page_size()); + return std::max(DEFAULT_METADATA_SUBBUF_SIZE, get_page_size()); } size_t default_get_kernel_channel_subbuf_size(void) { - return max(DEFAULT_KERNEL_CHANNEL_SUBBUF_SIZE, get_page_size()); + return std::max(DEFAULT_KERNEL_CHANNEL_SUBBUF_SIZE, get_page_size()); } size_t default_get_ust_pid_channel_subbuf_size(void) { - return max(DEFAULT_UST_PID_CHANNEL_SUBBUF_SIZE, get_page_size()); + return std::max(DEFAULT_UST_PID_CHANNEL_SUBBUF_SIZE, get_page_size()); } size_t default_get_ust_uid_channel_subbuf_size(void) { - return max(DEFAULT_UST_UID_CHANNEL_SUBBUF_SIZE, get_page_size()); + return std::max(DEFAULT_UST_UID_CHANNEL_SUBBUF_SIZE, get_page_size()); } pthread_attr_t *default_pthread_attr(void) @@ -108,7 +109,7 @@ static void __attribute__((constructor)) init_default_pthread_attr(void) } DBG("Default pthread stack size is %zu bytes", pthread_ss); - selected_ss = max_t(size_t, pthread_ss, system_ss); + selected_ss = std::max(pthread_ss, system_ss); if (selected_ss < DEFAULT_LTTNG_THREAD_STACK_SIZE) { DBG("Default stack size is too small, setting it to %zu bytes", (size_t) DEFAULT_LTTNG_THREAD_STACK_SIZE); diff --git a/src/common/domain.c b/src/common/domain.cpp similarity index 100% rename from src/common/domain.c rename to src/common/domain.cpp diff --git a/src/common/dynamic-array.c b/src/common/dynamic-array.cpp similarity index 100% rename from src/common/dynamic-array.c rename to src/common/dynamic-array.cpp diff --git a/src/common/dynamic-buffer.c b/src/common/dynamic-buffer.cpp similarity index 99% rename from src/common/dynamic-buffer.c rename to src/common/dynamic-buffer.cpp index d6ad6740f..945434ca9 100644 --- a/src/common/dynamic-buffer.c +++ b/src/common/dynamic-buffer.cpp @@ -162,7 +162,7 @@ int lttng_dynamic_buffer_set_capacity(struct lttng_dynamic_buffer *buffer, goto end; } - buffer->data = new_buf; + buffer->data = (char *) new_buf; buffer->_capacity = new_capacity; end: return ret; diff --git a/src/common/endpoint.c b/src/common/endpoint.cpp similarity index 100% rename from src/common/endpoint.c rename to src/common/endpoint.cpp diff --git a/src/common/error-query.c b/src/common/error-query.cpp similarity index 98% rename from src/common/error-query.c rename to src/common/error-query.cpp index d6bca73b7..5d369c9e0 100644 --- a/src/common/error-query.c +++ b/src/common/error-query.cpp @@ -111,7 +111,7 @@ struct lttng_error_query *lttng_error_query_trigger_create( goto end; } - query = zmalloc(sizeof(*query)); + query = (lttng_error_query_trigger *) zmalloc(sizeof(*query)); if (!query) { PERROR("Failed to allocate trigger error query"); goto error; @@ -142,7 +142,7 @@ struct lttng_error_query *lttng_error_query_condition_create( goto end; } - query = zmalloc(sizeof(*query)); + query = (lttng_error_query_condition *) zmalloc(sizeof(*query)); if (!query) { PERROR("Failed to allocate condition error query"); goto error; @@ -221,7 +221,7 @@ struct lttng_error_query *lttng_error_query_action_create( goto end; } - query = zmalloc(sizeof(*query)); + query = (lttng_error_query_action *) zmalloc(sizeof(*query)); if (!query) { PERROR("Failed to allocate action error query"); goto error; @@ -267,10 +267,12 @@ int lttng_error_query_result_counter_serialize( LTTNG_ASSERT(result->type == LTTNG_ERROR_QUERY_RESULT_TYPE_COUNTER); counter_result = container_of(result, typeof(*counter_result), parent); + lttng_error_query_result_counter_comm comm = { + .value = counter_result->value, + }; + return lttng_dynamic_buffer_append(&payload->buffer, - &(struct lttng_error_query_result_counter_comm) { - .value = counter_result->value - }, + &comm, sizeof(struct lttng_error_query_result_counter_comm)); } @@ -386,7 +388,7 @@ lttng_error_query_result_counter_create( int init_ret; struct lttng_error_query_result_counter *counter; - counter = zmalloc(sizeof(*counter)); + counter = (lttng_error_query_result_counter *) zmalloc(sizeof(*counter)); if (!counter) { PERROR("Failed to allocate error query counter result"); goto end; @@ -417,7 +419,7 @@ void destroy_result(void *ptr) struct lttng_error_query_results *lttng_error_query_results_create(void) { - struct lttng_error_query_results *set = zmalloc(sizeof(*set)); + struct lttng_error_query_results *set = (lttng_error_query_results *) zmalloc(sizeof(*set)); if (!set) { PERROR("Failed to allocate an error query result set"); diff --git a/src/common/error.c b/src/common/error.c deleted file mode 100644 index b888c2643..000000000 --- a/src/common/error.c +++ /dev/null @@ -1,283 +0,0 @@ -/* - * Copyright (C) 2012 David Goulet - * - * SPDX-License-Identifier: GPL-2.0-only - * - */ - -#define _LGPL_SOURCE -#include -#include -#include -#include - -#include -#include -#include -#include -#include - -#include "error.h" - -#define ERROR_INDEX(code) (code - LTTNG_OK) - -/* - * lttng_opt_abort_on_error: unset: -1, disabled: 0, enabled: 1. - * Controlled by the LTTNG_ABORT_ON_ERROR environment variable. - */ -static int lttng_opt_abort_on_error = -1; - -/* TLS variable that contains the time of one single log entry. */ -DEFINE_URCU_TLS(struct log_time, error_log_time); -DEFINE_URCU_TLS(const char *, logger_thread_name); - -const char *log_add_time(void) -{ - int ret; - struct tm tm, *res; - struct timespec tp; - time_t now; - const int errsv = errno; - - ret = lttng_clock_gettime(CLOCK_REALTIME, &tp); - if (ret < 0) { - goto error; - } - now = (time_t) tp.tv_sec; - - res = localtime_r(&now, &tm); - if (!res) { - goto error; - } - - /* Format time in the TLS variable. */ - ret = snprintf(URCU_TLS(error_log_time).str, sizeof(URCU_TLS(error_log_time).str), - "%02d:%02d:%02d.%09ld", - tm.tm_hour, tm.tm_min, tm.tm_sec, tp.tv_nsec); - if (ret < 0) { - goto error; - } - - errno = errsv; - return URCU_TLS(error_log_time).str; - -error: - /* Return an empty string on error so logging is not affected. */ - errno = errsv; - return ""; -} - -void logger_set_thread_name(const char *name, bool set_pthread_name) -{ - int ret; - - LTTNG_ASSERT(name); - URCU_TLS(logger_thread_name) = name; - - if (set_pthread_name) { - ret = lttng_thread_setname(name); - if (ret && ret != -ENOSYS) { - /* Don't fail as this is not essential. */ - DBG("Failed to set pthread name attribute"); - } - } -} - -/* - * Human readable error message. - */ -static const char *error_string_array[] = { - /* LTTNG_OK code MUST be at the top for the ERROR_INDEX macro to work */ - [ ERROR_INDEX(LTTNG_OK) ] = "Success", - [ ERROR_INDEX(LTTNG_ERR_UNK) ] = "Unknown error", - [ ERROR_INDEX(LTTNG_ERR_UND) ] = "Undefined command", - [ ERROR_INDEX(LTTNG_ERR_UNKNOWN_DOMAIN) ] = "Unknown tracing domain", - [ ERROR_INDEX(LTTNG_ERR_NO_SESSION) ] = "No session found", - [ ERROR_INDEX(LTTNG_ERR_CREATE_DIR_FAIL) ] = "Create directory failed", - [ ERROR_INDEX(LTTNG_ERR_SESSION_FAIL) ] = "Create session failed", - [ ERROR_INDEX(LTTNG_ERR_SESS_NOT_FOUND) ] = "Session name not found", - [ ERROR_INDEX(LTTNG_ERR_FATAL) ] = "Fatal error of the session daemon", - [ ERROR_INDEX(LTTNG_ERR_SELECT_SESS) ] = "A session MUST be selected", - [ ERROR_INDEX(LTTNG_ERR_EXIST_SESS) ] = "Session name already exists", - [ ERROR_INDEX(LTTNG_ERR_NO_EVENT) ] = "Event not found", - [ ERROR_INDEX(LTTNG_ERR_CONNECT_FAIL) ] = "Unable to connect to Unix socket", - [ ERROR_INDEX(LTTNG_ERR_EPERM) ] = "Permission denied", - [ ERROR_INDEX(LTTNG_ERR_KERN_NA) ] = "Kernel tracer not available", - [ ERROR_INDEX(LTTNG_ERR_KERN_VERSION) ] = "Kernel tracer version is not compatible", - [ ERROR_INDEX(LTTNG_ERR_KERN_EVENT_EXIST) ] = "Kernel event already exists", - [ ERROR_INDEX(LTTNG_ERR_KERN_SESS_FAIL) ] = "Kernel create session failed", - [ ERROR_INDEX(LTTNG_ERR_KERN_CHAN_EXIST) ] = "Kernel channel already exists", - [ ERROR_INDEX(LTTNG_ERR_KERN_CHAN_FAIL) ] = "Kernel create channel failed", - [ ERROR_INDEX(LTTNG_ERR_KERN_CHAN_NOT_FOUND) ] = "Kernel channel not found", - [ ERROR_INDEX(LTTNG_ERR_KERN_CHAN_DISABLE_FAIL) ] = "Disable kernel channel failed", - [ ERROR_INDEX(LTTNG_ERR_KERN_CHAN_ENABLE_FAIL) ] = "Enable kernel channel failed", - [ ERROR_INDEX(LTTNG_ERR_KERN_CONTEXT_FAIL) ] = "Add kernel context failed", - [ ERROR_INDEX(LTTNG_ERR_KERN_ENABLE_FAIL) ] = "Enable kernel event failed", - [ ERROR_INDEX(LTTNG_ERR_KERN_DISABLE_FAIL) ] = "Disable kernel event failed", - [ ERROR_INDEX(LTTNG_ERR_KERN_META_FAIL) ] = "Opening metadata failed", - [ ERROR_INDEX(LTTNG_ERR_KERN_START_FAIL) ] = "Starting kernel trace failed", - [ ERROR_INDEX(LTTNG_ERR_KERN_STOP_FAIL) ] = "Stopping kernel trace failed", - [ ERROR_INDEX(LTTNG_ERR_KERN_CONSUMER_FAIL) ] = "Kernel consumer start failed", - [ ERROR_INDEX(LTTNG_ERR_KERN_STREAM_FAIL) ] = "Kernel create stream failed", - [ ERROR_INDEX(LTTNG_ERR_KERN_LIST_FAIL) ] = "Listing kernel events failed", - [ ERROR_INDEX(LTTNG_ERR_UST_CALIBRATE_FAIL) ] = "UST calibration failed", - [ ERROR_INDEX(LTTNG_ERR_UST_SESS_FAIL) ] = "UST create session failed", - [ ERROR_INDEX(LTTNG_ERR_UST_CHAN_FAIL) ] = "UST create channel failed", - [ ERROR_INDEX(LTTNG_ERR_UST_CHAN_EXIST) ] = "UST channel already exist", - [ ERROR_INDEX(LTTNG_ERR_UST_CHAN_NOT_FOUND) ] = "UST channel not found", - [ ERROR_INDEX(LTTNG_ERR_UST_CHAN_DISABLE_FAIL) ] = "Disable UST channel failed", - [ ERROR_INDEX(LTTNG_ERR_UST_CHAN_ENABLE_FAIL) ] = "Enable UST channel failed", - [ ERROR_INDEX(LTTNG_ERR_UST_ENABLE_FAIL) ] = "Enable UST event failed", - [ ERROR_INDEX(LTTNG_ERR_UST_DISABLE_FAIL) ] = "Disable UST event failed", - [ ERROR_INDEX(LTTNG_ERR_UST_META_FAIL) ] = "Opening metadata failed", - [ ERROR_INDEX(LTTNG_ERR_UST_START_FAIL) ] = "Starting UST trace failed", - [ ERROR_INDEX(LTTNG_ERR_UST_STOP_FAIL) ] = "Stopping UST trace failed", - [ ERROR_INDEX(LTTNG_ERR_UST_CONSUMER64_FAIL) ] = "64-bit UST consumer start failed", - [ ERROR_INDEX(LTTNG_ERR_UST_CONSUMER32_FAIL) ] = "32-bit UST consumer start failed", - [ ERROR_INDEX(LTTNG_ERR_UST_STREAM_FAIL) ] = "UST create stream failed", - [ ERROR_INDEX(LTTNG_ERR_UST_LIST_FAIL) ] = "Listing UST events failed", - [ ERROR_INDEX(LTTNG_ERR_UST_EVENT_EXIST) ] = "UST event already exist", - [ ERROR_INDEX(LTTNG_ERR_UST_EVENT_NOT_FOUND)] = "UST event not found", - [ ERROR_INDEX(LTTNG_ERR_UST_CONTEXT_EXIST)] = "UST context already exist", - [ ERROR_INDEX(LTTNG_ERR_UST_CONTEXT_INVAL)] = "UST invalid context", - [ ERROR_INDEX(LTTNG_ERR_NEED_ROOT_SESSIOND) ] = "Tracing the kernel requires a root lttng-sessiond daemon, as well as \"tracing\" group membership or root user ID for the lttng client", - [ ERROR_INDEX(LTTNG_ERR_NO_UST) ] = "LTTng-UST tracer is not supported. Please rebuild lttng-tools with lttng-ust support enabled", - [ ERROR_INDEX(LTTNG_ERR_TRACE_ALREADY_STARTED) ] = "Tracing has already been started once", - [ ERROR_INDEX(LTTNG_ERR_TRACE_ALREADY_STOPPED) ] = "Tracing has already been stopped", - [ ERROR_INDEX(LTTNG_ERR_KERN_EVENT_ENOSYS) ] = "Kernel event type not supported", - [ ERROR_INDEX(LTTNG_ERR_NEED_CHANNEL_NAME) ] = "Non-default channel exists within session: channel name needs to be specified with '-c name'", - [ ERROR_INDEX(LTTNG_ERR_INVALID) ] = "Invalid parameter", - [ ERROR_INDEX(LTTNG_ERR_NO_USTCONSUMERD) ] = "No UST consumer detected", - [ ERROR_INDEX(LTTNG_ERR_NO_KERNCONSUMERD) ] = "No kernel consumer detected", - [ ERROR_INDEX(LTTNG_ERR_EVENT_EXIST_LOGLEVEL) ] = "Event already enabled with different loglevel", - [ ERROR_INDEX(LTTNG_ERR_URL_DATA_MISS) ] = "Missing data path URL", - [ ERROR_INDEX(LTTNG_ERR_URL_CTRL_MISS) ] = "Missing control path URL", - [ ERROR_INDEX(LTTNG_ERR_ENABLE_CONSUMER_FAIL) ] = "Enabling consumer failed", - [ ERROR_INDEX(LTTNG_ERR_RELAYD_CONNECT_FAIL) ] = "Unable to connect to lttng-relayd", - [ ERROR_INDEX(LTTNG_ERR_RELAYD_VERSION_FAIL) ] = "Relay daemon not compatible", - [ ERROR_INDEX(LTTNG_ERR_FILTER_INVAL) ] = "Invalid filter bytecode", - [ ERROR_INDEX(LTTNG_ERR_FILTER_NOMEM) ] = "Not enough memory for filter bytecode", - [ ERROR_INDEX(LTTNG_ERR_FILTER_EXIST) ] = "Filter already exist", - [ ERROR_INDEX(LTTNG_ERR_NO_CONSUMER) ] = "Consumer not found for recording session", - [ ERROR_INDEX(LTTNG_ERR_NO_SESSIOND) ] = "No session daemon is available", - [ ERROR_INDEX(LTTNG_ERR_SESSION_STARTED) ] = "Session is running", - [ ERROR_INDEX(LTTNG_ERR_NOT_SUPPORTED) ] = "Operation not supported", - [ ERROR_INDEX(LTTNG_ERR_UST_EVENT_ENABLED) ] = "UST event already enabled", - [ ERROR_INDEX(LTTNG_ERR_SET_URL) ] = "Error setting URL", - [ ERROR_INDEX(LTTNG_ERR_URL_EXIST) ] = "URL already exists", - [ ERROR_INDEX(LTTNG_ERR_BUFFER_NOT_SUPPORTED)] = "Buffer type not supported", - [ ERROR_INDEX(LTTNG_ERR_BUFFER_TYPE_MISMATCH)] = "Buffer type mismatch for session", - [ ERROR_INDEX(LTTNG_ERR_NOMEM)] = "Not enough memory", - [ ERROR_INDEX(LTTNG_ERR_SNAPSHOT_OUTPUT_EXIST) ] = "Snapshot output already exists", - [ ERROR_INDEX(LTTNG_ERR_START_SESSION_ONCE) ] = "Session needs to be started once", - [ ERROR_INDEX(LTTNG_ERR_SNAPSHOT_FAIL) ] = "Snapshot record failed", - [ ERROR_INDEX(LTTNG_ERR_CHAN_EXIST) ] = "Channel already exists", - [ ERROR_INDEX(LTTNG_ERR_SNAPSHOT_NODATA) ] = "No data available in snapshot", - [ ERROR_INDEX(LTTNG_ERR_NO_CHANNEL) ] = "No channel found in the session", - [ ERROR_INDEX(LTTNG_ERR_SESSION_INVALID_CHAR) ] = "Invalid character found in session name", - [ ERROR_INDEX(LTTNG_ERR_SAVE_FILE_EXIST) ] = "Session file already exists", - [ ERROR_INDEX(LTTNG_ERR_SAVE_IO_FAIL) ] = "IO error while writing session configuration", - [ ERROR_INDEX(LTTNG_ERR_LOAD_INVALID_CONFIG) ] = "Invalid session configuration", - [ ERROR_INDEX(LTTNG_ERR_LOAD_IO_FAIL) ] = "IO error while reading a session configuration", - [ ERROR_INDEX(LTTNG_ERR_LOAD_SESSION_NOENT) ] = "Session file not found", - [ ERROR_INDEX(LTTNG_ERR_MAX_SIZE_INVALID) ] = "Snapshot max size is invalid", - [ ERROR_INDEX(LTTNG_ERR_MI_OUTPUT_TYPE) ] = "Invalid MI output format", - [ ERROR_INDEX(LTTNG_ERR_MI_IO_FAIL) ] = "IO error while writing MI output", - [ ERROR_INDEX(LTTNG_ERR_MI_NOT_IMPLEMENTED) ] = "Mi feature not implemented", - [ ERROR_INDEX(LTTNG_ERR_INVALID_EVENT_NAME) ] = "Invalid event name", - [ ERROR_INDEX(LTTNG_ERR_INVALID_CHANNEL_NAME) ] = "Invalid channel name", - [ ERROR_INDEX(LTTNG_ERR_PROCESS_ATTR_EXISTS) ] = "Process attribute is already tracked", - [ ERROR_INDEX(LTTNG_ERR_PROCESS_ATTR_MISSING) ] = "Process attribute was not tracked", - [ ERROR_INDEX(LTTNG_ERR_INVALID_CHANNEL_DOMAIN) ] = "Invalid channel domain", - [ ERROR_INDEX(LTTNG_ERR_OVERFLOW) ] = "Overflow occurred", - [ ERROR_INDEX(LTTNG_ERR_SESSION_NOT_STARTED) ] = "Session not started", - [ ERROR_INDEX(LTTNG_ERR_LIVE_SESSION) ] = "Live sessions are not supported", - [ ERROR_INDEX(LTTNG_ERR_PER_PID_SESSION) ] = "Per-PID recording sessions are not supported", - [ ERROR_INDEX(LTTNG_ERR_KERN_CONTEXT_UNAVAILABLE) ] = "Context unavailable on this kernel", - [ ERROR_INDEX(LTTNG_ERR_REGEN_STATEDUMP_FAIL) ] = "Failed to regenerate the state dump", - [ ERROR_INDEX(LTTNG_ERR_REGEN_STATEDUMP_NOMEM) ] = "Failed to regenerate the state dump, not enough memory", - [ ERROR_INDEX(LTTNG_ERR_NOT_SNAPSHOT_SESSION) ] = "Snapshot command can't be applied to a non-snapshot session", - [ ERROR_INDEX(LTTNG_ERR_INVALID_TRIGGER) ] = "Invalid trigger", - [ ERROR_INDEX(LTTNG_ERR_TRIGGER_EXISTS) ] = "Trigger already registered", - [ ERROR_INDEX(LTTNG_ERR_TRIGGER_NOT_FOUND) ] = "Trigger not found", - [ ERROR_INDEX(LTTNG_ERR_COMMAND_CANCELLED) ] = "Command cancelled", - [ ERROR_INDEX(LTTNG_ERR_ROTATION_PENDING) ] = "Rotation already pending for this session", - [ ERROR_INDEX(LTTNG_ERR_ROTATION_NOT_AVAILABLE) ] = "Rotation feature not available for this session's creation mode", - [ ERROR_INDEX(LTTNG_ERR_ROTATION_SCHEDULE_SET) ] = "A session rotation schedule of this type is already set on the session", - [ ERROR_INDEX(LTTNG_ERR_ROTATION_SCHEDULE_NOT_SET) ] = "No session rotation schedule of this type is set on the session", - [ ERROR_INDEX(LTTNG_ERR_ROTATION_MULTIPLE_AFTER_STOP) ] = "Session was already rotated once since it became inactive", - [ ERROR_INDEX(LTTNG_ERR_ROTATION_WRONG_VERSION) ] = "Session rotation is not supported by this kernel tracer version", - [ ERROR_INDEX(LTTNG_ERR_NO_SESSION_OUTPUT) ] = "Session has no output", - [ ERROR_INDEX(LTTNG_ERR_ROTATION_NOT_AVAILABLE_RELAY) ] = "Rotation feature not available on the relay", - [ ERROR_INDEX(LTTNG_ERR_AGENT_TRACING_DISABLED) ] = "Session daemon agent tracing is disabled", - [ ERROR_INDEX(LTTNG_ERR_PROBE_LOCATION_INVAL) ] = "Invalid userspace probe location", - [ ERROR_INDEX(LTTNG_ERR_ELF_PARSING) ] = "ELF parsing error", - [ ERROR_INDEX(LTTNG_ERR_SDT_PROBE_SEMAPHORE) ] = "SDT probe guarded by a semaphore", - [ ERROR_INDEX(LTTNG_ERR_ROTATION_FAIL_CONSUMER) ] = "Rotation failure on consumer", - [ ERROR_INDEX(LTTNG_ERR_ROTATE_RENAME_FAIL_CONSUMER) ] = "Rotation rename failure on consumer", - [ ERROR_INDEX(LTTNG_ERR_ROTATION_PENDING_LOCAL_FAIL_CONSUMER) ] = "Rotation pending check (local) failure on consumer", - [ ERROR_INDEX(LTTNG_ERR_ROTATION_PENDING_RELAY_FAIL_CONSUMER) ] = "Rotation pending check (relay) failure on consumer", - [ ERROR_INDEX(LTTNG_ERR_MKDIR_FAIL_CONSUMER) ] = "Directory creation failure on consumer", - [ ERROR_INDEX(LTTNG_ERR_CHAN_NOT_FOUND) ] = "Channel not found", - [ ERROR_INDEX(LTTNG_ERR_SNAPSHOT_UNSUPPORTED) ] = "Session configuration does not allow the use of snapshots", - [ ERROR_INDEX(LTTNG_ERR_SESSION_NOT_EXIST) ] = "Recording session does not exist", - [ ERROR_INDEX(LTTNG_ERR_CREATE_TRACE_CHUNK_FAIL_CONSUMER) ] = "Trace chunk creation failed on consumer", - [ ERROR_INDEX(LTTNG_ERR_CLOSE_TRACE_CHUNK_FAIL_CONSUMER) ] = "Trace chunk close failed on consumer", - [ ERROR_INDEX(LTTNG_ERR_TRACE_CHUNK_EXISTS_FAIL_CONSUMER) ] = "Failed to query consumer for trace chunk existence", - [ ERROR_INDEX(LTTNG_ERR_INVALID_PROTOCOL) ] = "Protocol error occurred", - [ ERROR_INDEX(LTTNG_ERR_FILE_CREATION_ERROR) ] = "Failed to create file", - [ ERROR_INDEX(LTTNG_ERR_TIMER_STOP_ERROR) ] = "Failed to stop a timer", - [ ERROR_INDEX(LTTNG_ERR_ROTATION_NOT_AVAILABLE_KERNEL) ] = "Rotation feature not supported by the kernel tracer", - [ ERROR_INDEX(LTTNG_ERR_CLEAR_RELAY_DISALLOWED) ] = "Relayd daemon peer does not allow sessions to be cleared", - [ ERROR_INDEX(LTTNG_ERR_CLEAR_NOT_AVAILABLE_RELAY) ] = "Clearing a session is not supported by the relay daemon", - [ ERROR_INDEX(LTTNG_ERR_CLEAR_FAIL_CONSUMER) ] = "Consumer failed to clear the session", - [ ERROR_INDEX(LTTNG_ERR_ROTATION_AFTER_STOP_CLEAR) ] = "Session was already cleared since it became inactive", - [ ERROR_INDEX(LTTNG_ERR_USER_NOT_FOUND) ] = "User not found", - [ ERROR_INDEX(LTTNG_ERR_GROUP_NOT_FOUND) ] = "Group not found", - [ ERROR_INDEX(LTTNG_ERR_UNSUPPORTED_DOMAIN) ] = "Unsupported domain used", - [ ERROR_INDEX(LTTNG_ERR_PROCESS_ATTR_TRACKER_INVALID_TRACKING_POLICY) ] = "Operation does not apply to the process attribute tracker's tracking policy", - [ ERROR_INDEX(LTTNG_ERR_EVENT_NOTIFIER_GROUP_NOTIFICATION_FD) ] = "Failed to create an event notifier group notification file descriptor", - [ ERROR_INDEX(LTTNG_ERR_INVALID_CAPTURE_EXPRESSION) ] = "Invalid capture expression", - [ ERROR_INDEX(LTTNG_ERR_EVENT_NOTIFIER_REGISTRATION) ] = "Failed to create event notifier", - [ ERROR_INDEX(LTTNG_ERR_EVENT_NOTIFIER_ERROR_ACCOUNTING) ] = "Failed to initialize event notifier error accounting", - [ ERROR_INDEX(LTTNG_ERR_EVENT_NOTIFIER_ERROR_ACCOUNTING_FULL) ] = "No index available in event notifier error accounting", - [ ERROR_INDEX(LTTNG_ERR_BUFFER_FLUSH_FAILED) ] = "Failed to flush stream buffer", - - /* Last element */ - [ ERROR_INDEX(LTTNG_ERR_NR) ] = "Unknown error code" -}; - -/* - * Return ptr to string representing a human readable error code from the - * lttng_error_code enum. - * - * These code MUST be negative in other to treat that as an error value. - */ -const char *error_get_str(int32_t code) -{ - code = -code; - - if (code < LTTNG_OK || code > LTTNG_ERR_NR) { - code = LTTNG_ERR_NR; - } - - return error_string_array[ERROR_INDEX(code)]; -} - -void lttng_abort_on_error(void) -{ - if (lttng_opt_abort_on_error < 0) { - /* Use lttng_secure_getenv() to query its state. */ - const char *value; - - value = lttng_secure_getenv("LTTNG_ABORT_ON_ERROR"); - if (value && !strcmp(value, "1")) { - lttng_opt_abort_on_error = 1; - } else { - lttng_opt_abort_on_error = 0; - } - } - if (lttng_opt_abort_on_error > 0) { - abort(); - } -} diff --git a/src/common/error.cpp b/src/common/error.cpp new file mode 100644 index 000000000..6ca5557f4 --- /dev/null +++ b/src/common/error.cpp @@ -0,0 +1,447 @@ +/* + * Copyright (C) 2012 David Goulet + * + * SPDX-License-Identifier: GPL-2.0-only + * + */ + +#define _LGPL_SOURCE +#include +#include +#include +#include + +#include +#include +#include +#include +#include + +#include "error.h" + +/* + * lttng_opt_abort_on_error: unset: -1, disabled: 0, enabled: 1. + * Controlled by the LTTNG_ABORT_ON_ERROR environment variable. + */ +static int lttng_opt_abort_on_error = -1; + +/* TLS variable that contains the time of one single log entry. */ +DEFINE_URCU_TLS(struct log_time, error_log_time); +DEFINE_URCU_TLS(const char *, logger_thread_name); + +const char *log_add_time(void) +{ + int ret; + struct tm tm, *res; + struct timespec tp; + time_t now; + const int errsv = errno; + + ret = lttng_clock_gettime(CLOCK_REALTIME, &tp); + if (ret < 0) { + goto error; + } + now = (time_t) tp.tv_sec; + + res = localtime_r(&now, &tm); + if (!res) { + goto error; + } + + /* Format time in the TLS variable. */ + ret = snprintf(URCU_TLS(error_log_time).str, sizeof(URCU_TLS(error_log_time).str), + "%02d:%02d:%02d.%09ld", + tm.tm_hour, tm.tm_min, tm.tm_sec, tp.tv_nsec); + if (ret < 0) { + goto error; + } + + errno = errsv; + return URCU_TLS(error_log_time).str; + +error: + /* Return an empty string on error so logging is not affected. */ + errno = errsv; + return ""; +} + +void logger_set_thread_name(const char *name, bool set_pthread_name) +{ + int ret; + + LTTNG_ASSERT(name); + URCU_TLS(logger_thread_name) = name; + + if (set_pthread_name) { + ret = lttng_thread_setname(name); + if (ret && ret != -ENOSYS) { + /* Don't fail as this is not essential. */ + DBG("Failed to set pthread name attribute"); + } + } +} + +/* + * Human readable error message. + */ +static +const char *lttng_error_code_str(lttng_error_code code) +{ + switch (code) { + case LTTNG_OK: + return "Success"; + case LTTNG_ERR_UNK: + return "Unknown error"; + case LTTNG_ERR_UND: + return "Undefined command"; + case LTTNG_ERR_UNKNOWN_DOMAIN: + return "Unknown tracing domain"; + case LTTNG_ERR_NO_SESSION: + return "No session found"; + case LTTNG_ERR_CREATE_DIR_FAIL: + return "Create directory failed"; + case LTTNG_ERR_SESSION_FAIL: + return "Create session failed"; + case LTTNG_ERR_SESS_NOT_FOUND: + return "Session name not found"; + case LTTNG_ERR_FATAL: + return "Fatal error of the session daemon"; + case LTTNG_ERR_SELECT_SESS: + return "A session MUST be selected"; + case LTTNG_ERR_EXIST_SESS: + return "Session name already exists"; + case LTTNG_ERR_NO_EVENT: + return "Event not found"; + case LTTNG_ERR_CONNECT_FAIL: + return "Unable to connect to Unix socket"; + case LTTNG_ERR_EPERM: + return "Permission denied"; + case LTTNG_ERR_KERN_NA: + return "Kernel tracer not available"; + case LTTNG_ERR_KERN_VERSION: + return "Kernel tracer version is not compatible"; + case LTTNG_ERR_KERN_EVENT_EXIST: + return "Kernel event already exists"; + case LTTNG_ERR_KERN_SESS_FAIL: + return "Kernel create session failed"; + case LTTNG_ERR_KERN_CHAN_EXIST: + return "Kernel channel already exists"; + case LTTNG_ERR_KERN_CHAN_FAIL: + return "Kernel create channel failed"; + case LTTNG_ERR_KERN_CHAN_NOT_FOUND: + return "Kernel channel not found"; + case LTTNG_ERR_KERN_CHAN_DISABLE_FAIL: + return "Disable kernel channel failed"; + case LTTNG_ERR_KERN_CHAN_ENABLE_FAIL: + return "Enable kernel channel failed"; + case LTTNG_ERR_KERN_CONTEXT_FAIL: + return "Add kernel context failed"; + case LTTNG_ERR_KERN_ENABLE_FAIL: + return "Enable kernel event failed"; + case LTTNG_ERR_KERN_DISABLE_FAIL: + return "Disable kernel event failed"; + case LTTNG_ERR_KERN_META_FAIL: + return "Opening metadata failed"; + case LTTNG_ERR_KERN_START_FAIL: + return "Starting kernel trace failed"; + case LTTNG_ERR_KERN_STOP_FAIL: + return "Stopping kernel trace failed"; + case LTTNG_ERR_KERN_CONSUMER_FAIL: + return "Kernel consumer start failed"; + case LTTNG_ERR_KERN_STREAM_FAIL: + return "Kernel create stream failed"; + case LTTNG_ERR_KERN_LIST_FAIL: + return "Listing kernel events failed"; + case LTTNG_ERR_UST_CALIBRATE_FAIL: + return "UST calibration failed"; + case LTTNG_ERR_UST_SESS_FAIL: + return "UST create session failed"; + case LTTNG_ERR_UST_CHAN_FAIL: + return "UST create channel failed"; + case LTTNG_ERR_UST_CHAN_EXIST: + return "UST channel already exist"; + case LTTNG_ERR_UST_CHAN_NOT_FOUND: + return "UST channel not found"; + case LTTNG_ERR_UST_CHAN_DISABLE_FAIL: + return "Disable UST channel failed"; + case LTTNG_ERR_UST_CHAN_ENABLE_FAIL: + return "Enable UST channel failed"; + case LTTNG_ERR_UST_ENABLE_FAIL: + return "Enable UST event failed"; + case LTTNG_ERR_UST_DISABLE_FAIL: + return "Disable UST event failed"; + case LTTNG_ERR_UST_META_FAIL: + return "Opening metadata failed"; + case LTTNG_ERR_UST_START_FAIL: + return "Starting UST trace failed"; + case LTTNG_ERR_UST_STOP_FAIL: + return "Stopping UST trace failed"; + case LTTNG_ERR_UST_CONSUMER64_FAIL: + return "64-bit UST consumer start failed"; + case LTTNG_ERR_UST_CONSUMER32_FAIL: + return "32-bit UST consumer start failed"; + case LTTNG_ERR_UST_STREAM_FAIL: + return "UST create stream failed"; + case LTTNG_ERR_UST_LIST_FAIL: + return "Listing UST events failed"; + case LTTNG_ERR_UST_EVENT_EXIST: + return "UST event already exist"; + case LTTNG_ERR_UST_EVENT_NOT_FOUND: + return "UST event not found"; + case LTTNG_ERR_UST_CONTEXT_EXIST: + return "UST context already exist"; + case LTTNG_ERR_UST_CONTEXT_INVAL: + return "UST invalid context"; + case LTTNG_ERR_NEED_ROOT_SESSIOND: + return "Tracing the kernel requires a root lttng-sessiond daemon, as well as \"tracing\" group membership or root user ID for the lttng client"; + case LTTNG_ERR_NO_UST: + return "LTTng-UST tracer is not supported. Please rebuild lttng-tools with lttng-ust support enabled"; + case LTTNG_ERR_TRACE_ALREADY_STARTED: + return "Tracing has already been started once"; + case LTTNG_ERR_TRACE_ALREADY_STOPPED: + return "Tracing has already been stopped"; + case LTTNG_ERR_KERN_EVENT_ENOSYS: + return "Kernel event type not supported"; + case LTTNG_ERR_NEED_CHANNEL_NAME: + return "Non-default channel exists within session: channel name needs to be specified with '-c name'"; + case LTTNG_ERR_INVALID: + return "Invalid parameter"; + case LTTNG_ERR_NO_USTCONSUMERD: + return "No UST consumer detected"; + case LTTNG_ERR_NO_KERNCONSUMERD: + return "No kernel consumer detected"; + case LTTNG_ERR_EVENT_EXIST_LOGLEVEL: + return "Event already enabled with different loglevel"; + case LTTNG_ERR_URL_DATA_MISS: + return "Missing data path URL"; + case LTTNG_ERR_URL_CTRL_MISS: + return "Missing control path URL"; + case LTTNG_ERR_ENABLE_CONSUMER_FAIL: + return "Enabling consumer failed"; + case LTTNG_ERR_RELAYD_CONNECT_FAIL: + return "Unable to connect to lttng-relayd"; + case LTTNG_ERR_RELAYD_VERSION_FAIL: + return "Relay daemon not compatible"; + case LTTNG_ERR_FILTER_INVAL: + return "Invalid filter bytecode"; + case LTTNG_ERR_FILTER_NOMEM: + return "Not enough memory for filter bytecode"; + case LTTNG_ERR_FILTER_EXIST: + return "Filter already exist"; + case LTTNG_ERR_NO_CONSUMER: + return "Consumer not found for recording session"; + case LTTNG_ERR_EXCLUSION_INVAL: + return "Invalid event exclusion data"; + case LTTNG_ERR_EXCLUSION_NOMEM: + return "Lack of memory while processing event exclusions"; + case LTTNG_ERR_NO_SESSIOND: + return "No session daemon is available"; + case LTTNG_ERR_SESSION_STARTED: + return "Session is running"; + case LTTNG_ERR_NOT_SUPPORTED: + return "Operation not supported"; + case LTTNG_ERR_UST_EVENT_ENABLED: + return "UST event already enabled"; + case LTTNG_ERR_SET_URL: + return "Error setting URL"; + case LTTNG_ERR_URL_EXIST: + return "URL already exists"; + case LTTNG_ERR_BUFFER_NOT_SUPPORTED: + return "Buffer type not supported"; + case LTTNG_ERR_BUFFER_TYPE_MISMATCH: + return "Buffer type mismatch for session"; + case LTTNG_ERR_NOMEM: + return "Not enough memory"; + case LTTNG_ERR_SNAPSHOT_OUTPUT_EXIST: + return "Snapshot output already exists"; + case LTTNG_ERR_START_SESSION_ONCE: + return "Session needs to be started once"; + case LTTNG_ERR_SNAPSHOT_FAIL: + return "Snapshot record failed"; + case LTTNG_ERR_NO_STREAM: + return "Index without stream on relay"; + case LTTNG_ERR_CHAN_EXIST: + return "Channel already exists"; + case LTTNG_ERR_SNAPSHOT_NODATA: + return "No data available in snapshot"; + case LTTNG_ERR_NO_CHANNEL: + return "No channel found in the session"; + case LTTNG_ERR_SESSION_INVALID_CHAR: + return "Invalid character found in session name"; + case LTTNG_ERR_SAVE_FILE_EXIST: + return "Session file already exists"; + case LTTNG_ERR_SAVE_IO_FAIL: + return "IO error while writing session configuration"; + case LTTNG_ERR_LOAD_INVALID_CONFIG: + return "Invalid session configuration"; + case LTTNG_ERR_LOAD_IO_FAIL: + return "IO error while reading a session configuration"; + case LTTNG_ERR_LOAD_SESSION_NOENT: + return "Session file not found"; + case LTTNG_ERR_MAX_SIZE_INVALID: + return "Snapshot max size is invalid"; + case LTTNG_ERR_MI_OUTPUT_TYPE: + return "Invalid MI output format"; + case LTTNG_ERR_MI_IO_FAIL: + return "IO error while writing MI output"; + case LTTNG_ERR_MI_NOT_IMPLEMENTED: + return "Mi feature not implemented"; + case LTTNG_ERR_INVALID_EVENT_NAME: + return "Invalid event name"; + case LTTNG_ERR_INVALID_CHANNEL_NAME: + return "Invalid channel name"; + case LTTNG_ERR_PROCESS_ATTR_EXISTS: + return "Process attribute is already tracked"; + case LTTNG_ERR_PROCESS_ATTR_MISSING: + return "Process attribute was not tracked"; + case LTTNG_ERR_INVALID_CHANNEL_DOMAIN: + return "Invalid channel domain"; + case LTTNG_ERR_OVERFLOW: + return "Overflow occurred"; + case LTTNG_ERR_SESSION_NOT_STARTED: + return "Session not started"; + case LTTNG_ERR_LIVE_SESSION: + return "Live sessions are not supported"; + case LTTNG_ERR_PER_PID_SESSION: + return "Per-PID recording sessions are not supported"; + case LTTNG_ERR_KERN_CONTEXT_UNAVAILABLE: + return "Context unavailable on this kernel"; + case LTTNG_ERR_REGEN_STATEDUMP_FAIL: + return "Failed to regenerate the state dump"; + case LTTNG_ERR_REGEN_STATEDUMP_NOMEM: + return "Failed to regenerate the state dump, not enough memory"; + case LTTNG_ERR_NOT_SNAPSHOT_SESSION: + return "Snapshot command can't be applied to a non-snapshot session"; + case LTTNG_ERR_INVALID_TRIGGER: + return "Invalid trigger"; + case LTTNG_ERR_TRIGGER_EXISTS: + return "Trigger already registered"; + case LTTNG_ERR_TRIGGER_NOT_FOUND: + return "Trigger not found"; + case LTTNG_ERR_COMMAND_CANCELLED: + return "Command cancelled"; + case LTTNG_ERR_ROTATION_PENDING: + return "Rotation already pending for this session"; + case LTTNG_ERR_ROTATION_NOT_AVAILABLE: + return "Rotation feature not available for this session's creation mode"; + case LTTNG_ERR_ROTATION_SCHEDULE_SET: + return "A session rotation schedule of this type is already set on the session"; + case LTTNG_ERR_ROTATION_SCHEDULE_NOT_SET: + return "No session rotation schedule of this type is set on the session"; + case LTTNG_ERR_ROTATION_MULTIPLE_AFTER_STOP: + return "Session was already rotated once since it became inactive"; + case LTTNG_ERR_ROTATION_WRONG_VERSION: + return "Session rotation is not supported by this kernel tracer version"; + case LTTNG_ERR_NO_SESSION_OUTPUT: + return "Session has no output"; + case LTTNG_ERR_ROTATION_NOT_AVAILABLE_RELAY: + return "Rotation feature not available on the relay"; + case LTTNG_ERR_AGENT_TRACING_DISABLED: + return "Session daemon agent tracing is disabled"; + case LTTNG_ERR_PROBE_LOCATION_INVAL: + return "Invalid userspace probe location"; + case LTTNG_ERR_ELF_PARSING: + return "ELF parsing error"; + case LTTNG_ERR_SDT_PROBE_SEMAPHORE: + return "SDT probe guarded by a semaphore"; + case LTTNG_ERR_ROTATION_FAIL_CONSUMER: + return "Rotation failure on consumer"; + case LTTNG_ERR_ROTATE_RENAME_FAIL_CONSUMER: + return "Rotation rename failure on consumer"; + case LTTNG_ERR_ROTATION_PENDING_LOCAL_FAIL_CONSUMER: + return "Rotation pending check (local) failure on consumer"; + case LTTNG_ERR_ROTATION_PENDING_RELAY_FAIL_CONSUMER: + return "Rotation pending check (relay) failure on consumer"; + case LTTNG_ERR_MKDIR_FAIL_CONSUMER: + return "Directory creation failure on consumer"; + case LTTNG_ERR_CHAN_NOT_FOUND: + return "Channel not found"; + case LTTNG_ERR_SNAPSHOT_UNSUPPORTED: + return "Session configuration does not allow the use of snapshots"; + case LTTNG_ERR_SESSION_NOT_EXIST: + return "Recording session does not exist"; + case LTTNG_ERR_CREATE_TRACE_CHUNK_FAIL_CONSUMER: + return "Trace chunk creation failed on consumer"; + case LTTNG_ERR_CLOSE_TRACE_CHUNK_FAIL_CONSUMER: + return "Trace chunk close failed on consumer"; + case LTTNG_ERR_TRACE_CHUNK_EXISTS_FAIL_CONSUMER: + return "Failed to query consumer for trace chunk existence"; + case LTTNG_ERR_INVALID_PROTOCOL: + return "Protocol error occurred"; + case LTTNG_ERR_FILE_CREATION_ERROR: + return "Failed to create file"; + case LTTNG_ERR_TIMER_STOP_ERROR: + return "Failed to stop a timer"; + case LTTNG_ERR_ROTATION_NOT_AVAILABLE_KERNEL: + return "Rotation feature not supported by the kernel tracer"; + case LTTNG_ERR_CLEAR_RELAY_DISALLOWED: + return "Relayd daemon peer does not allow sessions to be cleared"; + case LTTNG_ERR_CLEAR_NOT_AVAILABLE_RELAY: + return "Clearing a session is not supported by the relay daemon"; + case LTTNG_ERR_CLEAR_FAIL_CONSUMER: + return "Consumer failed to clear the session"; + case LTTNG_ERR_ROTATION_AFTER_STOP_CLEAR: + return "Session was already cleared since it became inactive"; + case LTTNG_ERR_USER_NOT_FOUND: + return "User not found"; + case LTTNG_ERR_GROUP_NOT_FOUND: + return "Group not found"; + case LTTNG_ERR_UNSUPPORTED_DOMAIN: + return "Unsupported domain used"; + case LTTNG_ERR_PROCESS_ATTR_TRACKER_INVALID_TRACKING_POLICY: + return "Operation does not apply to the process attribute tracker's tracking policy"; + case LTTNG_ERR_EVENT_NOTIFIER_GROUP_NOTIFICATION_FD: + return "Failed to create an event notifier group notification file descriptor"; + case LTTNG_ERR_INVALID_CAPTURE_EXPRESSION: + return "Invalid capture expression"; + case LTTNG_ERR_EVENT_NOTIFIER_REGISTRATION: + return "Failed to create event notifier"; + case LTTNG_ERR_EVENT_NOTIFIER_ERROR_ACCOUNTING: + return "Failed to initialize event notifier error accounting"; + case LTTNG_ERR_EVENT_NOTIFIER_ERROR_ACCOUNTING_FULL: + return "No index available in event notifier error accounting"; + case LTTNG_ERR_INVALID_ERROR_QUERY_TARGET: + return "Invalid error query target."; + case LTTNG_ERR_BUFFER_FLUSH_FAILED: + return "Failed to flush stream buffer"; + case LTTNG_ERR_NR: + abort(); + } + + abort(); +}; + +/* + * Return ptr to string representing a human readable error code from the + * lttng_error_code enum. + * + * These code MUST be negative in other to treat that as an error value. + */ +const char *error_get_str(int32_t code) +{ + code = -code; + + if (code < LTTNG_OK || code >= LTTNG_ERR_NR) { + code = LTTNG_ERR_UNK; + } + + return lttng_error_code_str((lttng_error_code) code); +} + +void lttng_abort_on_error(void) +{ + if (lttng_opt_abort_on_error < 0) { + /* Use lttng_secure_getenv() to query its state. */ + const char *value; + + value = lttng_secure_getenv("LTTNG_ABORT_ON_ERROR"); + if (value && !strcmp(value, "1")) { + lttng_opt_abort_on_error = 1; + } else { + lttng_opt_abort_on_error = 0; + } + } + if (lttng_opt_abort_on_error > 0) { + abort(); + } +} diff --git a/src/common/evaluation.c b/src/common/evaluation.cpp similarity index 100% rename from src/common/evaluation.c rename to src/common/evaluation.cpp diff --git a/src/common/event-expr/event-expr.c b/src/common/event-expr/event-expr.cpp similarity index 99% rename from src/common/event-expr/event-expr.c rename to src/common/event-expr/event-expr.cpp index 7b07312f2..e80fb1d5d 100644 --- a/src/common/event-expr/event-expr.c +++ b/src/common/event-expr/event-expr.cpp @@ -40,7 +40,7 @@ struct lttng_event_expr *create_empty_expr(enum lttng_event_expr_type type, { struct lttng_event_expr *expr; - expr = zmalloc(size); + expr = (lttng_event_expr *) zmalloc(size); if (!expr) { goto end; } diff --git a/src/common/event-field-value.c b/src/common/event-field-value.cpp similarity index 97% rename from src/common/event-field-value.c rename to src/common/event-field-value.cpp index 850f9eda1..757271313 100644 --- a/src/common/event-field-value.c +++ b/src/common/event-field-value.cpp @@ -23,7 +23,7 @@ struct lttng_event_field_value *create_empty_field_val( { struct lttng_event_field_value *field_val; - field_val = zmalloc(size); + field_val = (lttng_event_field_value *) zmalloc(size); if (!field_val) { goto end; } @@ -209,7 +209,7 @@ struct lttng_event_field_value *lttng_event_field_value_string_create( static void destroy_field_val(void *field_val) { - lttng_event_field_value_destroy(field_val); + lttng_event_field_value_destroy((lttng_event_field_value *) field_val); } struct lttng_event_field_value *lttng_event_field_value_array_create(void) @@ -508,7 +508,7 @@ const char *lttng_event_field_value_enum_get_label_at_index( goto end; } - ret = lttng_dynamic_pointer_array_get_pointer(&enum_field_val->labels, + ret = (const char *) lttng_dynamic_pointer_array_get_pointer(&enum_field_val->labels, index); end: @@ -579,7 +579,7 @@ lttng_event_field_value_array_get_element_at_index( goto end; } - *elem_field_val = lttng_dynamic_pointer_array_get_pointer( + *elem_field_val = (lttng_event_field_value *) lttng_dynamic_pointer_array_get_pointer( &array_field_val->elems, index); if (*elem_field_val) { status = LTTNG_EVENT_FIELD_VALUE_STATUS_OK; diff --git a/src/common/event-rule/event-rule.c b/src/common/event-rule/event-rule.cpp similarity index 100% rename from src/common/event-rule/event-rule.c rename to src/common/event-rule/event-rule.cpp diff --git a/src/common/event-rule/jul-logging.c b/src/common/event-rule/jul-logging.cpp similarity index 99% rename from src/common/event-rule/jul-logging.c rename to src/common/event-rule/jul-logging.cpp index c6c05542d..77ae3800c 100644 --- a/src/common/event-rule/jul-logging.c +++ b/src/common/event-rule/jul-logging.cpp @@ -421,7 +421,7 @@ static struct lttng_event *lttng_event_rule_jul_logging_generate_lttng_event( jul_logging = container_of( rule, const struct lttng_event_rule_jul_logging, parent); - local_event = zmalloc(sizeof(*local_event)); + local_event = (lttng_event *) zmalloc(sizeof(*local_event)); if (!local_event) { goto error; } @@ -561,7 +561,7 @@ struct lttng_event_rule *lttng_event_rule_jul_logging_create(void) struct lttng_event_rule_jul_logging *tp_rule; enum lttng_event_rule_status status; - tp_rule = zmalloc(sizeof(struct lttng_event_rule_jul_logging)); + tp_rule = (lttng_event_rule_jul_logging *) zmalloc(sizeof(struct lttng_event_rule_jul_logging)); if (!tp_rule) { goto end; } diff --git a/src/common/event-rule/kernel-kprobe.c b/src/common/event-rule/kernel-kprobe.cpp similarity index 99% rename from src/common/event-rule/kernel-kprobe.c rename to src/common/event-rule/kernel-kprobe.cpp index 872d03a7e..d33d44605 100644 --- a/src/common/event-rule/kernel-kprobe.c +++ b/src/common/event-rule/kernel-kprobe.cpp @@ -287,7 +287,7 @@ struct lttng_event_rule *lttng_event_rule_kernel_kprobe_create( struct lttng_event_rule *rule = NULL; struct lttng_event_rule_kernel_kprobe *krule; - krule = zmalloc(sizeof(struct lttng_event_rule_kernel_kprobe)); + krule = (lttng_event_rule_kernel_kprobe *) zmalloc(sizeof(struct lttng_event_rule_kernel_kprobe)); if (!krule) { goto end; } diff --git a/src/common/event-rule/kernel-syscall.c b/src/common/event-rule/kernel-syscall.cpp similarity index 98% rename from src/common/event-rule/kernel-syscall.c rename to src/common/event-rule/kernel-syscall.cpp index 21aa1e221..3f8e64ed8 100644 --- a/src/common/event-rule/kernel-syscall.c +++ b/src/common/event-rule/kernel-syscall.cpp @@ -355,7 +355,7 @@ struct lttng_event_rule *lttng_event_rule_kernel_syscall_create( goto end; } - syscall_rule = zmalloc(sizeof(struct lttng_event_rule_kernel_syscall)); + syscall_rule = (lttng_event_rule_kernel_syscall *) zmalloc(sizeof(struct lttng_event_rule_kernel_syscall)); if (!syscall_rule) { goto end; } @@ -423,7 +423,7 @@ ssize_t lttng_event_rule_kernel_syscall_create_from_payload( } syscall_comm = (typeof(syscall_comm)) current_buffer_view.data; - rule = lttng_event_rule_kernel_syscall_create(syscall_comm->emission_site); + rule = lttng_event_rule_kernel_syscall_create((lttng_event_rule_kernel_syscall_emission_site) syscall_comm->emission_site); if (!rule) { ERR("Failed to create event rule syscall"); ret = -1; diff --git a/src/common/event-rule/kernel-tracepoint.c b/src/common/event-rule/kernel-tracepoint.cpp similarity index 99% rename from src/common/event-rule/kernel-tracepoint.c rename to src/common/event-rule/kernel-tracepoint.cpp index a1f5f625a..cff3048f3 100644 --- a/src/common/event-rule/kernel-tracepoint.c +++ b/src/common/event-rule/kernel-tracepoint.cpp @@ -333,7 +333,7 @@ struct lttng_event_rule *lttng_event_rule_kernel_tracepoint_create(void) struct lttng_event_rule_kernel_tracepoint *tp_rule; enum lttng_event_rule_status status; - tp_rule = zmalloc(sizeof(struct lttng_event_rule_kernel_tracepoint)); + tp_rule = (lttng_event_rule_kernel_tracepoint *) zmalloc(sizeof(struct lttng_event_rule_kernel_tracepoint)); if (!tp_rule) { goto end; } diff --git a/src/common/event-rule/kernel-uprobe.c b/src/common/event-rule/kernel-uprobe.cpp similarity index 99% rename from src/common/event-rule/kernel-uprobe.c rename to src/common/event-rule/kernel-uprobe.cpp index 805f2bc79..d53958df6 100644 --- a/src/common/event-rule/kernel-uprobe.c +++ b/src/common/event-rule/kernel-uprobe.cpp @@ -277,7 +277,7 @@ struct lttng_event_rule *lttng_event_rule_kernel_uprobe_create( struct lttng_event_rule *rule = NULL; struct lttng_event_rule_kernel_uprobe *urule; - urule = zmalloc(sizeof(struct lttng_event_rule_kernel_uprobe)); + urule = (lttng_event_rule_kernel_uprobe *) zmalloc(sizeof(struct lttng_event_rule_kernel_uprobe)); if (!urule) { goto end; } diff --git a/src/common/event-rule/log4j-logging.c b/src/common/event-rule/log4j-logging.cpp similarity index 99% rename from src/common/event-rule/log4j-logging.c rename to src/common/event-rule/log4j-logging.cpp index 6fd05521b..25f2c4c0e 100644 --- a/src/common/event-rule/log4j-logging.c +++ b/src/common/event-rule/log4j-logging.cpp @@ -421,7 +421,7 @@ static struct lttng_event *lttng_event_rule_log4j_logging_generate_lttng_event( log4j_logging = container_of( rule, const struct lttng_event_rule_log4j_logging, parent); - local_event = zmalloc(sizeof(*local_event)); + local_event = (lttng_event *) zmalloc(sizeof(*local_event)); if (!local_event) { goto error; } @@ -560,7 +560,7 @@ struct lttng_event_rule *lttng_event_rule_log4j_logging_create(void) struct lttng_event_rule_log4j_logging *tp_rule; enum lttng_event_rule_status status; - tp_rule = zmalloc(sizeof(struct lttng_event_rule_log4j_logging)); + tp_rule = (lttng_event_rule_log4j_logging *) zmalloc(sizeof(struct lttng_event_rule_log4j_logging)); if (!tp_rule) { goto end; } diff --git a/src/common/event-rule/python-logging.c b/src/common/event-rule/python-logging.cpp similarity index 99% rename from src/common/event-rule/python-logging.c rename to src/common/event-rule/python-logging.cpp index 4ec00c7ef..1ccd495cd 100644 --- a/src/common/event-rule/python-logging.c +++ b/src/common/event-rule/python-logging.cpp @@ -421,7 +421,7 @@ static struct lttng_event *lttng_event_rule_python_logging_generate_lttng_event( python_logging = container_of( rule, const struct lttng_event_rule_python_logging, parent); - local_event = zmalloc(sizeof(*local_event)); + local_event = (lttng_event *) zmalloc(sizeof(*local_event)); if (!local_event) { goto error; } @@ -560,7 +560,7 @@ struct lttng_event_rule *lttng_event_rule_python_logging_create(void) struct lttng_event_rule_python_logging *tp_rule; enum lttng_event_rule_status status; - tp_rule = zmalloc(sizeof(struct lttng_event_rule_python_logging)); + tp_rule = (lttng_event_rule_python_logging *) zmalloc(sizeof(struct lttng_event_rule_python_logging)); if (!tp_rule) { goto end; } diff --git a/src/common/event-rule/user-tracepoint.c b/src/common/event-rule/user-tracepoint.cpp similarity index 99% rename from src/common/event-rule/user-tracepoint.c rename to src/common/event-rule/user-tracepoint.cpp index cb384f851..5158eeaa0 100644 --- a/src/common/event-rule/user-tracepoint.c +++ b/src/common/event-rule/user-tracepoint.cpp @@ -362,7 +362,7 @@ lttng_event_rule_user_tracepoint_generate_exclusions( goto end; } - exclusions = zmalloc(sizeof(struct lttng_event_exclusion) + + exclusions = (lttng_event_exclusion *) zmalloc(sizeof(struct lttng_event_exclusion) + (LTTNG_SYMBOL_NAME_LEN * nb_exclusions)); if (!exclusions) { PERROR("Failed to allocate exclusions buffer"); @@ -558,7 +558,7 @@ struct lttng_event_rule *lttng_event_rule_user_tracepoint_create(void) struct lttng_event_rule_user_tracepoint *tp_rule; enum lttng_event_rule_status status; - tp_rule = zmalloc(sizeof(struct lttng_event_rule_user_tracepoint)); + tp_rule = (lttng_event_rule_user_tracepoint *) zmalloc(sizeof(struct lttng_event_rule_user_tracepoint)); if (!tp_rule) { goto end; } @@ -1074,7 +1074,7 @@ enum lttng_event_rule_status lttng_event_rule_user_tracepoint_get_name_pattern_e goto end; } - *exclusion = lttng_dynamic_pointer_array_get_pointer( + *exclusion = (const char *) lttng_dynamic_pointer_array_get_pointer( &tracepoint->exclusions, index); end: return status; diff --git a/src/common/event.c b/src/common/event.cpp similarity index 85% rename from src/common/event.c rename to src/common/event.cpp index f1792f931..6b22fecf5 100644 --- a/src/common/event.c +++ b/src/common/event.cpp @@ -13,7 +13,7 @@ struct lttng_event *lttng_event_copy(const struct lttng_event *event) struct lttng_event *new_event; struct lttng_event_extended *new_event_extended; - new_event = zmalloc(sizeof(*event)); + new_event = (lttng_event *) zmalloc(sizeof(*event)); if (!new_event) { PERROR("Error allocating event structure"); goto end; @@ -26,7 +26,7 @@ struct lttng_event *lttng_event_copy(const struct lttng_event *event) * We need to create a new extended since the previous pointer is now * invalid. */ - new_event_extended = zmalloc(sizeof(*new_event_extended)); + new_event_extended = (lttng_event_extended *) zmalloc(sizeof(*new_event_extended)); if (!new_event_extended) { PERROR("Error allocating event extended structure"); goto error; diff --git a/src/common/fd-handle.c b/src/common/fd-handle.cpp similarity index 97% rename from src/common/fd-handle.c rename to src/common/fd-handle.cpp index b2b7efd23..d8b5b785d 100644 --- a/src/common/fd-handle.c +++ b/src/common/fd-handle.cpp @@ -41,7 +41,7 @@ struct fd_handle *fd_handle_create(int fd) goto end; } - handle = zmalloc(sizeof(*handle)); + handle = (fd_handle *) zmalloc(sizeof(*handle)); if (!handle) { PERROR("Failed to allocate fd_handle"); goto end; diff --git a/src/common/filter.c b/src/common/filter.cpp similarity index 96% rename from src/common/filter.c rename to src/common/filter.cpp index 9195808ee..f74b6374b 100644 --- a/src/common/filter.c +++ b/src/common/filter.cpp @@ -23,7 +23,7 @@ struct bytecode_symbol_iterator *bytecode_symbol_iterator_create( goto end; } - it = zmalloc(sizeof(*it)); + it = (bytecode_symbol_iterator *) zmalloc(sizeof(*it)); if (!it) { goto end; } diff --git a/src/common/fs-handle.c b/src/common/fs-handle.cpp similarity index 100% rename from src/common/fs-handle.c rename to src/common/fs-handle.cpp diff --git a/src/common/futex.c b/src/common/futex.cpp similarity index 100% rename from src/common/futex.c rename to src/common/futex.cpp diff --git a/src/common/index-allocator.c b/src/common/index-allocator.cpp similarity index 95% rename from src/common/index-allocator.c rename to src/common/index-allocator.cpp index 8c73218a9..c48d708d0 100644 --- a/src/common/index-allocator.c +++ b/src/common/index-allocator.cpp @@ -32,7 +32,7 @@ struct lttng_index_allocator *lttng_index_allocator_create( { struct lttng_index_allocator *allocator = NULL; - allocator = zmalloc(sizeof(*allocator)); + allocator = (lttng_index_allocator *) zmalloc(sizeof(*allocator)); if (!allocator) { PERROR("Failed to allocate index allocator"); goto end; @@ -92,7 +92,7 @@ enum lttng_index_allocator_status lttng_index_allocator_release( LTTNG_ASSERT(idx < allocator->size); - index = zmalloc(sizeof(*index)); + index = (lttng_index *) zmalloc(sizeof(*index)); if (!index) { PERROR("Failed to allocate free index queue"); status = LTTNG_INDEX_ALLOCATOR_STATUS_ERROR; diff --git a/src/common/kernel-probe.c b/src/common/kernel-probe.cpp similarity index 99% rename from src/common/kernel-probe.c rename to src/common/kernel-probe.cpp index 33ba00fca..a05b451c3 100644 --- a/src/common/kernel-probe.c +++ b/src/common/kernel-probe.cpp @@ -117,7 +117,7 @@ lttng_kernel_probe_location_address_create(uint64_t address) struct lttng_kernel_probe_location *ret = NULL; struct lttng_kernel_probe_location_address *location; - location = zmalloc(sizeof(*location)); + location = (lttng_kernel_probe_location_address *) zmalloc(sizeof(*location)); if (!location) { PERROR("Error allocating userspace probe location."); goto end; @@ -154,7 +154,7 @@ lttng_kernel_probe_location_symbol_create(const char *symbol_name, goto error; } - location = zmalloc(sizeof(*location)); + location = (lttng_kernel_probe_location_symbol *) zmalloc(sizeof(*location)); if (!location) { PERROR("Failed to allocate kernel symbol probe location"); goto error; diff --git a/src/common/location.c b/src/common/location.cpp similarity index 99% rename from src/common/location.c rename to src/common/location.cpp index e68051ee5..80c4b4d55 100644 --- a/src/common/location.c +++ b/src/common/location.cpp @@ -16,7 +16,7 @@ struct lttng_trace_archive_location *lttng_trace_archive_location_create( { struct lttng_trace_archive_location *location; - location = zmalloc(sizeof(*location)); + location = (lttng_trace_archive_location *) zmalloc(sizeof(*location)); if (!location) { goto end; } diff --git a/src/common/log-level-rule.c b/src/common/log-level-rule.cpp similarity index 96% rename from src/common/log-level-rule.c rename to src/common/log-level-rule.cpp index d2bbd4176..e891222e0 100644 --- a/src/common/log-level-rule.c +++ b/src/common/log-level-rule.cpp @@ -44,7 +44,7 @@ struct lttng_log_level_rule *lttng_log_level_rule_exactly_create( { struct lttng_log_level_rule *rule = NULL; - rule = zmalloc(sizeof(struct lttng_log_level_rule)); + rule = (lttng_log_level_rule *) zmalloc(sizeof(struct lttng_log_level_rule)); if (!rule) { goto end; } @@ -77,7 +77,7 @@ lttng_log_level_rule_at_least_as_severe_as_create(int level) { struct lttng_log_level_rule *rule = NULL; - rule = zmalloc(sizeof(struct lttng_log_level_rule)); + rule = (lttng_log_level_rule *) zmalloc(sizeof(struct lttng_log_level_rule)); if (!rule) { goto end; } @@ -227,7 +227,7 @@ struct lttng_log_level_rule *lttng_log_level_rule_copy( LTTNG_ASSERT(source); - copy = zmalloc(sizeof(struct lttng_log_level_rule)); + copy = (lttng_log_level_rule *) zmalloc(sizeof(struct lttng_log_level_rule)); if (!copy) { goto end; } diff --git a/src/common/lttng-elf.c b/src/common/lttng-elf.cpp similarity index 98% rename from src/common/lttng-elf.c rename to src/common/lttng-elf.cpp index d6cef2fe8..992410a88 100644 --- a/src/common/lttng-elf.c +++ b/src/common/lttng-elf.cpp @@ -7,6 +7,7 @@ * */ +#include #include #include #include @@ -374,7 +375,7 @@ char *lttng_elf_get_section_name(struct lttng_elf *elf, off_t offset) if (!to_read) { goto error; } - read_len = lttng_read(elf->fd, buf, min_t(size_t, BUF_LEN, to_read)); + read_len = lttng_read(elf->fd, buf, std::min(BUF_LEN, to_read)); if (read_len <= 0) { PERROR("Error reading ELF string table section"); goto error; @@ -393,7 +394,7 @@ end: * We found the length of the section name, now seek back to the * beginning of the name and copy it in the newly allocated buffer. */ - name = zmalloc(sizeof(char) * (name_length + 1)); /* + 1 for \0 */ + name = (char *)zmalloc(sizeof(char) * (name_length + 1)); /* + 1 for \0 */ if (!name) { PERROR("Error allocating ELF section name buffer"); goto error; @@ -494,7 +495,7 @@ int lttng_elf_validate_and_populate(struct lttng_elf *elf) goto end; } - elf->ehdr = zmalloc(sizeof(struct lttng_elf_ehdr)); + elf->ehdr = (lttng_elf_ehdr *) zmalloc(sizeof(struct lttng_elf_ehdr)); if (!elf->ehdr) { PERROR("Error allocation buffer for ELF header"); ret = LTTNG_ERR_NOMEM; @@ -547,7 +548,7 @@ struct lttng_elf *lttng_elf_create(int fd) goto error; } - elf = zmalloc(sizeof(struct lttng_elf)); + elf = (lttng_elf *) zmalloc(sizeof(struct lttng_elf)); if (!elf) { PERROR("Error allocating struct lttng_elf"); goto error; @@ -650,7 +651,7 @@ char *lttng_elf_get_section_data(struct lttng_elf *elf, goto error; } - max_alloc_size = min_t(size_t, MAX_SECTION_DATA_SIZE, elf->file_size); + max_alloc_size = std::min(MAX_SECTION_DATA_SIZE, elf->file_size); section_offset = shdr->sh_offset; if (lseek(elf->fd, section_offset, SEEK_SET) < 0) { @@ -663,7 +664,7 @@ char *lttng_elf_get_section_data(struct lttng_elf *elf, max_alloc_size); goto error; } - data = zmalloc(shdr->sh_size); + data = (char *) zmalloc(shdr->sh_size); if (!data) { PERROR("Error allocating buffer for ELF section data"); goto error; @@ -1043,7 +1044,7 @@ int lttng_elf_get_sdt_probe_offsets(int fd, const char *provider_name, * Found a match with not semaphore, we need to copy the * probe_location to the output parameter. */ - new_probe_locs = realloc(probe_locs, new_size); + new_probe_locs = (uint64_t *) realloc(probe_locs, new_size); if (!new_probe_locs) { /* Error allocating a larger buffer */ DBG("Allocation error in SDT."); diff --git a/src/common/lttng-elf.h b/src/common/lttng-elf.h index 524b87846..41dd49605 100644 --- a/src/common/lttng-elf.h +++ b/src/common/lttng-elf.h @@ -10,9 +10,11 @@ #include -LTTNG_EXPORT int lttng_elf_get_symbol_offset(int fd, char *symbol, uint64_t *offset); +extern "C" LTTNG_EXPORT +int lttng_elf_get_symbol_offset(int fd, char *symbol, uint64_t *offset); -LTTNG_EXPORT int lttng_elf_get_sdt_probe_offsets(int fd, const char *provider_name, +extern "C" LTTNG_EXPORT +int lttng_elf_get_sdt_probe_offsets(int fd, const char *provider_name, const char *probe_name, uint64_t **offsets, uint32_t *nb_probe); #endif /* _LTTNG_ELF_H */ diff --git a/src/common/mi-lttng.c b/src/common/mi-lttng.cpp similarity index 99% rename from src/common/mi-lttng.c rename to src/common/mi-lttng.cpp index 1ff9f936c..d41a3cadc 100644 --- a/src/common/mi-lttng.c +++ b/src/common/mi-lttng.cpp @@ -435,14 +435,14 @@ const char *const mi_lttng_element_error_query_results = const char * const mi_lttng_element_context_symbol = "symbol"; /* Deprecated symbols preserved for ABI compatibility. */ -LTTNG_EXPORT const char * const mi_lttng_context_type_perf_counter; -LTTNG_EXPORT const char * const mi_lttng_context_type_perf_cpu_counter; -LTTNG_EXPORT const char * const mi_lttng_context_type_perf_thread_counter; -LTTNG_EXPORT const char * const mi_lttng_element_track_untrack_pid_target; -LTTNG_EXPORT const char * const mi_lttng_element_track_untrack_targets; -LTTNG_EXPORT const char * const mi_lttng_element_calibrate; -LTTNG_EXPORT const char * const mi_lttng_element_calibrate_function; -LTTNG_EXPORT const char * const mi_lttng_element_command_calibrate; +LTTNG_EXPORT const char *mi_lttng_context_type_perf_counter; +LTTNG_EXPORT const char *mi_lttng_context_type_perf_cpu_counter; +LTTNG_EXPORT const char *mi_lttng_context_type_perf_thread_counter; +LTTNG_EXPORT const char *mi_lttng_element_track_untrack_pid_target; +LTTNG_EXPORT const char *mi_lttng_element_track_untrack_targets; +LTTNG_EXPORT const char *mi_lttng_element_calibrate; +LTTNG_EXPORT const char *mi_lttng_element_calibrate_function; +LTTNG_EXPORT const char *mi_lttng_element_command_calibrate; /* This is a merge of jul loglevel and regular loglevel * Those should never overlap by definition @@ -774,7 +774,7 @@ struct mi_writer *mi_lttng_writer_create(int fd_output, int mi_output_type) { struct mi_writer *mi_writer; - mi_writer = zmalloc(sizeof(struct mi_writer)); + mi_writer = (struct mi_writer *) zmalloc(sizeof(struct mi_writer)); if (!mi_writer) { PERROR("zmalloc mi_writer_create"); goto end; @@ -2706,7 +2706,7 @@ close_location: if (ret) { goto end; } - + close_rotation: /* Close rotation element */ ret = mi_lttng_writer_close_element(writer); diff --git a/src/common/notification.c b/src/common/notification.cpp similarity index 98% rename from src/common/notification.c rename to src/common/notification.cpp index d1403574b..989c20ade 100644 --- a/src/common/notification.c +++ b/src/common/notification.cpp @@ -24,7 +24,7 @@ struct lttng_notification *lttng_notification_create( goto end; } - notification = zmalloc(sizeof(struct lttng_notification)); + notification = (lttng_notification *) zmalloc(sizeof(struct lttng_notification)); if (!notification) { goto end; } diff --git a/src/common/payload-view.c b/src/common/payload-view.cpp similarity index 93% rename from src/common/payload-view.c rename to src/common/payload-view.cpp index 2e6581bb4..b1a44368d 100644 --- a/src/common/payload-view.c +++ b/src/common/payload-view.cpp @@ -35,9 +35,11 @@ struct lttng_payload_view lttng_payload_view_from_view( .buffer = lttng_buffer_view_from_view( &view->buffer, offset, len), ._fd_handles = view->_fd_handles, - ._iterator.p_fd_handles_position = view->_iterator.p_fd_handles_position ?: + ._iterator = { + .p_fd_handles_position = view->_iterator.p_fd_handles_position ?: &view->_iterator.fd_handles_position, - } : (struct lttng_payload_view) {}; + } + } : (struct lttng_payload_view) {}; } struct lttng_payload_view lttng_payload_view_from_dynamic_buffer( @@ -112,7 +114,7 @@ struct fd_handle *lttng_payload_view_pop_fd_handle( pos = view->_iterator.p_fd_handles_position ? view->_iterator.p_fd_handles_position : &view->_iterator.fd_handles_position; - handle = lttng_dynamic_pointer_array_get_pointer(&view->_fd_handles, + handle = (fd_handle *) lttng_dynamic_pointer_array_get_pointer(&view->_fd_handles, *pos); (*pos)++; fd_handle_get(handle); diff --git a/src/common/payload.c b/src/common/payload.cpp similarity index 94% rename from src/common/payload.c rename to src/common/payload.cpp index f26585bb9..0097e65bc 100644 --- a/src/common/payload.c +++ b/src/common/payload.cpp @@ -13,7 +13,7 @@ static void release_fd_handle_ref(void *ptr) { - struct fd_handle *fd_handle = ptr; + struct fd_handle *fd_handle = (struct fd_handle *) ptr; fd_handle_put(fd_handle); } @@ -43,7 +43,7 @@ int lttng_payload_copy(const struct lttng_payload *src_payload, i++) { struct fd_handle *new_fd_handle; const struct fd_handle *src_fd_handle = - lttng_dynamic_pointer_array_get_pointer( + (fd_handle *) lttng_dynamic_pointer_array_get_pointer( &src_payload->_fd_handles, i); new_fd_handle = fd_handle_copy(src_fd_handle); diff --git a/src/common/pipe.c b/src/common/pipe.cpp similarity index 99% rename from src/common/pipe.c rename to src/common/pipe.cpp index 45be43fa3..2de91f5a0 100644 --- a/src/common/pipe.c +++ b/src/common/pipe.cpp @@ -108,7 +108,7 @@ static struct lttng_pipe *_pipe_create(void) int ret; struct lttng_pipe *p; - p = zmalloc(sizeof(*p)); + p = (lttng_pipe *) zmalloc(sizeof(*p)); if (!p) { PERROR("zmalloc pipe create"); goto end; diff --git a/src/common/readwrite.c b/src/common/readwrite.cpp similarity index 94% rename from src/common/readwrite.c rename to src/common/readwrite.cpp index 14ec171f9..857781c6a 100644 --- a/src/common/readwrite.c +++ b/src/common/readwrite.cpp @@ -37,7 +37,7 @@ ssize_t lttng_read(int fd, void *buf, size_t count) } do { - ret = read(fd, buf + i, count - i); + ret = read(fd, (char *) buf + i, count - i); if (ret < 0) { if (errno == EINTR) { continue; /* retry operation */ @@ -74,7 +74,7 @@ ssize_t lttng_write(int fd, const void *buf, size_t count) } do { - ret = write(fd, buf + i, count - i); + ret = write(fd, (char *) buf + i, count - i); if (ret < 0) { if (errno == EINTR) { continue; /* retry operation */ diff --git a/src/common/runas.c b/src/common/runas.cpp similarity index 97% rename from src/common/runas.c rename to src/common/runas.cpp index 930c973ff..3c9eea8c3 100644 --- a/src/common/runas.c +++ b/src/common/runas.cpp @@ -211,137 +211,137 @@ struct run_as_command_properties { }; static const struct run_as_command_properties command_properties[] = { - [RUN_AS_MKDIR] = { + { .in_fds_offset = offsetof(struct run_as_data, u.mkdir.dirfd), - .in_fd_count = 1, .out_fds_offset = -1, + .in_fd_count = 1, .out_fd_count = 0, .use_cwd_fd = true, }, - [RUN_AS_MKDIRAT] = { + { .in_fds_offset = offsetof(struct run_as_data, u.mkdir.dirfd), - .in_fd_count = 1, .out_fds_offset = -1, + .in_fd_count = 1, .out_fd_count = 0, .use_cwd_fd = false, }, - [RUN_AS_MKDIR_RECURSIVE] = { + { .in_fds_offset = offsetof(struct run_as_data, u.mkdir.dirfd), - .in_fd_count = 1, .out_fds_offset = -1, + .in_fd_count = 1, .out_fd_count = 0, .use_cwd_fd = true, }, - [RUN_AS_MKDIRAT_RECURSIVE] = { + { .in_fds_offset = offsetof(struct run_as_data, u.mkdir.dirfd), - .in_fd_count = 1, .out_fds_offset = -1, + .in_fd_count = 1, .out_fd_count = 0, .use_cwd_fd = false, }, - [RUN_AS_OPEN] = { + { .in_fds_offset = offsetof(struct run_as_data, u.open.dirfd), - .in_fd_count = 1, .out_fds_offset = offsetof(struct run_as_ret, u.open.fd), + .in_fd_count = 1, .out_fd_count = 1, .use_cwd_fd = true, }, - [RUN_AS_OPENAT] = { + { .in_fds_offset = offsetof(struct run_as_data, u.open.dirfd), - .in_fd_count = 1, .out_fds_offset = offsetof(struct run_as_ret, u.open.fd), + .in_fd_count = 1, .out_fd_count = 1, .use_cwd_fd = false, }, - [RUN_AS_UNLINK] = { + { .in_fds_offset = offsetof(struct run_as_data, u.unlink.dirfd), - .in_fd_count = 1, .out_fds_offset = -1, + .in_fd_count = 1, .out_fd_count = 0, .use_cwd_fd = true, }, - [RUN_AS_UNLINKAT] = { + { .in_fds_offset = offsetof(struct run_as_data, u.unlink.dirfd), - .in_fd_count = 1, .out_fds_offset = -1, + .in_fd_count = 1, .out_fd_count = 0, .use_cwd_fd = false, }, - [RUN_AS_RMDIR_RECURSIVE] = { + { .in_fds_offset = offsetof(struct run_as_data, u.rmdir.dirfd), - .in_fd_count = 1, .out_fds_offset = -1, + .in_fd_count = 1, .out_fd_count = 0, .use_cwd_fd = true, }, - [RUN_AS_RMDIRAT_RECURSIVE] = { + { .in_fds_offset = offsetof(struct run_as_data, u.rmdir.dirfd), - .in_fd_count = 1, .out_fds_offset = -1, + .in_fd_count = 1, .out_fd_count = 0, .use_cwd_fd = false, }, - [RUN_AS_RMDIR] = { + { .in_fds_offset = offsetof(struct run_as_data, u.rmdir.dirfd), - .in_fd_count = 1, .out_fds_offset = -1, + .in_fd_count = 1, .out_fd_count = 0, .use_cwd_fd = true, }, - [RUN_AS_RMDIRAT] = { + { .in_fds_offset = offsetof(struct run_as_data, u.rmdir.dirfd), - .in_fd_count = 1, .out_fds_offset = -1, + .in_fd_count = 1, .out_fd_count = 0, .use_cwd_fd = false, }, - [RUN_AS_RENAME] = { + { .in_fds_offset = offsetof(struct run_as_data, u.rename.dirfds), - .in_fd_count = 2, .out_fds_offset = -1, + .in_fd_count = 2, .out_fd_count = 0, .use_cwd_fd = true, }, - [RUN_AS_RENAMEAT] = { + { .in_fds_offset = offsetof(struct run_as_data, u.rename.dirfds), - .in_fd_count = 2, .out_fds_offset = -1, + .in_fd_count = 2, .out_fd_count = 0, .use_cwd_fd = false, }, - [RUN_AS_EXTRACT_ELF_SYMBOL_OFFSET] = { + { .in_fds_offset = offsetof(struct run_as_data, u.extract_elf_symbol_offset.fd), - .in_fd_count = 1, .out_fds_offset = -1, + .in_fd_count = 1, .out_fd_count = 0, .use_cwd_fd = false, }, - [RUN_AS_EXTRACT_SDT_PROBE_OFFSETS] = { + { .in_fds_offset = offsetof(struct run_as_data, u.extract_sdt_probe_offsets.fd), - .in_fd_count = 1, .out_fds_offset = -1, + .in_fd_count = 1, .out_fd_count = 0, .use_cwd_fd = false, }, - [RUN_AS_GENERATE_FILTER_BYTECODE] = { + { .in_fds_offset = -1, - .in_fd_count = 0, .out_fds_offset = -1, + .in_fd_count = 0, .out_fd_count = 0, .use_cwd_fd = false, }, }; -struct run_as_worker { +struct run_as_worker_data { pid_t pid; /* Worker PID. */ int sockpair[2]; char *procname; }; /* Single global worker per process (for now). */ -static struct run_as_worker *global_worker; +static run_as_worker_data *global_worker; /* Lock protecting the worker. */ static pthread_mutex_t worker_lock = PTHREAD_MUTEX_INITIALIZER; @@ -771,7 +771,7 @@ end: } static -int send_fds_to_worker(const struct run_as_worker *worker, +int send_fds_to_worker(const run_as_worker_data *worker, const struct run_as_data *data) { int ret = 0; @@ -802,7 +802,7 @@ end: } static -int send_fds_to_master(struct run_as_worker *worker, enum run_as_cmd cmd, +int send_fds_to_master(run_as_worker_data *worker, enum run_as_cmd cmd, struct run_as_ret *run_as_ret) { int ret = 0; @@ -835,7 +835,7 @@ end: } static -int recv_fds_from_worker(const struct run_as_worker *worker, enum run_as_cmd cmd, +int recv_fds_from_worker(const run_as_worker_data *worker, enum run_as_cmd cmd, struct run_as_ret *run_as_ret) { int ret = 0; @@ -855,7 +855,7 @@ end: } static -int recv_fds_from_master(struct run_as_worker *worker, struct run_as_data *data) +int recv_fds_from_master(run_as_worker_data *worker, struct run_as_data *data) { int ret = 0; @@ -928,7 +928,7 @@ static int get_user_infos_from_uid( get_pw_buf_size = (size_t) raw_get_pw_buf_size; - buf = zmalloc(get_pw_buf_size); + buf = (char *) zmalloc(get_pw_buf_size); if (buf == NULL) { PERROR("Failed to allocate buffer to get password file entries"); goto error; @@ -1096,7 +1096,7 @@ end: * Return < 0 on error, 0 if OK, 1 on hangup. */ static -int handle_one_cmd(struct run_as_worker *worker) +int handle_one_cmd(run_as_worker_data *worker) { int ret = 0, promote_ret; struct run_as_data data = {}; @@ -1201,7 +1201,7 @@ end: } static -int run_as_worker(struct run_as_worker *worker) +int run_as_worker(run_as_worker_data *worker) { int ret; ssize_t writelen; @@ -1248,7 +1248,7 @@ end: } static -int run_as_cmd(struct run_as_worker *worker, +int run_as_cmd(run_as_worker_data *worker, enum run_as_cmd cmd, struct run_as_data *data, struct run_as_ret *ret_value, @@ -1445,7 +1445,7 @@ int run_as_create_worker_no_lock(const char *procname, int i, ret = 0; ssize_t readlen; struct run_as_ret recvret; - struct run_as_worker *worker; + run_as_worker_data *worker; LTTNG_ASSERT(!global_worker); if (!use_clone()) { @@ -1456,7 +1456,7 @@ int run_as_create_worker_no_lock(const char *procname, ret = 0; goto end; } - worker = zmalloc(sizeof(*worker)); + worker = (run_as_worker_data *) zmalloc(sizeof(*worker)); if (!worker) { ret = -ENOMEM; goto end; @@ -1567,7 +1567,7 @@ error_procname_alloc: static void run_as_destroy_worker_no_lock(void) { - struct run_as_worker *worker = global_worker; + run_as_worker_data *worker = global_worker; DBG("Destroying run_as worker"); if (!worker) { @@ -1610,7 +1610,7 @@ void run_as_destroy_worker_no_lock(void) } static -int run_as_restart_worker(struct run_as_worker *worker) +int run_as_restart_worker(run_as_worker_data *worker) { int ret = 0; char *procname = NULL; @@ -1850,9 +1850,9 @@ error: return ret; } -int run_as_rename(const char *old, const char *new, uid_t uid, gid_t gid) +int run_as_rename(const char *old_name, const char *new_name, uid_t uid, gid_t gid) { - return run_as_renameat(AT_FDCWD, old, AT_FDCWD, new, uid, gid); + return run_as_renameat(AT_FDCWD, old_name, AT_FDCWD, new_name, uid, gid); } int run_as_renameat(int old_dirfd, const char *old_name, @@ -1957,7 +1957,7 @@ int run_as_extract_sdt_probe_offsets(int fd, const char* provider_name, } *num_offset = run_as_ret.u.extract_sdt_probe_offsets.num_offset; - *offsets = zmalloc(*num_offset * sizeof(uint64_t)); + *offsets = (uint64_t *) zmalloc(*num_offset * sizeof(uint64_t)); if (!*offsets) { ret = -ENOMEM; goto error; @@ -1999,7 +1999,7 @@ int run_as_generate_filter_bytecode(const char *filter_expression, view_bytecode = (const struct lttng_bytecode *) run_as_ret.u.generate_filter_bytecode.bytecode; - local_bytecode = zmalloc(sizeof(*local_bytecode) + view_bytecode->len); + local_bytecode = (lttng_bytecode *) zmalloc(sizeof(*local_bytecode) + view_bytecode->len); if (!local_bytecode) { ret = -ENOMEM; goto error; diff --git a/src/common/session-descriptor.c b/src/common/session-descriptor.cpp similarity index 97% rename from src/common/session-descriptor.c rename to src/common/session-descriptor.cpp index 93c7dfa47..ec510b0c6 100644 --- a/src/common/session-descriptor.c +++ b/src/common/session-descriptor.cpp @@ -71,7 +71,7 @@ struct lttng_uri *uri_copy(const struct lttng_uri *uri) goto end; } - new_uri = zmalloc(sizeof(*new_uri)); + new_uri = (lttng_uri *) zmalloc(sizeof(*new_uri)); if (!new_uri) { goto end; } @@ -179,8 +179,8 @@ int network_location_set_from_uri_strings( * session descriptors expect individually allocated lttng_uris. */ if (uri_count == 2) { - control_uri = zmalloc(sizeof(*control_uri)); - data_uri = zmalloc(sizeof(*data_uri)); + control_uri = (lttng_uri *) zmalloc(sizeof(*control_uri)); + data_uri = (lttng_uri *) zmalloc(sizeof(*data_uri)); if (!control_uri || !data_uri) { ret = -1; goto end; @@ -208,7 +208,7 @@ lttng_session_descriptor_create(const char *name) { struct lttng_session_descriptor *descriptor; - descriptor = zmalloc(sizeof(*descriptor)); + descriptor = (lttng_session_descriptor *) zmalloc(sizeof(*descriptor)); if (!descriptor) { goto error; } @@ -334,7 +334,7 @@ _lttng_session_descriptor_snapshot_create(const char *name) { struct lttng_session_descriptor_snapshot *descriptor; - descriptor = zmalloc(sizeof(*descriptor)); + descriptor = (lttng_session_descriptor_snapshot *) zmalloc(sizeof(*descriptor)); if (!descriptor) { goto error; } @@ -477,7 +477,7 @@ _lttng_session_descriptor_live_create(const char *name, if (live_timer_interval_us == 0) { goto error; } - descriptor = zmalloc(sizeof(*descriptor)); + descriptor = (lttng_session_descriptor_live *) zmalloc(sizeof(*descriptor)); if (!descriptor) { goto error; } @@ -644,7 +644,7 @@ ssize_t lttng_session_descriptor_create_from_buffer( goto end; } /* type has been validated. */ - type = base_header->type; + type = (lttng_session_descriptor_type) base_header->type; switch (base_header->output_type) { case LTTNG_SESSION_DESCRIPTOR_OUTPUT_TYPE_NONE: @@ -661,7 +661,7 @@ ssize_t lttng_session_descriptor_create_from_buffer( goto end; } /* output_type has been validated. */ - output_type = base_header->output_type; + output_type = (lttng_session_descriptor_output_type) base_header->output_type; /* Skip after header. */ offset += current_view.size; @@ -709,7 +709,7 @@ skip_name: } uri = (typeof(uri)) current_view.data; - uris[i] = zmalloc(sizeof(*uri)); + uris[i] = (lttng_uri *) zmalloc(sizeof(*uri)); if (!uris[i]) { ret = -1; goto end; @@ -811,10 +811,12 @@ int lttng_session_descriptor_serialize( size_t uri_count = 0; /* The live header is a superset of all headers. */ struct lttng_session_descriptor_live_comm header = { - .base.type = (uint8_t) descriptor->type, - .base.output_type = (uint8_t) descriptor->output_type, - .base.name_len = descriptor->name ? - strlen(descriptor->name) + 1 : 0, + .base = { + .type = (uint8_t) descriptor->type, + .output_type = (uint8_t) descriptor->output_type, + .name_len = (uint32_t) (descriptor->name ? + strlen(descriptor->name) + 1 : 0), + } }; const void *header_ptr = NULL; size_t header_size; diff --git a/src/common/shm.c b/src/common/shm.cpp similarity index 98% rename from src/common/shm.c rename to src/common/shm.cpp index c006258c7..99535c468 100644 --- a/src/common/shm.c +++ b/src/common/shm.cpp @@ -177,7 +177,7 @@ char *shm_ust_get_mmap(char *shm_path, int global) goto error; } - wait_shm_mmap = mmap(NULL, mmap_size, PROT_WRITE | PROT_READ, + wait_shm_mmap = (char *) mmap(NULL, mmap_size, PROT_WRITE | PROT_READ, MAP_SHARED, wait_shm_fd, 0); /* close shm fd immediately after taking the mmap reference */ diff --git a/src/common/snapshot.c b/src/common/snapshot.cpp similarity index 100% rename from src/common/snapshot.c rename to src/common/snapshot.cpp diff --git a/src/common/spawn-viewer.c b/src/common/spawn-viewer.cpp similarity index 98% rename from src/common/spawn-viewer.c rename to src/common/spawn-viewer.cpp index 52be70526..bcbc229a2 100644 --- a/src/common/spawn-viewer.c +++ b/src/common/spawn-viewer.cpp @@ -85,7 +85,7 @@ static char **alloc_argv_from_user_opts(char *opts, const char *trace_path) } while (*token != '\0'); /* Add two here for the NULL terminating element and trace path */ - argv = zmalloc(sizeof(char *) * (num_opts + 2)); + argv = (char **) zmalloc(sizeof(char *) * (num_opts + 2)); if (argv == NULL) { goto error; } @@ -141,7 +141,7 @@ static char **alloc_argv_from_local_opts(const char **opts, size_t opts_len, size = sizeof(char *) * mem_len; /* Add two here for the trace_path and the NULL terminating element. */ - argv = zmalloc(size); + argv = (char **) zmalloc(size); if (argv == NULL) { goto error; } diff --git a/src/common/thread.c b/src/common/thread.cpp similarity index 100% rename from src/common/thread.c rename to src/common/thread.cpp diff --git a/src/common/time.c b/src/common/time.cpp similarity index 97% rename from src/common/time.c rename to src/common/time.cpp index ccb587474..a08358ffc 100644 --- a/src/common/time.c +++ b/src/common/time.cpp @@ -16,6 +16,7 @@ #include #include #include +#include static bool utf8_output_supported; @@ -49,7 +50,7 @@ struct timespec timespec_abs_diff(struct timespec t1, struct timespec t2) (uint64_t) t1.tv_nsec; uint64_t ts2 = (uint64_t) t2.tv_sec * (uint64_t) NSEC_PER_SEC + (uint64_t) t2.tv_nsec; - uint64_t diff = max(ts1, ts2) - min(ts1, ts2); + uint64_t diff = std::max(ts1, ts2) - std::min(ts1, ts2); struct timespec res; res.tv_sec = diff / (uint64_t) NSEC_PER_SEC; diff --git a/src/common/trace-chunk.c b/src/common/trace-chunk.cpp similarity index 95% rename from src/common/trace-chunk.c rename to src/common/trace-chunk.cpp index d04d51637..eed3d558b 100644 --- a/src/common/trace-chunk.c +++ b/src/common/trace-chunk.cpp @@ -153,24 +153,38 @@ int fs_handle_untracked_unlink(struct fs_handle *handle); static int fs_handle_untracked_close(struct fs_handle *handle); -static const -char *close_command_names[] = { - [LTTNG_TRACE_CHUNK_COMMAND_TYPE_MOVE_TO_COMPLETED] = - "move to completed chunk folder", - [LTTNG_TRACE_CHUNK_COMMAND_TYPE_NO_OPERATION] = - "no operation", - [LTTNG_TRACE_CHUNK_COMMAND_TYPE_DELETE] = - "delete", +static +const char *lttng_trace_chunk_command_type_str( + lttng_trace_chunk_command_type type) { + switch (type) { + case LTTNG_TRACE_CHUNK_COMMAND_TYPE_MOVE_TO_COMPLETED: + return "move to completed chunk folder"; + case LTTNG_TRACE_CHUNK_COMMAND_TYPE_NO_OPERATION: + return "no operation"; + case LTTNG_TRACE_CHUNK_COMMAND_TYPE_DELETE: + return "delete"; + case LTTNG_TRACE_CHUNK_COMMAND_TYPE_MAX: + abort(); + } + + abort(); }; -static const -chunk_command close_command_post_release_funcs[] = { - [LTTNG_TRACE_CHUNK_COMMAND_TYPE_MOVE_TO_COMPLETED] = - lttng_trace_chunk_move_to_completed_post_release, - [LTTNG_TRACE_CHUNK_COMMAND_TYPE_NO_OPERATION] = - lttng_trace_chunk_no_operation, - [LTTNG_TRACE_CHUNK_COMMAND_TYPE_DELETE] = - lttng_trace_chunk_delete_post_release, +static +const chunk_command close_command_get_post_release_func( + lttng_trace_chunk_command_type type) { + switch (type) { + case LTTNG_TRACE_CHUNK_COMMAND_TYPE_MOVE_TO_COMPLETED: + return lttng_trace_chunk_move_to_completed_post_release; + case LTTNG_TRACE_CHUNK_COMMAND_TYPE_NO_OPERATION: + return lttng_trace_chunk_no_operation; + case LTTNG_TRACE_CHUNK_COMMAND_TYPE_DELETE: + return lttng_trace_chunk_delete_post_release; + case LTTNG_TRACE_CHUNK_COMMAND_TYPE_MAX: + abort(); + } + + abort(); }; static @@ -189,7 +203,7 @@ struct fs_handle *fs_handle_untracked_create( goto end; } - handle = zmalloc(sizeof(typeof(*handle))); + handle = (fs_handle_untracked *) zmalloc(sizeof(typeof(*handle))); if (!handle) { PERROR("Failed to allocate untracked filesystem handle"); goto end; @@ -332,7 +346,7 @@ char *generate_chunk_name(uint64_t chunk_id, time_t creation_timestamp, goto error; } } - new_name = zmalloc(GENERATED_CHUNK_NAME_LEN); + new_name = (char *) zmalloc(GENERATED_CHUNK_NAME_LEN); if (!new_name) { ERR("Failed to allocate buffer for automatically-generated trace chunk name"); goto error; @@ -385,7 +399,7 @@ struct lttng_trace_chunk *lttng_trace_chunk_allocate(void) { struct lttng_trace_chunk *chunk = NULL; - chunk = zmalloc(sizeof(*chunk)); + chunk = (lttng_trace_chunk *) zmalloc(sizeof(*chunk)); if (!chunk) { ERR("Failed to allocate trace chunk"); goto end; @@ -838,7 +852,7 @@ enum lttng_trace_chunk_status lttng_trace_chunk_rename_path_no_lock( /* Move toplevel directories. */ for (i = 0; i < count; i++) { const char *top_level_name = - lttng_dynamic_pointer_array_get_pointer( + (const char *) lttng_dynamic_pointer_array_get_pointer( &chunk->top_level_directories, i); ret = lttng_directory_handle_rename_as_user( @@ -876,7 +890,7 @@ enum lttng_trace_chunk_status lttng_trace_chunk_rename_path_no_lock( /* Move toplevel directories. */ for (i = 0; i < count; i++) { const char *top_level_name = - lttng_dynamic_pointer_array_get_pointer( + (const char *) lttng_dynamic_pointer_array_get_pointer( &chunk->top_level_directories, i); ret = lttng_directory_handle_rename_as_user( @@ -904,7 +918,7 @@ enum lttng_trace_chunk_status lttng_trace_chunk_rename_path_no_lock( rename_directory = NULL; /* Remove old directory. */ - status = lttng_directory_handle_remove_subdirectory( + status = (lttng_trace_chunk_status) lttng_directory_handle_remove_subdirectory( chunk->session_output_directory, old_path); if (status != LTTNG_TRACE_CHUNK_STATUS_OK) { @@ -972,8 +986,8 @@ enum lttng_trace_chunk_status lttng_trace_chunk_set_credentials( { enum lttng_trace_chunk_status status = LTTNG_TRACE_CHUNK_STATUS_OK; const struct chunk_credentials credentials = { - .user = *user_credentials, .use_current_user = false, + .user = *user_credentials, }; pthread_mutex_lock(&chunk->lock); @@ -1162,7 +1176,7 @@ int add_top_level_directory_unique(struct lttng_trace_chunk *chunk, new_path_separator_pos - new_path : strlen(new_path); for (i = 0; i < count; i++) { - const char *path = lttng_dynamic_pointer_array_get_pointer( + const char *path = (const char *) lttng_dynamic_pointer_array_get_pointer( &chunk->top_level_directories, i); const ptrdiff_t path_top_level_len = strlen(path); @@ -1268,8 +1282,8 @@ bool lttng_trace_chunk_find_file(struct lttng_trace_chunk *chunk, count = lttng_dynamic_pointer_array_get_count(&chunk->files); for (i = 0; i < count; i++) { const char *iter_path = - lttng_dynamic_pointer_array_get_pointer( - &chunk->files, i); + (const char *) lttng_dynamic_pointer_array_get_pointer( + &chunk->files, i); if (!strcmp(iter_path, path)) { if (index) { *index = i; @@ -1644,10 +1658,10 @@ int lttng_trace_chunk_delete_post_release_user( const char *path; /* Remove first. */ - path = lttng_dynamic_pointer_array_get_pointer( - &trace_chunk->files, 0); + path = (const char *) lttng_dynamic_pointer_array_get_pointer( + &trace_chunk->files, 0); DBG("Unlink file: %s", path); - status = lttng_trace_chunk_unlink_file(trace_chunk, path); + status = (lttng_trace_chunk_status) lttng_trace_chunk_unlink_file(trace_chunk, path); if (status != LTTNG_TRACE_CHUNK_STATUS_OK) { ERR("Error unlinking file '%s' when deleting chunk", path); ret = -1; @@ -1682,10 +1696,10 @@ int lttng_trace_chunk_delete_post_release_owner( for (i = 0; i < count; i++) { const char *top_level_name = - lttng_dynamic_pointer_array_get_pointer( - &trace_chunk->top_level_directories, i); + (const char *) lttng_dynamic_pointer_array_get_pointer( + &trace_chunk->top_level_directories, i); - status = lttng_trace_chunk_remove_subdirectory_recursive(trace_chunk, top_level_name); + status = (lttng_trace_chunk_status) lttng_trace_chunk_remove_subdirectory_recursive(trace_chunk, top_level_name); if (status != LTTNG_TRACE_CHUNK_STATUS_OK) { ERR("Error recursively removing subdirectory '%s' file when deleting chunk", top_level_name); @@ -1698,7 +1712,7 @@ int lttng_trace_chunk_delete_post_release_owner( trace_chunk->chunk_directory = NULL; if (trace_chunk->path && trace_chunk->path[0] != '\0') { - status = lttng_directory_handle_remove_subdirectory( + status = (lttng_trace_chunk_status) lttng_directory_handle_remove_subdirectory( trace_chunk->session_output_directory, trace_chunk->path); if (status != LTTNG_TRACE_CHUNK_STATUS_OK) { @@ -1767,11 +1781,11 @@ enum lttng_trace_chunk_status lttng_trace_chunk_set_close_command( pthread_mutex_lock(&chunk->lock); if (chunk->close_command.is_set) { DBG("Overriding trace chunk close command from \"%s\" to \"%s\"", - close_command_names[chunk->close_command.value], - close_command_names[close_command]); + lttng_trace_chunk_command_type_str(chunk->close_command.value), + lttng_trace_chunk_command_type_str(close_command)); } else { DBG("Setting trace chunk close command to \"%s\"", - close_command_names[close_command]); + lttng_trace_chunk_command_type_str(close_command)); } /* * Unset close command for no-op for backward compatibility with relayd @@ -1854,10 +1868,11 @@ void lttng_trace_chunk_release(struct urcu_ref *ref) ref); if (chunk->close_command.is_set) { - if (close_command_post_release_funcs[ - chunk->close_command.value](chunk)) { + chunk_command func = close_command_get_post_release_func(chunk->close_command.value); + + if (func(chunk)) { ERR("Trace chunk post-release command %s has failed.", - close_command_names[chunk->close_command.value]); + lttng_trace_chunk_command_type_str(chunk->close_command.value)); } } @@ -1897,7 +1912,7 @@ struct lttng_trace_chunk_registry *lttng_trace_chunk_registry_create(void) { struct lttng_trace_chunk_registry *registry; - registry = zmalloc(sizeof(*registry)); + registry = (lttng_trace_chunk_registry *) zmalloc(sizeof(*registry)); if (!registry) { goto end; } @@ -1933,7 +1948,7 @@ lttng_trace_chunk_registry_element_create_from_chunk( struct lttng_trace_chunk *chunk, uint64_t session_id) { struct lttng_trace_chunk_registry_element *element = - zmalloc(sizeof(*element)); + (lttng_trace_chunk_registry_element *) zmalloc(sizeof(*element)); if (!element) { goto end; @@ -2034,7 +2049,7 @@ lttng_trace_chunk_registry_publish_chunk( } /* * A reference to the previously published trace chunk could not - * be acquired. Hence, retry to publish our copy of the trace + * be acquired. Hence, retry to publish our copy of the trace * chunk. */ } @@ -2057,11 +2072,12 @@ struct lttng_trace_chunk *_lttng_trace_chunk_registry_find_chunk( const struct lttng_trace_chunk_registry *registry, uint64_t session_id, uint64_t *chunk_id) { - const struct lttng_trace_chunk_registry_element target_element = { - .chunk.id.is_set = !!chunk_id, - .chunk.id.value = chunk_id ? *chunk_id : 0, - .session_id = session_id, - }; + lttng_trace_chunk_registry_element target_element {}; + + target_element.chunk.id.is_set = !!chunk_id; + target_element.chunk.id.value = chunk_id ? *chunk_id : 0; + target_element.session_id = session_id; + const unsigned long element_hash = lttng_trace_chunk_registry_element_hash( &target_element); @@ -2106,11 +2122,12 @@ int lttng_trace_chunk_registry_chunk_exists( uint64_t session_id, uint64_t chunk_id, bool *chunk_exists) { int ret = 0; - const struct lttng_trace_chunk_registry_element target_element = { - .chunk.id.is_set = true, - .chunk.id.value = chunk_id, - .session_id = session_id, - }; + lttng_trace_chunk_registry_element target_element; + + target_element.chunk.id.is_set = true; + target_element.chunk.id.value = chunk_id; + target_element.session_id = session_id; + const unsigned long element_hash = lttng_trace_chunk_registry_element_hash( &target_element); diff --git a/src/common/tracker.c b/src/common/tracker.cpp similarity index 97% rename from src/common/tracker.c rename to src/common/tracker.cpp index f3a9f258b..84b6c6b8f 100644 --- a/src/common/tracker.c +++ b/src/common/tracker.cpp @@ -69,7 +69,7 @@ enum lttng_error_code process_attr_value_from_comm( { char *name = NULL; enum lttng_error_code ret = LTTNG_OK; - struct process_attr_value *value = zmalloc(sizeof(*value)); + struct process_attr_value *value = (process_attr_value *) zmalloc(sizeof(*value)); if (!value) { ret = LTTNG_ERR_NOMEM; @@ -212,7 +212,7 @@ static void process_attr_tracker_value_destructor(void *ptr) struct lttng_process_attr_values *lttng_process_attr_values_create(void) { - struct lttng_process_attr_values *values = zmalloc(sizeof(*values)); + struct lttng_process_attr_values *values = (lttng_process_attr_values *) zmalloc(sizeof(*values)); if (!values) { goto end; @@ -235,7 +235,7 @@ const struct process_attr_value *lttng_process_attr_tracker_values_get_at_index( const struct lttng_process_attr_values *values, unsigned int index) { - return lttng_dynamic_pointer_array_get_pointer(&values->array, index); + return (process_attr_value *) lttng_dynamic_pointer_array_get_pointer(&values->array, index); } static @@ -423,7 +423,7 @@ struct process_attr_value *process_attr_value_copy( goto end; } - new_value = zmalloc(sizeof(*new_value)); + new_value = (process_attr_value *) zmalloc(sizeof(*new_value)); if (!new_value) { goto end; } diff --git a/src/common/trigger.c b/src/common/trigger.cpp similarity index 99% rename from src/common/trigger.c rename to src/common/trigger.cpp index 76082a085..3782f49ca 100644 --- a/src/common/trigger.c +++ b/src/common/trigger.cpp @@ -55,7 +55,7 @@ struct lttng_trigger *lttng_trigger_create( goto end; } - trigger = zmalloc(sizeof(struct lttng_trigger)); + trigger = (lttng_trigger *) zmalloc(sizeof(struct lttng_trigger)); if (!trigger) { goto end; } @@ -495,7 +495,7 @@ void lttng_trigger_put(struct lttng_trigger *trigger) static void delete_trigger_array_element(void *ptr) { - struct lttng_trigger *trigger = ptr; + struct lttng_trigger *trigger = (lttng_trigger *) ptr; lttng_trigger_put(trigger); } @@ -504,7 +504,7 @@ struct lttng_triggers *lttng_triggers_create(void) { struct lttng_triggers *triggers = NULL; - triggers = zmalloc(sizeof(*triggers)); + triggers = (lttng_triggers *) zmalloc(sizeof(*triggers)); if (!triggers) { goto end; } diff --git a/src/common/unix.c b/src/common/unix.cpp similarity index 99% rename from src/common/unix.c rename to src/common/unix.cpp index 9918db2e6..504970ea8 100644 --- a/src/common/unix.c +++ b/src/common/unix.cpp @@ -189,7 +189,7 @@ ssize_t lttcomm_recv_unix_sock(int sock, void *buf, size_t len) len_last = iov[0].iov_len; ret = lttng_recvmsg_nosigpipe(sock, &msg); if (ret > 0) { - iov[0].iov_base += ret; + iov[0].iov_base = (char *) iov[0].iov_base + ret; iov[0].iov_len -= ret; LTTNG_ASSERT(ret <= len_last); } @@ -299,7 +299,7 @@ ssize_t lttcomm_send_unix_sock(int sock, const void *buf, size_t len) } } iov[0].iov_len -= ret; - iov[0].iov_base += ret; + iov[0].iov_base = (char *) iov[0].iov_base + ret; } ret = len; end: @@ -1066,7 +1066,7 @@ ssize_t lttcomm_recv_creds_unix_sock(int sock, void *buf, size_t len, len_last = iov[0].iov_len; ret = recvmsg(sock, &msg, 0); if (ret > 0) { - iov[0].iov_base += ret; + iov[0].iov_base = (char *) iov[0].iov_base + ret; iov[0].iov_len -= ret; LTTNG_ASSERT(ret <= len_last); } diff --git a/src/common/uri.c b/src/common/uri.cpp similarity index 98% rename from src/common/uri.c rename to src/common/uri.cpp index fef21b38d..b1c2c63d0 100644 --- a/src/common/uri.c +++ b/src/common/uri.cpp @@ -35,7 +35,7 @@ struct uri_proto { /* Supported protocols */ static const struct uri_proto proto_uri[] = { - { .name = "file", .leading_string = "file://", .code = P_FILE, .type = 0, .dtype = LTTNG_DST_PATH }, + { .name = "file", .leading_string = "file://", .code = P_FILE, .type = LTTNG_PROTO_TYPE_NONE, .dtype = LTTNG_DST_PATH }, { .name = "net", .leading_string = "net://", .code = P_NET, .type = LTTNG_TCP, .dtype = LTTNG_DST_IPV4 }, { .name = "net4", .leading_string = "net4://", .code = P_NET, .type = LTTNG_TCP, .dtype = LTTNG_DST_IPV4 }, { .name = "net6", .leading_string = "net6://", .code = P_NET6, .type = LTTNG_TCP, .dtype = LTTNG_DST_IPV6 }, @@ -43,7 +43,7 @@ static const struct uri_proto proto_uri[] = { { .name = "tcp4", .leading_string = "tcp4://", .code = P_TCP, .type = LTTNG_TCP, .dtype = LTTNG_DST_IPV4 }, { .name = "tcp6", .leading_string = "tcp6://", .code = P_TCP6, .type = LTTNG_TCP, .dtype = LTTNG_DST_IPV6 }, /* Invalid proto marking the end of the array. */ - { NULL, NULL, 0, 0, 0 } + { 0 } }; /* @@ -52,9 +52,9 @@ static const struct uri_proto proto_uri[] = { */ static inline const char *strpbrk_or_eos(const char *s, const char *accept) { - char *p = strpbrk(s, accept); + char *p = (char *) strpbrk(s, accept); if (p == NULL) { - p = strchr(s, '\0'); + p = (char *) strchr(s, '\0'); } return p; @@ -306,7 +306,7 @@ ssize_t uri_parse(const char *str_uri, struct lttng_uri **uris) } /* Allocate URI array */ - tmp_uris = zmalloc(sizeof(struct lttng_uri) * size); + tmp_uris = (lttng_uri *) zmalloc(sizeof(struct lttng_uri) * size); if (tmp_uris == NULL) { PERROR("zmalloc uri"); goto error; @@ -634,7 +634,7 @@ ssize_t uri_parse_str_urls(const char *ctrl_url, const char *data_url, goto error; } - tmp_uris = zmalloc(sizeof(struct lttng_uri) * uri_count); + tmp_uris = (lttng_uri *) zmalloc(sizeof(struct lttng_uri) * uri_count); if (tmp_uris == NULL) { PERROR("zmalloc uris"); goto error; diff --git a/src/common/uri.h b/src/common/uri.h index a270db9d9..3a02dda5c 100644 --- a/src/common/uri.h +++ b/src/common/uri.h @@ -44,6 +44,7 @@ enum lttng_stream_type { * should be ignored. */ enum lttng_proto_type { + LTTNG_PROTO_TYPE_NONE = 0, LTTNG_TCP = 1, /* * UDP protocol is not supported for now. diff --git a/src/common/userspace-probe.c b/src/common/userspace-probe.cpp similarity index 99% rename from src/common/userspace-probe.c rename to src/common/userspace-probe.cpp index 084fec5c4..4ade5d84f 100644 --- a/src/common/userspace-probe.c +++ b/src/common/userspace-probe.cpp @@ -72,7 +72,7 @@ lttng_userspace_probe_location_lookup_method_function_elf_create(void) struct lttng_userspace_probe_location_lookup_method *ret = NULL; struct lttng_userspace_probe_location_lookup_method_elf *elf_method; - elf_method = zmalloc(sizeof(*elf_method)); + elf_method = (lttng_userspace_probe_location_lookup_method_elf *) zmalloc(sizeof(*elf_method)); if (!elf_method) { PERROR("zmalloc"); goto end; @@ -90,7 +90,7 @@ lttng_userspace_probe_location_lookup_method_tracepoint_sdt_create(void) struct lttng_userspace_probe_location_lookup_method *ret = NULL; struct lttng_userspace_probe_location_lookup_method_sdt *sdt_method; - sdt_method = zmalloc(sizeof(*sdt_method)); + sdt_method = (lttng_userspace_probe_location_lookup_method_sdt *) zmalloc(sizeof(*sdt_method)); if (!sdt_method) { PERROR("zmalloc"); goto end; @@ -311,7 +311,7 @@ lttng_userspace_probe_location_function_create_no_check(const char *binary_path, goto error; } - location = zmalloc(sizeof(*location)); + location = (lttng_userspace_probe_location_function *) zmalloc(sizeof(*location)); if (!location) { PERROR("Error allocating userspace probe location"); goto error; @@ -448,7 +448,7 @@ lttng_userspace_probe_location_tracepoint_create_no_check(const char *binary_pat goto error; } - location = zmalloc(sizeof(*location)); + location = (lttng_userspace_probe_location_tracepoint *) zmalloc(sizeof(*location)); if (!location) { PERROR("zmalloc"); goto error; @@ -547,7 +547,7 @@ lttng_userspace_probe_location_lookup_method_function_elf_copy( LTTNG_ASSERT(lookup_method->type == LTTNG_USERSPACE_PROBE_LOCATION_LOOKUP_METHOD_TYPE_FUNCTION_ELF); - elf_method = zmalloc(sizeof(*elf_method)); + elf_method = (lttng_userspace_probe_location_lookup_method_elf *) zmalloc(sizeof(*elf_method)); if (!elf_method) { PERROR("Error allocating ELF userspace probe lookup method"); goto error; @@ -574,7 +574,7 @@ lttng_userspace_probe_location_lookup_method_tracepoint_sdt_copy( LTTNG_ASSERT(lookup_method->type == LTTNG_USERSPACE_PROBE_LOCATION_LOOKUP_METHOD_TYPE_TRACEPOINT_SDT); - sdt_method = zmalloc(sizeof(*sdt_method)); + sdt_method = (lttng_userspace_probe_location_lookup_method_sdt *) zmalloc(sizeof(*sdt_method)); if (!sdt_method) { PERROR("zmalloc"); goto error; @@ -1560,7 +1560,7 @@ end: static int lttng_userspace_probe_location_function_set_binary_fd_handle( struct lttng_userspace_probe_location *location, - struct fd_handle *binary_fd) + struct fd_handle *binary_fd) { int ret = 0; struct lttng_userspace_probe_location_function *function_location; diff --git a/src/common/utils.c b/src/common/utils.cpp similarity index 97% rename from src/common/utils.c rename to src/common/utils.cpp index eebed2adb..8aa4ff9f9 100644 --- a/src/common/utils.c +++ b/src/common/utils.cpp @@ -111,7 +111,7 @@ char *utils_partial_realpath(const char *path) goto error; } - try_path_buf = zmalloc(LTTNG_PATH_MAX); + try_path_buf = (char *) zmalloc(LTTNG_PATH_MAX); if (!try_path_buf) { PERROR("zmalloc"); goto error; @@ -149,7 +149,7 @@ char *utils_partial_realpath(const char *path) } /* Allocate memory for the resolved path. */ - resolved_path = zmalloc(LTTNG_PATH_MAX); + resolved_path = (char *) zmalloc(LTTNG_PATH_MAX); if (resolved_path == NULL) { PERROR("zmalloc resolved path"); goto error; @@ -230,7 +230,7 @@ int expand_double_slashes_dot_and_dotdot(char *path) break; } - next_slash = memchr(curr_char, '/', path_last_char - curr_char); + next_slash = (const char *) memchr(curr_char, '/', path_last_char - curr_char); if (next_slash == NULL) { /* Reached the end of the provided path. */ next_slash = path_last_char; @@ -271,7 +271,7 @@ int expand_double_slashes_dot_and_dotdot(char *path) * previous forward slash and substract that * len to the resulting path. */ - prev_slash = lttng_memrchr(path, '/', expanded_path_len); + prev_slash = (const char *) lttng_memrchr(path, '/', expanded_path_len); /* * If prev_slash is NULL, we reached the * beginning of the path. We can't go back any @@ -329,7 +329,7 @@ char *_utils_expand_path(const char *path, bool keep_symlink) } /* Allocate memory for the absolute_path */ - absolute_path = zmalloc(LTTNG_PATH_MAX); + absolute_path = (char *) zmalloc(LTTNG_PATH_MAX); if (absolute_path == NULL) { PERROR("zmalloc expand path"); goto error; @@ -545,7 +545,7 @@ char *utils_strdupdelim(const char *begin, const char *end) { char *str; - str = zmalloc(end - begin + 1); + str = (char *) zmalloc(end - begin + 1); if (str == NULL) { PERROR("zmalloc strdupdelim"); goto error; @@ -667,8 +667,8 @@ int utils_mkdir(const char *path, mode_t mode, int uid, int gid) int ret; struct lttng_directory_handle *handle; const struct lttng_credentials creds = { - .uid = LTTNG_OPTIONAL_INIT_VALUE(uid), - .gid = LTTNG_OPTIONAL_INIT_VALUE(gid), + .uid = LTTNG_OPTIONAL_INIT_VALUE((uid_t) uid), + .gid = LTTNG_OPTIONAL_INIT_VALUE((gid_t) gid), }; handle = lttng_directory_handle_create(NULL); @@ -695,8 +695,8 @@ int utils_mkdir_recursive(const char *path, mode_t mode, int uid, int gid) int ret; struct lttng_directory_handle *handle; const struct lttng_credentials creds = { - .uid = LTTNG_OPTIONAL_INIT_VALUE(uid), - .gid = LTTNG_OPTIONAL_INIT_VALUE(gid), + .uid = LTTNG_OPTIONAL_INIT_VALUE((uid_t) uid), + .gid = LTTNG_OPTIONAL_INIT_VALUE((gid_t) gid), }; handle = lttng_directory_handle_create(NULL); @@ -1156,7 +1156,7 @@ char *utils_get_user_home_dir(uid_t uid) goto end; } retry: - buf = zmalloc(buflen); + buf = (char *) zmalloc(buflen); if (!buf) { goto end; } @@ -1303,7 +1303,7 @@ char *utils_generate_optstring(const struct option *long_options, string_len += long_options[i].has_arg ? 1 : 0; } - optstring = zmalloc(string_len); + optstring = (char *) zmalloc(string_len); if (!optstring) { goto end; } @@ -1523,7 +1523,7 @@ enum lttng_error_code utils_user_id_from_name(const char *user_name, uid_t *uid) buflen = FALLBACK_USER_BUFLEN; } - buf = zmalloc(buflen); + buf = (char *) zmalloc(buflen); if (!buf) { ret_val = LTTNG_ERR_NOMEM; goto end; @@ -1537,7 +1537,7 @@ enum lttng_error_code utils_user_id_from_name(const char *user_name, uid_t *uid) case ERANGE: buflen *= 2; free(buf); - buf = zmalloc(buflen); + buf = (char *) zmalloc(buflen); if (!buf) { ret_val = LTTNG_ERR_NOMEM; goto end; @@ -1588,7 +1588,7 @@ enum lttng_error_code utils_group_id_from_name( buflen = FALLBACK_GROUP_BUFLEN; } - buf = zmalloc(buflen); + buf = (char *) zmalloc(buflen); if (!buf) { ret_val = LTTNG_ERR_NOMEM; goto end; @@ -1602,7 +1602,7 @@ enum lttng_error_code utils_group_id_from_name( case ERANGE: buflen *= 2; free(buf); - buf = zmalloc(buflen); + buf = (char *) zmalloc(buflen); if (!buf) { ret_val = LTTNG_ERR_NOMEM; goto end; diff --git a/src/common/uuid.c b/src/common/uuid.cpp similarity index 98% rename from src/common/uuid.c rename to src/common/uuid.cpp index 26fb61e99..77b9a767b 100644 --- a/src/common/uuid.c +++ b/src/common/uuid.cpp @@ -16,7 +16,7 @@ #include "uuid.h" -static const lttng_uuid nil_uuid; +static const lttng_uuid nil_uuid = { 0 }; static bool lttng_uuid_is_init; void lttng_uuid_to_str(const lttng_uuid uuid, char *uuid_str) diff --git a/src/common/waiter.c b/src/common/waiter.cpp similarity index 100% rename from src/common/waiter.c rename to src/common/waiter.cpp diff --git a/tests/regression/tools/notification/Makefile.am b/tests/regression/tools/notification/Makefile.am index eaab5314a..2f1a9174e 100644 --- a/tests/regression/tools/notification/Makefile.am +++ b/tests/regression/tools/notification/Makefile.am @@ -62,7 +62,7 @@ notification_LDADD = $(LIB_LTTNG_CTL) $(LIBTAP) -lm rotation_SOURCES = rotation.c rotation_LDADD = $(LIB_LTTNG_CTL) $(LIBTAP) -lm -default_pipe_size_getter_SOURCES = default_pipe_size_getter.c +default_pipe_size_getter_SOURCES = default_pipe_size_getter.cpp default_pipe_size_getter_LDADD = $(top_builddir)/src/common/libcommon.la noinst_SCRIPTS = \ diff --git a/tests/regression/tools/notification/default_pipe_size_getter.c b/tests/regression/tools/notification/default_pipe_size_getter.cpp similarity index 100% rename from tests/regression/tools/notification/default_pipe_size_getter.c rename to tests/regression/tools/notification/default_pipe_size_getter.cpp -- 2.34.1