2 * Copyright (C) 2021 Simon Marchi <simon.marchi@efficios.com>
4 * SPDX-License-Identifier: GPL-2.0-only
11 #include "../command.h"
12 #include "../loglevel.h"
13 #include "../uprobe.h"
15 #include "common/argpar/argpar.h"
16 #include "common/dynamic-array.h"
17 #include "common/string-utils/string-utils.h"
18 #include "common/utils.h"
19 /* For lttng_event_rule_type_str(). */
20 #include <lttng/event-rule/event-rule-internal.h>
21 #include <lttng/lttng.h>
22 #include "common/filter/filter-ast.h"
23 #include "common/filter/filter-ir.h"
24 #include "common/dynamic-array.h"
26 #if (LTTNG_SYMBOL_NAME_LEN == 256)
27 #define LTTNG_SYMBOL_NAME_LEN_SCANF_IS_A_BROKEN_API "255"
30 #ifdef LTTNG_EMBED_HELP
31 static const char help_msg
[] =
32 #include <lttng-add-trigger.1.h>
75 static const struct argpar_opt_descr event_rule_opt_descrs
[] = {
76 { OPT_ALL
, 'a', "all", false },
77 { OPT_FILTER
, 'f', "filter", true },
78 { OPT_EXCLUDE
, 'x', "exclude", true },
79 { OPT_LOGLEVEL
, '\0', "loglevel", true },
80 { OPT_LOGLEVEL_ONLY
, '\0', "loglevel-only", true },
83 { OPT_USERSPACE
, 'u', "userspace", false },
84 { OPT_KERNEL
, 'k', "kernel", false },
85 { OPT_LOG4J
, 'l', "log4j", false },
86 { OPT_JUL
, 'j', "jul", false },
87 { OPT_PYTHON
, 'p', "python", false },
89 /* Event rule types */
90 { OPT_FUNCTION
, '\0', "function", true },
91 { OPT_PROBE
, '\0', "probe", true },
92 { OPT_USERSPACE_PROBE
, '\0', "userspace-probe", true },
93 { OPT_SYSCALL
, '\0', "syscall" },
94 { OPT_TRACEPOINT
, '\0', "tracepoint" },
96 /* Capture descriptor */
97 { OPT_CAPTURE
, '\0', "capture", true },
99 ARGPAR_OPT_DESCR_SENTINEL
103 bool assign_domain_type(enum lttng_domain_type
*dest
,
104 enum lttng_domain_type src
)
108 if (*dest
== LTTNG_DOMAIN_NONE
|| *dest
== src
) {
112 ERR("Multiple domains specified.");
120 bool assign_event_rule_type(enum lttng_event_rule_type
*dest
,
121 enum lttng_event_rule_type src
)
125 if (*dest
== LTTNG_EVENT_RULE_TYPE_UNKNOWN
|| *dest
== src
) {
129 ERR("Multiple event types specified.");
137 bool assign_string(char **dest
, const char *src
, const char *opt_name
)
142 ERR("Duplicate '%s' given.", opt_name
);
148 PERROR("Failed to allocate string '%s'.", opt_name
);
162 /* This is defined in enable_events.c. */
164 int create_exclusion_list_and_validate(const char *event_name
,
165 const char *exclusions_arg
,
166 char ***exclusion_list
);
169 * Parse `str` as a log level in domain `domain_type`. Return -1 if the string
170 * is not recognized as a valid log level.
173 int parse_loglevel_string(const char *str
, enum lttng_domain_type domain_type
)
175 switch (domain_type
) {
176 case LTTNG_DOMAIN_UST
:
178 enum lttng_loglevel loglevel
;
179 const int ret
= loglevel_name_to_value(str
, &loglevel
);
181 return ret
== -1 ? ret
: (int) loglevel
;
183 case LTTNG_DOMAIN_LOG4J
:
185 enum lttng_loglevel_log4j loglevel
;
186 const int ret
= loglevel_log4j_name_to_value(str
, &loglevel
);
188 return ret
== -1 ? ret
: (int) loglevel
;
190 case LTTNG_DOMAIN_JUL
:
192 enum lttng_loglevel_jul loglevel
;
193 const int ret
= loglevel_jul_name_to_value(str
, &loglevel
);
195 return ret
== -1 ? ret
: (int) loglevel
;
197 case LTTNG_DOMAIN_PYTHON
:
199 enum lttng_loglevel_python loglevel
;
200 const int ret
= loglevel_python_name_to_value(str
, &loglevel
);
202 return ret
== -1 ? ret
: (int) loglevel
;
205 /* Invalid domain type. */
210 static int parse_kernel_probe_opts(const char *source
,
211 struct lttng_kernel_probe_location
**location
)
216 char name
[LTTNG_SYMBOL_NAME_LEN
];
217 char *symbol_name
= NULL
;
220 /* Check for symbol+offset. */
221 match
= sscanf(source
,
222 "%" LTTNG_SYMBOL_NAME_LEN_SCANF_IS_A_BROKEN_API
226 if (*s_hex
== '\0') {
227 ERR("Kernel probe symbol offset is missing.");
231 symbol_name
= strndup(name
, LTTNG_SYMBOL_NAME_LEN
);
233 PERROR("Failed to copy kernel probe location symbol name.");
236 offset
= strtoul(s_hex
, NULL
, 0);
238 *location
= lttng_kernel_probe_location_symbol_create(
239 symbol_name
, offset
);
241 ERR("Failed to create symbol kernel probe location.");
248 /* Check for symbol. */
249 if (isalpha(name
[0]) || name
[0] == '_') {
250 match
= sscanf(source
,
251 "%" LTTNG_SYMBOL_NAME_LEN_SCANF_IS_A_BROKEN_API
255 symbol_name
= strndup(name
, LTTNG_SYMBOL_NAME_LEN
);
257 ERR("Failed to copy kernel probe location symbol name.");
261 *location
= lttng_kernel_probe_location_symbol_create(
264 ERR("Failed to create symbol kernel probe location.");
272 /* Check for address. */
273 match
= sscanf(source
, "%18s", s_hex
);
277 if (*s_hex
== '\0') {
278 ERR("Invalid kernel probe location address.");
282 address
= strtoul(s_hex
, NULL
, 0);
283 *location
= lttng_kernel_probe_location_address_create(address
);
285 ERR("Failed to create symbol kernel probe location.");
303 struct lttng_event_expr
*ir_op_load_expr_to_event_expr(
304 const struct ir_load_expression
*load_expr
,
305 const char *capture_str
)
307 char *provider_name
= NULL
;
308 struct lttng_event_expr
*event_expr
= NULL
;
309 const struct ir_load_expression_op
*load_expr_op
= load_expr
->child
;
310 const enum ir_load_expression_type load_expr_child_type
=
313 switch (load_expr_child_type
) {
314 case IR_LOAD_EXPRESSION_GET_PAYLOAD_ROOT
:
315 case IR_LOAD_EXPRESSION_GET_CONTEXT_ROOT
:
317 const char *field_name
;
319 load_expr_op
= load_expr_op
->next
;
320 assert(load_expr_op
);
321 assert(load_expr_op
->type
== IR_LOAD_EXPRESSION_GET_SYMBOL
);
322 field_name
= load_expr_op
->u
.symbol
;
325 event_expr
= load_expr_child_type
== IR_LOAD_EXPRESSION_GET_PAYLOAD_ROOT
?
326 lttng_event_expr_event_payload_field_create(field_name
) :
327 lttng_event_expr_channel_context_field_create(field_name
);
329 ERR("Failed to create %s event expression: field name = `%s`.",
330 load_expr_child_type
== IR_LOAD_EXPRESSION_GET_PAYLOAD_ROOT
?
331 "payload field" : "channel context",
338 case IR_LOAD_EXPRESSION_GET_APP_CONTEXT_ROOT
:
341 const char *type_name
;
342 const char *field_name
;
344 load_expr_op
= load_expr_op
->next
;
345 assert(load_expr_op
);
346 assert(load_expr_op
->type
== IR_LOAD_EXPRESSION_GET_SYMBOL
);
347 field_name
= load_expr_op
->u
.symbol
;
351 * The field name needs to be of the form PROVIDER:TYPE. We
354 colon
= strchr(field_name
, ':');
356 ERR("Invalid app-specific context field name: missing colon in `%s`.",
361 type_name
= colon
+ 1;
362 if (*type_name
== '\0') {
363 ERR("Invalid app-specific context field name: missing type name after colon in `%s`.",
368 provider_name
= strndup(field_name
, colon
- field_name
);
369 if (!provider_name
) {
370 PERROR("Failed to allocate field name string");
374 event_expr
= lttng_event_expr_app_specific_context_field_create(
375 provider_name
, type_name
);
377 ERR("Failed to create app-specific context field event expression: provider name = `%s`, type name = `%s`",
378 provider_name
, type_name
);
385 ERR("%s: unexpected load expr type %d.", __func__
,
390 load_expr_op
= load_expr_op
->next
;
392 /* There may be a single array index after that. */
393 if (load_expr_op
->type
== IR_LOAD_EXPRESSION_GET_INDEX
) {
394 struct lttng_event_expr
*index_event_expr
;
395 const uint64_t index
= load_expr_op
->u
.index
;
397 index_event_expr
= lttng_event_expr_array_field_element_create(event_expr
, index
);
398 if (!index_event_expr
) {
399 ERR("Failed to create array field element event expression.");
403 event_expr
= index_event_expr
;
404 load_expr_op
= load_expr_op
->next
;
407 switch (load_expr_op
->type
) {
408 case IR_LOAD_EXPRESSION_LOAD_FIELD
:
410 * This is what we expect, IR_LOAD_EXPRESSION_LOAD_FIELD is
411 * always found at the end of the chain.
414 case IR_LOAD_EXPRESSION_GET_SYMBOL
:
415 ERR("While parsing expression `%s`: Capturing subfields is not supported.",
420 ERR("%s: unexpected load expression operator %s.", __func__
,
421 ir_load_expression_type_str(load_expr_op
->type
));
428 lttng_event_expr_destroy(event_expr
);
438 struct lttng_event_expr
*ir_op_load_to_event_expr(
439 const struct ir_op
*ir
, const char *capture_str
)
441 struct lttng_event_expr
*event_expr
= NULL
;
443 assert(ir
->op
== IR_OP_LOAD
);
445 switch (ir
->data_type
) {
446 case IR_DATA_EXPRESSION
:
448 const struct ir_load_expression
*ir_load_expr
=
449 ir
->u
.load
.u
.expression
;
451 event_expr
= ir_op_load_expr_to_event_expr(
452 ir_load_expr
, capture_str
);
456 ERR("%s: unexpected data type: %s.", __func__
,
457 ir_data_type_str(ir
->data_type
));
465 const char *ir_operator_type_human_str(enum ir_op_type op
)
487 struct lttng_event_expr
*ir_op_root_to_event_expr(const struct ir_op
*ir
,
488 const char *capture_str
)
490 struct lttng_event_expr
*event_expr
= NULL
;
492 assert(ir
->op
== IR_OP_ROOT
);
493 ir
= ir
->u
.root
.child
;
497 event_expr
= ir_op_load_to_event_expr(ir
, capture_str
);
502 ERR("While parsing expression `%s`: %s operators are not allowed in capture expressions.",
504 ir_operator_type_human_str(ir
->op
));
507 ERR("%s: unexpected IR op type: %s.", __func__
,
508 ir_op_type_str(ir
->op
));
516 void destroy_event_expr(void *ptr
)
518 lttng_event_expr_destroy(ptr
);
521 struct parse_event_rule_res
{
523 struct lttng_event_rule
*er
;
525 /* Array of `struct lttng_event_expr *` */
526 struct lttng_dynamic_pointer_array capture_descriptors
;
530 struct parse_event_rule_res
parse_event_rule(int *argc
, const char ***argv
)
532 enum lttng_domain_type domain_type
= LTTNG_DOMAIN_NONE
;
533 enum lttng_event_rule_type event_rule_type
=
534 LTTNG_EVENT_RULE_TYPE_UNKNOWN
;
535 struct argpar_state
*state
;
536 struct argpar_item
*item
= NULL
;
538 int consumed_args
= -1;
539 struct lttng_kernel_probe_location
*kernel_probe_location
= NULL
;
540 struct lttng_userspace_probe_location
*userspace_probe_location
= NULL
;
541 struct parse_event_rule_res res
= { 0 };
542 struct lttng_event_expr
*event_expr
= NULL
;
543 struct filter_parser_ctx
*parser_ctx
= NULL
;
545 /* Was the -a/--all flag provided? */
546 bool all_events
= false;
548 /* Tracepoint name (non-option argument). */
549 const char *tracepoint_name
= NULL
;
551 /* Holds the argument of --probe / --userspace-probe. */
558 char *exclude
= NULL
;
559 char **exclusion_list
= NULL
;
562 char *loglevel_str
= NULL
;
563 bool loglevel_only
= false;
565 lttng_dynamic_pointer_array_init(&res
.capture_descriptors
,
567 state
= argpar_state_create(*argc
, *argv
, event_rule_opt_descrs
);
569 ERR("Failed to allocate an argpar state.");
574 enum argpar_state_parse_next_status status
;
576 ARGPAR_ITEM_DESTROY_AND_RESET(item
);
577 status
= argpar_state_parse_next(state
, &item
, &error
);
578 if (status
== ARGPAR_STATE_PARSE_NEXT_STATUS_ERROR
) {
581 } else if (status
== ARGPAR_STATE_PARSE_NEXT_STATUS_ERROR_UNKNOWN_OPT
) {
582 /* Just stop parsing here. */
584 } else if (status
== ARGPAR_STATE_PARSE_NEXT_STATUS_END
) {
588 assert(status
== ARGPAR_STATE_PARSE_NEXT_STATUS_OK
);
590 if (item
->type
== ARGPAR_ITEM_TYPE_OPT
) {
591 const struct argpar_item_opt
*item_opt
=
592 (const struct argpar_item_opt
*) item
;
594 switch (item_opt
->descr
->id
) {
597 if (!assign_domain_type(&domain_type
, LTTNG_DOMAIN_UST
)) {
603 if (!assign_domain_type(&domain_type
, LTTNG_DOMAIN_KERNEL
)) {
609 if (!assign_domain_type(&domain_type
, LTTNG_DOMAIN_LOG4J
)) {
615 if (!assign_domain_type(&domain_type
, LTTNG_DOMAIN_JUL
)) {
621 if (!assign_domain_type(&domain_type
, LTTNG_DOMAIN_PYTHON
)) {
627 /* Event rule types */
629 if (!assign_event_rule_type(&event_rule_type
,
630 LTTNG_EVENT_RULE_TYPE_KRETPROBE
)) {
636 if (!assign_event_rule_type(&event_rule_type
,
637 LTTNG_EVENT_RULE_TYPE_KERNEL_PROBE
)) {
641 if (!assign_string(&source
, item_opt
->arg
, "source")) {
646 case OPT_USERSPACE_PROBE
:
647 if (!assign_event_rule_type(&event_rule_type
,
648 LTTNG_EVENT_RULE_TYPE_UPROBE
)) {
652 if (!assign_string(&source
, item_opt
->arg
, "source")) {
658 if (!assign_event_rule_type(&event_rule_type
,
659 LTTNG_EVENT_RULE_TYPE_SYSCALL
)) {
665 if (!assign_event_rule_type(&event_rule_type
,
666 LTTNG_EVENT_RULE_TYPE_TRACEPOINT
)) {
675 if (!assign_string(&filter
, item_opt
->arg
,
682 if (!assign_string(&exclude
, item_opt
->arg
,
689 case OPT_LOGLEVEL_ONLY
:
690 if (!assign_string(&loglevel_str
, item_opt
->arg
,
691 "--loglevel/--loglevel-only")) {
695 loglevel_only
= item_opt
->descr
->id
==
701 const char *capture_str
= item_opt
->arg
;
703 ret
= filter_parser_ctx_create_from_filter_expression(
704 capture_str
, &parser_ctx
);
706 ERR("Failed to parse capture expression `%s`.",
711 event_expr
= ir_op_root_to_event_expr(
716 * ir_op_root_to_event_expr has printed
722 ret
= lttng_dynamic_pointer_array_add_pointer(
723 &res
.capture_descriptors
,
730 * The ownership of event expression was
731 * transferred to the dynamic array.
741 const struct argpar_item_non_opt
*item_non_opt
=
742 (const struct argpar_item_non_opt
*)
746 * Don't accept two non-option arguments/tracepoint
749 if (tracepoint_name
) {
750 ERR("Unexpected argument '%s'",
755 tracepoint_name
= item_non_opt
->arg
;
759 if (event_rule_type
== LTTNG_EVENT_RULE_TYPE_UNKNOWN
) {
760 event_rule_type
= LTTNG_EVENT_RULE_TYPE_TRACEPOINT
;
764 * Option -a is applicable to event rules of type tracepoint and
765 * syscall, and it is equivalent to using "*" as the tracepoint name.
768 switch (event_rule_type
) {
769 case LTTNG_EVENT_RULE_TYPE_TRACEPOINT
:
770 case LTTNG_EVENT_RULE_TYPE_SYSCALL
:
773 ERR("Can't use -a/--all with %s event rules.",
774 lttng_event_rule_type_str(event_rule_type
));
778 if (tracepoint_name
) {
779 ERR("Can't provide a tracepoint name with -a/--all.");
783 /* In which case, it's equivalent to tracepoint name "*". */
784 tracepoint_name
= "*";
788 * A tracepoint name (or -a, for the event rule types that accept it)
791 if (!tracepoint_name
) {
792 ERR("Need to provide either a tracepoint name or -a/--all.");
797 * We don't support multiple tracepoint names for now.
799 if (strchr(tracepoint_name
, ',')) {
800 ERR("Comma separated tracepoint names are not supported.");
805 * Update *argc and *argv so our caller can keep parsing what follows.
807 consumed_args
= argpar_state_get_ingested_orig_args(state
);
808 assert(consumed_args
>= 0);
809 *argc
-= consumed_args
;
810 *argv
+= consumed_args
;
812 /* Need to specify a domain. */
813 if (domain_type
== LTTNG_DOMAIN_NONE
) {
814 ERR("Please specify a domain (--kernel/--userspace/--jul/--log4j/--python).");
818 /* Validate event rule type against domain. */
819 switch (event_rule_type
) {
820 case LTTNG_EVENT_RULE_TYPE_KERNEL_PROBE
:
821 case LTTNG_EVENT_RULE_TYPE_KRETPROBE
:
822 case LTTNG_EVENT_RULE_TYPE_UPROBE
:
823 case LTTNG_EVENT_RULE_TYPE_SYSCALL
:
824 if (domain_type
!= LTTNG_DOMAIN_KERNEL
) {
825 ERR("Event type not available for user-space tracing.");
830 case LTTNG_EVENT_RULE_TYPE_TRACEPOINT
:
838 * Adding a filter to a probe, function or userspace-probe would be
839 * denied by the kernel tracer as it's not supported at the moment. We
840 * do an early check here to warn the user.
842 if (filter
&& domain_type
== LTTNG_DOMAIN_KERNEL
) {
843 switch (event_rule_type
) {
844 case LTTNG_EVENT_RULE_TYPE_TRACEPOINT
:
845 case LTTNG_EVENT_RULE_TYPE_SYSCALL
:
848 ERR("Filter expressions are not supported for %s event rules.",
849 lttng_event_rule_type_str(event_rule_type
));
854 /* If --exclude/-x was passed, split it into an exclusion list. */
856 if (domain_type
!= LTTNG_DOMAIN_UST
) {
857 ERR("Event name exclusions are not yet implemented for %s event rules.",
858 get_domain_str(domain_type
));
863 if (create_exclusion_list_and_validate(tracepoint_name
, exclude
,
864 &exclusion_list
) != 0) {
865 ERR("Failed to create exclusion list.");
870 if (loglevel_str
&& event_rule_type
!= LTTNG_EVENT_RULE_TYPE_TRACEPOINT
) {
871 ERR("Log levels are only applicable to tracepoint event rules.");
875 /* Finally, create the event rule object. */
876 switch (event_rule_type
) {
877 case LTTNG_EVENT_RULE_TYPE_TRACEPOINT
:
879 enum lttng_event_rule_status event_rule_status
;
881 res
.er
= lttng_event_rule_tracepoint_create(domain_type
);
883 ERR("Failed to create tracepoint event rule.");
888 event_rule_status
= lttng_event_rule_tracepoint_set_pattern(
889 res
.er
, tracepoint_name
);
890 if (event_rule_status
!= LTTNG_EVENT_RULE_STATUS_OK
) {
891 ERR("Failed to set tracepoint event rule's pattern to '%s'.",
898 event_rule_status
= lttng_event_rule_tracepoint_set_filter(
900 if (event_rule_status
!= LTTNG_EVENT_RULE_STATUS_OK
) {
901 ERR("Failed to set tracepoint event rule's filter to '%s'.",
907 /* Set exclusion list. */
908 if (exclusion_list
) {
911 for (n
= 0; exclusion_list
[n
]; n
++) {
912 event_rule_status
= lttng_event_rule_tracepoint_add_exclusion(
915 if (event_rule_status
!=
916 LTTNG_EVENT_RULE_STATUS_OK
) {
917 ERR("Failed to set tracepoint exclusion list element '%s'",
927 if (domain_type
== LTTNG_DOMAIN_KERNEL
) {
928 ERR("Log levels are not supported by the kernel tracer.");
932 loglevel
= parse_loglevel_string(
933 loglevel_str
, domain_type
);
935 ERR("Failed to parse `%s` as a log level.",
941 event_rule_status
= lttng_event_rule_tracepoint_set_log_level(
945 event_rule_status
= lttng_event_rule_tracepoint_set_log_level_range_lower_bound(
950 if (event_rule_status
!= LTTNG_EVENT_RULE_STATUS_OK
) {
951 ERR("Failed to set log level on event fule.");
958 case LTTNG_EVENT_RULE_TYPE_KERNEL_PROBE
:
961 enum lttng_event_rule_status event_rule_status
;
963 res
.er
= lttng_event_rule_kernel_probe_create();
965 ERR("Failed to create kprobe event rule.");
969 ret
= parse_kernel_probe_opts(source
, &kernel_probe_location
);
971 ERR("Failed to parse kernel probe location.");
975 event_rule_status
= lttng_event_rule_kernel_probe_set_name(res
.er
, tracepoint_name
);
976 if (event_rule_status
!= LTTNG_EVENT_RULE_STATUS_OK
) {
977 ERR("Failed to set kprobe event rule's name to '%s'.", tracepoint_name
);
981 assert(kernel_probe_location
);
982 event_rule_status
= lttng_event_rule_kernel_probe_set_location(res
.er
, kernel_probe_location
);
983 if (event_rule_status
!= LTTNG_EVENT_RULE_STATUS_OK
) {
984 ERR("Failed to set kprobe event rule's location.");
990 case LTTNG_EVENT_RULE_TYPE_UPROBE
:
993 enum lttng_event_rule_status event_rule_status
;
995 ret
= parse_userspace_probe_opts(
996 source
, &userspace_probe_location
);
998 ERR("Failed to parse user space probe location.");
1002 res
.er
= lttng_event_rule_uprobe_create();
1004 ERR("Failed to create userspace probe event rule.");
1008 event_rule_status
= lttng_event_rule_uprobe_set_location(
1009 res
.er
, userspace_probe_location
);
1010 if (event_rule_status
!= LTTNG_EVENT_RULE_STATUS_OK
) {
1011 ERR("Failed to set user space probe event rule's location.");
1015 event_rule_status
= lttng_event_rule_uprobe_set_name(
1016 res
.er
, tracepoint_name
);
1017 if (event_rule_status
!= LTTNG_EVENT_RULE_STATUS_OK
) {
1018 ERR("Failed to set user space probe event rule's name to '%s'.",
1025 case LTTNG_EVENT_RULE_TYPE_SYSCALL
:
1027 enum lttng_event_rule_status event_rule_status
;
1029 res
.er
= lttng_event_rule_syscall_create();
1031 ERR("Failed to create syscall event rule.");
1035 event_rule_status
= lttng_event_rule_syscall_set_pattern(
1036 res
.er
, tracepoint_name
);
1037 if (event_rule_status
!= LTTNG_EVENT_RULE_STATUS_OK
) {
1038 ERR("Failed to set syscall event rule's pattern to '%s'.",
1044 event_rule_status
= lttng_event_rule_syscall_set_filter(
1046 if (event_rule_status
!= LTTNG_EVENT_RULE_STATUS_OK
) {
1047 ERR("Failed to set syscall event rule's filter to '%s'.",
1063 lttng_event_rule_destroy(res
.er
);
1065 lttng_dynamic_pointer_array_reset(&res
.capture_descriptors
);
1069 filter_parser_ctx_free(parser_ctx
);
1072 lttng_event_expr_destroy(event_expr
);
1073 argpar_item_destroy(item
);
1075 argpar_state_destroy(state
);
1080 strutils_free_null_terminated_array_of_strings(exclusion_list
);
1081 lttng_kernel_probe_location_destroy(kernel_probe_location
);
1082 lttng_userspace_probe_location_destroy(userspace_probe_location
);
1087 struct lttng_condition
*handle_condition_event(int *argc
, const char ***argv
)
1089 struct parse_event_rule_res res
;
1090 struct lttng_condition
*c
;
1093 res
= parse_event_rule(argc
, argv
);
1099 c
= lttng_condition_event_rule_create(res
.er
);
1100 lttng_event_rule_destroy(res
.er
);
1106 for (i
= 0; i
< lttng_dynamic_pointer_array_get_count(&res
.capture_descriptors
);
1108 enum lttng_condition_status status
;
1109 struct lttng_event_expr
**expr
=
1110 lttng_dynamic_array_get_element(
1111 &res
.capture_descriptors
.array
, i
);
1115 status
= lttng_condition_event_rule_append_capture_descriptor(
1117 if (status
!= LTTNG_CONDITION_STATUS_OK
) {
1118 if (status
== LTTNG_CONDITION_STATUS_UNSUPPORTED
) {
1119 ERR("The capture feature is unsupported by the event-rule condition type");
1125 /* Ownership of event expression moved to `c` */
1132 lttng_condition_destroy(c
);
1136 lttng_dynamic_pointer_array_reset(&res
.capture_descriptors
);
1137 lttng_event_rule_destroy(res
.er
);
1142 struct lttng_condition
*handle_condition_session_consumed_size(int *argc
, const char ***argv
)
1144 struct lttng_condition
*cond
= NULL
;
1145 struct argpar_state
*state
= NULL
;
1146 struct argpar_item
*item
= NULL
;
1147 const char *threshold_arg
= NULL
;
1148 const char *session_name_arg
= NULL
;
1151 enum lttng_condition_status condition_status
;
1153 state
= argpar_state_create(*argc
, *argv
, event_rule_opt_descrs
);
1155 ERR("Failed to allocate an argpar state.");
1160 enum argpar_state_parse_next_status status
;
1162 ARGPAR_ITEM_DESTROY_AND_RESET(item
);
1163 status
= argpar_state_parse_next(state
, &item
, &error
);
1164 if (status
== ARGPAR_STATE_PARSE_NEXT_STATUS_ERROR
) {
1167 } else if (status
== ARGPAR_STATE_PARSE_NEXT_STATUS_ERROR_UNKNOWN_OPT
) {
1168 /* Just stop parsing here. */
1170 } else if (status
== ARGPAR_STATE_PARSE_NEXT_STATUS_END
) {
1174 assert(status
== ARGPAR_STATE_PARSE_NEXT_STATUS_OK
);
1176 if (item
->type
== ARGPAR_ITEM_TYPE_OPT
) {
1177 const struct argpar_item_opt
*item_opt
=
1178 (const struct argpar_item_opt
*) item
;
1180 switch (item_opt
->descr
->id
) {
1185 const struct argpar_item_non_opt
*item_non_opt
;
1187 assert(item
->type
== ARGPAR_ITEM_TYPE_NON_OPT
);
1189 item_non_opt
= (const struct argpar_item_non_opt
*) item
;
1191 switch (item_non_opt
->non_opt_index
) {
1193 session_name_arg
= item_non_opt
->arg
;
1196 threshold_arg
= item_non_opt
->arg
;
1199 ERR("Unexpected argument `%s`.",
1206 *argc
-= argpar_state_get_ingested_orig_args(state
);
1207 *argv
+= argpar_state_get_ingested_orig_args(state
);
1209 if (!session_name_arg
) {
1210 ERR("Missing session name argument.");
1214 if (!threshold_arg
) {
1215 ERR("Missing threshold argument.");
1219 if (utils_parse_size_suffix(threshold_arg
, &threshold
) != 0) {
1220 ERR("Failed to parse `%s` as a size.", threshold_arg
);
1224 cond
= lttng_condition_session_consumed_size_create();
1226 ERR("Failed to allocate a session consumed size condition.");
1230 condition_status
= lttng_condition_session_consumed_size_set_session_name(
1231 cond
, session_name_arg
);
1232 if (condition_status
!= LTTNG_CONDITION_STATUS_OK
) {
1233 ERR("Failed to set session consumed size condition's session name to '%s'.",
1238 condition_status
= lttng_condition_session_consumed_size_set_threshold(
1240 if (condition_status
!= LTTNG_CONDITION_STATUS_OK
) {
1241 ERR("Failed to set session consumed size condition threshold.");
1248 lttng_condition_destroy(cond
);
1252 argpar_state_destroy(state
);
1253 argpar_item_destroy(item
);
1259 struct lttng_condition
*handle_condition_buffer_usage_high(int *argc
, const char ***argv
)
1261 ERR("High buffer usage threshold conditions are unsupported for the moment.");
1266 struct lttng_condition
*handle_condition_buffer_usage_low(int *argc
, const char ***argv
)
1268 ERR("Low buffer usage threshold conditions are unsupported for the moment.");
1273 struct lttng_condition
*handle_condition_session_rotation_ongoing(int *argc
, const char ***argv
)
1275 ERR("Session rotation ongoing conditions are unsupported for the moment.");
1280 struct lttng_condition
*handle_condition_session_rotation_completed(int *argc
, const char ***argv
)
1282 ERR("Session rotation completed conditions are unsupported for the moment.");
1286 struct condition_descr
{
1288 struct lttng_condition
*(*handler
) (int *argc
, const char ***argv
);
1292 struct condition_descr condition_descrs
[] = {
1293 { "on-event", handle_condition_event
},
1294 { "on-session-consumed-size", handle_condition_session_consumed_size
},
1295 { "on-buffer-usage-high", handle_condition_buffer_usage_high
},
1296 { "on-buffer-usage-low", handle_condition_buffer_usage_low
},
1297 { "on-session-rotation-ongoing", handle_condition_session_rotation_ongoing
},
1298 { "on-session-rotation-completed", handle_condition_session_rotation_completed
},
1302 struct lttng_condition
*parse_condition(int *argc
, const char ***argv
)
1305 struct lttng_condition
*cond
;
1306 const char *condition_name
;
1307 const struct condition_descr
*descr
= NULL
;
1310 ERR("Missing condition name.");
1314 condition_name
= (*argv
)[0];
1319 for (i
= 0; i
< ARRAY_SIZE(condition_descrs
); i
++) {
1320 if (strcmp(condition_name
, condition_descrs
[i
].name
) == 0) {
1321 descr
= &condition_descrs
[i
];
1327 ERR("Unknown condition name '%s'", condition_name
);
1331 cond
= descr
->handler(argc
, argv
);
1333 /* The handler has already printed an error message. */
1346 struct lttng_action
*handle_action_notify(int *argc
, const char ***argv
)
1348 return lttng_action_notify_create();
1351 static const struct argpar_opt_descr no_opt_descrs
[] = {
1352 ARGPAR_OPT_DESCR_SENTINEL
1356 * Generic handler for a kind of action that takes a session name as its sole
1361 struct lttng_action
*handle_action_simple_session(
1362 int *argc
, const char ***argv
,
1363 struct lttng_action
*(*create_action_cb
)(void),
1364 enum lttng_action_status (*set_session_name_cb
)(struct lttng_action
*, const char *),
1365 const char *action_name
)
1367 struct lttng_action
*action
= NULL
;
1368 struct argpar_state
*state
= NULL
;
1369 struct argpar_item
*item
= NULL
;
1370 const char *session_name_arg
= NULL
;
1372 enum lttng_action_status action_status
;
1374 state
= argpar_state_create(*argc
, *argv
, no_opt_descrs
);
1376 ERR("Failed to allocate an argpar state.");
1381 enum argpar_state_parse_next_status status
;
1382 const struct argpar_item_non_opt
*item_non_opt
;
1384 ARGPAR_ITEM_DESTROY_AND_RESET(item
);
1385 status
= argpar_state_parse_next(state
, &item
, &error
);
1386 if (status
== ARGPAR_STATE_PARSE_NEXT_STATUS_ERROR
) {
1389 } else if (status
== ARGPAR_STATE_PARSE_NEXT_STATUS_ERROR_UNKNOWN_OPT
) {
1390 /* Just stop parsing here. */
1392 } else if (status
== ARGPAR_STATE_PARSE_NEXT_STATUS_END
) {
1396 assert(status
== ARGPAR_STATE_PARSE_NEXT_STATUS_OK
);
1397 assert(item
->type
== ARGPAR_ITEM_TYPE_NON_OPT
);
1399 item_non_opt
= (const struct argpar_item_non_opt
*) item
;
1401 switch (item_non_opt
->non_opt_index
) {
1403 session_name_arg
= item_non_opt
->arg
;
1406 ERR("Unexpected argument `%s`.", item_non_opt
->arg
);
1411 *argc
-= argpar_state_get_ingested_orig_args(state
);
1412 *argv
+= argpar_state_get_ingested_orig_args(state
);
1414 if (!session_name_arg
) {
1415 ERR("Missing session name.");
1419 action
= create_action_cb();
1421 ERR("Failed to allocate %s session action.", action_name
);
1425 action_status
= set_session_name_cb(action
, session_name_arg
);
1426 if (action_status
!= LTTNG_ACTION_STATUS_OK
) {
1427 ERR("Failed to set action %s session's session name to '%s'.",
1428 action_name
, session_name_arg
);
1435 lttng_action_destroy(action
);
1437 argpar_item_destroy(item
);
1440 argpar_state_destroy(state
);
1445 struct lttng_action
*handle_action_start_session(int *argc
,
1448 return handle_action_simple_session(argc
, argv
,
1449 lttng_action_start_session_create
,
1450 lttng_action_start_session_set_session_name
,
1455 struct lttng_action
*handle_action_stop_session(int *argc
,
1458 return handle_action_simple_session(argc
, argv
,
1459 lttng_action_stop_session_create
,
1460 lttng_action_stop_session_set_session_name
,
1465 struct lttng_action
*handle_action_rotate_session(int *argc
,
1468 return handle_action_simple_session(argc
, argv
,
1469 lttng_action_rotate_session_create
,
1470 lttng_action_rotate_session_set_session_name
,
1474 static const struct argpar_opt_descr snapshot_action_opt_descrs
[] = {
1475 { OPT_NAME
, 'n', "name", true },
1476 { OPT_MAX_SIZE
, 'm', "max-size", true },
1477 { OPT_CTRL_URL
, '\0', "ctrl-url", true },
1478 { OPT_DATA_URL
, '\0', "data-url", true },
1479 { OPT_URL
, '\0', "url", true },
1480 { OPT_PATH
, '\0', "path", true },
1481 ARGPAR_OPT_DESCR_SENTINEL
1485 struct lttng_action
*handle_action_snapshot_session(int *argc
,
1488 struct lttng_action
*action
= NULL
;
1489 struct argpar_state
*state
= NULL
;
1490 struct argpar_item
*item
= NULL
;
1491 const char *session_name_arg
= NULL
;
1492 char *snapshot_name_arg
= NULL
;
1493 char *ctrl_url_arg
= NULL
;
1494 char *data_url_arg
= NULL
;
1495 char *max_size_arg
= NULL
;
1496 char *url_arg
= NULL
;
1497 char *path_arg
= NULL
;
1499 enum lttng_action_status action_status
;
1500 struct lttng_snapshot_output
*snapshot_output
= NULL
;
1502 unsigned int locations_specified
= 0;
1504 state
= argpar_state_create(*argc
, *argv
, snapshot_action_opt_descrs
);
1506 ERR("Failed to allocate an argpar state.");
1511 enum argpar_state_parse_next_status status
;
1513 ARGPAR_ITEM_DESTROY_AND_RESET(item
);
1514 status
= argpar_state_parse_next(state
, &item
, &error
);
1515 if (status
== ARGPAR_STATE_PARSE_NEXT_STATUS_ERROR
) {
1518 } else if (status
== ARGPAR_STATE_PARSE_NEXT_STATUS_ERROR_UNKNOWN_OPT
) {
1519 /* Just stop parsing here. */
1521 } else if (status
== ARGPAR_STATE_PARSE_NEXT_STATUS_END
) {
1525 assert(status
== ARGPAR_STATE_PARSE_NEXT_STATUS_OK
);
1527 if (item
->type
== ARGPAR_ITEM_TYPE_OPT
) {
1528 const struct argpar_item_opt
*item_opt
=
1529 (const struct argpar_item_opt
*) item
;
1531 switch (item_opt
->descr
->id
) {
1533 if (!assign_string(&snapshot_name_arg
, item_opt
->arg
, "--name/-n")) {
1539 if (!assign_string(&max_size_arg
, item_opt
->arg
, "--max-size/-m")) {
1545 if (!assign_string(&ctrl_url_arg
, item_opt
->arg
, "--ctrl-url")) {
1551 if (!assign_string(&data_url_arg
, item_opt
->arg
, "--data-url")) {
1557 if (!assign_string(&url_arg
, item_opt
->arg
, "--url")) {
1563 if (!assign_string(&path_arg
, item_opt
->arg
, "--path")) {
1572 const struct argpar_item_non_opt
*item_non_opt
;
1574 assert(item
->type
== ARGPAR_ITEM_TYPE_NON_OPT
);
1576 item_non_opt
= (const struct argpar_item_non_opt
*) item
;
1578 switch (item_non_opt
->non_opt_index
) {
1580 session_name_arg
= item_non_opt
->arg
;
1583 ERR("Unexpected argument `%s`.",
1590 *argc
-= argpar_state_get_ingested_orig_args(state
);
1591 *argv
+= argpar_state_get_ingested_orig_args(state
);
1593 if (!session_name_arg
) {
1594 ERR("Missing session name.");
1598 /* --ctrl-url and --data-url must come in pair. */
1599 if (ctrl_url_arg
&& !data_url_arg
) {
1600 ERR("--ctrl-url is specified, but --data-url is missing.");
1604 if (!ctrl_url_arg
&& data_url_arg
) {
1605 ERR("--data-url is specified, but --ctrl-url is missing.");
1609 locations_specified
+= !!(ctrl_url_arg
|| data_url_arg
);
1610 locations_specified
+= !!url_arg
;
1611 locations_specified
+= !!path_arg
;
1613 /* --ctrl-url/--data-url, --url and --path are mutually exclusive. */
1614 if (locations_specified
> 1) {
1615 ERR("The --ctrl-url/--data-url, --url, and --path options can't be used together.");
1620 * Did the user specify an option that implies using a
1621 * custom/unregistered output?
1623 if (url_arg
|| ctrl_url_arg
|| path_arg
) {
1624 snapshot_output
= lttng_snapshot_output_create();
1625 if (!snapshot_output
) {
1626 ERR("Failed to allocate a snapshot output.");
1631 action
= lttng_action_snapshot_session_create();
1633 ERR("Failed to allocate snapshot session action.");
1637 action_status
= lttng_action_snapshot_session_set_session_name(
1638 action
, session_name_arg
);
1639 if (action_status
!= LTTNG_ACTION_STATUS_OK
) {
1640 ERR("Failed to set action snapshot session's session name to '%s'.",
1645 if (snapshot_name_arg
) {
1646 if (!snapshot_output
) {
1647 ERR("Can't provide a snapshot output name without a snapshot output destination.");
1651 ret
= lttng_snapshot_output_set_name(
1652 snapshot_name_arg
, snapshot_output
);
1654 ERR("Failed to set name of snapshot output.");
1662 if (!snapshot_output
) {
1663 ERR("Can't provide a snapshot output max size without a snapshot output destination.");
1667 ret
= utils_parse_size_suffix(max_size_arg
, &max_size
);
1669 ERR("Failed to parse `%s` as a size.", max_size_arg
);
1673 ret
= lttng_snapshot_output_set_size(max_size
, snapshot_output
);
1675 ERR("Failed to set snapshot output's max size to %" PRIu64
" bytes.",
1683 struct lttng_uri
*uris
;
1685 if (!strstr(url_arg
, "://")) {
1686 ERR("Failed to parse '%s' as an URL.", url_arg
);
1690 num_uris
= uri_parse_str_urls(url_arg
, NULL
, &uris
);
1692 ERR("Failed to parse '%s' as an URL.", url_arg
);
1696 if (uris
[0].dtype
== LTTNG_DST_PATH
) {
1697 ret
= lttng_snapshot_output_set_local_path(
1698 uris
[0].dst
.path
, snapshot_output
);
1701 ERR("Failed to assign '%s' as a local destination.",
1706 ret
= lttng_snapshot_output_set_network_url(
1707 url_arg
, snapshot_output
);
1710 ERR("Failed to assign '%s' as a network URL.",
1718 ret
= lttng_snapshot_output_set_local_path(
1719 path_arg
, snapshot_output
);
1721 ERR("Failed to parse '%s' as a local path.", path_arg
);
1728 * Two argument form, network output with separate control and
1731 ret
= lttng_snapshot_output_set_network_urls(
1732 ctrl_url_arg
, data_url_arg
, snapshot_output
);
1734 ERR("Failed to parse `%s` and `%s` as control and data URLs.",
1735 ctrl_url_arg
, data_url_arg
);
1740 if (snapshot_output
) {
1741 action_status
= lttng_action_snapshot_session_set_output(
1742 action
, snapshot_output
);
1743 if (action_status
!= LTTNG_ACTION_STATUS_OK
) {
1744 ERR("Failed to set snapshot session action's output.");
1748 /* Ownership of `snapshot_output` has been transferred to the action. */
1749 snapshot_output
= NULL
;
1755 lttng_action_destroy(action
);
1759 free(snapshot_name_arg
);
1764 free(snapshot_output
);
1766 argpar_state_destroy(state
);
1767 argpar_item_destroy(item
);
1771 struct action_descr
{
1773 struct lttng_action
*(*handler
) (int *argc
, const char ***argv
);
1777 struct action_descr action_descrs
[] = {
1778 { "notify", handle_action_notify
},
1779 { "start-session", handle_action_start_session
},
1780 { "stop-session", handle_action_stop_session
},
1781 { "rotate-session", handle_action_rotate_session
},
1782 { "snapshot-session", handle_action_snapshot_session
},
1786 struct lttng_action
*parse_action(int *argc
, const char ***argv
)
1789 struct lttng_action
*action
;
1790 const char *action_name
;
1791 const struct action_descr
*descr
= NULL
;
1794 ERR("Missing action name.");
1798 action_name
= (*argv
)[0];
1803 for (i
= 0; i
< ARRAY_SIZE(action_descrs
); i
++) {
1804 if (strcmp(action_name
, action_descrs
[i
].name
) == 0) {
1805 descr
= &action_descrs
[i
];
1811 ERR("Unknown action name: %s", action_name
);
1815 action
= descr
->handler(argc
, argv
);
1817 /* The handler has already printed an error message. */
1829 struct argpar_opt_descr add_trigger_options
[] = {
1830 { OPT_HELP
, 'h', "help", false },
1831 { OPT_LIST_OPTIONS
, '\0', "list-options", false },
1832 { OPT_CONDITION
, '\0', "condition", false },
1833 { OPT_ACTION
, '\0', "action", false },
1834 { OPT_ID
, '\0', "id", true },
1835 { OPT_FIRE_ONCE_AFTER
, '\0', "fire-once-after", true },
1836 { OPT_FIRE_EVERY
, '\0', "fire-every", true },
1837 { OPT_USER_ID
, '\0', "user-id", true },
1838 ARGPAR_OPT_DESCR_SENTINEL
,
1842 void lttng_actions_destructor(void *p
)
1844 struct lttng_action
*action
= p
;
1846 lttng_action_destroy(action
);
1849 int cmd_add_trigger(int argc
, const char **argv
)
1852 int my_argc
= argc
- 1;
1853 const char **my_argv
= argv
+ 1;
1854 struct lttng_condition
*condition
= NULL
;
1855 struct lttng_dynamic_pointer_array actions
;
1856 struct argpar_state
*argpar_state
= NULL
;
1857 struct argpar_item
*argpar_item
= NULL
;
1858 struct lttng_action
*action_group
= NULL
;
1859 struct lttng_action
*action
= NULL
;
1860 struct lttng_trigger
*trigger
= NULL
;
1864 char *fire_once_after_str
= NULL
;
1865 char *fire_every_str
= NULL
;
1866 char *user_id
= NULL
;
1868 lttng_dynamic_pointer_array_init(&actions
, lttng_actions_destructor
);
1871 enum argpar_state_parse_next_status status
;
1872 const struct argpar_item_opt
*item_opt
;
1875 argpar_state_destroy(argpar_state
);
1876 argpar_state
= argpar_state_create(my_argc
, my_argv
,
1877 add_trigger_options
);
1878 if (!argpar_state
) {
1879 ERR("Failed to create argpar state.");
1883 ARGPAR_ITEM_DESTROY_AND_RESET(argpar_item
);
1884 status
= argpar_state_parse_next(argpar_state
, &argpar_item
, &error
);
1885 if (status
== ARGPAR_STATE_PARSE_NEXT_STATUS_ERROR
) {
1888 } else if (status
== ARGPAR_STATE_PARSE_NEXT_STATUS_ERROR_UNKNOWN_OPT
) {
1891 } else if (status
== ARGPAR_STATE_PARSE_NEXT_STATUS_END
) {
1895 assert(status
== ARGPAR_STATE_PARSE_NEXT_STATUS_OK
);
1897 if (argpar_item
->type
== ARGPAR_ITEM_TYPE_NON_OPT
) {
1898 const struct argpar_item_non_opt
*item_non_opt
=
1899 (const struct argpar_item_non_opt
*)
1902 ERR("Unexpected argument `%s`.", item_non_opt
->arg
);
1906 item_opt
= (const struct argpar_item_opt
*) argpar_item
;
1908 ingested_args
= argpar_state_get_ingested_orig_args(
1911 my_argc
-= ingested_args
;
1912 my_argv
+= ingested_args
;
1914 switch (item_opt
->descr
->id
) {
1919 case OPT_LIST_OPTIONS
:
1920 list_cmd_options_argpar(stdout
, add_trigger_options
);
1926 ERR("A --condition was already given.");
1930 condition
= parse_condition(&my_argc
, &my_argv
);
1933 * An error message was already printed by
1943 action
= parse_action(&my_argc
, &my_argv
);
1946 * An error message was already printed by
1952 ret
= lttng_dynamic_pointer_array_add_pointer(
1955 ERR("Failed to add pointer to pointer array.");
1959 /* Ownership of the action was transferred to the group. */
1966 if (!assign_string(&id
, item_opt
->arg
, "--id")) {
1972 case OPT_FIRE_ONCE_AFTER
:
1974 if (!assign_string(&fire_once_after_str
, item_opt
->arg
,
1975 "--fire-once-after")) {
1981 case OPT_FIRE_EVERY
:
1983 if (!assign_string(&fire_every_str
, item_opt
->arg
,
1992 if (!assign_string(&user_id
, item_opt
->arg
,
2005 ERR("Missing --condition.");
2009 if (lttng_dynamic_pointer_array_get_count(&actions
) == 0) {
2010 ERR("Need at least one --action.");
2014 if (fire_every_str
&& fire_once_after_str
) {
2015 ERR("Can't specify both --fire-once-after and --fire-every.");
2019 action_group
= lttng_action_group_create();
2020 if (!action_group
) {
2024 for (i
= 0; i
< lttng_dynamic_pointer_array_get_count(&actions
); i
++) {
2025 enum lttng_action_status status
;
2027 action
= lttng_dynamic_pointer_array_steal_pointer(&actions
, i
);
2029 status
= lttng_action_group_add_action(action_group
, action
);
2030 if (status
!= LTTNG_ACTION_STATUS_OK
) {
2035 * The `lttng_action_group_add_action()` takes a reference to
2036 * the action. We can destroy ours.
2038 lttng_action_destroy(action
);
2042 trigger
= lttng_trigger_create(condition
, action_group
);
2048 enum lttng_trigger_status trigger_status
=
2049 lttng_trigger_set_name(trigger
, id
);
2051 if (trigger_status
!= LTTNG_TRIGGER_STATUS_OK
) {
2052 ERR("Failed to set trigger id.");
2057 if (fire_once_after_str
) {
2058 unsigned long long threshold
;
2059 enum lttng_trigger_status trigger_status
;
2061 if (utils_parse_unsigned_long_long(fire_once_after_str
, &threshold
) != 0) {
2062 ERR("Failed to parse `%s` as an integer.", fire_once_after_str
);
2066 trigger_status
= lttng_trigger_set_firing_policy(trigger
,
2067 LTTNG_TRIGGER_FIRING_POLICY_ONCE_AFTER_N
,
2069 if (trigger_status
!= LTTNG_TRIGGER_STATUS_OK
) {
2070 ERR("Failed to set trigger's policy to `fire once after N`.");
2075 if (fire_every_str
) {
2076 unsigned long long threshold
;
2077 enum lttng_trigger_status trigger_status
;
2079 if (utils_parse_unsigned_long_long(fire_every_str
, &threshold
) != 0) {
2080 ERR("Failed to parse `%s` as an integer.", fire_every_str
);
2084 trigger_status
= lttng_trigger_set_firing_policy(trigger
,
2085 LTTNG_TRIGGER_FIRING_POLICY_EVERY_N
, threshold
);
2086 if (trigger_status
!= LTTNG_TRIGGER_STATUS_OK
) {
2087 ERR("Failed to set trigger's policy to `fire every N`.");
2093 enum lttng_trigger_status trigger_status
;
2098 uid
= strtol(user_id
, &end
, 10);
2099 if (end
== user_id
|| *end
!= '\0' || errno
!= 0) {
2100 ERR("Failed to parse `%s` as a user id.", user_id
);
2103 trigger_status
= lttng_trigger_set_owner_uid(trigger
, uid
);
2104 if (trigger_status
!= LTTNG_TRIGGER_STATUS_OK
) {
2105 ERR("Failed to set trigger's user identity.");
2110 ret
= lttng_register_trigger(trigger
);
2112 ERR("Failed to register trigger: %s.", lttng_strerror(ret
));
2116 MSG("Trigger registered successfully.");
2124 argpar_state_destroy(argpar_state
);
2125 argpar_item_destroy(argpar_item
);
2126 lttng_dynamic_pointer_array_reset(&actions
);
2127 lttng_condition_destroy(condition
);
2128 lttng_action_destroy(action_group
);
2129 lttng_action_destroy(action
);
2130 lttng_trigger_destroy(trigger
);
2133 free(fire_once_after_str
);
2134 free(fire_every_str
);