From: Jérémie Galarneau Date: Fri, 13 Jan 2023 17:02:15 +0000 (-0500) Subject: Run clang-format on the whole tree X-Git-Url: https://git.lttng.org./?a=commitdiff_plain;h=28ab034a2c3582d07d3423d2d746731f87d3969f;p=lttng-tools.git Run clang-format on the whole tree Generated by running: find -not \( -path "./src/vendor*" -prune \) -iname "*.h" -o -iname "*.hpp" -o -iname "*.c" -o -iname "*.cpp" -exec clang-format -i {} \; Signed-off-by: Jérémie Galarneau Change-Id: I9557e7d84e305187475ef88124857cf2f438bbb1 --- diff --git a/doc/examples/trigger-condition-event-matches/notification-client.cpp b/doc/examples/trigger-condition-event-matches/notification-client.cpp index bce5d815d..91a1d0711 100644 --- a/doc/examples/trigger-condition-event-matches/notification-client.cpp +++ b/doc/examples/trigger-condition-event-matches/notification-client.cpp @@ -5,6 +5,8 @@ * */ +#include + #include #include @@ -16,14 +18,12 @@ #include #include -#include - static int print_capture(const struct lttng_condition *condition, - const struct lttng_event_field_value *capture, - unsigned int indent_level); + const struct lttng_event_field_value *capture, + unsigned int indent_level); static int print_array(const struct lttng_condition *condition, - const struct lttng_event_field_value *array, - unsigned int indent_level); + const struct lttng_event_field_value *array, + unsigned int indent_level); static void indent(unsigned int indentation_level) { @@ -44,8 +44,7 @@ static void print_one_event_expr(const struct lttng_event_expr *event_expr) { const char *name; - name = lttng_event_expr_event_payload_field_get_name( - event_expr); + name = lttng_event_expr_event_payload_field_get_name(event_expr); printf("%s", name); break; @@ -55,8 +54,7 @@ static void print_one_event_expr(const struct lttng_event_expr *event_expr) { const char *name; - name = lttng_event_expr_channel_context_field_get_name( - event_expr); + name = lttng_event_expr_channel_context_field_get_name(event_expr); printf("$ctx.%s", name); break; @@ -67,10 +65,9 @@ static void print_one_event_expr(const struct lttng_event_expr *event_expr) const char *provider_name; const char *type_name; - provider_name = lttng_event_expr_app_specific_context_field_get_provider_name( - event_expr); - type_name = lttng_event_expr_app_specific_context_field_get_type_name( - event_expr); + provider_name = + lttng_event_expr_app_specific_context_field_get_provider_name(event_expr); + type_name = lttng_event_expr_app_specific_context_field_get_type_name(event_expr); printf("$app.%s:%s", provider_name, type_name); @@ -83,14 +80,12 @@ static void print_one_event_expr(const struct lttng_event_expr *event_expr) const struct lttng_event_expr *parent_expr; enum lttng_event_expr_status status; - parent_expr = lttng_event_expr_array_field_element_get_parent_expr( - event_expr); + parent_expr = lttng_event_expr_array_field_element_get_parent_expr(event_expr); LTTNG_ASSERT(parent_expr != NULL); print_one_event_expr(parent_expr); - status = lttng_event_expr_array_field_element_get_index( - event_expr, &index); + status = lttng_event_expr_array_field_element_get_index(event_expr, &index); LTTNG_ASSERT(status == LTTNG_EVENT_EXPR_STATUS_OK); printf("[%u]", index); @@ -103,12 +98,10 @@ static void print_one_event_expr(const struct lttng_event_expr *event_expr) } } -static bool action_group_contains_notify( - const struct lttng_action *action_group) +static bool action_group_contains_notify(const struct lttng_action *action_group) { unsigned int i, count; - enum lttng_action_status status = - lttng_action_list_get_count(action_group, &count); + enum lttng_action_status status = lttng_action_list_get_count(action_group, &count); if (status != LTTNG_ACTION_STATUS_OK) { printf("Failed to get action count from action group\n"); @@ -116,10 +109,8 @@ static bool action_group_contains_notify( } for (i = 0; i < count; i++) { - const struct lttng_action *action = - lttng_action_list_get_at_index(action_group, i); - const enum lttng_action_type action_type = - lttng_action_get_type(action); + const struct lttng_action *action = lttng_action_list_get_at_index(action_group, i); + const enum lttng_action_type action_type = lttng_action_get_type(action); if (action_type == LTTNG_ACTION_TYPE_NOTIFY) { return true; @@ -129,8 +120,8 @@ static bool action_group_contains_notify( } static int print_capture(const struct lttng_condition *condition, - const struct lttng_event_field_value *capture, - unsigned int indent_level) + const struct lttng_event_field_value *capture, + unsigned int indent_level) { int ret = 0; enum lttng_event_field_value_status event_field_status; @@ -143,8 +134,7 @@ static int print_capture(const struct lttng_condition *condition, case LTTNG_EVENT_FIELD_VALUE_TYPE_UNSIGNED_INT: { event_field_status = - lttng_event_field_value_unsigned_int_get_value( - capture, &u_val); + lttng_event_field_value_unsigned_int_get_value(capture, &u_val); if (event_field_status != LTTNG_EVENT_FIELD_VALUE_STATUS_OK) { ret = 1; goto end; @@ -155,9 +145,7 @@ static int print_capture(const struct lttng_condition *condition, } case LTTNG_EVENT_FIELD_VALUE_TYPE_SIGNED_INT: { - event_field_status = - lttng_event_field_value_signed_int_get_value( - capture, &s_val); + event_field_status = lttng_event_field_value_signed_int_get_value(capture, &s_val); if (event_field_status != LTTNG_EVENT_FIELD_VALUE_STATUS_OK) { ret = 1; goto end; @@ -169,8 +157,7 @@ static int print_capture(const struct lttng_condition *condition, case LTTNG_EVENT_FIELD_VALUE_TYPE_UNSIGNED_ENUM: { event_field_status = - lttng_event_field_value_unsigned_int_get_value( - capture, &u_val); + lttng_event_field_value_unsigned_int_get_value(capture, &u_val); if (event_field_status != LTTNG_EVENT_FIELD_VALUE_STATUS_OK) { ret = 1; goto end; @@ -181,9 +168,7 @@ static int print_capture(const struct lttng_condition *condition, } case LTTNG_EVENT_FIELD_VALUE_TYPE_SIGNED_ENUM: { - event_field_status = - lttng_event_field_value_signed_int_get_value( - capture, &s_val); + event_field_status = lttng_event_field_value_signed_int_get_value(capture, &s_val); if (event_field_status != LTTNG_EVENT_FIELD_VALUE_STATUS_OK) { ret = 1; goto end; @@ -194,8 +179,7 @@ static int print_capture(const struct lttng_condition *condition, } case LTTNG_EVENT_FIELD_VALUE_TYPE_REAL: { - event_field_status = lttng_event_field_value_real_get_value( - capture, &d_val); + event_field_status = lttng_event_field_value_real_get_value(capture, &d_val); if (event_field_status != LTTNG_EVENT_FIELD_VALUE_STATUS_OK) { ret = 1; goto end; @@ -206,8 +190,7 @@ static int print_capture(const struct lttng_condition *condition, } case LTTNG_EVENT_FIELD_VALUE_TYPE_STRING: { - event_field_status = lttng_event_field_value_string_get_value( - capture, &string_val); + event_field_status = lttng_event_field_value_string_get_value(capture, &string_val); if (event_field_status != LTTNG_EVENT_FIELD_VALUE_STATUS_OK) { ret = 1; goto end; @@ -239,15 +222,14 @@ static void print_unavailabe(void) } static int print_array(const struct lttng_condition *condition, - const struct lttng_event_field_value *array, - unsigned int indent_level) + const struct lttng_event_field_value *array, + unsigned int indent_level) { int ret = 0; enum lttng_event_field_value_status event_field_status; unsigned int captured_field_count; - event_field_status = lttng_event_field_value_array_get_length( - array, &captured_field_count); + event_field_status = lttng_event_field_value_array_get_length(array, &captured_field_count); if (event_field_status != LTTNG_EVENT_FIELD_VALUE_STATUS_OK) { ret = 1; goto end; @@ -256,8 +238,8 @@ static int print_array(const struct lttng_condition *condition, for (unsigned int i = 0; i < captured_field_count; i++) { const struct lttng_event_field_value *captured_field = NULL; const struct lttng_event_expr *expr = - lttng_condition_event_rule_matches_get_capture_descriptor_at_index( - condition, i); + lttng_condition_event_rule_matches_get_capture_descriptor_at_index( + condition, i); LTTNG_ASSERT(expr); indent(indent_level + 1); @@ -266,20 +248,17 @@ static int print_array(const struct lttng_condition *condition, print_one_event_expr(expr); printf(" Value: "); - event_field_status = - lttng_event_field_value_array_get_element_at_index( - array, i, &captured_field); + event_field_status = lttng_event_field_value_array_get_element_at_index( + array, i, &captured_field); if (event_field_status != LTTNG_EVENT_FIELD_VALUE_STATUS_OK) { - if (event_field_status == - LTTNG_EVENT_FIELD_VALUE_STATUS_UNAVAILABLE) { + if (event_field_status == LTTNG_EVENT_FIELD_VALUE_STATUS_UNAVAILABLE) { print_unavailabe(); } else { ret = 1; goto end; } } else { - print_capture(condition, captured_field, - indent_level + 1); + print_capture(condition, captured_field, indent_level + 1); } if (i + 1 < captured_field_count) { @@ -297,10 +276,8 @@ end: static int print_captures(struct lttng_notification *notification) { int ret = 0; - const struct lttng_evaluation *evaluation = - lttng_notification_get_evaluation(notification); - const struct lttng_condition *condition = - lttng_notification_get_condition(notification); + const struct lttng_evaluation *evaluation = lttng_notification_get_evaluation(notification); + const struct lttng_condition *condition = lttng_notification_get_condition(notification); /* Status */ enum lttng_condition_status condition_status; @@ -310,12 +287,10 @@ static int print_captures(struct lttng_notification *notification) unsigned int expected_capture_field_count; LTTNG_ASSERT(lttng_evaluation_get_type(evaluation) == - LTTNG_CONDITION_TYPE_EVENT_RULE_MATCHES); + LTTNG_CONDITION_TYPE_EVENT_RULE_MATCHES); - condition_status = - lttng_condition_event_rule_matches_get_capture_descriptor_count( - condition, - &expected_capture_field_count); + condition_status = lttng_condition_event_rule_matches_get_capture_descriptor_count( + condition, &expected_capture_field_count); if (condition_status != LTTNG_CONDITION_STATUS_OK) { ret = 1; goto end; @@ -326,9 +301,8 @@ static int print_captures(struct lttng_notification *notification) goto end; } - evaluation_status = - lttng_evaluation_event_rule_matches_get_captured_values( - evaluation, &captured_field_array); + evaluation_status = lttng_evaluation_event_rule_matches_get_captured_values( + evaluation, &captured_field_array); if (evaluation_status != LTTNG_EVALUATION_EVENT_RULE_MATCHES_STATUS_OK) { ret = 1; goto end; @@ -343,10 +317,8 @@ end: static int print_notification(struct lttng_notification *notification) { int ret = 0; - const struct lttng_evaluation *evaluation = - lttng_notification_get_evaluation(notification); - const enum lttng_condition_type type = - lttng_evaluation_get_type(evaluation); + const struct lttng_evaluation *evaluation = lttng_notification_get_evaluation(notification); + const enum lttng_condition_type type = lttng_evaluation_get_type(evaluation); switch (type) { case LTTNG_CONDITION_TYPE_SESSION_CONSUMED_SIZE: @@ -374,8 +346,7 @@ static int print_notification(struct lttng_notification *notification) gettimeofday(&tv, NULL); the_time = tv.tv_sec; - strftime(time_str, sizeof(time_str), "[%m-%d-%Y] %T", - localtime(&the_time)); + strftime(time_str, sizeof(time_str), "[%m-%d-%Y] %T", localtime(&the_time)); printf("%s.%ld - ", time_str, tv.tv_usec); trigger = lttng_notification_get_trigger(notification); @@ -391,7 +362,7 @@ static int print_notification(struct lttng_notification *notification) } printf("Received notification of event rule matches trigger \"%s\"\n", - trigger_name); + trigger_name); ret = print_captures(notification); break; } @@ -420,8 +391,8 @@ int main(int argc, char **argv) trigger_count = argc - 1; - notification_channel = lttng_notification_channel_create( - lttng_session_daemon_notification_endpoint); + notification_channel = + lttng_notification_channel_create(lttng_session_daemon_notification_endpoint); if (!notification_channel) { fprintf(stderr, "Failed to create notification channel\n"); ret = -1; @@ -442,14 +413,11 @@ int main(int argc, char **argv) } for (i = 0; i < count; i++) { - const struct lttng_trigger *trigger = - lttng_triggers_get_at_index(triggers, i); + const struct lttng_trigger *trigger = lttng_triggers_get_at_index(triggers, i); const struct lttng_condition *condition = - lttng_trigger_get_const_condition(trigger); - const struct lttng_action *action = - lttng_trigger_get_const_action(trigger); - const enum lttng_action_type action_type = - lttng_action_get_type(action); + lttng_trigger_get_const_condition(trigger); + const struct lttng_action *action = lttng_trigger_get_const_action(trigger); + const enum lttng_action_type action_type = lttng_action_get_type(action); enum lttng_notification_channel_status channel_status; const char *trigger_name = NULL; bool subscribe = false; @@ -467,28 +435,27 @@ int main(int argc, char **argv) } if (!((action_type == LTTNG_ACTION_TYPE_LIST && - action_group_contains_notify(action)) || - action_type == LTTNG_ACTION_TYPE_NOTIFY)) { + action_group_contains_notify(action)) || + action_type == LTTNG_ACTION_TYPE_NOTIFY)) { printf("The action of trigger \"%s\" is not \"notify\", skipping.\n", - trigger_name); + trigger_name); continue; } - channel_status = lttng_notification_channel_subscribe( - notification_channel, condition); - if (channel_status == - LTTNG_NOTIFICATION_CHANNEL_STATUS_ALREADY_SUBSCRIBED) { + channel_status = + lttng_notification_channel_subscribe(notification_channel, condition); + if (channel_status == LTTNG_NOTIFICATION_CHANNEL_STATUS_ALREADY_SUBSCRIBED) { continue; } if (channel_status) { - fprintf(stderr, "Failed to subscribe to notifications of trigger \"%s\"\n", - trigger_name); + fprintf(stderr, + "Failed to subscribe to notifications of trigger \"%s\"\n", + trigger_name); ret = -1; goto end; } - printf("Subscribed to notifications of trigger \"%s\"\n", - trigger_name); + printf("Subscribed to notifications of trigger \"%s\"\n", trigger_name); subcription_count++; } @@ -502,10 +469,8 @@ int main(int argc, char **argv) struct lttng_notification *notification; enum lttng_notification_channel_status channel_status; - channel_status = - lttng_notification_channel_get_next_notification( - notification_channel, - ¬ification); + channel_status = lttng_notification_channel_get_next_notification( + notification_channel, ¬ification); switch (channel_status) { case LTTNG_NOTIFICATION_CHANNEL_STATUS_NOTIFICATIONS_DROPPED: printf("Dropped notification\n"); @@ -524,7 +489,8 @@ int main(int argc, char **argv) printf("Notification channel was closed by peer.\n"); break; default: - fprintf(stderr, "A communication error occurred on the notification channel.\n"); + fprintf(stderr, + "A communication error occurred on the notification channel.\n"); ret = -1; goto end; } diff --git a/src/bin/lttng-consumerd/health-consumerd.cpp b/src/bin/lttng-consumerd/health-consumerd.cpp index f8be972c5..fc4988d68 100644 --- a/src/bin/lttng-consumerd/health-consumerd.cpp +++ b/src/bin/lttng-consumerd/health-consumerd.cpp @@ -6,44 +6,44 @@ */ #define _LGPL_SOURCE +#include "health-consumerd.hpp" +#include "lttng-consumerd.hpp" + +#include +#include +#include +#include +#include +#include +#include + #include #include #include +#include #include +#include #include #include #include #include #include #include +#include #include #include #include #include #include -#include -#include +#include #include -#include #include -#include -#include - -#include -#include -#include -#include -#include -#include -#include - -#include "lttng-consumerd.hpp" -#include "health-consumerd.hpp" +#include /* Global health check unix path */ static char health_unix_sock_path[PATH_MAX]; -int health_quit_pipe[2] = {-1, -1}; +int health_quit_pipe[2] = { -1, -1 }; /* * Send data on a unix socket using the liblttsessiondcomm API. @@ -60,8 +60,7 @@ static int send_unix_sock(int sock, void *buf, size_t len) return lttcomm_send_unix_sock(sock, buf, len); } -static -int setup_health_path(void) +static int setup_health_path(void) { int is_root, ret = 0; enum lttng_consumer_type type; @@ -76,16 +75,19 @@ int setup_health_path(void) } switch (type) { case LTTNG_CONSUMER_KERNEL: - snprintf(health_unix_sock_path, sizeof(health_unix_sock_path), - DEFAULT_GLOBAL_KCONSUMER_HEALTH_UNIX_SOCK); + snprintf(health_unix_sock_path, + sizeof(health_unix_sock_path), + DEFAULT_GLOBAL_KCONSUMER_HEALTH_UNIX_SOCK); break; case LTTNG_CONSUMER64_UST: - snprintf(health_unix_sock_path, sizeof(health_unix_sock_path), - DEFAULT_GLOBAL_USTCONSUMER64_HEALTH_UNIX_SOCK); + snprintf(health_unix_sock_path, + sizeof(health_unix_sock_path), + DEFAULT_GLOBAL_USTCONSUMER64_HEALTH_UNIX_SOCK); break; case LTTNG_CONSUMER32_UST: - snprintf(health_unix_sock_path, sizeof(health_unix_sock_path), - DEFAULT_GLOBAL_USTCONSUMER32_HEALTH_UNIX_SOCK); + snprintf(health_unix_sock_path, + sizeof(health_unix_sock_path), + DEFAULT_GLOBAL_USTCONSUMER32_HEALTH_UNIX_SOCK); break; default: ret = -EINVAL; @@ -106,16 +108,22 @@ int setup_health_path(void) } switch (type) { case LTTNG_CONSUMER_KERNEL: - snprintf(health_unix_sock_path, sizeof(health_unix_sock_path), - DEFAULT_HOME_KCONSUMER_HEALTH_UNIX_SOCK, home_path); + snprintf(health_unix_sock_path, + sizeof(health_unix_sock_path), + DEFAULT_HOME_KCONSUMER_HEALTH_UNIX_SOCK, + home_path); break; case LTTNG_CONSUMER64_UST: - snprintf(health_unix_sock_path, sizeof(health_unix_sock_path), - DEFAULT_HOME_USTCONSUMER64_HEALTH_UNIX_SOCK, home_path); + snprintf(health_unix_sock_path, + sizeof(health_unix_sock_path), + DEFAULT_HOME_USTCONSUMER64_HEALTH_UNIX_SOCK, + home_path); break; case LTTNG_CONSUMER32_UST: - snprintf(health_unix_sock_path, sizeof(health_unix_sock_path), - DEFAULT_HOME_USTCONSUMER32_HEALTH_UNIX_SOCK, home_path); + snprintf(health_unix_sock_path, + sizeof(health_unix_sock_path), + DEFAULT_HOME_USTCONSUMER32_HEALTH_UNIX_SOCK, + home_path); break; default: ret = -EINVAL; @@ -174,8 +182,7 @@ void *thread_manage_health_consumerd(void *data __attribute__((unused))) goto error; } - ret = chmod(health_unix_sock_path, - S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP); + ret = chmod(health_unix_sock_path, S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP); if (ret < 0) { ERR("Unable to set permissions on %s", health_unix_sock_path); PERROR("chmod"); @@ -221,7 +228,7 @@ void *thread_manage_health_consumerd(void *data __attribute__((unused))) DBG("Health check ready"); /* Inifinite blocking call, waiting for transmission */ -restart: + restart: ret = lttng_poll_wait(&events, -1); if (ret < 0) { /* @@ -249,8 +256,8 @@ restart: /* Event on the registration socket */ if (pollfd == sock) { - if (revents & (LPOLLERR | LPOLLHUP | LPOLLRDHUP) - && !(revents & LPOLLIN)) { + if (revents & (LPOLLERR | LPOLLHUP | LPOLLRDHUP) && + !(revents & LPOLLIN)) { ERR("Health socket poll error"); goto error; } @@ -269,7 +276,7 @@ restart: (void) utils_set_fd_cloexec(new_sock); DBG("Receiving data from client for health..."); - ret = lttcomm_recv_unix_sock(new_sock, (void *)&msg, sizeof(msg)); + ret = lttcomm_recv_unix_sock(new_sock, (void *) &msg, sizeof(msg)); if (ret <= 0) { DBG("Nothing recv() from client... continuing"); ret = close(new_sock); diff --git a/src/bin/lttng-consumerd/lttng-consumerd.cpp b/src/bin/lttng-consumerd/lttng-consumerd.cpp index a8bda52ba..407545d8a 100644 --- a/src/bin/lttng-consumerd/lttng-consumerd.cpp +++ b/src/bin/lttng-consumerd/lttng-consumerd.cpp @@ -7,53 +7,53 @@ */ #define _LGPL_SOURCE +#include "health-consumerd.hpp" +#include "lttng-consumerd.hpp" + +#include +#include +#include +#include +#include +#include +#include +#include + #include #include #include #include +#include #include #include #include #include #include #include +#include #include #include #include #include #include -#include -#include +#include #include -#include #include -#include - -#include -#include -#include -#include -#include -#include -#include -#include - -#include "lttng-consumerd.hpp" -#include "health-consumerd.hpp" +#include /* threads (channel handling, poll, metadata, sessiond) */ -static pthread_t channel_thread, data_thread, metadata_thread, - sessiond_thread, metadata_timer_thread, health_thread; +static pthread_t channel_thread, data_thread, metadata_thread, sessiond_thread, + metadata_timer_thread, health_thread; static bool metadata_timer_thread_online; /* to count the number of times the user pressed ctrl+c */ static int sigintcount = 0; /* Argument variables */ -int lttng_opt_quiet; /* not static in error.h */ -int lttng_opt_verbose; /* not static in error.h */ -int lttng_opt_mi; /* not static in error.h */ +int lttng_opt_quiet; /* not static in error.h */ +int lttng_opt_verbose; /* not static in error.h */ +int lttng_opt_mi; /* not static in error.h */ static int opt_daemon; static const char *progname; @@ -82,8 +82,7 @@ enum lttng_consumer_type lttng_consumer_get_type(void) /* * Signal handler for the daemon */ -static void sighandler(int sig, siginfo_t *siginfo, - void *arg __attribute__((unused))) +static void sighandler(int sig, siginfo_t *siginfo, void *arg __attribute__((unused))) { if (sig == SIGINT && sigintcount++ == 0) { DBG("ignoring first SIGINT"); @@ -162,32 +161,42 @@ static int set_signal_handler(void) static void usage(FILE *fp) { fprintf(fp, "Usage: %s OPTIONS\n\nOptions:\n", progname); - fprintf(fp, " -h, --help " - "Display this usage.\n"); - fprintf(fp, " -c, --consumerd-cmd-sock PATH " - "Specify path for the command socket\n"); - fprintf(fp, " -e, --consumerd-err-sock PATH " - "Specify path for the error socket\n"); - fprintf(fp, " -d, --daemonize " - "Start as a daemon.\n"); - fprintf(fp, " -q, --quiet " - "No output at all.\n"); - fprintf(fp, " -v, --verbose " - "Verbose mode. Activate DBG() macro.\n"); - fprintf(fp, " -V, --version " - "Show version number.\n"); - fprintf(fp, " -g, --group NAME " - "Specify the tracing group name. (default: tracing)\n"); - fprintf(fp, " -k, --kernel " - "Consumer kernel buffers (default).\n"); - fprintf(fp, " -u, --ust " - "Consumer UST buffers.%s\n", + fprintf(fp, + " -h, --help " + "Display this usage.\n"); + fprintf(fp, + " -c, --consumerd-cmd-sock PATH " + "Specify path for the command socket\n"); + fprintf(fp, + " -e, --consumerd-err-sock PATH " + "Specify path for the error socket\n"); + fprintf(fp, + " -d, --daemonize " + "Start as a daemon.\n"); + fprintf(fp, + " -q, --quiet " + "No output at all.\n"); + fprintf(fp, + " -v, --verbose " + "Verbose mode. Activate DBG() macro.\n"); + fprintf(fp, + " -V, --version " + "Show version number.\n"); + fprintf(fp, + " -g, --group NAME " + "Specify the tracing group name. (default: tracing)\n"); + fprintf(fp, + " -k, --kernel " + "Consumer kernel buffers (default).\n"); + fprintf(fp, + " -u, --ust " + "Consumer UST buffers.%s\n", #ifdef HAVE_LIBLTTNG_UST_CTL - "" + "" #else - " (support not compiled in)" + " (support not compiled in)" #endif - ); + ); } /* @@ -197,34 +206,35 @@ static int parse_args(int argc, char **argv) { int c, ret = 0; - static struct option long_options[] = { - { "consumerd-cmd-sock", 1, 0, 'c' }, - { "consumerd-err-sock", 1, 0, 'e' }, - { "daemonize", 0, 0, 'd' }, - { "group", 1, 0, 'g' }, - { "help", 0, 0, 'h' }, - { "quiet", 0, 0, 'q' }, - { "verbose", 0, 0, 'v' }, - { "version", 0, 0, 'V' }, - { "kernel", 0, 0, 'k' }, + static struct option long_options[] = { { "consumerd-cmd-sock", 1, 0, 'c' }, + { "consumerd-err-sock", 1, 0, 'e' }, + { "daemonize", 0, 0, 'd' }, + { "group", 1, 0, 'g' }, + { "help", 0, 0, 'h' }, + { "quiet", 0, 0, 'q' }, + { "verbose", 0, 0, 'v' }, + { "version", 0, 0, 'V' }, + { "kernel", 0, 0, 'k' }, #ifdef HAVE_LIBLTTNG_UST_CTL - { "ust", 0, 0, 'u' }, + { "ust", 0, 0, 'u' }, #endif - { NULL, 0, 0, 0 } - }; + { NULL, 0, 0, 0 } }; while (1) { int option_index = 0; - c = getopt_long(argc, argv, "dhqvVku" "c:e:g:", - long_options, &option_index); + c = getopt_long(argc, + argv, + "dhqvVku" + "c:e:g:", + long_options, + &option_index); if (c == -1) { break; } switch (c) { case 0: - fprintf(stderr, "option %s", - long_options[option_index].name); + fprintf(stderr, "option %s", long_options[option_index].name); if (optarg) { fprintf(stderr, " with arg %s\n", optarg); ret = -1; @@ -234,7 +244,7 @@ static int parse_args(int argc, char **argv) case 'c': if (lttng_is_setuid_setgid()) { WARN("Getting '%s' argument from setuid/setgid binary refused for security reasons.", - "-c, --consumerd-cmd-sock"); + "-c, --consumerd-cmd-sock"); } else { snprintf(command_sock_path, PATH_MAX, "%s", optarg); } @@ -242,7 +252,7 @@ static int parse_args(int argc, char **argv) case 'e': if (lttng_is_setuid_setgid()) { WARN("Getting '%s' argument from setuid/setgid binary refused for security reasons.", - "-e, --consumerd-err-sock"); + "-e, --consumerd-err-sock"); } else { snprintf(error_sock_path, PATH_MAX, "%s", optarg); } @@ -253,7 +263,7 @@ static int parse_args(int argc, char **argv) case 'g': if (lttng_is_setuid_setgid()) { WARN("Getting '%s' argument from setuid/setgid binary refused for security reasons.", - "-g, --group"); + "-g, --group"); } else { tracing_group_name = optarg; } @@ -275,13 +285,13 @@ static int parse_args(int argc, char **argv) break; #ifdef HAVE_LIBLTTNG_UST_CTL case 'u': -# if (CAA_BITS_PER_LONG == 64) +#if (CAA_BITS_PER_LONG == 64) opt_type = LTTNG_CONSUMER64_UST; -# elif (CAA_BITS_PER_LONG == 32) +#elif (CAA_BITS_PER_LONG == 32) opt_type = LTTNG_CONSUMER32_UST; -# else -# error "Unknown bitness" -# endif +#else +#error "Unknown bitness" +#endif break; #endif default: @@ -379,27 +389,30 @@ int main(int argc, char **argv) if (*command_sock_path == '\0') { switch (opt_type) { case LTTNG_CONSUMER_KERNEL: - ret = snprintf(command_sock_path, PATH_MAX, - DEFAULT_KCONSUMERD_CMD_SOCK_PATH, - DEFAULT_LTTNG_RUNDIR); + ret = snprintf(command_sock_path, + PATH_MAX, + DEFAULT_KCONSUMERD_CMD_SOCK_PATH, + DEFAULT_LTTNG_RUNDIR); if (ret < 0) { retval = -1; goto exit_init_data; } break; case LTTNG_CONSUMER64_UST: - ret = snprintf(command_sock_path, PATH_MAX, - DEFAULT_USTCONSUMERD64_CMD_SOCK_PATH, - DEFAULT_LTTNG_RUNDIR); + ret = snprintf(command_sock_path, + PATH_MAX, + DEFAULT_USTCONSUMERD64_CMD_SOCK_PATH, + DEFAULT_LTTNG_RUNDIR); if (ret < 0) { retval = -1; goto exit_init_data; } break; case LTTNG_CONSUMER32_UST: - ret = snprintf(command_sock_path, PATH_MAX, - DEFAULT_USTCONSUMERD32_CMD_SOCK_PATH, - DEFAULT_LTTNG_RUNDIR); + ret = snprintf(command_sock_path, + PATH_MAX, + DEFAULT_USTCONSUMERD32_CMD_SOCK_PATH, + DEFAULT_LTTNG_RUNDIR); if (ret < 0) { retval = -1; goto exit_init_data; @@ -429,8 +442,8 @@ int main(int argc, char **argv) } /* create the consumer instance with and assign the callbacks */ - the_consumer_context = lttng_consumer_create(opt_type, lttng_consumer_read_subbuffer, - NULL, lttng_consumer_on_recv_stream, NULL); + the_consumer_context = lttng_consumer_create( + opt_type, lttng_consumer_read_subbuffer, NULL, lttng_consumer_on_recv_stream, NULL); if (!the_consumer_context) { retval = -1; goto exit_init_data; @@ -440,27 +453,30 @@ int main(int argc, char **argv) if (*error_sock_path == '\0') { switch (opt_type) { case LTTNG_CONSUMER_KERNEL: - ret = snprintf(error_sock_path, PATH_MAX, - DEFAULT_KCONSUMERD_ERR_SOCK_PATH, - DEFAULT_LTTNG_RUNDIR); + ret = snprintf(error_sock_path, + PATH_MAX, + DEFAULT_KCONSUMERD_ERR_SOCK_PATH, + DEFAULT_LTTNG_RUNDIR); if (ret < 0) { retval = -1; goto exit_init_data; } break; case LTTNG_CONSUMER64_UST: - ret = snprintf(error_sock_path, PATH_MAX, - DEFAULT_USTCONSUMERD64_ERR_SOCK_PATH, - DEFAULT_LTTNG_RUNDIR); + ret = snprintf(error_sock_path, + PATH_MAX, + DEFAULT_USTCONSUMERD64_ERR_SOCK_PATH, + DEFAULT_LTTNG_RUNDIR); if (ret < 0) { retval = -1; goto exit_init_data; } break; case LTTNG_CONSUMER32_UST: - ret = snprintf(error_sock_path, PATH_MAX, - DEFAULT_USTCONSUMERD32_ERR_SOCK_PATH, - DEFAULT_LTTNG_RUNDIR); + ret = snprintf(error_sock_path, + PATH_MAX, + DEFAULT_USTCONSUMERD32_ERR_SOCK_PATH, + DEFAULT_LTTNG_RUNDIR); if (ret < 0) { retval = -1; goto exit_init_data; @@ -502,8 +518,10 @@ int main(int argc, char **argv) } /* Create thread to manage the client socket */ - ret = pthread_create(&health_thread, default_pthread_attr(), - thread_manage_health_consumerd, (void *) NULL); + ret = pthread_create(&health_thread, + default_pthread_attr(), + thread_manage_health_consumerd, + (void *) NULL); if (ret) { errno = ret; PERROR("pthread_create health"); @@ -518,14 +536,14 @@ int main(int argc, char **argv) while (uatomic_read(<tng_consumer_ready)) { usleep(100000); } - cmm_smp_mb(); /* Read ready before following operations */ + cmm_smp_mb(); /* Read ready before following operations */ /* * Create the thread to manage the UST metadata periodic timer and * live timer. */ - ret = pthread_create(&metadata_timer_thread, NULL, - consumer_timer_thread, (void *) the_consumer_context); + ret = pthread_create( + &metadata_timer_thread, NULL, consumer_timer_thread, (void *) the_consumer_context); if (ret) { errno = ret; PERROR("pthread_create"); @@ -535,9 +553,10 @@ int main(int argc, char **argv) metadata_timer_thread_online = true; /* Create thread to manage channels */ - ret = pthread_create(&channel_thread, default_pthread_attr(), - consumer_thread_channel_poll, - (void *) the_consumer_context); + ret = pthread_create(&channel_thread, + default_pthread_attr(), + consumer_thread_channel_poll, + (void *) the_consumer_context); if (ret) { errno = ret; PERROR("pthread_create"); @@ -546,9 +565,10 @@ int main(int argc, char **argv) } /* Create thread to manage the polling/writing of trace metadata */ - ret = pthread_create(&metadata_thread, default_pthread_attr(), - consumer_thread_metadata_poll, - (void *) the_consumer_context); + ret = pthread_create(&metadata_thread, + default_pthread_attr(), + consumer_thread_metadata_poll, + (void *) the_consumer_context); if (ret) { errno = ret; PERROR("pthread_create"); @@ -557,8 +577,10 @@ int main(int argc, char **argv) } /* Create thread to manage the polling/writing of trace data */ - ret = pthread_create(&data_thread, default_pthread_attr(), - consumer_thread_data_poll, (void *) the_consumer_context); + ret = pthread_create(&data_thread, + default_pthread_attr(), + consumer_thread_data_poll, + (void *) the_consumer_context); if (ret) { errno = ret; PERROR("pthread_create"); @@ -567,9 +589,10 @@ int main(int argc, char **argv) } /* Create the thread to manage the reception of fds */ - ret = pthread_create(&sessiond_thread, default_pthread_attr(), - consumer_thread_sessiond_poll, - (void *) the_consumer_context); + ret = pthread_create(&sessiond_thread, + default_pthread_attr(), + consumer_thread_sessiond_poll, + (void *) the_consumer_context); if (ret) { errno = ret; PERROR("pthread_create"); @@ -577,7 +600,6 @@ int main(int argc, char **argv) goto exit_sessiond_thread; } - /* * This is where we start awaiting program completion (e.g. through * signal that asks threads to teardown. @@ -666,7 +688,7 @@ exit_init_data: } tmp_ctx = the_consumer_context; the_consumer_context = NULL; - cmm_barrier(); /* Clear ctx for signal handler. */ + cmm_barrier(); /* Clear ctx for signal handler. */ lttng_consumer_destroy(tmp_ctx); if (health_consumerd) { diff --git a/src/bin/lttng-crash/lttng-crash.cpp b/src/bin/lttng-crash/lttng-crash.cpp index 3987a60dd..8b1e41be4 100644 --- a/src/bin/lttng-crash/lttng-crash.cpp +++ b/src/bin/lttng-crash/lttng-crash.cpp @@ -6,34 +6,34 @@ * */ +#include +#include +#include +#include + +#include + +#include +#include +#include #include +#include #include +#include #include #include #include +#include #include #include -#include -#include -#include #include #include -#include -#include -#include -#include -#include - #include -#include -#include -#include -#include -#define COPY_BUFLEN 4096 -#define RB_CRASH_DUMP_ABI_LEN 32 +#define COPY_BUFLEN 4096 +#define RB_CRASH_DUMP_ABI_LEN 32 -#define RB_CRASH_DUMP_ABI_MAGIC_LEN 16 +#define RB_CRASH_DUMP_ABI_MAGIC_LEN 16 /* * The 128-bit magic number is xor'd in the process data so it does not @@ -42,29 +42,28 @@ * 0x17, 0x7B, 0xF1, 0x77, 0xBF, 0x17, 0x7B, 0xF1, * 0x77, 0xBF, 0x17, 0x7B, 0xF1, 0x77, 0xBF, 0x17, */ -#define RB_CRASH_DUMP_ABI_MAGIC_XOR \ - { \ - 0x17 ^ 0xFF, 0x7B ^ 0xFF, 0xF1 ^ 0xFF, 0x77 ^ 0xFF, \ - 0xBF ^ 0xFF, 0x17 ^ 0xFF, 0x7B ^ 0xFF, 0xF1 ^ 0xFF, \ - 0x77 ^ 0xFF, 0xBF ^ 0xFF, 0x17 ^ 0xFF, 0x7B ^ 0xFF, \ - 0xF1 ^ 0xFF, 0x77 ^ 0xFF, 0xBF ^ 0xFF, 0x17 ^ 0xFF, \ +#define RB_CRASH_DUMP_ABI_MAGIC_XOR \ + { \ + 0x17 ^ 0xFF, 0x7B ^ 0xFF, 0xF1 ^ 0xFF, 0x77 ^ 0xFF, 0xBF ^ 0xFF, 0x17 ^ 0xFF, \ + 0x7B ^ 0xFF, 0xF1 ^ 0xFF, 0x77 ^ 0xFF, 0xBF ^ 0xFF, 0x17 ^ 0xFF, \ + 0x7B ^ 0xFF, 0xF1 ^ 0xFF, 0x77 ^ 0xFF, 0xBF ^ 0xFF, 0x17 ^ 0xFF, \ } static const char *help_msg = #ifdef LTTNG_EMBED_HELP #include #else -NULL + NULL #endif -; + ; /* * Non-static to ensure the compiler does not optimize away the xor. */ uint8_t lttng_crash_expected_magic_xor[] = RB_CRASH_DUMP_ABI_MAGIC_XOR; -#define RB_CRASH_ENDIAN 0x1234 -#define RB_CRASH_ENDIAN_REVERSE 0x3412 +#define RB_CRASH_ENDIAN 0x1234 +#define RB_CRASH_ENDIAN_REVERSE 0x3412 enum lttng_crash_type { LTTNG_CRASH_TYPE_UST = 0, @@ -73,43 +72,43 @@ enum lttng_crash_type { /* LTTng ring buffer defines (copied) */ -#define HALF_ULONG_BITS(wl) (((wl) * CHAR_BIT) >> 1) +#define HALF_ULONG_BITS(wl) (((wl) *CHAR_BIT) >> 1) -#define SB_ID_OFFSET_SHIFT(wl) (HALF_ULONG_BITS(wl) + 1) -#define SB_ID_OFFSET_COUNT(wl) (1UL << SB_ID_OFFSET_SHIFT(wl)) -#define SB_ID_OFFSET_MASK(wl) (~(SB_ID_OFFSET_COUNT(wl) - 1)) +#define SB_ID_OFFSET_SHIFT(wl) (HALF_ULONG_BITS(wl) + 1) +#define SB_ID_OFFSET_COUNT(wl) (1UL << SB_ID_OFFSET_SHIFT(wl)) +#define SB_ID_OFFSET_MASK(wl) (~(SB_ID_OFFSET_COUNT(wl) - 1)) /* * Lowest bit of top word half belongs to noref. Used only for overwrite mode. */ -#define SB_ID_NOREF_SHIFT(wl) (SB_ID_OFFSET_SHIFT(wl) - 1) -#define SB_ID_NOREF_COUNT(wl) (1UL << SB_ID_NOREF_SHIFT(wl)) -#define SB_ID_NOREF_MASK(wl) SB_ID_NOREF_COUNT(wl) +#define SB_ID_NOREF_SHIFT(wl) (SB_ID_OFFSET_SHIFT(wl) - 1) +#define SB_ID_NOREF_COUNT(wl) (1UL << SB_ID_NOREF_SHIFT(wl)) +#define SB_ID_NOREF_MASK(wl) SB_ID_NOREF_COUNT(wl) /* * In overwrite mode: lowest half of word is used for index. * Limit of 2^16 subbuffers per buffer on 32-bit, 2^32 on 64-bit. * In producer-consumer mode: whole word used for index. */ -#define SB_ID_INDEX_SHIFT(wl) 0 -#define SB_ID_INDEX_COUNT(wl) (1UL << SB_ID_INDEX_SHIFT(wl)) -#define SB_ID_INDEX_MASK(wl) (SB_ID_NOREF_COUNT(wl) - 1) +#define SB_ID_INDEX_SHIFT(wl) 0 +#define SB_ID_INDEX_COUNT(wl) (1UL << SB_ID_INDEX_SHIFT(wl)) +#define SB_ID_INDEX_MASK(wl) (SB_ID_NOREF_COUNT(wl) - 1) enum rb_modes { - RING_BUFFER_OVERWRITE = 0, /* Overwrite when buffer full */ - RING_BUFFER_DISCARD = 1, /* Discard when buffer full */ + RING_BUFFER_OVERWRITE = 0, /* Overwrite when buffer full */ + RING_BUFFER_DISCARD = 1, /* Discard when buffer full */ }; namespace { struct crash_abi_unknown { uint8_t magic[RB_CRASH_DUMP_ABI_MAGIC_LEN]; - uint64_t mmap_length; /* Overall length of crash record */ - uint16_t endian; /* - * { 0x12, 0x34 }: big endian - * { 0x34, 0x12 }: little endian - */ - uint16_t major; /* Major number. */ - uint16_t minor; /* Minor number. */ - uint8_t word_size; /* Word size (bytes). */ - uint8_t layout_type; /* enum lttng_crash_layout */ + uint64_t mmap_length; /* Overall length of crash record */ + uint16_t endian; /* + * { 0x12, 0x34 }: big endian + * { 0x34, 0x12 }: little endian + */ + uint16_t major; /* Major number. */ + uint16_t minor; /* Minor number. */ + uint8_t word_size; /* Word size (bytes). */ + uint8_t layout_type; /* enum lttng_crash_layout */ } __attribute__((packed)); struct crash_abi_0_0 { @@ -144,26 +143,21 @@ struct crash_abi_0_0 { uint32_t sb_array; } __attribute__((packed)) stride; - uint64_t buf_size; /* Size of the buffer */ - uint64_t subbuf_size; /* Sub-buffer size */ - uint64_t num_subbuf; /* Number of sub-buffers for writer */ - uint32_t mode; /* Buffer mode: 0: overwrite, 1: discard */ + uint64_t buf_size; /* Size of the buffer */ + uint64_t subbuf_size; /* Sub-buffer size */ + uint64_t num_subbuf; /* Number of sub-buffers for writer */ + uint32_t mode; /* Buffer mode: 0: overwrite, 1: discard */ } __attribute__((packed)); struct lttng_crash_layout { struct { - int prod_offset, consumed_offset, - commit_hot_array, commit_hot_seq, - buf_wsb_array, buf_wsb_id, - sb_array, sb_array_shmp_offset, - sb_backend_p_offset, content_size, - packet_size; + int prod_offset, consumed_offset, commit_hot_array, commit_hot_seq, buf_wsb_array, + buf_wsb_id, sb_array, sb_array_shmp_offset, sb_backend_p_offset, + content_size, packet_size; } offset; struct { - int prod_offset, consumed_offset, - commit_hot_seq, buf_wsb_id, - sb_array_shmp_offset, sb_backend_p_offset, - content_size, packet_size; + int prod_offset, consumed_offset, commit_hot_seq, buf_wsb_id, sb_array_shmp_offset, + sb_backend_p_offset, content_size, packet_size; } length; struct { int commit_hot_array, buf_wsb_array, sb_array; @@ -172,11 +166,11 @@ struct lttng_crash_layout { int reverse_byte_order; int word_size; - uint64_t mmap_length; /* Length of crash record */ - uint64_t buf_size; /* Size of the buffer */ - uint64_t subbuf_size; /* Sub-buffer size */ - uint64_t num_subbuf; /* Number of sub-buffers for writer */ - uint32_t mode; /* Buffer mode: 0: overwrite, 1: discard */ + uint64_t mmap_length; /* Length of crash record */ + uint64_t buf_size; /* Size of the buffer */ + uint64_t subbuf_size; /* Sub-buffer size */ + uint64_t num_subbuf; /* Number of sub-buffers for writer */ + uint32_t mode; /* Buffer mode: 0: overwrite, 1: discard */ }; } /* namespace */ @@ -195,12 +189,9 @@ enum { /* Getopt options. No first level command. */ static struct option long_options[] = { - { "version", 0, NULL, 'V' }, - { "help", 0, NULL, 'h' }, - { "verbose", 0, NULL, 'v' }, - { "viewer", 1, NULL, 'e' }, - { "extract", 1, NULL, 'x' }, - { "list-options", 0, NULL, OPT_DUMP_OPTIONS }, + { "version", 0, NULL, 'V' }, { "help", 0, NULL, 'h' }, + { "verbose", 0, NULL, 'v' }, { "viewer", 1, NULL, 'e' }, + { "extract", 1, NULL, 'x' }, { "list-options", 0, NULL, OPT_DUMP_OPTIONS }, { NULL, 0, NULL, 0 }, }; @@ -217,11 +208,11 @@ static void usage(void) static void version(FILE *ofp) { - fprintf(ofp, "%s (LTTng Crash Trace Viewer) " VERSION " - " VERSION_NAME - "%s%s\n", - progname, - GIT_VERSION[0] == '\0' ? "" : " - " GIT_VERSION, - EXTRA_VERSION_NAME[0] == '\0' ? "" : " - " EXTRA_VERSION_NAME); + fprintf(ofp, + "%s (LTTng Crash Trace Viewer) " VERSION " - " VERSION_NAME "%s%s\n", + progname, + GIT_VERSION[0] == '\0' ? "" : " - " GIT_VERSION, + EXTRA_VERSION_NAME[0] == '\0' ? "" : " - " EXTRA_VERSION_NAME); } /* @@ -310,8 +301,7 @@ error: return -1; } -static -int copy_file(const char *file_dest, const char *file_src) +static int copy_file(const char *file_dest, const char *file_src) { int fd_src = -1, fd_dest = -1; ssize_t readlen, writelen; @@ -326,8 +316,7 @@ int copy_file(const char *file_dest, const char *file_src) ret = -errno; goto error; } - fd_dest = open(file_dest, O_RDWR | O_CREAT | O_EXCL, - S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP); + fd_dest = open(file_dest, O_RDWR | O_CREAT | O_EXCL, S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP); if (fd_dest < 0) { PERROR("Error opening %s for writing", file_dest); ret = -errno; @@ -368,25 +357,26 @@ error: return ret; } -static -uint64_t _crash_get_field(const struct lttng_crash_layout *layout, - const char *ptr, size_t size) +static uint64_t +_crash_get_field(const struct lttng_crash_layout *layout, const char *ptr, size_t size) { switch (size) { - case 1: return *(uint8_t *) ptr; - case 2: if (layout->reverse_byte_order) { + case 1: + return *(uint8_t *) ptr; + case 2: + if (layout->reverse_byte_order) { return bswap_16(*(uint16_t *) ptr); } else { return *(uint16_t *) ptr; - } - case 4: if (layout->reverse_byte_order) { + case 4: + if (layout->reverse_byte_order) { return bswap_32(*(uint32_t *) ptr); } else { return *(uint32_t *) ptr; - } - case 8: if (layout->reverse_byte_order) { + case 8: + if (layout->reverse_byte_order) { return bswap_64(*(uint64_t *) ptr); } else { return *(uint64_t *) ptr; @@ -395,37 +385,30 @@ uint64_t _crash_get_field(const struct lttng_crash_layout *layout, abort(); return -1; } - } -#define crash_get_field(layout, map, name) \ - _crash_get_field(layout, (map) + (layout)->offset.name, \ - layout->length.name) - -#define crash_get_array_field(layout, map, array_name, idx, field_name) \ - _crash_get_field(layout, \ - (map) + (layout)->offset.array_name \ - + (idx * (layout)->stride.array_name) \ - + (layout)->offset.field_name, \ - (layout)->length.field_name) - -#define crash_get_hdr_raw_field(layout, hdr, name) ((hdr)->name) - -#define crash_get_hdr_field(layout, hdr, name) \ - _crash_get_field(layout, (const char *) &(hdr)->name, \ - sizeof((hdr)->name)) - -#define crash_get_layout(layout, hdr, name) \ - do { \ - (layout)->name = crash_get_hdr_field(layout, hdr, \ - name); \ - DBG("layout.%s = %" PRIu64, #name, \ - (uint64_t) (layout)->name); \ +#define crash_get_field(layout, map, name) \ + _crash_get_field(layout, (map) + (layout)->offset.name, layout->length.name) + +#define crash_get_array_field(layout, map, array_name, idx, field_name) \ + _crash_get_field(layout, \ + (map) + (layout)->offset.array_name + \ + (idx * (layout)->stride.array_name) + \ + (layout)->offset.field_name, \ + (layout)->length.field_name) + +#define crash_get_hdr_raw_field(layout, hdr, name) ((hdr)->name) + +#define crash_get_hdr_field(layout, hdr, name) \ + _crash_get_field(layout, (const char *) &(hdr)->name, sizeof((hdr)->name)) + +#define crash_get_layout(layout, hdr, name) \ + do { \ + (layout)->name = crash_get_hdr_field(layout, hdr, name); \ + DBG("layout.%s = %" PRIu64, #name, (uint64_t) (layout)->name); \ } while (0) -static -int get_crash_layout_0_0(struct lttng_crash_layout *layout, - char *map) +static int get_crash_layout_0_0(struct lttng_crash_layout *layout, char *map) { const struct crash_abi_0_0 *abi = (const struct crash_abi_0_0 *) map; @@ -462,18 +445,28 @@ int get_crash_layout_0_0(struct lttng_crash_layout *layout, return 0; } -static -void print_dbg_magic(const uint8_t *magic) +static void print_dbg_magic(const uint8_t *magic) { DBG("magic: 0x%X%X%X%X%X%X%X%X%X%X%X%X%X%X%X%X", - magic[0], magic[1], magic[2], magic[3], - magic[4], magic[5], magic[6], magic[7], - magic[8], magic[9], magic[10], magic[11], - magic[12], magic[13], magic[14], magic[15]); + magic[0], + magic[1], + magic[2], + magic[3], + magic[4], + magic[5], + magic[6], + magic[7], + magic[8], + magic[9], + magic[10], + magic[11], + magic[12], + magic[13], + magic[14], + magic[15]); } -static -int check_magic(const uint8_t *magic) +static int check_magic(const uint8_t *magic) { int i; @@ -485,9 +478,7 @@ int check_magic(const uint8_t *magic) return 0; } -static -int get_crash_layout(struct lttng_crash_layout *layout, int fd, - const char *input_file) +static int get_crash_layout(struct lttng_crash_layout *layout, int fd, const char *input_file) { char *map; int ret = 0, unmapret; @@ -507,14 +498,14 @@ int get_crash_layout(struct lttng_crash_layout *layout, int fd, } if (stat.st_size < RB_CRASH_DUMP_ABI_LEN) { ERR("File '%s' truncated: file length of %" PRIi64 - " bytes does not meet the minimal expected " - "length of %d bytes", - input_file, (int64_t) stat.st_size, - RB_CRASH_DUMP_ABI_LEN); + " bytes does not meet the minimal expected " + "length of %d bytes", + input_file, + (int64_t) stat.st_size, + RB_CRASH_DUMP_ABI_LEN); return -1; } - map = (char *) mmap(NULL, RB_CRASH_DUMP_ABI_LEN, PROT_READ, MAP_PRIVATE, - fd, 0); + map = (char *) mmap(NULL, RB_CRASH_DUMP_ABI_LEN, PROT_READ, MAP_PRIVATE, fd, 0); if (map == MAP_FAILED) { PERROR("Mapping file"); return -1; @@ -524,7 +515,7 @@ int get_crash_layout(struct lttng_crash_layout *layout, int fd, print_dbg_magic(magic); if (check_magic(magic)) { DBG("Unknown magic number"); - ret = 1; /* positive return value, skip */ + ret = 1; /* positive return value, skip */ goto end; } endian = crash_get_hdr_field(layout, abi, endian); @@ -536,7 +527,7 @@ int get_crash_layout(struct lttng_crash_layout *layout, int fd, break; default: DBG("Unknown endianness value: 0x%X", (unsigned int) endian); - ret = 1; /* positive return value, skip */ + ret = 1; /* positive return value, skip */ goto end; } layout_type = (enum lttng_crash_type) crash_get_hdr_field(layout, abi, layout_type); @@ -545,11 +536,11 @@ int get_crash_layout(struct lttng_crash_layout *layout, int fd, break; case LTTNG_CRASH_TYPE_KERNEL: ERR("lttng-modules buffer layout support not implemented"); - ret = 1; /* positive return value, skip */ + ret = 1; /* positive return value, skip */ goto end; default: ERR("Unknown layout type %u", (unsigned int) layout_type); - ret = 1; /* positive return value, skip */ + ret = 1; /* positive return value, skip */ goto end; } mmap_length = crash_get_hdr_field(layout, abi, mmap_length); @@ -590,43 +581,36 @@ end: } /* buf_trunc mask selects only the buffer number. */ -static inline -uint64_t buf_trunc(uint64_t offset, uint64_t buf_size) +static inline uint64_t buf_trunc(uint64_t offset, uint64_t buf_size) { return offset & ~(buf_size - 1); } /* subbuf_trunc mask selects the subbuffer number. */ -static inline -uint64_t subbuf_trunc(uint64_t offset, uint64_t subbuf_size) +static inline uint64_t subbuf_trunc(uint64_t offset, uint64_t subbuf_size) { return offset & ~(subbuf_size - 1); } /* buf_offset mask selects only the offset within the current buffer. */ -static inline -uint64_t buf_offset(uint64_t offset, uint64_t buf_size) +static inline uint64_t buf_offset(uint64_t offset, uint64_t buf_size) { return offset & (buf_size - 1); } /* subbuf_offset mask selects the offset within the current subbuffer. */ -static inline -uint64_t subbuf_offset(uint64_t offset, uint64_t subbuf_size) +static inline uint64_t subbuf_offset(uint64_t offset, uint64_t subbuf_size) { return offset & (subbuf_size - 1); } /* subbuf_index returns the index of the current subbuffer within the buffer. */ -static inline -uint64_t subbuf_index(uint64_t offset, uint64_t buf_size, uint64_t subbuf_size) +static inline uint64_t subbuf_index(uint64_t offset, uint64_t buf_size, uint64_t subbuf_size) { return buf_offset(offset, buf_size) / subbuf_size; } -static inline -uint64_t subbuffer_id_get_index(uint32_t mode, uint64_t id, - unsigned int wl) +static inline uint64_t subbuffer_id_get_index(uint32_t mode, uint64_t id, unsigned int wl) { if (mode == RING_BUFFER_OVERWRITE) return id & SB_ID_INDEX_MASK(wl); @@ -634,14 +618,11 @@ uint64_t subbuffer_id_get_index(uint32_t mode, uint64_t id, return id; } -static -int copy_crash_subbuf(const struct lttng_crash_layout *layout, - int fd_dest, char *buf, uint64_t offset) +static int +copy_crash_subbuf(const struct lttng_crash_layout *layout, int fd_dest, char *buf, uint64_t offset) { - uint64_t buf_size, subbuf_size, num_subbuf, sbidx, id, - sb_bindex, rpages_offset, p_offset, seq_cc, - committed, commit_count_mask, consumed_cur, - packet_size; + uint64_t buf_size, subbuf_size, num_subbuf, sbidx, id, sb_bindex, rpages_offset, p_offset, + seq_cc, committed, commit_count_mask, consumed_cur, packet_size; char *subbuf_ptr; ssize_t writelen; @@ -656,13 +637,14 @@ int copy_crash_subbuf(const struct lttng_crash_layout *layout, num_subbuf = layout->num_subbuf; switch (layout->word_size) { - case 4: commit_count_mask = 0xFFFFFFFFULL / num_subbuf; + case 4: + commit_count_mask = 0xFFFFFFFFULL / num_subbuf; break; - case 8: commit_count_mask = 0xFFFFFFFFFFFFFFFFULL / num_subbuf; + case 8: + commit_count_mask = 0xFFFFFFFFFFFFFFFFULL / num_subbuf; break; default: - ERR("Unsupported word size: %u", - (unsigned int) layout->word_size); + ERR("Unsupported word size: %u", (unsigned int) layout->word_size); return -EINVAL; } @@ -673,16 +655,16 @@ int copy_crash_subbuf(const struct lttng_crash_layout *layout, * Find where the seq cc is located. Compute length of data to * copy. */ - seq_cc = crash_get_array_field(layout, buf, commit_hot_array, - sbidx, commit_hot_seq); + seq_cc = crash_get_array_field(layout, buf, commit_hot_array, sbidx, commit_hot_seq); consumed_cur = crash_get_field(layout, buf, consumed_offset); /* * Check that the buffer we are getting is after or at * consumed_cur position. */ - if ((long) subbuf_trunc(offset, subbuf_size) - - (long) subbuf_trunc(consumed_cur, subbuf_size) < 0) { + if ((long) subbuf_trunc(offset, subbuf_size) - + (long) subbuf_trunc(consumed_cur, subbuf_size) < + 0) { DBG("No data: position is before consumed_cur"); goto nodata; } @@ -690,9 +672,9 @@ int copy_crash_subbuf(const struct lttng_crash_layout *layout, /* * Check if subbuffer has been fully committed. */ - if (((seq_cc - subbuf_size) & commit_count_mask) - - (buf_trunc(offset, buf_size) / num_subbuf) - == 0) { + if (((seq_cc - subbuf_size) & commit_count_mask) - + (buf_trunc(offset, buf_size) / num_subbuf) == + 0) { committed = subbuf_size; } else { committed = subbuf_offset(seq_cc, subbuf_size); @@ -703,14 +685,11 @@ int copy_crash_subbuf(const struct lttng_crash_layout *layout, } /* Find actual physical offset in subbuffer table */ - id = crash_get_array_field(layout, buf, buf_wsb_array, - sbidx, buf_wsb_id); - sb_bindex = subbuffer_id_get_index(layout->mode, id, - layout->word_size); - rpages_offset = crash_get_array_field(layout, buf, sb_array, - sb_bindex, sb_array_shmp_offset); - p_offset = crash_get_field(layout, buf + rpages_offset, - sb_backend_p_offset); + id = crash_get_array_field(layout, buf, buf_wsb_array, sbidx, buf_wsb_id); + sb_bindex = subbuffer_id_get_index(layout->mode, id, layout->word_size); + rpages_offset = + crash_get_array_field(layout, buf, sb_array, sb_bindex, sb_array_shmp_offset); + p_offset = crash_get_field(layout, buf + rpages_offset, sb_backend_p_offset); subbuf_ptr = buf + p_offset; if (committed == subbuf_size) { @@ -719,8 +698,8 @@ int copy_crash_subbuf(const struct lttng_crash_layout *layout, */ if (layout->length.packet_size) { memcpy(&packet_size, - subbuf_ptr + layout->offset.packet_size, - layout->length.packet_size); + subbuf_ptr + layout->offset.packet_size, + layout->length.packet_size); if (layout->reverse_byte_order) { packet_size = bswap_64(packet_size); } @@ -742,11 +721,13 @@ int copy_crash_subbuf(const struct lttng_crash_layout *layout, } if (layout->length.content_size) { memcpy(subbuf_ptr + layout->offset.content_size, - &patch_size, layout->length.content_size); + &patch_size, + layout->length.content_size); } if (layout->length.packet_size) { memcpy(subbuf_ptr + layout->offset.packet_size, - &patch_size, layout->length.packet_size); + &patch_size, + layout->length.packet_size); } packet_size = committed; } @@ -766,9 +747,7 @@ nodata: return -ENODATA; } -static -int copy_crash_data(const struct lttng_crash_layout *layout, int fd_dest, - int fd_src) +static int copy_crash_data(const struct lttng_crash_layout *layout, int fd_dest, int fd_src) { char *buf; int ret = 0, has_data = 0; @@ -800,8 +779,7 @@ int copy_crash_data(const struct lttng_crash_layout *layout, int fd_dest, DBG("consumed_offset: 0x%" PRIx64, consumed_offset); subbuf_size = layout->subbuf_size; - for (offset = consumed_offset; offset < prod_offset; - offset += subbuf_size) { + for (offset = consumed_offset; offset < prod_offset; offset += subbuf_size) { ret = copy_crash_subbuf(layout, fd_dest, buf, offset); if (!ret) { has_data = 1; @@ -822,20 +800,18 @@ end: } } -static -int extract_file(int output_dir_fd, const char *output_file, - int input_dir_fd, const char *input_file) +static int +extract_file(int output_dir_fd, const char *output_file, int input_dir_fd, const char *input_file) { int fd_dest, fd_src, ret = 0, closeret; struct lttng_crash_layout layout; - layout.reverse_byte_order = 0; /* For reading magic number */ + layout.reverse_byte_order = 0; /* For reading magic number */ DBG("Extract file '%s'", input_file); fd_src = openat(input_dir_fd, input_file, O_RDONLY); if (fd_src < 0) { - PERROR("Error opening '%s' for reading", - input_file); + PERROR("Error opening '%s' for reading", input_file); ret = -1; goto end; } @@ -846,12 +822,12 @@ int extract_file(int output_dir_fd, const char *output_file, goto close_src; } - fd_dest = openat(output_dir_fd, output_file, - O_RDWR | O_CREAT | O_EXCL, - S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP); + fd_dest = openat(output_dir_fd, + output_file, + O_RDWR | O_CREAT | O_EXCL, + S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP); if (fd_dest < 0) { - PERROR("Error opening '%s' for writing", - output_file); + PERROR("Error opening '%s' for writing", output_file); ret = -1; goto close_src; } @@ -881,13 +857,11 @@ end: return ret; } -static -int extract_all_files(const char *output_path, - const char *input_path) +static int extract_all_files(const char *output_path, const char *input_path) { DIR *input_dir, *output_dir; int input_dir_fd, output_dir_fd, ret = 0, closeret; - struct dirent *entry; /* input */ + struct dirent *entry; /* input */ /* Open input directory */ input_dir = opendir(input_path); @@ -914,11 +888,9 @@ int extract_all_files(const char *output_path, } while ((entry = readdir(input_dir))) { - if (!strcmp(entry->d_name, ".") - || !strcmp(entry->d_name, "..")) + if (!strcmp(entry->d_name, ".") || !strcmp(entry->d_name, "..")) continue; - ret = extract_file(output_dir_fd, entry->d_name, - input_dir_fd, entry->d_name); + ret = extract_file(output_dir_fd, entry->d_name, input_dir_fd, entry->d_name); if (ret == -ENODATA) { DBG("No data in file '%s', skipping", entry->d_name); ret = 0; @@ -942,9 +914,7 @@ int extract_all_files(const char *output_path, return ret; } -static -int extract_one_trace(const char *output_path, - const char *input_path) +static int extract_one_trace(const char *output_path, const char *input_path) { char dest[PATH_MAX], src[PATH_MAX]; int ret; @@ -969,9 +939,7 @@ int extract_one_trace(const char *output_path, return extract_all_files(output_path, input_path); } -static -int extract_trace_recursive(const char *output_path, - const char *input_path) +static int extract_trace_recursive(const char *output_path, const char *input_path) { DIR *dir; int dir_fd, ret = 0, closeret; @@ -999,20 +967,19 @@ int extract_trace_recursive(const char *output_path, size_t name_len; char filename[PATH_MAX]; - if (!strcmp(entry->d_name, ".") - || !strcmp(entry->d_name, "..")) { + if (!strcmp(entry->d_name, ".") || !strcmp(entry->d_name, "..")) { continue; } name_len = strlen(entry->d_name); if (path_len + name_len + 2 > sizeof(filename)) { ERR("Failed to remove file: path name too long (%s/%s)", - input_path, entry->d_name); + input_path, + entry->d_name); continue; } - if (snprintf(filename, sizeof(filename), "%s/%s", - input_path, entry->d_name) < 0) { + if (snprintf(filename, sizeof(filename), "%s/%s", input_path, entry->d_name) < 0) { ERR("Failed to format path."); continue; } @@ -1026,12 +993,13 @@ int extract_trace_recursive(const char *output_path, char output_subpath[PATH_MAX]; char input_subpath[PATH_MAX]; - strncpy(output_subpath, output_path, - sizeof(output_subpath)); + strncpy(output_subpath, output_path, sizeof(output_subpath)); output_subpath[sizeof(output_subpath) - 1] = '\0'; - strncat(output_subpath, "/", + strncat(output_subpath, + "/", sizeof(output_subpath) - strlen(output_subpath) - 1); - strncat(output_subpath, entry->d_name, + strncat(output_subpath, + entry->d_name, sizeof(output_subpath) - strlen(output_subpath) - 1); ret = mkdir(output_subpath, S_IRWXU | S_IRWXG); @@ -1041,26 +1009,25 @@ int extract_trace_recursive(const char *output_path, goto end; } - strncpy(input_subpath, input_path, - sizeof(input_subpath)); + strncpy(input_subpath, input_path, sizeof(input_subpath)); input_subpath[sizeof(input_subpath) - 1] = '\0'; - strncat(input_subpath, "/", + strncat(input_subpath, + "/", sizeof(input_subpath) - strlen(input_subpath) - 1); - strncat(input_subpath, entry->d_name, + strncat(input_subpath, + entry->d_name, sizeof(input_subpath) - strlen(input_subpath) - 1); - ret = extract_trace_recursive(output_subpath, - input_subpath); + ret = extract_trace_recursive(output_subpath, input_subpath); if (ret) { has_warning = 1; } } else if (S_ISREG(st.st_mode) || S_ISLNK(st.st_mode)) { if (!strcmp(entry->d_name, "metadata")) { - ret = extract_one_trace(output_path, - input_path); + ret = extract_one_trace(output_path, input_path); if (ret) { WARN("Error extracting trace '%s', continuing anyway.", - input_path); + input_path); has_warning = 1; } } @@ -1077,8 +1044,7 @@ end: return has_warning; } -static -int delete_dir_recursive(const char *path) +static int delete_dir_recursive(const char *path) { DIR *dir; int dir_fd, ret = 0, closeret; @@ -1090,7 +1056,7 @@ int delete_dir_recursive(const char *path) if (!dir) { PERROR("Cannot open '%s' path", path); ret = -errno; - goto end_no_closedir; + goto end_no_closedir; } path_len = strlen(path); @@ -1107,20 +1073,19 @@ int delete_dir_recursive(const char *path) size_t name_len; char filename[PATH_MAX]; - if (!strcmp(entry->d_name, ".") - || !strcmp(entry->d_name, "..")) { + if (!strcmp(entry->d_name, ".") || !strcmp(entry->d_name, "..")) { continue; } name_len = strlen(entry->d_name); if (path_len + name_len + 2 > sizeof(filename)) { ERR("Failed to remove file: path name too long (%s/%s)", - path, entry->d_name); + path, + entry->d_name); continue; } - if (snprintf(filename, sizeof(filename), "%s/%s", - path, entry->d_name) < 0) { + if (snprintf(filename, sizeof(filename), "%s/%s", path, entry->d_name) < 0) { ERR("Failed to format path."); continue; } @@ -1140,10 +1105,8 @@ int delete_dir_recursive(const char *path) } strncpy(subpath, path, PATH_MAX); subpath[PATH_MAX - 1] = '\0'; - strncat(subpath, "/", - PATH_MAX - strlen(subpath) - 1); - strncat(subpath, entry->d_name, - PATH_MAX - strlen(subpath) - 1); + strncat(subpath, "/", PATH_MAX - strlen(subpath) - 1); + strncat(subpath, entry->d_name, PATH_MAX - strlen(subpath) - 1); ret = delete_dir_recursive(subpath); free(subpath); @@ -1177,8 +1140,7 @@ end_no_closedir: return ret; } -static -int view_trace(const char *trace_path, char *viewer_path) +static int view_trace(const char *trace_path, char *viewer_path) { pid_t pid; diff --git a/src/bin/lttng-relayd/backward-compatibility-group-by.cpp b/src/bin/lttng-relayd/backward-compatibility-group-by.cpp index 78f8a1971..c56742720 100644 --- a/src/bin/lttng-relayd/backward-compatibility-group-by.cpp +++ b/src/bin/lttng-relayd/backward-compatibility-group-by.cpp @@ -5,20 +5,19 @@ * */ +#include "backward-compatibility-group-by.hpp" #include "common/time.hpp" -#include -#include -#include -#include #include #include #include -#include "backward-compatibility-group-by.hpp" +#include +#include +#include +#include -#define DATETIME_REGEX \ - ".*-[1-2][0-9][0-9][0-9][0-1][0-9][0-3][0-9]-[0-2][0-9][0-5][0-9][0-5][0-9]$" +#define DATETIME_REGEX ".*-[1-2][0-9][0-9][0-9][0-1][0-9][0-3][0-9]-[0-2][0-9][0-5][0-9][0-5][0-9]$" /* * Provide support for --group-output-by-session for producer >= 2.4 and < 2.11. @@ -28,8 +27,8 @@ * Return the allocated string containing the new stream path or else NULL. */ char *backward_compat_group_by_session(const char *path, - const char *local_session_name, - time_t relay_session_creation_time) + const char *local_session_name, + time_t relay_session_creation_time) { int ret; size_t len; @@ -48,7 +47,8 @@ char *backward_compat_group_by_session(const char *path, LTTNG_ASSERT(local_session_name[0] != '\0'); DBG("Parsing path \"%s\" of session \"%s\" to create a new path that is grouped by session", - path, local_session_name); + path, + local_session_name); /* Get a local copy for strtok */ local_copy = strdup(path); @@ -74,15 +74,13 @@ char *backward_compat_group_by_session(const char *path, */ hostname_ptr = strtok_r(local_copy, "/", &leftover_ptr); if (!hostname_ptr) { - ERR("Failed to parse session path \"%s\": couldn't identify hostname", - path); + ERR("Failed to parse session path \"%s\": couldn't identify hostname", path); goto error; } second_token_ptr = strtok_r(NULL, "/", &leftover_ptr); if (!second_token_ptr) { - ERR("Failed to parse session path \"%s\": couldn't identify session name", - path); + ERR("Failed to parse session path \"%s\": couldn't identify session name", path); goto error; } @@ -100,8 +98,7 @@ char *backward_compat_group_by_session(const char *path, * --