2 * Copyright (C) 2013 David Goulet <dgoulet@efficios.com>
4 * SPDX-License-Identifier: GPL-2.0-only
12 #include <common/common.h>
13 #include <common/hashtable/utils.h>
14 #include <lttng/lttng.h>
16 #include "ust-registry.h"
18 #include "ust-field-utils.h"
20 #include "lttng-sessiond.h"
21 #include "notification-thread-commands.h"
25 * Hash table match function for event in the registry.
27 static int ht_match_event(struct cds_lfht_node
*node
, const void *_key
)
29 const struct ust_registry_event
*key
;
30 struct ust_registry_event
*event
;
36 event
= caa_container_of(node
, struct ust_registry_event
, node
.node
);
40 /* It has to be a perfect match. First, compare the event names. */
41 if (strncmp(event
->name
, key
->name
, sizeof(event
->name
))) {
45 /* Compare log levels. */
46 if (event
->loglevel_value
!= key
->loglevel_value
) {
50 /* Compare the number of fields. */
51 if (event
->nr_fields
!= key
->nr_fields
) {
55 /* Compare each field individually. */
56 for (i
= 0; i
< event
->nr_fields
; i
++) {
57 if (!match_ustctl_field(&event
->fields
[i
], &key
->fields
[i
])) {
62 /* Compare model URI. */
63 if (event
->model_emf_uri
!= NULL
&& key
->model_emf_uri
== NULL
) {
65 } else if(event
->model_emf_uri
== NULL
&& key
->model_emf_uri
!= NULL
) {
67 } else if (event
->model_emf_uri
!= NULL
&& key
->model_emf_uri
!= NULL
) {
68 if (strcmp(event
->model_emf_uri
, key
->model_emf_uri
)) {
80 static unsigned long ht_hash_event(const void *_key
, unsigned long seed
)
83 const struct ust_registry_event
*key
= _key
;
87 hashed_key
= (uint64_t) hash_key_str(key
->name
, seed
);
89 return hash_key_u64(&hashed_key
, seed
);
92 static int compare_enums(const struct ust_registry_enum
*reg_enum_a
,
93 const struct ust_registry_enum
*reg_enum_b
)
98 assert(strcmp(reg_enum_a
->name
, reg_enum_b
->name
) == 0);
99 if (reg_enum_a
->nr_entries
!= reg_enum_b
->nr_entries
) {
103 for (i
= 0; i
< reg_enum_a
->nr_entries
; i
++) {
104 const struct ustctl_enum_entry
*entries_a
, *entries_b
;
106 entries_a
= ®_enum_a
->entries
[i
];
107 entries_b
= ®_enum_b
->entries
[i
];
108 if (entries_a
->start
.value
!= entries_b
->start
.value
) {
112 if (entries_a
->end
.value
!= entries_b
->end
.value
) {
116 if (entries_a
->start
.signedness
!= entries_b
->start
.signedness
) {
120 if (entries_a
->end
.signedness
!= entries_b
->end
.signedness
) {
125 if (strcmp(entries_a
->string
, entries_b
->string
)) {
135 * Hash table match function for enumerations in the session. Match is
136 * performed on enumeration name, and confirmed by comparing the enum
139 static int ht_match_enum(struct cds_lfht_node
*node
, const void *_key
)
141 struct ust_registry_enum
*_enum
;
142 const struct ust_registry_enum
*key
;
147 _enum
= caa_container_of(node
, struct ust_registry_enum
,
152 if (strncmp(_enum
->name
, key
->name
, LTTNG_UST_SYM_NAME_LEN
)) {
155 if (compare_enums(_enum
, key
)) {
167 * Hash table match function for enumerations in the session. Match is
168 * performed by enumeration ID.
170 static int ht_match_enum_id(struct cds_lfht_node
*node
, const void *_key
)
172 struct ust_registry_enum
*_enum
;
173 const struct ust_registry_enum
*key
= _key
;
178 _enum
= caa_container_of(node
, struct ust_registry_enum
, node
.node
);
181 if (_enum
->id
!= key
->id
) {
193 * Hash table hash function for enumerations in the session. The
194 * enumeration name is used for hashing.
196 static unsigned long ht_hash_enum(void *_key
, unsigned long seed
)
198 struct ust_registry_enum
*key
= _key
;
201 return hash_key_str(key
->name
, seed
);
205 * Return negative value on error, 0 if OK.
207 * TODO: we could add stricter verification of more types to catch
208 * errors in liblttng-ust implementation earlier than consumption by the
212 int validate_event_field(struct ustctl_field
*field
,
213 const char *event_name
,
218 switch(field
->type
.atype
) {
219 case ustctl_atype_integer
:
220 case ustctl_atype_enum
:
221 case ustctl_atype_array
:
222 case ustctl_atype_sequence
:
223 case ustctl_atype_string
:
224 case ustctl_atype_variant
:
226 case ustctl_atype_struct
:
227 if (field
->type
.u
._struct
.nr_fields
!= 0) {
228 WARN("Unsupported non-empty struct field.");
234 case ustctl_atype_float
:
235 switch (field
->type
.u
.basic
._float
.mant_dig
) {
237 WARN("UST application '%s' (pid: %d) has unknown float mantissa '%u' "
238 "in field '%s', rejecting event '%s'",
240 field
->type
.u
.basic
._float
.mant_dig
,
259 int validate_event_fields(size_t nr_fields
, struct ustctl_field
*fields
,
260 const char *event_name
, struct ust_app
*app
)
264 for (i
= 0; i
< nr_fields
; i
++) {
265 if (validate_event_field(&fields
[i
], event_name
, app
) < 0)
272 * Allocate event and initialize it. This does NOT set a valid event id from a
275 static struct ust_registry_event
*alloc_event(int session_objd
,
276 int channel_objd
, char *name
, char *sig
, size_t nr_fields
,
277 struct ustctl_field
*fields
, int loglevel_value
,
278 char *model_emf_uri
, struct ust_app
*app
)
280 struct ust_registry_event
*event
= NULL
;
283 * Ensure that the field content is valid.
285 if (validate_event_fields(nr_fields
, fields
, name
, app
) < 0) {
289 event
= zmalloc(sizeof(*event
));
291 PERROR("zmalloc ust registry event");
295 event
->session_objd
= session_objd
;
296 event
->channel_objd
= channel_objd
;
297 /* Allocated by ustctl. */
298 event
->signature
= sig
;
299 event
->nr_fields
= nr_fields
;
300 event
->fields
= fields
;
301 event
->loglevel_value
= loglevel_value
;
302 event
->model_emf_uri
= model_emf_uri
;
304 /* Copy event name and force NULL byte. */
305 strncpy(event
->name
, name
, sizeof(event
->name
));
306 event
->name
[sizeof(event
->name
) - 1] = '\0';
308 cds_lfht_node_init(&event
->node
.node
);
315 * Free event data structure. This does NOT delete it from any hash table. It's
316 * safe to pass a NULL pointer. This shoudl be called inside a call RCU if the
317 * event is previously deleted from a rcu hash table.
319 static void destroy_event(struct ust_registry_event
*event
)
326 free(event
->model_emf_uri
);
327 free(event
->signature
);
332 * Destroy event function call of the call RCU.
334 static void destroy_event_rcu(struct rcu_head
*head
)
336 struct lttng_ht_node_u64
*node
=
337 caa_container_of(head
, struct lttng_ht_node_u64
, head
);
338 struct ust_registry_event
*event
=
339 caa_container_of(node
, struct ust_registry_event
, node
);
341 destroy_event(event
);
345 * Find an event using the name and signature in the given registry. RCU read
346 * side lock MUST be acquired before calling this function and as long as the
347 * event reference is kept by the caller.
349 * On success, the event pointer is returned else NULL.
351 struct ust_registry_event
*ust_registry_find_event(
352 struct ust_registry_channel
*chan
, char *name
, char *sig
)
354 struct lttng_ht_node_u64
*node
;
355 struct lttng_ht_iter iter
;
356 struct ust_registry_event
*event
= NULL
;
357 struct ust_registry_event key
;
363 /* Setup key for the match function. */
364 strncpy(key
.name
, name
, sizeof(key
.name
));
365 key
.name
[sizeof(key
.name
) - 1] = '\0';
368 cds_lfht_lookup(chan
->ht
->ht
, chan
->ht
->hash_fct(&key
, lttng_ht_seed
),
369 chan
->ht
->match_fct
, &key
, &iter
.iter
);
370 node
= lttng_ht_iter_get_node_u64(&iter
);
374 event
= caa_container_of(node
, struct ust_registry_event
, node
);
381 * Create a ust_registry_event from the given parameters and add it to the
382 * registry hash table. If event_id is valid, it is set with the newly created
385 * On success, return 0 else a negative value. The created event MUST be unique
386 * so on duplicate entry -EINVAL is returned. On error, event_id is untouched.
388 * Should be called with session registry mutex held.
390 int ust_registry_create_event(struct ust_registry_session
*session
,
391 uint64_t chan_key
, int session_objd
, int channel_objd
, char *name
,
392 char *sig
, size_t nr_fields
, struct ustctl_field
*fields
,
393 int loglevel_value
, char *model_emf_uri
, int buffer_type
,
394 uint32_t *event_id_p
, struct ust_app
*app
)
398 struct cds_lfht_node
*nptr
;
399 struct ust_registry_event
*event
= NULL
;
400 struct ust_registry_channel
*chan
;
410 * This should not happen but since it comes from the UST tracer, an
411 * external party, don't assert and simply validate values.
413 if (session_objd
< 0 || channel_objd
< 0) {
418 chan
= ust_registry_channel_find(session
, chan_key
);
424 /* Check if we've reached the maximum possible id. */
425 if (ust_registry_is_max_id(chan
->used_event_id
)) {
430 event
= alloc_event(session_objd
, channel_objd
, name
, sig
, nr_fields
,
431 fields
, loglevel_value
, model_emf_uri
, app
);
437 DBG3("UST registry creating event with event: %s, sig: %s, id: %u, "
438 "chan_objd: %u, sess_objd: %u, chan_id: %u", event
->name
,
439 event
->signature
, event
->id
, event
->channel_objd
,
440 event
->session_objd
, chan
->chan_id
);
443 * This is an add unique with a custom match function for event. The node
444 * are matched using the event name and signature.
446 nptr
= cds_lfht_add_unique(chan
->ht
->ht
, chan
->ht
->hash_fct(event
,
447 lttng_ht_seed
), chan
->ht
->match_fct
, event
, &event
->node
.node
);
448 if (nptr
!= &event
->node
.node
) {
449 if (buffer_type
== LTTNG_BUFFER_PER_UID
) {
451 * This is normal, we just have to send the event id of the
452 * returned node and make sure we destroy the previously allocated
455 destroy_event(event
);
456 event
= caa_container_of(nptr
, struct ust_registry_event
,
459 event_id
= event
->id
;
461 ERR("UST registry create event add unique failed for event: %s, "
462 "sig: %s, id: %u, chan_objd: %u, sess_objd: %u",
463 event
->name
, event
->signature
, event
->id
,
464 event
->channel_objd
, event
->session_objd
);
469 /* Request next event id if the node was successfully added. */
470 event_id
= event
->id
= ust_registry_get_next_event_id(chan
);
473 *event_id_p
= event_id
;
475 if (!event
->metadata_dumped
) {
476 /* Append to metadata */
477 ret
= ust_metadata_event_statedump(session
, chan
, event
);
479 ERR("Error appending event metadata (errno = %d)", ret
);
494 destroy_event(event
);
499 * For a given event in a registry, delete the entry and destroy the event.
500 * This MUST be called within a RCU read side lock section.
502 void ust_registry_destroy_event(struct ust_registry_channel
*chan
,
503 struct ust_registry_event
*event
)
506 struct lttng_ht_iter iter
;
511 /* Delete the node first. */
512 iter
.iter
.node
= &event
->node
.node
;
513 ret
= lttng_ht_del(chan
->ht
, &iter
);
516 call_rcu(&event
->node
.head
, destroy_event_rcu
);
521 static void destroy_enum(struct ust_registry_enum
*reg_enum
)
526 free(reg_enum
->entries
);
530 static void destroy_enum_rcu(struct rcu_head
*head
)
532 struct ust_registry_enum
*reg_enum
=
533 caa_container_of(head
, struct ust_registry_enum
, rcu_head
);
535 destroy_enum(reg_enum
);
539 * Lookup enumeration by name and comparing enumeration entries.
540 * Needs to be called from RCU read-side critical section.
542 static struct ust_registry_enum
*ust_registry_lookup_enum(
543 struct ust_registry_session
*session
,
544 const struct ust_registry_enum
*reg_enum_lookup
)
546 struct ust_registry_enum
*reg_enum
= NULL
;
547 struct lttng_ht_node_str
*node
;
548 struct lttng_ht_iter iter
;
550 cds_lfht_lookup(session
->enums
->ht
,
551 ht_hash_enum((void *) reg_enum_lookup
, lttng_ht_seed
),
552 ht_match_enum
, reg_enum_lookup
, &iter
.iter
);
553 node
= lttng_ht_iter_get_node_str(&iter
);
557 reg_enum
= caa_container_of(node
, struct ust_registry_enum
, node
);
563 * Lookup enumeration by enum ID.
564 * Needs to be called from RCU read-side critical section.
566 struct ust_registry_enum
*
567 ust_registry_lookup_enum_by_id(struct ust_registry_session
*session
,
568 const char *enum_name
, uint64_t enum_id
)
570 struct ust_registry_enum
*reg_enum
= NULL
;
571 struct lttng_ht_node_str
*node
;
572 struct lttng_ht_iter iter
;
573 struct ust_registry_enum reg_enum_lookup
;
575 memset(®_enum_lookup
, 0, sizeof(reg_enum_lookup
));
576 strncpy(reg_enum_lookup
.name
, enum_name
, LTTNG_UST_SYM_NAME_LEN
);
577 reg_enum_lookup
.name
[LTTNG_UST_SYM_NAME_LEN
- 1] = '\0';
578 reg_enum_lookup
.id
= enum_id
;
579 cds_lfht_lookup(session
->enums
->ht
,
580 ht_hash_enum((void *) ®_enum_lookup
, lttng_ht_seed
),
581 ht_match_enum_id
, ®_enum_lookup
, &iter
.iter
);
582 node
= lttng_ht_iter_get_node_str(&iter
);
586 reg_enum
= caa_container_of(node
, struct ust_registry_enum
, node
);
592 * Create a ust_registry_enum from the given parameters and add it to the
593 * registry hash table, or find it if already there.
595 * On success, return 0 else a negative value.
597 * Should be called with session registry mutex held.
599 * We receive ownership of entries.
601 int ust_registry_create_or_find_enum(struct ust_registry_session
*session
,
602 int session_objd
, char *enum_name
,
603 struct ustctl_enum_entry
*entries
, size_t nr_entries
,
607 struct cds_lfht_node
*nodep
;
608 struct ust_registry_enum
*reg_enum
= NULL
, *old_reg_enum
;
616 * This should not happen but since it comes from the UST tracer, an
617 * external party, don't assert and simply validate values.
619 if (session_objd
< 0) {
624 /* Check if the enumeration was already dumped */
625 reg_enum
= zmalloc(sizeof(*reg_enum
));
627 PERROR("zmalloc ust registry enumeration");
631 strncpy(reg_enum
->name
, enum_name
, LTTNG_UST_SYM_NAME_LEN
);
632 reg_enum
->name
[LTTNG_UST_SYM_NAME_LEN
- 1] = '\0';
633 /* entries will be owned by reg_enum. */
634 reg_enum
->entries
= entries
;
635 reg_enum
->nr_entries
= nr_entries
;
638 old_reg_enum
= ust_registry_lookup_enum(session
, reg_enum
);
640 DBG("enum %s already in sess_objd: %u", enum_name
, session_objd
);
641 /* Fall through. Use prior enum. */
642 destroy_enum(reg_enum
);
643 reg_enum
= old_reg_enum
;
645 DBG("UST registry creating enum: %s, sess_objd: %u",
646 enum_name
, session_objd
);
647 if (session
->next_enum_id
== -1ULL) {
649 destroy_enum(reg_enum
);
652 reg_enum
->id
= session
->next_enum_id
++;
653 cds_lfht_node_init(®_enum
->node
.node
);
654 nodep
= cds_lfht_add_unique(session
->enums
->ht
,
655 ht_hash_enum(reg_enum
, lttng_ht_seed
),
656 ht_match_enum_id
, reg_enum
,
657 ®_enum
->node
.node
);
658 assert(nodep
== ®_enum
->node
.node
);
660 DBG("UST registry reply with enum %s with id %" PRIu64
" in sess_objd: %u",
661 enum_name
, reg_enum
->id
, session_objd
);
662 *enum_id
= reg_enum
->id
;
670 * For a given enumeration in a registry, delete the entry and destroy
672 * This MUST be called within a RCU read side lock section.
674 static void ust_registry_destroy_enum(struct ust_registry_session
*reg_session
,
675 struct ust_registry_enum
*reg_enum
)
678 struct lttng_ht_iter iter
;
683 /* Delete the node first. */
684 iter
.iter
.node
= ®_enum
->node
.node
;
685 ret
= lttng_ht_del(reg_session
->enums
, &iter
);
687 call_rcu(®_enum
->rcu_head
, destroy_enum_rcu
);
691 * We need to execute ht_destroy outside of RCU read-side critical
692 * section and outside of call_rcu thread, so we postpone its execution
693 * using ht_cleanup_push. It is simpler than to change the semantic of
694 * the many callers of delete_ust_app_session().
697 void destroy_channel_rcu(struct rcu_head
*head
)
699 struct ust_registry_channel
*chan
=
700 caa_container_of(head
, struct ust_registry_channel
, rcu_head
);
703 ht_cleanup_push(chan
->ht
);
705 free(chan
->ctx_fields
);
710 * Destroy every element of the registry and free the memory. This does NOT
711 * free the registry pointer since it might not have been allocated before so
712 * it's the caller responsability.
714 static void destroy_channel(struct ust_registry_channel
*chan
, bool notif
)
716 struct lttng_ht_iter iter
;
717 struct ust_registry_event
*event
;
718 enum lttng_error_code cmd_ret
;
723 cmd_ret
= notification_thread_command_remove_channel(
724 notification_thread_handle
, chan
->consumer_key
,
726 if (cmd_ret
!= LTTNG_OK
) {
727 ERR("Failed to remove channel from notification thread");
733 /* Destroy all event associated with this registry. */
734 cds_lfht_for_each_entry(
735 chan
->ht
->ht
, &iter
.iter
, event
, node
.node
) {
736 /* Delete the node from the ht and free it. */
737 ust_registry_destroy_event(chan
, event
);
741 call_rcu(&chan
->rcu_head
, destroy_channel_rcu
);
745 * Initialize registry with default values.
747 int ust_registry_channel_add(struct ust_registry_session
*session
,
751 struct ust_registry_channel
*chan
;
755 chan
= zmalloc(sizeof(*chan
));
757 PERROR("zmalloc ust registry channel");
762 chan
->ht
= lttng_ht_new(0, LTTNG_HT_TYPE_STRING
);
768 /* Set custom match function. */
769 chan
->ht
->match_fct
= ht_match_event
;
770 chan
->ht
->hash_fct
= ht_hash_event
;
773 * Assign a channel ID right now since the event notification comes
774 * *before* the channel notify so the ID needs to be set at this point so
775 * the metadata can be dumped for that event.
777 if (ust_registry_is_max_id(session
->used_channel_id
)) {
781 chan
->chan_id
= ust_registry_get_next_chan_id(session
);
784 lttng_ht_node_init_u64(&chan
->node
, key
);
785 lttng_ht_add_unique_u64(session
->channels
, &chan
->node
);
791 destroy_channel(chan
, false);
797 * Find a channel in the given registry. RCU read side lock MUST be acquired
798 * before calling this function and as long as the event reference is kept by
801 * On success, the pointer is returned else NULL.
803 struct ust_registry_channel
*ust_registry_channel_find(
804 struct ust_registry_session
*session
, uint64_t key
)
806 struct lttng_ht_node_u64
*node
;
807 struct lttng_ht_iter iter
;
808 struct ust_registry_channel
*chan
= NULL
;
811 assert(session
->channels
);
813 DBG3("UST registry channel finding key %" PRIu64
, key
);
815 lttng_ht_lookup(session
->channels
, &key
, &iter
);
816 node
= lttng_ht_iter_get_node_u64(&iter
);
820 chan
= caa_container_of(node
, struct ust_registry_channel
, node
);
827 * Remove channel using key from registry and free memory.
829 void ust_registry_channel_del_free(struct ust_registry_session
*session
,
830 uint64_t key
, bool notif
)
832 struct lttng_ht_iter iter
;
833 struct ust_registry_channel
*chan
;
839 chan
= ust_registry_channel_find(session
, key
);
845 iter
.iter
.node
= &chan
->node
.node
;
846 ret
= lttng_ht_del(session
->channels
, &iter
);
849 destroy_channel(chan
, notif
);
856 * Initialize registry with default values and set the newly allocated session
857 * pointer to sessionp.
859 * Return 0 on success and sessionp is set or else return -1 and sessionp is
862 int ust_registry_session_init(struct ust_registry_session
**sessionp
,
864 uint32_t bits_per_long
,
865 uint32_t uint8_t_alignment
,
866 uint32_t uint16_t_alignment
,
867 uint32_t uint32_t_alignment
,
868 uint32_t uint64_t_alignment
,
869 uint32_t long_alignment
,
873 const char *root_shm_path
,
874 const char *shm_path
,
881 struct ust_registry_session
*session
;
885 session
= zmalloc(sizeof(*session
));
887 PERROR("zmalloc ust registry session");
891 pthread_mutex_init(&session
->lock
, NULL
);
892 session
->bits_per_long
= bits_per_long
;
893 session
->uint8_t_alignment
= uint8_t_alignment
;
894 session
->uint16_t_alignment
= uint16_t_alignment
;
895 session
->uint32_t_alignment
= uint32_t_alignment
;
896 session
->uint64_t_alignment
= uint64_t_alignment
;
897 session
->long_alignment
= long_alignment
;
898 session
->byte_order
= byte_order
;
899 session
->metadata_fd
= -1;
902 session
->next_enum_id
= 0;
903 session
->major
= major
;
904 session
->minor
= minor
;
905 strncpy(session
->root_shm_path
, root_shm_path
,
906 sizeof(session
->root_shm_path
));
907 session
->root_shm_path
[sizeof(session
->root_shm_path
) - 1] = '\0';
909 strncpy(session
->shm_path
, shm_path
,
910 sizeof(session
->shm_path
));
911 session
->shm_path
[sizeof(session
->shm_path
) - 1] = '\0';
912 strncpy(session
->metadata_path
, shm_path
,
913 sizeof(session
->metadata_path
));
914 session
->metadata_path
[sizeof(session
->metadata_path
) - 1] = '\0';
915 strncat(session
->metadata_path
, "/metadata",
916 sizeof(session
->metadata_path
)
917 - strlen(session
->metadata_path
) - 1);
919 if (session
->shm_path
[0]) {
920 ret
= run_as_mkdir_recursive(session
->shm_path
,
924 PERROR("run_as_mkdir_recursive");
928 if (session
->metadata_path
[0]) {
929 /* Create metadata file */
930 ret
= run_as_open(session
->metadata_path
,
931 O_WRONLY
| O_CREAT
| O_EXCL
,
932 S_IRUSR
| S_IWUSR
, euid
, egid
);
934 PERROR("Opening metadata file");
937 session
->metadata_fd
= ret
;
940 session
->enums
= lttng_ht_new(0, LTTNG_HT_TYPE_STRING
);
941 if (!session
->enums
) {
942 ERR("Failed to create enums hash table");
945 /* hash/match functions are specified at call site. */
946 session
->enums
->match_fct
= NULL
;
947 session
->enums
->hash_fct
= NULL
;
949 session
->channels
= lttng_ht_new(0, LTTNG_HT_TYPE_U64
);
950 if (!session
->channels
) {
954 ret
= lttng_uuid_generate(session
->uuid
);
956 ERR("Failed to generate UST uuid (errno = %d)", ret
);
960 session
->tracing_id
= tracing_id
;
961 session
->tracing_uid
= tracing_uid
;
963 pthread_mutex_lock(&session
->lock
);
964 ret
= ust_metadata_session_statedump(session
, app
, major
, minor
);
965 pthread_mutex_unlock(&session
->lock
);
967 ERR("Failed to generate session metadata (errno = %d)", ret
);
976 ust_registry_session_destroy(session
);
983 * Destroy session registry. This does NOT free the given pointer since it
984 * might get passed as a reference. The registry lock should NOT be acquired.
986 void ust_registry_session_destroy(struct ust_registry_session
*reg
)
989 struct lttng_ht_iter iter
;
990 struct ust_registry_channel
*chan
;
991 struct ust_registry_enum
*reg_enum
;
997 /* On error, EBUSY can be returned if lock. Code flow error. */
998 ret
= pthread_mutex_destroy(®
->lock
);
1001 if (reg
->channels
) {
1003 /* Destroy all event associated with this registry. */
1004 cds_lfht_for_each_entry(reg
->channels
->ht
, &iter
.iter
, chan
,
1006 /* Delete the node from the ht and free it. */
1007 ret
= lttng_ht_del(reg
->channels
, &iter
);
1009 destroy_channel(chan
, true);
1012 ht_cleanup_push(reg
->channels
);
1015 free(reg
->metadata
);
1016 if (reg
->metadata_fd
>= 0) {
1017 ret
= close(reg
->metadata_fd
);
1021 ret
= run_as_unlink(reg
->metadata_path
,
1022 reg
->uid
, reg
->gid
);
1027 if (reg
->root_shm_path
[0]) {
1029 * Try deleting the directory hierarchy.
1031 (void) run_as_rmdir_recursive(reg
->root_shm_path
,
1033 LTTNG_DIRECTORY_HANDLE_SKIP_NON_EMPTY_FLAG
);
1035 /* Destroy the enum hash table */
1038 /* Destroy all enum entries associated with this registry. */
1039 cds_lfht_for_each_entry(reg
->enums
->ht
, &iter
.iter
, reg_enum
,
1041 ust_registry_destroy_enum(reg
, reg_enum
);
1044 ht_cleanup_push(reg
->enums
);