{
int ret;
struct ust_app_notify_sock_obj *obj =
- caa_container_of(head, struct ust_app_notify_sock_obj, head);
+ lttng::utils::container_of(head, &ust_app_notify_sock_obj::head);
/* Must have a valid fd here. */
LTTNG_ASSERT(obj->fd >= 0);
static
void free_ust_app_event_notifier_rule_rcu(struct rcu_head *head)
{
- struct ust_app_event_notifier_rule *obj = caa_container_of(
- head, struct ust_app_event_notifier_rule, rcu_head);
+ struct ust_app_event_notifier_rule *obj = lttng::utils::container_of(
+ head, &ust_app_event_notifier_rule::rcu_head);
free(obj);
}
void delete_ust_app_channel_rcu(struct rcu_head *head)
{
struct ust_app_channel *ua_chan =
- caa_container_of(head, struct ust_app_channel, rcu_head);
+ lttng::utils::container_of(head, &ust_app_channel::rcu_head);
lttng_ht_destroy(ua_chan->ctx);
lttng_ht_destroy(ua_chan->events);
void delete_ust_app_session_rcu(struct rcu_head *head)
{
struct ust_app_session *ua_sess =
- caa_container_of(head, struct ust_app_session, rcu_head);
+ lttng::utils::container_of(head, &ust_app_session::rcu_head);
lttng_ht_destroy(ua_sess->channels);
free(ua_sess);
void delete_ust_app_rcu(struct rcu_head *head)
{
struct lttng_ht_node_ulong *node =
- caa_container_of(head, struct lttng_ht_node_ulong, head);
+ lttng::utils::container_of(head, <tng_ht_node_ulong::head);
struct ust_app *app =
- caa_container_of(node, struct ust_app, pid_n);
+ lttng::utils::container_of(node, &ust_app::pid_n);
DBG3("Call RCU deleting app PID %d", app->pid);
delete_ust_app(app);
goto error;
}
- return caa_container_of(node, struct ust_app, sock_n);
+ return lttng::utils::container_of(node, &ust_app::sock_n);
error:
return NULL;
goto error;
}
- return caa_container_of(node, struct ust_app, notify_sock_n);
+ return lttng::utils::container_of(node, &ust_app::notify_sock_n);
error:
return NULL;
goto end;
}
- event = caa_container_of(node, struct ust_app_event, node);
+ event = lttng::utils::container_of(node, &ust_app_event::node);
end:
return event;
goto end;
}
- event_notifier_rule = caa_container_of(
- node, struct ust_app_event_notifier_rule, node);
+ event_notifier_rule = lttng::utils::container_of(
+ node, &ust_app_event_notifier_rule::node);
end:
return event_notifier_rule;
}
goto error;
}
- return caa_container_of(node, struct ust_app_session, node);
+ return lttng::utils::container_of(node, &ust_app_session::node);
error:
return NULL;
goto end;
}
- app_ctx = caa_container_of(node, struct ust_app_ctx, node);
+ app_ctx = lttng::utils::container_of(node, &ust_app_ctx::node);
end:
return app_ctx;
goto error;
}
- ua_chan = caa_container_of(ua_chan_node, struct ust_app_channel, node);
+ ua_chan = lttng::utils::container_of(ua_chan_node, &ust_app_channel::node);
ret = enable_ust_channel(app, ua_sess, ua_chan);
if (ret < 0) {
lttng_ht_lookup(ua_sess->channels, (void *)uchan->name, &iter);
ua_chan_node = lttng_ht_iter_get_node_str(&iter);
if (ua_chan_node != NULL) {
- ua_chan = caa_container_of(ua_chan_node, struct ust_app_channel, node);
+ ua_chan = lttng::utils::container_of(ua_chan_node, &ust_app_channel::node);
goto end;
}
DBG2("Found UST app by pid %d", pid);
- app = caa_container_of(node, struct ust_app, pid_n);
+ app = lttng::utils::container_of(node, &ust_app::pid_n);
error:
return app;
node = lttng_ht_iter_get_node_ulong(&ust_app_sock_iter);
LTTNG_ASSERT(node);
- lta = caa_container_of(node, struct ust_app, sock_n);
+ lta = lttng::utils::container_of(node, &ust_app::sock_n);
DBG("PID %d unregistering with sock %d", lta->pid, sock);
/*
/* If the session if found for the app, the channel must be there */
LTTNG_ASSERT(ua_chan_node);
- ua_chan = caa_container_of(ua_chan_node, struct ust_app_channel, node);
+ 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);
"Skipping", uchan->name, usess->id, app->pid);
continue;
}
- ua_chan = caa_container_of(ua_chan_node, struct ust_app_channel, node);
+ ua_chan = lttng::utils::container_of(ua_chan_node, &ust_app_channel::node);
ua_event = find_ust_app_event(ua_chan->events, uevent->attr.name,
uevent->filter, uevent->attr.loglevel,
continue;
}
- ua_chan = caa_container_of(ua_chan_node, struct ust_app_channel, node);
+ ua_chan = lttng::utils::container_of(ua_chan_node, &ust_app_channel::node);
/* Get event node */
ua_event = find_ust_app_event(ua_chan->events, uevent->attr.name,
/* If the channel is not found, there is a code flow error */
LTTNG_ASSERT(ua_chan_node);
- ua_chan = caa_container_of(ua_chan_node, struct ust_app_channel, node);
+ ua_chan = lttng::utils::container_of(ua_chan_node, &ust_app_channel::node);
ret = create_ust_app_event(ua_chan, uevent, app);
pthread_mutex_unlock(&ua_sess->lock);
/* Session is being or is deleted. */
goto end;
}
- ua_sess = caa_container_of(node, struct ust_app_session, node);
+ ua_sess = lttng::utils::container_of(node, &ust_app_session::node);
health_code_update();
destroy_app_session(app, ua_sess);
goto error;
}
- ua_sess = caa_container_of(node, struct ust_app_session, ust_objd_node);
+ ua_sess = lttng::utils::container_of(node, &ust_app_session::ust_objd_node);
error:
return ua_sess;
goto error;
}
- ua_chan = caa_container_of(node, struct ust_app_channel, ust_objd_node);
+ ua_chan = lttng::utils::container_of(node, &ust_app_channel::ust_objd_node);
error:
return ua_chan;
*
* On success 0 is returned else a negative value.
*/
-static int add_enum_ust_registry(int sock, int sobjd, char *name,
- struct lttng_ust_ctl_enum_entry *entries, size_t nr_entries)
+static int add_enum_ust_registry(int sock, int sobjd, const char *name,
+ struct lttng_ust_ctl_enum_entry *raw_entries, size_t nr_entries)
{
- int ret = 0, ret_code;
+ int ret = 0;
struct ust_app *app;
struct ust_app_session *ua_sess;
- lsu::registry_session *registry;
uint64_t enum_id = -1ULL;
-
- rcu_read_lock();
+ lttng::urcu::read_lock_guard read_lock_guard;
+ auto entries = lttng::make_unique_wrapper<struct lttng_ust_ctl_enum_entry, lttng::free>(
+ raw_entries);
/* Lookup application. If not found, there is a code flow error. */
app = find_app_by_notify_sock(sock);
/* Return an error since this is not an error */
DBG("Application socket %d is being torn down. Aborting enum registration",
sock);
- free(entries);
- ret = -1;
- goto error_rcu_unlock;
+ return -1;
}
/* Lookup session by UST object descriptor. */
if (!ua_sess) {
/* Return an error since this is not an error */
DBG("Application session is being torn down (session not found). Aborting enum registration.");
- free(entries);
- goto error_rcu_unlock;
+ return 0;
}
- registry = get_session_registry(ua_sess);
- if (!registry) {
+ auto locked_registry = get_locked_session_registry(ua_sess);
+ if (!locked_registry) {
DBG("Application session is being torn down (registry not found). Aborting enum registration.");
- free(entries);
- goto error_rcu_unlock;
+ return 0;
}
- pthread_mutex_lock(®istry->_lock);
-
/*
* From this point on, the callee acquires the ownership of
* entries. The variable entries MUST NOT be read/written after
* call.
*/
- ret_code = ust_registry_create_or_find_enum(registry, sobjd, name,
- entries, nr_entries, &enum_id);
- entries = NULL;
+ int application_reply_code;
+ try {
+ locked_registry->create_or_find_enum(
+ sobjd, name, entries.release(), nr_entries, &enum_id);
+ application_reply_code = 0;
+ } catch (const std::exception& ex) {
+ ERR("%s: %s", fmt::format("Failed to create or find enumeration provided by application: app = {}, enumeration name = {}",
+ *app, name).c_str(), ex.what());
+ application_reply_code = -1;
+ }
/*
* The return value is returned to ustctl so in case of an error, the
* application can be notified. In case of an error, it's important not to
* return a negative error or else the application will get closed.
*/
- ret = lttng_ust_ctl_reply_register_enum(sock, enum_id, ret_code);
+ ret = lttng_ust_ctl_reply_register_enum(sock, enum_id, application_reply_code);
if (ret < 0) {
if (ret == -EPIPE || ret == -LTTNG_UST_ERR_EXITING) {
DBG3("UST app reply enum failed. Application died: pid = %d, sock = %d",
* No need to wipe the create enum since the application socket will
* get close on error hence cleaning up everything by itself.
*/
- goto error;
+ return ret;
}
DBG3("UST registry enum %s added successfully or already found", name);
-
-error:
- pthread_mutex_unlock(®istry->_lock);
-error_rcu_unlock:
- rcu_read_unlock();
- return ret;
+ return 0;
}
/*
/* If the session is found for the app, the channel must be there */
LTTNG_ASSERT(ua_chan_node);
- ua_chan = caa_container_of(ua_chan_node, struct ust_app_channel, node);
+ ua_chan = lttng::utils::container_of(ua_chan_node, &ust_app_channel::node);
if (overwrite) {
uint64_t _lost;