From 66cefebdc240cbae0bc79594305f509b0779fa98 Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=A9mie=20Galarneau?= Date: Sat, 28 Jan 2023 13:18:32 -0500 Subject: [PATCH] Clean-up: replace uses of `int enabled` with boolean flags MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Jérémie Galarneau Change-Id: If9cf1b6e2db67d461479a43d8ed3c3e07c4133ba --- src/bin/lttng-sessiond/channel.cpp | 12 ++-- src/bin/lttng-sessiond/cmd.cpp | 16 +++--- src/bin/lttng-sessiond/consumer.cpp | 2 +- src/bin/lttng-sessiond/consumer.hpp | 2 +- src/bin/lttng-sessiond/event.cpp | 12 ++-- src/bin/lttng-sessiond/kernel.cpp | 10 ++-- src/bin/lttng-sessiond/session.hpp | 9 +-- src/bin/lttng-sessiond/trace-kernel.cpp | 6 +- src/bin/lttng-sessiond/trace-kernel.hpp | 8 +-- src/bin/lttng-sessiond/trace-ust.hpp | 6 +- src/bin/lttng-sessiond/ust-app.cpp | 26 ++++----- src/bin/lttng-sessiond/ust-app.hpp | 10 ++-- src/bin/lttng/commands/disable_channels.cpp | 17 +++--- src/bin/lttng/commands/disable_events.cpp | 63 +++++++++++---------- tests/unit/test_kernel_data.cpp | 4 +- tests/unit/test_ust_data.cpp | 8 +-- 16 files changed, 106 insertions(+), 105 deletions(-) diff --git a/src/bin/lttng-sessiond/channel.cpp b/src/bin/lttng-sessiond/channel.cpp index 2e7ed527d..fc2da6ab8 100644 --- a/src/bin/lttng-sessiond/channel.cpp +++ b/src/bin/lttng-sessiond/channel.cpp @@ -145,7 +145,7 @@ int channel_kernel_disable(struct ltt_kernel_session *ksession, char *channel_na } /* Only if channel is enabled disable it. */ - if (kchan->enabled == 1) { + if (kchan->enabled) { ret = kernel_disable_channel(kchan); if (ret < 0 && ret != -EEXIST) { ret = LTTNG_ERR_KERN_CHAN_DISABLE_FAIL; @@ -170,7 +170,7 @@ enum lttng_error_code channel_kernel_enable(struct ltt_kernel_session *ksession, LTTNG_ASSERT(ksession); LTTNG_ASSERT(kchan); - if (kchan->enabled == 0) { + if (!kchan->enabled) { if (kernel_enable_channel(kchan) < 0) { ret_code = LTTNG_ERR_KERN_CHAN_ENABLE_FAIL; goto error; @@ -284,7 +284,7 @@ enum lttng_error_code channel_ust_enable(struct ltt_ust_session *usess, ret_code = LTTNG_ERR_UST_CHAN_EXIST; goto end; } else { - uchan->enabled = 1; + uchan->enabled = true; DBG2("Channel %s enabled successfully", uchan->name); } @@ -425,7 +425,7 @@ enum lttng_error_code channel_ust_create(struct ltt_ust_session *usess, goto error; } - uchan->enabled = 1; + uchan->enabled = true; if (trace_ust_is_max_id(usess->used_channel_id)) { ret_code = LTTNG_ERR_UST_CHAN_FAIL; goto error; @@ -501,12 +501,12 @@ int channel_ust_disable(struct ltt_ust_session *usess, struct ltt_ust_channel *u LTTNG_ASSERT(uchan); /* Already disabled */ - if (uchan->enabled == 0) { + if (!uchan->enabled) { DBG2("Channel UST %s already disabled", uchan->name); goto end; } - uchan->enabled = 0; + uchan->enabled = false; /* * If session is inactive we don't notify the tracer right away. We diff --git a/src/bin/lttng-sessiond/cmd.cpp b/src/bin/lttng-sessiond/cmd.cpp index 8f274abcb..9ef4d379f 100644 --- a/src/bin/lttng-sessiond/cmd.cpp +++ b/src/bin/lttng-sessiond/cmd.cpp @@ -921,7 +921,7 @@ close_sock: * since the relayd connection failed thus making any tracing or/and * streaming not usable. */ - consumer->enabled = 0; + consumer->enabled = false; } (void) relayd_close(rsock); free(rsock); @@ -1149,7 +1149,7 @@ int start_kernel_session(struct ltt_kernel_session *ksess) /* Quiescent wait after starting trace */ kernel_wait_quiescent(); - ksess->active = 1; + ksess->active = true; ret = LTTNG_OK; @@ -1194,7 +1194,7 @@ int stop_kernel_session(struct ltt_kernel_session *ksess) } } - ksess->active = 0; + ksess->active = false; if (error_occurred) { ret = LTTNG_ERR_UNK; } else { @@ -2758,7 +2758,7 @@ int cmd_start_trace(struct ltt_session *session) goto error; } - session->active = 1; + session->active = true; session->rotated_after_last_stop = false; session->cleared_after_last_stop = false; if (session->output_traces && !session->current_trace_chunk) { @@ -2852,9 +2852,9 @@ int cmd_start_trace(struct ltt_session *session) error: if (ret == LTTNG_OK) { /* Flag this after a successful start. */ - session->has_been_started |= 1; + session->has_been_started = true; } else { - session->active = 0; + session->active = false; /* Restore initial state on error. */ session->rotated_after_last_stop = session_rotated_after_last_stop; session->cleared_after_last_stop = session_cleared_after_last_stop; @@ -2900,7 +2900,7 @@ int cmd_stop_trace(struct ltt_session *session) DBG("Completed stop session \"%s\" (id %" PRIu64 ")", session->name, session->id); /* Flag inactive after a successful stop. */ - session->active = 0; + session->active = false; ret = LTTNG_OK; error: @@ -3202,7 +3202,7 @@ cmd_create_session_from_descriptor(struct lttng_session_descriptor *descriptor, if (ret_code != LTTNG_OK) { goto end; } - new_session->consumer->enabled = 1; + new_session->consumer->enabled = true; ret_code = LTTNG_OK; end: /* Release reference provided by the session_create function. */ diff --git a/src/bin/lttng-sessiond/consumer.cpp b/src/bin/lttng-sessiond/consumer.cpp index eba07eb91..e84347025 100644 --- a/src/bin/lttng-sessiond/consumer.cpp +++ b/src/bin/lttng-sessiond/consumer.cpp @@ -519,7 +519,7 @@ struct consumer_output *consumer_create_output(enum consumer_dst_type type) } /* By default, consumer output is enabled */ - output->enabled = 1; + output->enabled = true; output->type = type; output->net_seq_index = (uint64_t) -1ULL; urcu_ref_init(&output->ref); diff --git a/src/bin/lttng-sessiond/consumer.hpp b/src/bin/lttng-sessiond/consumer.hpp index 6851edbf6..6875360e6 100644 --- a/src/bin/lttng-sessiond/consumer.hpp +++ b/src/bin/lttng-sessiond/consumer.hpp @@ -147,7 +147,7 @@ struct consumer_output { struct urcu_ref ref; /* Refcount */ /* If the consumer is enabled meaning that should be used */ - unsigned int enabled; + bool enabled; enum consumer_dst_type type; /* diff --git a/src/bin/lttng-sessiond/event.cpp b/src/bin/lttng-sessiond/event.cpp index e81fa9417..3976f0fce 100644 --- a/src/bin/lttng-sessiond/event.cpp +++ b/src/bin/lttng-sessiond/event.cpp @@ -128,7 +128,7 @@ int event_kernel_enable_event(struct ltt_kernel_channel *kchan, if (ret) { goto end; } - } else if (kevent->enabled == 0) { + } else if (!kevent->enabled) { ret = kernel_enable_event(kevent); if (ret < 0) { ret = LTTNG_ERR_KERN_ENABLE_FAIL; @@ -202,7 +202,7 @@ int event_ust_enable_tracepoint(struct ltt_ust_session *usess, goto end; } - uevent->enabled = 1; + uevent->enabled = true; if (to_create) { /* Add ltt ust event to channel */ add_unique_ust_event(uchan->events, uevent); @@ -285,11 +285,11 @@ int event_ust_disable_tracepoint(struct ltt_ust_session *usess, uevent = lttng::utils::container_of(node, <t_ust_event::node); LTTNG_ASSERT(uevent); - if (uevent->enabled == 0) { + if (!uevent->enabled) { /* It's already disabled so everything is OK */ goto next; } - uevent->enabled = 0; + uevent->enabled = false; DBG2("Event UST %s disabled in channel %s", uevent->attr.name, uchan->name); if (!usess->active) { @@ -331,7 +331,7 @@ int event_ust_disable_all_tracepoints(struct ltt_ust_session *usess, struct ltt_ /* Disabling existing events */ cds_lfht_for_each_entry (uchan->events->ht, &iter.iter, uevent, node.node) { - if (uevent->enabled == 1) { + if (uevent->enabled) { ret = event_ust_disable_tracepoint(usess, uchan, uevent->attr.name); if (ret < 0) { error = LTTNG_ERR_UST_DISABLE_FAIL; @@ -807,7 +807,7 @@ static int event_agent_disable_one(struct ltt_ust_session *usess, * Flag event that it's disabled so the shadow copy on the ust app side * will disable it if an application shows up. */ - uevent->enabled = 0; + uevent->enabled = false; ret = agent_disable_event(aevent, agt->domain); if (ret != LTTNG_OK) { diff --git a/src/bin/lttng-sessiond/kernel.cpp b/src/bin/lttng-sessiond/kernel.cpp index ab34f4dd0..e27de2436 100644 --- a/src/bin/lttng-sessiond/kernel.cpp +++ b/src/bin/lttng-sessiond/kernel.cpp @@ -691,7 +691,7 @@ int kernel_disable_channel(struct ltt_kernel_channel *chan) goto error; } - chan->enabled = 0; + chan->enabled = false; DBG("Kernel channel %s disabled (fd: %d, key: %" PRIu64 ")", chan->channel->name, chan->fd, @@ -718,7 +718,7 @@ int kernel_enable_channel(struct ltt_kernel_channel *chan) goto error; } - chan->enabled = 1; + chan->enabled = true; DBG("Kernel channel %s enabled (fd: %d, key: %" PRIu64 ")", chan->channel->name, chan->fd, @@ -752,7 +752,7 @@ int kernel_enable_event(struct ltt_kernel_event *event) goto error; } - event->enabled = 1; + event->enabled = true; DBG("Kernel event %s enabled (fd: %d)", event->event->name, event->fd); return 0; @@ -778,7 +778,7 @@ int kernel_disable_event(struct ltt_kernel_event *event) goto error; } - event->enabled = 0; + event->enabled = false; DBG("Kernel event %s disabled (fd: %d)", event->event->name, event->fd); return 0; @@ -808,7 +808,7 @@ static int kernel_disable_event_notifier_rule(struct ltt_kernel_event_notifier_r goto error; } - event->enabled = 0; + event->enabled = false; DBG("Disabled kernel event notifier: fd = %d, token = %" PRIu64, event->fd, event->token); error: diff --git a/src/bin/lttng-sessiond/session.hpp b/src/bin/lttng-sessiond/session.hpp index 48f3532f1..0c4f71d47 100644 --- a/src/bin/lttng-sessiond/session.hpp +++ b/src/bin/lttng-sessiond/session.hpp @@ -125,12 +125,9 @@ struct ltt_session { */ bool has_user_specified_directory; /* Did at least ONE start command has been triggered?. */ - unsigned int has_been_started:1; - /* - * Is the session active? Start trace command sets this to 1 and the stop - * command reset it to 0. - */ - unsigned int active:1; + bool has_been_started; + /* Is the session active? */ + bool active; /* Snapshot representation in a session. */ struct snapshot snapshot; diff --git a/src/bin/lttng-sessiond/trace-kernel.cpp b/src/bin/lttng-sessiond/trace-kernel.cpp index e695f1295..e5d185223 100644 --- a/src/bin/lttng-sessiond/trace-kernel.cpp +++ b/src/bin/lttng-sessiond/trace-kernel.cpp @@ -257,7 +257,7 @@ struct ltt_kernel_channel *trace_kernel_create_channel(struct lttng_channel *cha lkc->fd = -1; lkc->stream_count = 0; lkc->event_count = 0; - lkc->enabled = 1; + lkc->enabled = true; lkc->published_to_notification_thread = false; /* Init linked list */ CDS_INIT_LIST_HEAD(&lkc->events_list.head); @@ -459,7 +459,7 @@ enum lttng_error_code trace_kernel_create_event(struct lttng_event *ev, /* Setting up a kernel event */ local_kernel_event->fd = -1; local_kernel_event->event = attr; - local_kernel_event->enabled = 1; + local_kernel_event->enabled = true; local_kernel_event->filter_expression = filter_expression; local_kernel_event->filter = filter; local_kernel_event->userspace_probe_location = userspace_probe_location; @@ -518,7 +518,7 @@ trace_kernel_create_event_notifier_rule(struct lttng_trigger *trigger, } local_kernel_token_event_rule->fd = -1; - local_kernel_token_event_rule->enabled = 1; + local_kernel_token_event_rule->enabled = true; local_kernel_token_event_rule->token = token; local_kernel_token_event_rule->error_counter_index = error_counter_index; diff --git a/src/bin/lttng-sessiond/trace-kernel.hpp b/src/bin/lttng-sessiond/trace-kernel.hpp index febdf2e41..a563faa28 100644 --- a/src/bin/lttng-sessiond/trace-kernel.hpp +++ b/src/bin/lttng-sessiond/trace-kernel.hpp @@ -43,7 +43,7 @@ struct ltt_kernel_context { /* Kernel event */ struct ltt_kernel_event { int fd; - int enabled; + bool enabled; enum lttng_event_type type; struct lttng_kernel_abi_event *event; struct cds_list_head list; @@ -56,7 +56,7 @@ struct ltt_kernel_event { struct ltt_kernel_event_notifier_rule { int fd; uint64_t error_counter_index; - int enabled; + bool enabled; enum lttng_event_type type; struct lttng_trigger *trigger; uint64_t token; @@ -71,7 +71,7 @@ struct ltt_kernel_event_notifier_rule { struct ltt_kernel_channel { int fd; uint64_t key; /* Key to reference this channel with the consumer. */ - int enabled; + bool enabled; unsigned int stream_count; unsigned int event_count; bool published_to_notification_thread; @@ -121,7 +121,7 @@ struct ltt_kernel_session { /* Tracing session id */ uint64_t id; /* Session is active or not meaning it has been started or stopped. */ - unsigned int active:1; + bool active; /* Tell or not if the session has to output the traces. */ unsigned int output_traces; unsigned int snapshot_mode; diff --git a/src/bin/lttng-sessiond/trace-ust.hpp b/src/bin/lttng-sessiond/trace-ust.hpp index 38662ec58..46a69fe9d 100644 --- a/src/bin/lttng-sessiond/trace-ust.hpp +++ b/src/bin/lttng-sessiond/trace-ust.hpp @@ -39,7 +39,7 @@ struct ltt_ust_context { /* UST event */ struct ltt_ust_event { - unsigned int enabled; + bool enabled; struct lttng_ust_abi_event attr; struct lttng_ht_node_str node; char *filter_expression; @@ -57,7 +57,7 @@ struct ltt_ust_event { /* UST channel */ struct ltt_ust_channel { uint64_t id; /* unique id per session. */ - unsigned int enabled; + bool enabled; /* * A UST channel can be part of a userspace sub-domain such as JUL, * Log4j, Python. @@ -100,7 +100,7 @@ struct ltt_ust_session { uid_t uid; gid_t gid; /* Is the session active meaning has is been started or stopped. */ - unsigned int active:1; + bool active; struct consumer_output *consumer; /* Sequence number for filters so the tracer knows the ordering. */ uint64_t filter_seq_num; diff --git a/src/bin/lttng-sessiond/ust-app.cpp b/src/bin/lttng-sessiond/ust-app.cpp index 684dec869..90b0b65b7 100644 --- a/src/bin/lttng-sessiond/ust-app.cpp +++ b/src/bin/lttng-sessiond/ust-app.cpp @@ -1205,7 +1205,7 @@ static struct ust_app_channel *alloc_ust_app_channel(const char *name, strncpy(ua_chan->name, name, sizeof(ua_chan->name)); ua_chan->name[sizeof(ua_chan->name) - 1] = '\0'; - ua_chan->enabled = 1; + ua_chan->enabled = true; ua_chan->handle = -1; ua_chan->session = ua_sess; ua_chan->key = get_next_channel_key(); @@ -1274,7 +1274,7 @@ static struct ust_app_event *alloc_ust_app_event(char *name, struct lttng_ust_ab goto error; } - ua_event->enabled = 1; + ua_event->enabled = true; strncpy(ua_event->name, name, sizeof(ua_event->name)); ua_event->name[sizeof(ua_event->name) - 1] = '\0'; lttng_ht_node_init_str(&ua_event->node, ua_event->name); @@ -1310,7 +1310,7 @@ alloc_ust_app_event_notifier_rule(struct lttng_trigger *trigger) goto error; } - ua_event_notifier_rule->enabled = 1; + ua_event_notifier_rule->enabled = true; ua_event_notifier_rule->token = lttng_trigger_get_tracer_token(trigger); lttng_ht_node_init_u64(&ua_event_notifier_rule->node, ua_event_notifier_rule->token); @@ -1910,7 +1910,7 @@ static int enable_ust_channel(struct ust_app *app, goto error; } - ua_chan->enabled = 1; + ua_chan->enabled = true; DBG2("UST app channel %s enabled successfully for app: pid = %d", ua_chan->name, app->pid); @@ -2952,7 +2952,7 @@ static int enable_ust_app_event(struct ust_app_event *ua_event, struct ust_app * goto error; } - ua_event->enabled = 1; + ua_event->enabled = true; error: return ret; @@ -2970,7 +2970,7 @@ static int disable_ust_app_event(struct ust_app_event *ua_event, struct ust_app goto error; } - ua_event->enabled = 0; + ua_event->enabled = false; error: return ret; @@ -2990,7 +2990,7 @@ static int disable_ust_app_channel(struct ust_app_session *ua_sess, goto error; } - ua_chan->enabled = 0; + ua_chan->enabled = false; error: return ret; @@ -4870,7 +4870,7 @@ int ust_app_disable_channel_glb(struct ltt_ust_session *usess, struct ltt_ust_ch ua_chan = lttng::utils::container_of(ua_chan_node, &ust_app_channel::node); /* The channel must not be already disabled */ - LTTNG_ASSERT(ua_chan->enabled == 1); + LTTNG_ASSERT(ua_chan->enabled); /* Disable channel onto application */ ret = disable_ust_app_channel(ua_sess, ua_chan, app); @@ -5311,8 +5311,8 @@ skip_setup: } /* Indicate that the session has been started once */ - ua_sess->started = 1; - ua_sess->enabled = 1; + ua_sess->started = true; + ua_sess->enabled = true; pthread_mutex_unlock(&ua_sess->lock); @@ -5417,7 +5417,7 @@ static int ust_app_stop_trace(struct ltt_ust_session *usess, struct ust_app *app } health_code_update(); - ua_sess->enabled = 0; + ua_sess->enabled = false; /* Quiescent wait after stopping trace */ pthread_mutex_lock(&app->sock_lock); @@ -5810,7 +5810,7 @@ int ust_app_start_trace_all(struct ltt_ust_session *usess) * Even though the start trace might fail, flag this session active so * other application coming in are started by default. */ - usess->active = 1; + usess->active = true; rcu_read_lock(); @@ -5847,7 +5847,7 @@ int ust_app_stop_trace_all(struct ltt_ust_session *usess) * Even though the stop trace might fail, flag this session inactive so * other application coming in are not started by default. */ - usess->active = 0; + usess->active = false; rcu_read_lock(); diff --git a/src/bin/lttng-sessiond/ust-app.hpp b/src/bin/lttng-sessiond/ust-app.hpp index 2071a8984..2aa79df44 100644 --- a/src/bin/lttng-sessiond/ust-app.hpp +++ b/src/bin/lttng-sessiond/ust-app.hpp @@ -106,7 +106,7 @@ struct ust_app_ctx { }; struct ust_app_event { - int enabled; + bool enabled; int handle; struct lttng_ust_abi_object_data *obj; struct lttng_ust_abi_event attr; @@ -117,7 +117,7 @@ struct ust_app_event { }; struct ust_app_event_notifier_rule { - int enabled; + bool enabled; uint64_t error_counter_index; int handle; struct lttng_ust_abi_object_data *obj; @@ -145,7 +145,7 @@ struct ust_app_stream { }; struct ust_app_channel { - int enabled; + bool enabled; int handle; /* * Unique key used to identify the channel on the consumer side. @@ -196,9 +196,9 @@ struct ust_app_session { */ pthread_mutex_t lock; - int enabled; + bool enabled; /* started: has the session been in started state at any time ? */ - int started; /* allows detection of start vs restart. */ + bool started; /* allows detection of start vs restart. */ int handle; /* used has unique identifier for app session */ bool deleted; /* Session deleted flag. Check with lock held. */ diff --git a/src/bin/lttng/commands/disable_channels.cpp b/src/bin/lttng/commands/disable_channels.cpp index 3b188b8d3..2c006552c 100644 --- a/src/bin/lttng/commands/disable_channels.cpp +++ b/src/bin/lttng/commands/disable_channels.cpp @@ -92,10 +92,9 @@ end: */ static int disable_channels(char *session_name, char *channel_list) { - int ret = CMD_SUCCESS, warn = 0, success; - - /* Normal case for disable channed is enabled = 0 */ - unsigned int enabled = 0; + int ret = CMD_SUCCESS; + /* Normal case for disable channed is enabled = false */ + bool warn = false, success, enabled = false; char *channel_name; struct lttng_domain dom; @@ -138,7 +137,7 @@ static int disable_channels(char *session_name, char *channel_list) channel_name, lttng_strerror(ret), session_name); - warn = 1; + warn = true; /* * Mi: @@ -147,16 +146,16 @@ static int disable_channels(char *session_name, char *channel_list) * The client should look at the stderr stream * for more informations. */ - enabled = 1; - success = 0; + enabled = true; + success = false; } else { MSG("%s channel %s disabled for session %s", lttng_domain_type_str(dom.type), channel_name, session_name); - enabled = 0; - success = 1; + enabled = false; + success = true; } /* Print the channel */ diff --git a/src/bin/lttng/commands/disable_events.cpp b/src/bin/lttng/commands/disable_events.cpp index 6cf5119c2..f78222d97 100644 --- a/src/bin/lttng/commands/disable_events.cpp +++ b/src/bin/lttng/commands/disable_events.cpp @@ -147,8 +147,8 @@ end: */ static int disable_events(char *session_name, char *event_list) { - int ret = CMD_SUCCESS, warn = 0, command_ret = CMD_SUCCESS; - int enabled = 1, success = 1; + enum cmd_error_code ret = CMD_SUCCESS, command_ret = CMD_SUCCESS; + bool enabled = true, success = true, warn = false; char *event_name, *channel_name = nullptr; struct lttng_domain dom; struct lttng_event event; @@ -175,28 +175,28 @@ static int disable_events(char *session_name, char *event_list) handle = lttng_create_handle(session_name, &dom); if (handle == nullptr) { - ret = -1; + ret = CMD_ERROR; goto error; } /* Mi print the channel and open the events element */ if (lttng_opt_mi) { - ret = mi_lttng_writer_open_element(writer, config_element_channel); - if (ret) { + int mi_ret = mi_lttng_writer_open_element(writer, config_element_channel); + if (mi_ret) { ret = CMD_ERROR; goto end; } - ret = mi_lttng_writer_write_element_string( + mi_ret = mi_lttng_writer_write_element_string( writer, config_element_name, print_channel_name(channel_name)); - if (ret) { + if (mi_ret) { ret = CMD_ERROR; goto end; } /* Open events element */ - ret = mi_lttng_writer_open_element(writer, config_element_events); - if (ret) { + mi_ret = mi_lttng_writer_open_element(writer, config_element_events); + if (mi_ret) { ret = CMD_ERROR; goto end; } @@ -210,15 +210,16 @@ static int disable_events(char *session_name, char *event_list) event.type = (lttng_event_type) opt_event_type; if (opt_disable_all) { - command_ret = lttng_disable_event_ext(handle, &event, channel_name, nullptr); - if (command_ret < 0) { - ERR("%s", lttng_strerror(command_ret)); - enabled = 1; - success = 0; + const int disable_ret = lttng_disable_event_ext(handle, &event, channel_name, nullptr); + if (disable_ret < 0) { + ERR("%s", lttng_strerror(command_ret)); + command_ret = CMD_ERROR; + enabled = true; + success = false; } else { - enabled = 0; - success = 1; + enabled = false; + success = true; MSG("All %s events of type %s are disabled in channel %s", lttng_domain_type_str(dom.type), print_event_type((lttng_event_type) opt_event_type), @@ -226,8 +227,9 @@ static int disable_events(char *session_name, char *event_list) } if (lttng_opt_mi) { - ret = mi_print_event("*", enabled, success); - if (ret) { + const int mi_ret = mi_print_event("*", enabled, success); + + if (mi_ret) { ret = CMD_ERROR; goto error; } @@ -240,9 +242,9 @@ static int disable_events(char *session_name, char *event_list) strncpy(event.name, event_name, sizeof(event.name)); event.name[sizeof(event.name) - 1] = '\0'; - command_ret = + const int disable_ret = lttng_disable_event_ext(handle, &event, channel_name, nullptr); - if (command_ret < 0) { + if (disable_ret < 0) { ERR("%s of type %s : %s (channel %s, session %s)", event_name, print_event_type((lttng_event_type) opt_event_type), @@ -251,13 +253,14 @@ static int disable_events(char *session_name, char *event_list) print_raw_channel_name(channel_name) : print_channel_name(channel_name), session_name); - warn = 1; - success = 0; + warn = true; + success = false; /* * If an error occurred we assume that the event is still * enabled. */ - enabled = 1; + enabled = true; + command_ret = CMD_ERROR; } else { MSG("%s %s of type %s disabled in channel %s for session %s", lttng_domain_type_str(dom.type), @@ -265,13 +268,14 @@ static int disable_events(char *session_name, char *event_list) print_event_type((lttng_event_type) opt_event_type), print_channel_name(channel_name), session_name); - success = 1; - enabled = 0; + success = true; + enabled = false; } if (lttng_opt_mi) { - ret = mi_print_event(event_name, enabled, success); - if (ret) { + const int mi_ret = mi_print_event(event_name, enabled, success); + + if (mi_ret) { ret = CMD_ERROR; goto error; } @@ -285,8 +289,9 @@ static int disable_events(char *session_name, char *event_list) end: if (lttng_opt_mi) { /* Close events element and channel element */ - ret = mi_lttng_close_multi_element(writer, 2); - if (ret) { + const int mi_ret = mi_lttng_close_multi_element(writer, 2); + + if (mi_ret) { ret = CMD_ERROR; } } diff --git a/tests/unit/test_kernel_data.cpp b/tests/unit/test_kernel_data.cpp index 3814daa6f..2deaef720 100644 --- a/tests/unit/test_kernel_data.cpp +++ b/tests/unit/test_kernel_data.cpp @@ -104,7 +104,7 @@ static void test_create_kernel_channel() return; } - ok(chan->fd == -1 && chan->enabled == 1 && chan->stream_count == 0 && + ok(chan->fd == -1 && chan->enabled && chan->stream_count == 0 && chan->channel->attr.overwrite == attr.attr.overwrite, "Validate kernel channel"); @@ -133,7 +133,7 @@ static void test_create_kernel_event() return; } - ok(event->fd == -1 && event->enabled == 1 && + ok(event->fd == -1 && event->enabled && event->event->instrumentation == LTTNG_KERNEL_ABI_TRACEPOINT && strlen(event->event->name), "Validate kernel event"); diff --git a/tests/unit/test_ust_data.cpp b/tests/unit/test_ust_data.cpp index 93875491b..ec945a036 100644 --- a/tests/unit/test_ust_data.cpp +++ b/tests/unit/test_ust_data.cpp @@ -66,7 +66,7 @@ static void test_create_one_ust_session() return; } - ok(usess->id == 42 && usess->active == 0 && usess->domain_global.channels != nullptr && + ok(usess->id == 42 && !usess->active && usess->domain_global.channels != nullptr && usess->uid == 0 && usess->gid == 0, "Validate UST session"); @@ -94,7 +94,7 @@ static void test_create_ust_channel() return; } - ok(uchan->enabled == 0 && strncmp(uchan->name, "channel0", 8) == 0 && + ok(!uchan->enabled && strncmp(uchan->name, "channel0", 8) == 0 && uchan->name[LTTNG_UST_ABI_SYM_NAME_LEN - 1] == '\0' && uchan->ctx != nullptr && uchan->events != nullptr && uchan->attr.overwrite == attr.attr.overwrite, "Validate UST channel"); @@ -123,7 +123,7 @@ static void test_create_ust_event() return; } - ok(event->enabled == 0 && event->attr.instrumentation == LTTNG_UST_ABI_TRACEPOINT && + ok(!event->enabled && event->attr.instrumentation == LTTNG_UST_ABI_TRACEPOINT && strcmp(event->attr.name, ev.name) == 0 && event->attr.name[LTTNG_UST_ABI_SYM_NAME_LEN - 1] == '\0', "Validate UST event"); @@ -226,7 +226,7 @@ static void test_create_ust_event_exclusion() goto end; } - ok(event->enabled == 0 && event->attr.instrumentation == LTTNG_UST_ABI_TRACEPOINT && + ok(!event->enabled && event->attr.instrumentation == LTTNG_UST_ABI_TRACEPOINT && strcmp(event->attr.name, ev.name) == 0 && event->exclusion != nullptr && event->exclusion->count == exclusion_count && !memcmp(event->exclusion->names, -- 2.34.1