+ if (chan_kern_created) {
+ struct ltt_kernel_channel *kchan =
+ trace_kernel_get_channel_by_name(DEFAULT_CHANNEL_NAME,
+ session->kernel_session);
+ /* Created previously, this should NOT fail. */
+ assert(kchan);
+ kernel_destroy_channel(kchan);
+ }
+
+ if (chan_ust_created) {
+ struct ltt_ust_channel *uchan =
+ trace_ust_find_channel_by_name(
+ session->ust_session->domain_global.channels,
+ DEFAULT_CHANNEL_NAME);
+ /* Created previously, this should NOT fail. */
+ assert(uchan);
+ /* Remove from the channel list of the session. */
+ trace_ust_delete_channel(session->ust_session->domain_global.channels,
+ uchan);
+ trace_ust_destroy_channel(uchan);
+ }
+ return ret;
+}
+
+static int validate_event_name(const char *name)
+{
+ int ret = 0;
+ const char *c = name;
+ const char *event_name_end = c + LTTNG_SYMBOL_NAME_LEN;
+ bool null_terminated = false;
+
+ /*
+ * Make sure that unescaped wildcards are only used as the last
+ * character of the event name.
+ */
+ while (c < event_name_end) {
+ switch (*c) {
+ case '\0':
+ null_terminated = true;
+ goto end;
+ case '\\':
+ c++;
+ break;
+ case '*':
+ if ((c + 1) < event_name_end && *(c + 1)) {
+ /* Wildcard is not the last character */
+ ret = LTTNG_ERR_INVALID_EVENT_NAME;
+ goto end;
+ }
+ default:
+ break;
+ }
+ c++;
+ }
+end:
+ if (!ret && !null_terminated) {
+ ret = LTTNG_ERR_INVALID_EVENT_NAME;
+ }
+ return ret;
+}
+
+static inline bool name_starts_with(const char *name, const char *prefix)
+{
+ const size_t max_cmp_len = min(strlen(prefix), LTTNG_SYMBOL_NAME_LEN);
+
+ return !strncmp(name, prefix, max_cmp_len);
+}
+
+/* Perform userspace-specific event name validation */
+static int validate_ust_event_name(const char *name)
+{
+ int ret = 0;
+
+ if (!name) {
+ ret = -1;
+ goto end;
+ }
+
+ /*
+ * Check name against all internal UST event component namespaces used
+ * by the agents.
+ */
+ if (name_starts_with(name, DEFAULT_JUL_EVENT_COMPONENT) ||
+ name_starts_with(name, DEFAULT_LOG4J_EVENT_COMPONENT) ||
+ name_starts_with(name, DEFAULT_PYTHON_EVENT_COMPONENT)) {
+ ret = -1;
+ }
+
+end: