X-Git-Url: https://git.lttng.org/?a=blobdiff_plain;f=src%2Fbin%2Flttng-sessiond%2Fust-app.cpp;h=fcc4267ad5ea8360ae6e139bada338f6f1dff83e;hb=64803277bbdbe0a943360d918298a48157d9da55;hp=62d323ee95619263864553464bb5bb4fa643def3;hpb=48b7cdc221a445188d6d9bd08fc1686837e71224;p=lttng-tools.git diff --git a/src/bin/lttng-sessiond/ust-app.cpp b/src/bin/lttng-sessiond/ust-app.cpp index 62d323ee9..fcc4267ad 100644 --- a/src/bin/lttng-sessiond/ust-app.cpp +++ b/src/bin/lttng-sessiond/ust-app.cpp @@ -21,35 +21,35 @@ #include #include -#include -#include -#include -#include +#include +#include +#include +#include #include -#include +#include #include #include -#include +#include #include -#include -#include - -#include "buffer-registry.h" -#include "condition-internal.h" -#include "fd-limit.h" -#include "health-sessiond.h" -#include "ust-app.h" -#include "ust-consumer.h" -#include "lttng-ust-ctl.h" -#include "lttng-ust-error.h" -#include "utils.h" -#include "session.h" -#include "lttng-sessiond.h" -#include "notification-thread-commands.h" -#include "rotate.h" -#include "event.h" -#include "event-notifier-error-accounting.h" -#include "ust-field-utils.h" +#include +#include + +#include "buffer-registry.hpp" +#include "condition-internal.hpp" +#include "fd-limit.hpp" +#include "health-sessiond.hpp" +#include "ust-app.hpp" +#include "ust-consumer.hpp" +#include "lttng-ust-ctl.hpp" +#include "lttng-ust-error.hpp" +#include "utils.hpp" +#include "session.hpp" +#include "lttng-sessiond.hpp" +#include "notification-thread-commands.hpp" +#include "rotate.hpp" +#include "event.hpp" +#include "event-notifier-error-accounting.hpp" +#include "ust-field-utils.hpp" struct lttng_ht *ust_app_ht; struct lttng_ht *ust_app_ht_by_sock; @@ -696,7 +696,7 @@ ssize_t ust_app_push_metadata(struct ust_registry_session *registry, } /* Allocate only what we have to send. */ - metadata_str = (char *) zmalloc(len); + metadata_str = calloc(len); if (!metadata_str) { PERROR("zmalloc ust app metadata string"); ret_val = -ENOMEM; @@ -1160,7 +1160,7 @@ struct ust_app_session *alloc_ust_app_session(void) struct ust_app_session *ua_sess; /* Init most of the default value by allocating and zeroing */ - ua_sess = (ust_app_session *) zmalloc(sizeof(struct ust_app_session)); + ua_sess = zmalloc(); if (ua_sess == NULL) { PERROR("malloc"); goto error_free; @@ -1188,7 +1188,7 @@ struct ust_app_channel *alloc_ust_app_channel(const char *name, struct ust_app_channel *ua_chan; /* Init most of the default value by allocating and zeroing */ - ua_chan = (ust_app_channel *) zmalloc(sizeof(struct ust_app_channel)); + ua_chan = zmalloc(); if (ua_chan == NULL) { PERROR("malloc"); goto error; @@ -1240,7 +1240,7 @@ struct ust_app_stream *ust_app_alloc_stream(void) { struct ust_app_stream *stream = NULL; - stream = (ust_app_stream *) zmalloc(sizeof(*stream)); + stream = zmalloc(); if (stream == NULL) { PERROR("zmalloc ust app stream"); goto error; @@ -1263,7 +1263,7 @@ struct ust_app_event *alloc_ust_app_event(char *name, struct ust_app_event *ua_event; /* Init most of the default value by allocating and zeroing */ - ua_event = (ust_app_event *) zmalloc(sizeof(struct ust_app_event)); + ua_event = zmalloc(); if (ua_event == NULL) { PERROR("Failed to allocate ust_app_event structure"); goto error; @@ -1300,7 +1300,7 @@ static struct ust_app_event_notifier_rule *alloc_ust_app_event_notifier_rule( struct lttng_condition *condition = NULL; const struct lttng_event_rule *event_rule = NULL; - ua_event_notifier_rule = (ust_app_event_notifier_rule *) zmalloc(sizeof(struct ust_app_event_notifier_rule)); + ua_event_notifier_rule = zmalloc(); if (ua_event_notifier_rule == NULL) { PERROR("Failed to allocate ust_app_event_notifier_rule structure"); goto error; @@ -1360,7 +1360,7 @@ struct ust_app_ctx *alloc_ust_app_ctx(struct lttng_ust_context_attr *uctx) { struct ust_app_ctx *ua_ctx; - ua_ctx = (ust_app_ctx *) zmalloc(sizeof(struct ust_app_ctx)); + ua_ctx = zmalloc(); if (ua_ctx == NULL) { goto error; } @@ -1403,7 +1403,7 @@ static struct lttng_ust_abi_filter_bytecode *create_ust_filter_bytecode_from_byt struct lttng_ust_abi_filter_bytecode *filter = NULL; /* Copy filter bytecode. */ - filter = (lttng_ust_abi_filter_bytecode *) zmalloc(sizeof(*filter) + orig_f->len); + filter = zmalloc(sizeof(*filter) + orig_f->len); if (!filter) { PERROR("Failed to allocate lttng_ust_filter_bytecode: bytecode len = %" PRIu32 " bytes", orig_f->len); goto error; @@ -1427,7 +1427,7 @@ create_ust_capture_bytecode_from_bytecode(const struct lttng_bytecode *orig_f) struct lttng_ust_abi_capture_bytecode *capture = NULL; /* Copy capture bytecode. */ - capture = (lttng_ust_abi_capture_bytecode *) zmalloc(sizeof(*capture) + orig_f->len); + capture = zmalloc(sizeof(*capture) + orig_f->len); if (!capture) { PERROR("Failed to allocate lttng_ust_abi_capture_bytecode: bytecode len = %" PRIu32 " bytes", orig_f->len); goto error; @@ -1711,7 +1711,7 @@ struct lttng_ust_abi_event_exclusion *create_ust_exclusion_from_exclusion( size_t exclusion_alloc_size = sizeof(struct lttng_ust_abi_event_exclusion) + LTTNG_UST_ABI_SYM_NAME_LEN * exclusion->count; - ust_exclusion = (lttng_ust_abi_event_exclusion *) zmalloc(exclusion_alloc_size); + ust_exclusion = zmalloc(exclusion_alloc_size); if (!ust_exclusion) { PERROR("malloc"); goto end; @@ -1998,7 +1998,7 @@ error: * Should be called with session mutex held. */ static -int create_ust_event(struct ust_app *app, struct ust_app_session *ua_sess, +int create_ust_event(struct ust_app *app, struct ust_app_channel *ua_chan, struct ust_app_event *ua_event) { int ret = 0; @@ -2149,7 +2149,7 @@ static int init_ust_event_notifier_from_event_rule( event_notifier->event.instrumentation = LTTNG_UST_ABI_TRACEPOINT; ret = lttng_strncpy(event_notifier->event.name, pattern, - LTTNG_UST_ABI_SYM_NAME_LEN - 1); + sizeof(event_notifier->event.name)); if (ret) { ERR("Failed to copy event rule pattern to notifier: pattern = '%s' ", pattern); @@ -2331,7 +2331,7 @@ static void shadow_copy_event(struct ust_app_event *ua_event, if (uevent->exclusion) { exclusion_alloc_size = sizeof(struct lttng_event_exclusion) + LTTNG_UST_ABI_SYM_NAME_LEN * uevent->exclusion->count; - ua_event->exclusion = (lttng_event_exclusion *) zmalloc(exclusion_alloc_size); + ua_event->exclusion = zmalloc(exclusion_alloc_size); if (ua_event->exclusion == NULL) { PERROR("malloc"); } else { @@ -2886,8 +2886,8 @@ error: * Called with UST app session lock held. */ static -int enable_ust_app_event(struct ust_app_session *ua_sess, - struct ust_app_event *ua_event, struct ust_app *app) +int enable_ust_app_event(struct ust_app_event *ua_event, + struct ust_app *app) { int ret; @@ -2905,8 +2905,8 @@ error: /* * Disable on the tracer side a ust app event for the session and channel. */ -static int disable_ust_app_event(struct ust_app_session *ua_sess, - struct ust_app_event *ua_event, struct ust_app *app) +static int disable_ust_app_event(struct ust_app_event *ua_event, + struct ust_app *app) { int ret; @@ -2983,8 +2983,7 @@ error: */ static int do_consumer_create_channel(struct ltt_ust_session *usess, struct ust_app_session *ua_sess, struct ust_app_channel *ua_chan, - int bitness, struct ust_registry_session *registry, - uint64_t trace_archive_id) + int bitness, struct ust_registry_session *registry) { int ret; unsigned int nb_fd = 0; @@ -3320,7 +3319,7 @@ static int send_channel_uid_to_ust(struct buffer_reg_channel *buf_reg_chan, /* Send all streams to application. */ pthread_mutex_lock(&buf_reg_chan->stream_list_lock); cds_list_for_each_entry(reg_stream, &buf_reg_chan->streams, lnode) { - struct ust_app_stream stream; + struct ust_app_stream stream = {}; ret = duplicate_stream_object(reg_stream, &stream); if (ret < 0) { @@ -3337,8 +3336,8 @@ static int send_channel_uid_to_ust(struct buffer_reg_channel *buf_reg_chan, * Treat this the same way as an application * that is exiting. */ - WARN("Communication with application %d timed out on send_stream for stream \"%s\" of channel \"%s\" of session \"%" PRIu64 "\".", - app->pid, stream.name, + WARN("Communication with application %d timed out on send_stream for stream of channel \"%s\" of session \"%" PRIu64 "\".", + app->pid, ua_chan->name, ua_sess->tracing_id); ret = -ENOTCONN; @@ -3420,8 +3419,7 @@ static int create_channel_per_uid(struct ust_app *app, * ust app channel object with all streams and data object. */ ret = do_consumer_create_channel(usess, ua_sess, ua_chan, - app->bits_per_long, reg_uid->registry->reg.ust, - session->most_recent_chunk_id.value); + app->bits_per_long, reg_uid->registry->reg.ust); if (ret < 0) { ERR("Error creating UST channel \"%s\" on the consumer daemon", ua_chan->name); @@ -3535,8 +3533,7 @@ static int create_channel_per_pid(struct ust_app *app, /* Create and get channel on the consumer side. */ ret = do_consumer_create_channel(usess, ua_sess, ua_chan, - app->bits_per_long, registry, - session->most_recent_chunk_id.value); + app->bits_per_long, registry); if (ret < 0) { ERR("Error creating UST channel \"%s\" on the consumer daemon", ua_chan->name); @@ -3656,7 +3653,8 @@ error: */ static int ust_app_channel_allocate(struct ust_app_session *ua_sess, struct ltt_ust_channel *uchan, - enum lttng_ust_abi_chan_type type, struct ltt_ust_session *usess, + enum lttng_ust_abi_chan_type type, + struct ltt_ust_session *usess __attribute__((unused)), struct ust_app_channel **ua_chanp) { int ret = 0; @@ -3706,8 +3704,8 @@ error: * Called with ust app session mutex held. */ static -int create_ust_app_event(struct ust_app_session *ua_sess, - struct ust_app_channel *ua_chan, struct ltt_ust_event *uevent, +int create_ust_app_event(struct ust_app_channel *ua_chan, + struct ltt_ust_event *uevent, struct ust_app *app) { int ret = 0; @@ -3724,7 +3722,7 @@ int create_ust_app_event(struct ust_app_session *ua_sess, shadow_copy_event(ua_event, uevent); /* Create it on the tracer side */ - ret = create_ust_event(app, ua_sess, ua_chan, ua_event); + ret = create_ust_event(app, ua_chan, ua_event); if (ret < 0) { /* * Not found previously means that it does not exist on the @@ -3995,7 +3993,7 @@ struct ust_app *ust_app_create(struct ust_register_msg *msg, int sock) goto error; } - lta = (ust_app *) zmalloc(sizeof(struct ust_app)); + lta = zmalloc(); if (lta == NULL) { PERROR("malloc"); goto error_free_pipe; @@ -4371,7 +4369,7 @@ int ust_app_list_events(struct lttng_event **events) struct lttng_event *tmp_event; nbmem = UST_APP_EVENT_LIST_SIZE; - tmp_event = (lttng_event *) zmalloc(nbmem * sizeof(struct lttng_event)); + tmp_event = calloc(nbmem); if (tmp_event == NULL) { PERROR("zmalloc ust app events"); ret = -ENOMEM; @@ -4506,7 +4504,7 @@ int ust_app_list_event_fields(struct lttng_event_field **fields) struct lttng_event_field *tmp_event; nbmem = UST_APP_EVENT_LIST_SIZE; - tmp_event = (lttng_event_field *) zmalloc(nbmem * sizeof(struct lttng_event_field)); + tmp_event = calloc(nbmem); if (tmp_event == NULL) { PERROR("zmalloc ust app event fields"); ret = -ENOMEM; @@ -4860,7 +4858,7 @@ int ust_app_disable_event_glb(struct ltt_ust_session *usess, continue; } - ret = disable_ust_app_event(ua_sess, ua_event, app); + ret = disable_ust_app_event(ua_event, app); if (ret < 0) { /* XXX: Report error someday... */ continue; @@ -5019,7 +5017,7 @@ int ust_app_enable_event_glb(struct ltt_ust_session *usess, goto next_app; } - ret = enable_ust_app_event(ua_sess, ua_event, app); + ret = enable_ust_app_event(ua_event, app); if (ret < 0) { pthread_mutex_unlock(&ua_sess->lock); goto error; @@ -5083,7 +5081,7 @@ int ust_app_create_event_glb(struct ltt_ust_session *usess, ua_chan = caa_container_of(ua_chan_node, struct ust_app_channel, node); - ret = create_ust_app_event(ua_sess, ua_chan, uevent, app); + ret = create_ust_app_event(ua_chan, uevent, app); pthread_mutex_unlock(&ua_sess->lock); if (ret < 0) { if (ret != -LTTNG_UST_ERR_EXIST) { @@ -5779,7 +5777,7 @@ end: static int ust_app_channel_synchronize_event(struct ust_app_channel *ua_chan, - struct ltt_ust_event *uevent, struct ust_app_session *ua_sess, + struct ltt_ust_event *uevent, struct ust_app *app) { int ret = 0; @@ -5788,15 +5786,15 @@ int ust_app_channel_synchronize_event(struct ust_app_channel *ua_chan, ua_event = find_ust_app_event(ua_chan->events, uevent->attr.name, uevent->filter, uevent->attr.loglevel, uevent->exclusion); if (!ua_event) { - ret = create_ust_app_event(ua_sess, ua_chan, uevent, app); + ret = create_ust_app_event(ua_chan, uevent, app); if (ret < 0) { goto end; } } else { if (ua_event->enabled != uevent->enabled) { ret = uevent->enabled ? - enable_ust_app_event(ua_sess, ua_event, app) : - disable_ust_app_event(ua_sess, ua_event, app); + enable_ust_app_event(ua_event, app) : + disable_ust_app_event(ua_event, app); } } @@ -5999,7 +5997,7 @@ void ust_app_synchronize_all_channels(struct ltt_ust_session *usess, cds_lfht_for_each_entry(uchan->events->ht, &uevent_iter, uevent, node.node) { ret = ust_app_channel_synchronize_event(ua_chan, - uevent, ua_sess, app); + uevent, app); if (ret) { goto end; } @@ -6391,11 +6389,13 @@ static int ust_app_fixup_legacy_context_fields(size_t *_nr_fields, if (!found) { goto end; } - new_fields = (struct lttng_ust_ctl_field *) zmalloc(sizeof(*new_fields) * new_nr_fields); + + new_fields = calloc(new_nr_fields); if (!new_fields) { ret = -ENOMEM; goto end; } + for (i = 0, j = 0; i < nr_fields; i++, j++) { const struct lttng_ust_ctl_field *field = &fields[i]; struct lttng_ust_ctl_field *new_field = &new_fields[j]; @@ -6946,7 +6946,7 @@ void ust_app_notify_sock_unregister(int sock) rcu_read_lock(); - obj = (ust_app_notify_sock_obj *) zmalloc(sizeof(*obj)); + obj = zmalloc(); if (!obj) { /* * An ENOMEM is kind of uncool. If this strikes we continue the @@ -7023,7 +7023,7 @@ void ust_app_destroy(struct ust_app *app) */ enum lttng_error_code ust_app_snapshot_record( const struct ltt_ust_session *usess, - const struct consumer_output *output, int wait, + const struct consumer_output *output, uint64_t nb_packets_per_stream) { int ret = 0; @@ -7083,8 +7083,7 @@ enum lttng_error_code ust_app_snapshot_record( buf_reg_chan, node.node) { status = consumer_snapshot_channel(socket, buf_reg_chan->consumer_key, - output, 0, usess->uid, - usess->gid, &trace_path[consumer_path_offset], wait, + output, 0, &trace_path[consumer_path_offset], nb_packets_per_stream); if (status != LTTNG_OK) { goto error; @@ -7092,8 +7091,7 @@ enum lttng_error_code ust_app_snapshot_record( } status = consumer_snapshot_channel(socket, reg->registry->reg.ust->metadata_key, output, 1, - usess->uid, usess->gid, &trace_path[consumer_path_offset], - wait, 0); + &trace_path[consumer_path_offset], 0); if (status != LTTNG_OK) { goto error; } @@ -7146,9 +7144,7 @@ enum lttng_error_code ust_app_snapshot_record( ua_chan, node.node) { status = consumer_snapshot_channel(socket, ua_chan->key, output, 0, - lttng_credentials_get_uid(&ua_sess->effective_credentials), - lttng_credentials_get_gid(&ua_sess->effective_credentials), - &trace_path[consumer_path_offset], wait, + &trace_path[consumer_path_offset], nb_packets_per_stream); switch (status) { case LTTNG_OK: @@ -7167,9 +7163,7 @@ enum lttng_error_code ust_app_snapshot_record( } status = consumer_snapshot_channel(socket, registry->metadata_key, output, 1, - lttng_credentials_get_uid(&ua_sess->effective_credentials), - lttng_credentials_get_gid(&ua_sess->effective_credentials), - &trace_path[consumer_path_offset], wait, 0); + &trace_path[consumer_path_offset], 0); switch (status) { case LTTNG_OK: break; @@ -7462,7 +7456,6 @@ enum lttng_error_code ust_app_rotate_session(struct ltt_session *session) buf_reg_chan, node.node) { ret = consumer_rotate_channel(socket, buf_reg_chan->consumer_key, - usess->uid, usess->gid, usess->consumer, /* is_metadata_channel */ false); if (ret < 0) { @@ -7488,7 +7481,6 @@ enum lttng_error_code ust_app_rotate_session(struct ltt_session *session) ret = consumer_rotate_channel(socket, reg->registry->reg.ust->metadata_key, - usess->uid, usess->gid, usess->consumer, /* is_metadata_channel */ true); if (ret < 0) { @@ -7532,8 +7524,6 @@ enum lttng_error_code ust_app_rotate_session(struct ltt_session *session) ua_chan, node.node) { ret = consumer_rotate_channel(socket, ua_chan->key, - lttng_credentials_get_uid(&ua_sess->effective_credentials), - lttng_credentials_get_gid(&ua_sess->effective_credentials), ua_sess->consumer, /* is_metadata_channel */ false); if (ret < 0) { @@ -7549,8 +7539,6 @@ enum lttng_error_code ust_app_rotate_session(struct ltt_session *session) (void) push_metadata(registry, usess->consumer); ret = consumer_rotate_channel(socket, registry->metadata_key, - lttng_credentials_get_uid(&ua_sess->effective_credentials), - lttng_credentials_get_gid(&ua_sess->effective_credentials), ua_sess->consumer, /* is_metadata_channel */ true); if (ret < 0) {