2 * Copyright (C) 2019 Jonathan Rajotte <jonathan.rajotte-julien@efficios.com>
4 * SPDX-License-Identifier: LGPL-2.1-only
9 #include <common/credentials.h>
10 #include <common/error.h>
11 #include <common/macros.h>
12 #include <common/optional.h>
13 #include <common/payload.h>
14 #include <common/payload-view.h>
15 #include <common/runas.h>
16 #include <common/hashtable/hashtable.h>
17 #include <common/hashtable/utils.h>
18 #include <common/string-utils/string-utils.h>
19 #include <lttng/event-rule/event-rule-internal.h>
20 #include <lttng/event-rule/user-tracepoint-internal.h>
21 #include <lttng/log-level-rule.h>
22 #include <lttng/event.h>
24 #define IS_USER_TRACEPOINT_EVENT_RULE(rule) \
25 (lttng_event_rule_get_type(rule) == LTTNG_EVENT_RULE_TYPE_USER_TRACEPOINT)
27 static void lttng_event_rule_user_tracepoint_destroy(struct lttng_event_rule
*rule
)
29 struct lttng_event_rule_user_tracepoint
*tracepoint
;
35 tracepoint
= container_of(
36 rule
, struct lttng_event_rule_user_tracepoint
, parent
);
38 lttng_log_level_rule_destroy(tracepoint
->log_level_rule
);
39 lttng_dynamic_pointer_array_reset(&tracepoint
->exclusions
);
40 free(tracepoint
->pattern
);
41 free(tracepoint
->filter_expression
);
42 free(tracepoint
->internal_filter
.filter
);
43 free(tracepoint
->internal_filter
.bytecode
);
47 static bool lttng_event_rule_user_tracepoint_validate(
48 const struct lttng_event_rule
*rule
)
51 struct lttng_event_rule_user_tracepoint
*tracepoint
;
57 tracepoint
= container_of(
58 rule
, struct lttng_event_rule_user_tracepoint
, parent
);
61 if (!tracepoint
->pattern
) {
62 ERR("Invalid user tracepoint event rule: a pattern must be set.");
71 static int lttng_event_rule_user_tracepoint_serialize(
72 const struct lttng_event_rule
*rule
,
73 struct lttng_payload
*payload
)
76 size_t pattern_len
, filter_expression_len
, exclusions_len
, header_offset
;
77 size_t size_before_log_level_rule
;
78 struct lttng_event_rule_user_tracepoint
*tracepoint
;
79 struct lttng_event_rule_user_tracepoint_comm tracepoint_comm
;
80 enum lttng_event_rule_status status
;
81 unsigned int exclusion_count
;
82 size_t exclusions_appended_len
= 0;
83 struct lttng_event_rule_user_tracepoint_comm
*header
;
85 if (!rule
|| !IS_USER_TRACEPOINT_EVENT_RULE(rule
)) {
90 header_offset
= payload
->buffer
.size
;
92 DBG("Serializing user tracepoint event rule.");
93 tracepoint
= container_of(
94 rule
, struct lttng_event_rule_user_tracepoint
, parent
);
96 status
= lttng_event_rule_user_tracepoint_get_name_pattern_exclusion_count(rule
, &exclusion_count
);
97 assert(status
== LTTNG_EVENT_RULE_STATUS_OK
);
99 pattern_len
= strlen(tracepoint
->pattern
) + 1;
101 if (tracepoint
->filter_expression
!= NULL
) {
102 filter_expression_len
=
103 strlen(tracepoint
->filter_expression
) + 1;
105 filter_expression_len
= 0;
109 for (i
= 0; i
< exclusion_count
; i
++) {
110 const char *exclusion
;
112 status
= lttng_event_rule_user_tracepoint_get_name_pattern_exclusion_at_index(
113 rule
, i
, &exclusion
);
114 assert(status
== LTTNG_EVENT_RULE_STATUS_OK
);
117 exclusions_len
+= sizeof(uint32_t);
118 /* Payload (null terminated). */
119 exclusions_len
+= strlen(exclusion
) + 1;
122 tracepoint_comm
.pattern_len
= pattern_len
;
123 tracepoint_comm
.filter_expression_len
= filter_expression_len
;
124 tracepoint_comm
.exclusions_count
= exclusion_count
;
125 tracepoint_comm
.exclusions_len
= exclusions_len
;
127 ret
= lttng_dynamic_buffer_append(&payload
->buffer
, &tracepoint_comm
,
128 sizeof(tracepoint_comm
));
133 ret
= lttng_dynamic_buffer_append(
134 &payload
->buffer
, tracepoint
->pattern
, pattern_len
);
139 ret
= lttng_dynamic_buffer_append(&payload
->buffer
, tracepoint
->filter_expression
,
140 filter_expression_len
);
145 size_before_log_level_rule
= payload
->buffer
.size
;
147 ret
= lttng_log_level_rule_serialize(tracepoint
->log_level_rule
, payload
);
152 header
= (typeof(header
)) ((char *) payload
->buffer
.data
+ header_offset
);
153 header
->log_level_rule_len
=
154 payload
->buffer
.size
- size_before_log_level_rule
;
156 for (i
= 0; i
< exclusion_count
; i
++) {
158 const char *exclusion
;
160 status
= lttng_event_rule_user_tracepoint_get_name_pattern_exclusion_at_index(
161 rule
, i
, &exclusion
);
162 assert(status
== LTTNG_EVENT_RULE_STATUS_OK
);
164 len
= strlen(exclusion
) + 1;
165 /* Append exclusion length, includes the null terminator. */
166 ret
= lttng_dynamic_buffer_append(
167 &payload
->buffer
, &len
, sizeof(uint32_t));
172 exclusions_appended_len
+= sizeof(uint32_t);
174 /* Include the '\0' in the payload. */
175 ret
= lttng_dynamic_buffer_append(
176 &payload
->buffer
, exclusion
, len
);
181 exclusions_appended_len
+= len
;
184 assert(exclusions_len
== exclusions_appended_len
);
190 static bool lttng_event_rule_user_tracepoint_is_equal(
191 const struct lttng_event_rule
*_a
,
192 const struct lttng_event_rule
*_b
)
195 bool is_equal
= false;
196 struct lttng_event_rule_user_tracepoint
*a
, *b
;
197 unsigned int count_a
, count_b
;
198 enum lttng_event_rule_status status
;
200 a
= container_of(_a
, struct lttng_event_rule_user_tracepoint
, parent
);
201 b
= container_of(_b
, struct lttng_event_rule_user_tracepoint
, parent
);
203 status
= lttng_event_rule_user_tracepoint_get_name_pattern_exclusion_count(_a
, &count_a
);
204 assert(status
== LTTNG_EVENT_RULE_STATUS_OK
);
205 status
= lttng_event_rule_user_tracepoint_get_name_pattern_exclusion_count(_b
, &count_b
);
206 assert(status
== LTTNG_EVENT_RULE_STATUS_OK
);
209 if (count_a
!= count_b
) {
213 if (!!a
->filter_expression
!= !!b
->filter_expression
) {
220 if (strcmp(a
->pattern
, b
->pattern
)) {
224 if (a
->filter_expression
&& b
->filter_expression
) {
225 if (strcmp(a
->filter_expression
, b
->filter_expression
)) {
228 } else if (!!a
->filter_expression
!= !!b
->filter_expression
) {
229 /* One is set; not the other. */
233 if (!lttng_log_level_rule_is_equal(
234 a
->log_level_rule
, b
->log_level_rule
)) {
238 for (i
= 0; i
< count_a
; i
++) {
239 const char *exclusion_a
, *exclusion_b
;
241 status
= lttng_event_rule_user_tracepoint_get_name_pattern_exclusion_at_index(
242 _a
, i
, &exclusion_a
);
243 assert(status
== LTTNG_EVENT_RULE_STATUS_OK
);
244 status
= lttng_event_rule_user_tracepoint_get_name_pattern_exclusion_at_index(
245 _b
, i
, &exclusion_b
);
246 assert(status
== LTTNG_EVENT_RULE_STATUS_OK
);
247 if (strcmp(exclusion_a
, exclusion_b
)) {
257 static enum lttng_error_code
258 lttng_event_rule_user_tracepoint_generate_filter_bytecode(
259 struct lttng_event_rule
*rule
,
260 const struct lttng_credentials
*creds
)
263 enum lttng_error_code ret_code
;
264 struct lttng_event_rule_user_tracepoint
*tracepoint
;
265 enum lttng_event_rule_status status
;
267 struct lttng_bytecode
*bytecode
= NULL
;
271 tracepoint
= container_of(
272 rule
, struct lttng_event_rule_user_tracepoint
, parent
);
274 status
= lttng_event_rule_user_tracepoint_get_filter(rule
, &filter
);
275 if (status
== LTTNG_EVENT_RULE_STATUS_UNSET
) {
277 } else if (status
!= LTTNG_EVENT_RULE_STATUS_OK
) {
278 ret_code
= LTTNG_ERR_FILTER_INVAL
;
282 if (filter
&& filter
[0] == '\0') {
283 ret_code
= LTTNG_ERR_FILTER_INVAL
;
288 tracepoint
->internal_filter
.filter
= strdup(filter
);
289 if (tracepoint
->internal_filter
.filter
== NULL
) {
290 ret_code
= LTTNG_ERR_NOMEM
;
294 tracepoint
->internal_filter
.filter
= NULL
;
297 if (tracepoint
->internal_filter
.filter
== NULL
) {
302 ret
= run_as_generate_filter_bytecode(
303 tracepoint
->internal_filter
.filter
, creds
,
306 ret_code
= LTTNG_ERR_FILTER_INVAL
;
310 tracepoint
->internal_filter
.bytecode
= bytecode
;
320 static const char *lttng_event_rule_user_tracepoint_get_internal_filter(
321 const struct lttng_event_rule
*rule
)
323 struct lttng_event_rule_user_tracepoint
*tracepoint
;
326 tracepoint
= container_of(
327 rule
, struct lttng_event_rule_user_tracepoint
, parent
);
328 return tracepoint
->internal_filter
.filter
;
331 static const struct lttng_bytecode
*
332 lttng_event_rule_user_tracepoint_get_internal_filter_bytecode(
333 const struct lttng_event_rule
*rule
)
335 struct lttng_event_rule_user_tracepoint
*tracepoint
;
338 tracepoint
= container_of(
339 rule
, struct lttng_event_rule_user_tracepoint
, parent
);
340 return tracepoint
->internal_filter
.bytecode
;
343 static enum lttng_event_rule_generate_exclusions_status
344 lttng_event_rule_user_tracepoint_generate_exclusions(
345 const struct lttng_event_rule
*rule
,
346 struct lttng_event_exclusion
**_exclusions
)
348 unsigned int nb_exclusions
= 0, i
;
349 struct lttng_event_exclusion
*exclusions
;
350 enum lttng_event_rule_status event_rule_status
;
351 enum lttng_event_rule_generate_exclusions_status ret_status
;
355 event_rule_status
= lttng_event_rule_user_tracepoint_get_name_pattern_exclusion_count(
356 rule
, &nb_exclusions
);
357 assert(event_rule_status
== LTTNG_EVENT_RULE_STATUS_OK
);
358 if (nb_exclusions
== 0) {
361 ret_status
= LTTNG_EVENT_RULE_GENERATE_EXCLUSIONS_STATUS_NONE
;
365 exclusions
= zmalloc(sizeof(struct lttng_event_exclusion
) +
366 (LTTNG_SYMBOL_NAME_LEN
* nb_exclusions
));
368 PERROR("Failed to allocate exclusions buffer");
369 ret_status
= LTTNG_EVENT_RULE_GENERATE_EXCLUSIONS_STATUS_OUT_OF_MEMORY
;
373 exclusions
->count
= nb_exclusions
;
374 for (i
= 0; i
< nb_exclusions
; i
++) {
376 const char *exclusion_str
;
379 lttng_event_rule_user_tracepoint_get_name_pattern_exclusion_at_index(
380 rule
, i
, &exclusion_str
);
381 assert(event_rule_status
== LTTNG_EVENT_RULE_STATUS_OK
);
383 copy_ret
= lttng_strncpy(exclusions
->names
[i
], exclusion_str
,
384 LTTNG_SYMBOL_NAME_LEN
);
388 ret_status
= LTTNG_EVENT_RULE_GENERATE_EXCLUSIONS_STATUS_ERROR
;
393 ret_status
= LTTNG_EVENT_RULE_GENERATE_EXCLUSIONS_STATUS_OK
;
396 *_exclusions
= exclusions
;
400 static void destroy_lttng_exclusions_element(void *ptr
)
405 static unsigned long lttng_event_rule_user_tracepoint_hash(
406 const struct lttng_event_rule
*rule
)
409 unsigned int i
, exclusion_count
;
410 enum lttng_event_rule_status status
;
411 struct lttng_event_rule_user_tracepoint
*tp_rule
=
412 container_of(rule
, typeof(*tp_rule
), parent
);
414 hash
= hash_key_ulong((void *) LTTNG_EVENT_RULE_TYPE_USER_TRACEPOINT
,
416 hash
^= hash_key_str(tp_rule
->pattern
, lttng_ht_seed
);
418 if (tp_rule
->filter_expression
) {
419 hash
^= hash_key_str(tp_rule
->filter_expression
, lttng_ht_seed
);
422 if (tp_rule
->log_level_rule
) {
423 hash
^= lttng_log_level_rule_hash(tp_rule
->log_level_rule
);
426 status
= lttng_event_rule_user_tracepoint_get_name_pattern_exclusion_count(rule
,
428 assert(status
== LTTNG_EVENT_RULE_STATUS_OK
);
430 for (i
= 0; i
< exclusion_count
; i
++) {
431 const char *exclusion
;
433 status
= lttng_event_rule_user_tracepoint_get_name_pattern_exclusion_at_index(
434 rule
, i
, &exclusion
);
435 assert(status
== LTTNG_EVENT_RULE_STATUS_OK
);
436 hash
^= hash_key_str(exclusion
, lttng_ht_seed
);
442 struct lttng_event_rule
*lttng_event_rule_user_tracepoint_create(void)
444 struct lttng_event_rule
*rule
= NULL
;
445 struct lttng_event_rule_user_tracepoint
*tp_rule
;
446 enum lttng_event_rule_status status
;
448 tp_rule
= zmalloc(sizeof(struct lttng_event_rule_user_tracepoint
));
453 rule
= &tp_rule
->parent
;
454 lttng_event_rule_init(&tp_rule
->parent
, LTTNG_EVENT_RULE_TYPE_USER_TRACEPOINT
);
455 tp_rule
->parent
.validate
= lttng_event_rule_user_tracepoint_validate
;
456 tp_rule
->parent
.serialize
= lttng_event_rule_user_tracepoint_serialize
;
457 tp_rule
->parent
.equal
= lttng_event_rule_user_tracepoint_is_equal
;
458 tp_rule
->parent
.destroy
= lttng_event_rule_user_tracepoint_destroy
;
459 tp_rule
->parent
.generate_filter_bytecode
=
460 lttng_event_rule_user_tracepoint_generate_filter_bytecode
;
461 tp_rule
->parent
.get_filter
=
462 lttng_event_rule_user_tracepoint_get_internal_filter
;
463 tp_rule
->parent
.get_filter_bytecode
=
464 lttng_event_rule_user_tracepoint_get_internal_filter_bytecode
;
465 tp_rule
->parent
.generate_exclusions
=
466 lttng_event_rule_user_tracepoint_generate_exclusions
;
467 tp_rule
->parent
.hash
= lttng_event_rule_user_tracepoint_hash
;
469 /* Not necessary for now. */
470 tp_rule
->parent
.generate_lttng_event
= NULL
;
472 tp_rule
->log_level_rule
= NULL
;
474 lttng_dynamic_pointer_array_init(&tp_rule
->exclusions
,
475 destroy_lttng_exclusions_element
);
477 /* Default pattern is '*'. */
478 status
= lttng_event_rule_user_tracepoint_set_name_pattern(rule
, "*");
479 if (status
!= LTTNG_EVENT_RULE_STATUS_OK
) {
480 lttng_event_rule_destroy(rule
);
489 ssize_t
lttng_event_rule_user_tracepoint_create_from_payload(
490 struct lttng_payload_view
*view
,
491 struct lttng_event_rule
**_event_rule
)
493 ssize_t ret
, offset
= 0;
495 enum lttng_event_rule_status status
;
496 const struct lttng_event_rule_user_tracepoint_comm
*tracepoint_comm
;
498 const char *filter_expression
= NULL
;
499 const char **exclusions
= NULL
;
500 const uint32_t *exclusion_len
;
501 const char *exclusion
;
502 struct lttng_buffer_view current_buffer_view
;
503 struct lttng_event_rule
*rule
= NULL
;
504 struct lttng_log_level_rule
*log_level_rule
= NULL
;
511 current_buffer_view
= lttng_buffer_view_from_view(
512 &view
->buffer
, offset
, sizeof(*tracepoint_comm
));
513 if (!lttng_buffer_view_is_valid(¤t_buffer_view
)) {
514 ERR("Failed to initialize from malformed event rule tracepoint: buffer too short to contain header.");
519 tracepoint_comm
= (typeof(tracepoint_comm
)) current_buffer_view
.data
;
521 rule
= lttng_event_rule_user_tracepoint_create();
523 ERR("Failed to create event rule user tracepoint.");
528 /* Skip to payload. */
529 offset
+= current_buffer_view
.size
;
531 /* Map the pattern. */
532 current_buffer_view
= lttng_buffer_view_from_view(
533 &view
->buffer
, offset
, tracepoint_comm
->pattern_len
);
535 if (!lttng_buffer_view_is_valid(¤t_buffer_view
)) {
540 pattern
= current_buffer_view
.data
;
541 if (!lttng_buffer_view_contains_string(¤t_buffer_view
, pattern
,
542 tracepoint_comm
->pattern_len
)) {
547 /* Skip after the pattern. */
548 offset
+= tracepoint_comm
->pattern_len
;
550 if (!tracepoint_comm
->filter_expression_len
) {
551 goto skip_filter_expression
;
554 /* Map the filter_expression. */
555 current_buffer_view
= lttng_buffer_view_from_view(&view
->buffer
, offset
,
556 tracepoint_comm
->filter_expression_len
);
557 if (!lttng_buffer_view_is_valid(¤t_buffer_view
)) {
562 filter_expression
= current_buffer_view
.data
;
563 if (!lttng_buffer_view_contains_string(¤t_buffer_view
,
565 tracepoint_comm
->filter_expression_len
)) {
570 /* Skip after the pattern. */
571 offset
+= tracepoint_comm
->filter_expression_len
;
573 skip_filter_expression
:
574 if (!tracepoint_comm
->log_level_rule_len
) {
575 goto skip_log_level_rule
;
579 /* Map the log level rule. */
580 struct lttng_payload_view current_payload_view
=
581 lttng_payload_view_from_view(view
, offset
,
582 tracepoint_comm
->log_level_rule_len
);
584 ret
= lttng_log_level_rule_create_from_payload(
585 ¤t_payload_view
, &log_level_rule
);
591 assert(ret
== tracepoint_comm
->log_level_rule_len
);
594 /* Skip after the log level rule. */
595 offset
+= tracepoint_comm
->log_level_rule_len
;
598 for (i
= 0; i
< tracepoint_comm
->exclusions_count
; i
++) {
599 current_buffer_view
= lttng_buffer_view_from_view(
600 &view
->buffer
, offset
, sizeof(*exclusion_len
));
601 if (!lttng_buffer_view_is_valid(¤t_buffer_view
)) {
606 exclusion_len
= (typeof(exclusion_len
)) current_buffer_view
.data
;
607 offset
+= sizeof(*exclusion_len
);
609 current_buffer_view
= lttng_buffer_view_from_view(
610 &view
->buffer
, offset
, *exclusion_len
);
611 if (!lttng_buffer_view_is_valid(¤t_buffer_view
)) {
616 exclusion
= current_buffer_view
.data
;
617 if (!lttng_buffer_view_contains_string(¤t_buffer_view
,
618 exclusion
, *exclusion_len
)) {
623 status
= lttng_event_rule_user_tracepoint_add_name_pattern_exclusion(rule
, exclusion
);
624 if (status
!= LTTNG_EVENT_RULE_STATUS_OK
) {
625 ERR("Failed to add event rule user tracepoint exclusion \"%s\".",
631 /* Skip to next exclusion. */
632 offset
+= *exclusion_len
;
635 status
= lttng_event_rule_user_tracepoint_set_name_pattern(rule
, pattern
);
636 if (status
!= LTTNG_EVENT_RULE_STATUS_OK
) {
637 ERR("Failed to set event rule user tracepoint pattern.");
642 if (filter_expression
) {
643 status
= lttng_event_rule_user_tracepoint_set_filter(
644 rule
, filter_expression
);
645 if (status
!= LTTNG_EVENT_RULE_STATUS_OK
) {
646 ERR("Failed to set event rule user tracepoint pattern.");
652 if (log_level_rule
) {
653 status
= lttng_event_rule_user_tracepoint_set_log_level_rule(
654 rule
, log_level_rule
);
655 if (status
!= LTTNG_EVENT_RULE_STATUS_OK
) {
656 ERR("Failed to set event rule user tracepoint log level rule.");
667 lttng_log_level_rule_destroy(log_level_rule
);
668 lttng_event_rule_destroy(rule
);
672 enum lttng_event_rule_status
lttng_event_rule_user_tracepoint_set_name_pattern(
673 struct lttng_event_rule
*rule
, const char *pattern
)
675 char *pattern_copy
= NULL
;
676 struct lttng_event_rule_user_tracepoint
*tracepoint
;
677 enum lttng_event_rule_status status
= LTTNG_EVENT_RULE_STATUS_OK
;
679 if (!rule
|| !IS_USER_TRACEPOINT_EVENT_RULE(rule
) || !pattern
||
680 strlen(pattern
) == 0) {
681 status
= LTTNG_EVENT_RULE_STATUS_INVALID
;
685 tracepoint
= container_of(
686 rule
, struct lttng_event_rule_user_tracepoint
, parent
);
687 pattern_copy
= strdup(pattern
);
689 status
= LTTNG_EVENT_RULE_STATUS_ERROR
;
693 /* Normalize the pattern. */
694 strutils_normalize_star_glob_pattern(pattern_copy
);
696 free(tracepoint
->pattern
);
698 tracepoint
->pattern
= pattern_copy
;
704 enum lttng_event_rule_status
lttng_event_rule_user_tracepoint_get_name_pattern(
705 const struct lttng_event_rule
*rule
, const char **pattern
)
707 struct lttng_event_rule_user_tracepoint
*tracepoint
;
708 enum lttng_event_rule_status status
= LTTNG_EVENT_RULE_STATUS_OK
;
710 if (!rule
|| !IS_USER_TRACEPOINT_EVENT_RULE(rule
) || !pattern
) {
711 status
= LTTNG_EVENT_RULE_STATUS_INVALID
;
715 tracepoint
= container_of(
716 rule
, struct lttng_event_rule_user_tracepoint
, parent
);
717 if (!tracepoint
->pattern
) {
718 status
= LTTNG_EVENT_RULE_STATUS_UNSET
;
722 *pattern
= tracepoint
->pattern
;
727 enum lttng_event_rule_status
lttng_event_rule_user_tracepoint_set_filter(
728 struct lttng_event_rule
*rule
, const char *expression
)
730 char *expression_copy
= NULL
;
731 struct lttng_event_rule_user_tracepoint
*tracepoint
;
732 enum lttng_event_rule_status status
= LTTNG_EVENT_RULE_STATUS_OK
;
734 if (!rule
|| !IS_USER_TRACEPOINT_EVENT_RULE(rule
) || !expression
||
735 strlen(expression
) == 0) {
736 status
= LTTNG_EVENT_RULE_STATUS_INVALID
;
740 tracepoint
= container_of(
741 rule
, struct lttng_event_rule_user_tracepoint
, parent
);
742 expression_copy
= strdup(expression
);
743 if (!expression_copy
) {
744 PERROR("Failed to copy filter expression");
745 status
= LTTNG_EVENT_RULE_STATUS_ERROR
;
749 if (tracepoint
->filter_expression
) {
750 free(tracepoint
->filter_expression
);
753 tracepoint
->filter_expression
= expression_copy
;
754 expression_copy
= NULL
;
759 enum lttng_event_rule_status
lttng_event_rule_user_tracepoint_get_filter(
760 const struct lttng_event_rule
*rule
, const char **expression
)
762 struct lttng_event_rule_user_tracepoint
*tracepoint
;
763 enum lttng_event_rule_status status
= LTTNG_EVENT_RULE_STATUS_OK
;
765 if (!rule
|| !IS_USER_TRACEPOINT_EVENT_RULE(rule
) || !expression
) {
766 status
= LTTNG_EVENT_RULE_STATUS_INVALID
;
770 tracepoint
= container_of(
771 rule
, struct lttng_event_rule_user_tracepoint
, parent
);
772 if (!tracepoint
->filter_expression
) {
773 status
= LTTNG_EVENT_RULE_STATUS_UNSET
;
777 *expression
= tracepoint
->filter_expression
;
782 static bool log_level_rule_valid(const struct lttng_log_level_rule
*rule
)
785 enum lttng_log_level_rule_status status
;
788 switch (lttng_log_level_rule_get_type(rule
)) {
789 case LTTNG_LOG_LEVEL_RULE_TYPE_EXACTLY
:
790 status
= lttng_log_level_rule_exactly_get_level(rule
, &level
);
792 case LTTNG_LOG_LEVEL_RULE_TYPE_AT_LEAST_AS_SEVERE_AS
:
793 status
= lttng_log_level_rule_at_least_as_severe_as_get_level(
800 assert(status
== LTTNG_LOG_LEVEL_RULE_STATUS_OK
);
802 if (level
< LTTNG_LOGLEVEL_EMERG
) {
806 if (level
> LTTNG_LOGLEVEL_DEBUG
) {
817 enum lttng_event_rule_status
lttng_event_rule_user_tracepoint_set_log_level_rule(
818 struct lttng_event_rule
*rule
,
819 const struct lttng_log_level_rule
*log_level_rule
)
821 struct lttng_event_rule_user_tracepoint
*tracepoint
;
822 enum lttng_event_rule_status status
= LTTNG_EVENT_RULE_STATUS_OK
;
823 struct lttng_log_level_rule
*copy
= NULL
;
825 if (!rule
|| !IS_USER_TRACEPOINT_EVENT_RULE(rule
)) {
826 status
= LTTNG_EVENT_RULE_STATUS_INVALID
;
830 tracepoint
= container_of(
831 rule
, struct lttng_event_rule_user_tracepoint
, parent
);
833 if (!log_level_rule_valid(log_level_rule
)) {
834 status
= LTTNG_EVENT_RULE_STATUS_INVALID
;
838 copy
= lttng_log_level_rule_copy(log_level_rule
);
840 status
= LTTNG_EVENT_RULE_STATUS_ERROR
;
844 if (tracepoint
->log_level_rule
) {
845 lttng_log_level_rule_destroy(tracepoint
->log_level_rule
);
848 tracepoint
->log_level_rule
= copy
;
854 enum lttng_event_rule_status
lttng_event_rule_user_tracepoint_get_log_level_rule(
855 const struct lttng_event_rule
*rule
,
856 const struct lttng_log_level_rule
**log_level_rule
859 struct lttng_event_rule_user_tracepoint
*tracepoint
;
860 enum lttng_event_rule_status status
= LTTNG_EVENT_RULE_STATUS_OK
;
862 if (!rule
|| !IS_USER_TRACEPOINT_EVENT_RULE(rule
) || !log_level_rule
) {
863 status
= LTTNG_EVENT_RULE_STATUS_INVALID
;
867 tracepoint
= container_of(
868 rule
, struct lttng_event_rule_user_tracepoint
, parent
);
869 if (tracepoint
->log_level_rule
== NULL
) {
870 status
= LTTNG_EVENT_RULE_STATUS_UNSET
;
874 *log_level_rule
= tracepoint
->log_level_rule
;
879 enum lttng_event_rule_status
lttng_event_rule_user_tracepoint_add_name_pattern_exclusion(
880 struct lttng_event_rule
*rule
,
881 const char *exclusion
)
884 char *exclusion_copy
= NULL
;
885 struct lttng_event_rule_user_tracepoint
*tracepoint
;
886 enum lttng_event_rule_status status
= LTTNG_EVENT_RULE_STATUS_OK
;
888 if (!rule
|| !IS_USER_TRACEPOINT_EVENT_RULE(rule
) ||
890 status
= LTTNG_EVENT_RULE_STATUS_INVALID
;
894 tracepoint
= container_of(
895 rule
, struct lttng_event_rule_user_tracepoint
, parent
);
897 if (strlen(exclusion
) >= LTTNG_SYMBOL_NAME_LEN
) {
898 status
= LTTNG_EVENT_RULE_STATUS_INVALID
;
902 exclusion_copy
= strdup(exclusion
);
903 if (!exclusion_copy
) {
904 status
= LTTNG_EVENT_RULE_STATUS_ERROR
;
908 ret
= lttng_dynamic_pointer_array_add_pointer(&tracepoint
->exclusions
,
911 status
= LTTNG_EVENT_RULE_STATUS_ERROR
;
915 exclusion_copy
= NULL
;
917 free(exclusion_copy
);
921 enum lttng_event_rule_status
lttng_event_rule_user_tracepoint_get_name_pattern_exclusion_count(
922 const struct lttng_event_rule
*rule
, unsigned int *count
)
924 struct lttng_event_rule_user_tracepoint
*tracepoint
;
925 enum lttng_event_rule_status status
= LTTNG_EVENT_RULE_STATUS_OK
;
927 if (!rule
|| !IS_USER_TRACEPOINT_EVENT_RULE(rule
) || !count
) {
928 status
= LTTNG_EVENT_RULE_STATUS_INVALID
;
932 tracepoint
= container_of(
933 rule
, struct lttng_event_rule_user_tracepoint
, parent
);
934 *count
= lttng_dynamic_pointer_array_get_count(&tracepoint
->exclusions
);
939 enum lttng_event_rule_status
lttng_event_rule_user_tracepoint_get_name_pattern_exclusion_at_index(
940 const struct lttng_event_rule
*rule
,
942 const char **exclusion
)
945 struct lttng_event_rule_user_tracepoint
*tracepoint
;
946 enum lttng_event_rule_status status
= LTTNG_EVENT_RULE_STATUS_OK
;
948 if (!rule
|| !IS_USER_TRACEPOINT_EVENT_RULE(rule
) || !exclusion
) {
949 status
= LTTNG_EVENT_RULE_STATUS_INVALID
;
953 tracepoint
= container_of(
954 rule
, struct lttng_event_rule_user_tracepoint
, parent
);
955 if (lttng_event_rule_user_tracepoint_get_name_pattern_exclusion_count(rule
, &count
) !=
956 LTTNG_EVENT_RULE_STATUS_OK
) {
960 if (index
>= count
) {
964 *exclusion
= lttng_dynamic_pointer_array_get_pointer(
965 &tracepoint
->exclusions
, index
);