4 #include "../command.h"
7 #include "common/argpar/argpar.h"
8 #include "common/dynamic-array.h"
9 #include "common/string-utils/string-utils.h"
10 #include "common/utils.h"
11 #include "lttng/condition/event-rule.h"
12 #include "lttng/event-internal.h"
13 #include "lttng/event-expr.h"
14 #include <lttng/event-rule/event-rule-internal.h>
15 #include "lttng/event-rule/kprobe.h"
16 #include "lttng/event-rule/syscall.h"
17 #include <lttng/event-rule/tracepoint.h>
18 #include "lttng/event-rule/uprobe.h"
19 #include "lttng/kernel-probe.h"
20 #include "common/filter/filter-ast.h"
21 #include "common/filter/filter-ir.h"
22 #include "common/dynamic-array.h"
25 #if (LTTNG_SYMBOL_NAME_LEN == 256)
26 #define LTTNG_SYMBOL_NAME_LEN_SCANF_IS_A_BROKEN_API "255"
29 #ifdef LTTNG_EMBED_HELP
30 static const char help_msg
[] =
31 #include <lttng-add-trigger.1.h>
72 static const struct argpar_opt_descr event_rule_opt_descrs
[] = {
73 { OPT_ALL
, 'a', "all", false },
74 { OPT_FILTER
, 'f', "filter", true },
75 { OPT_EXCLUDE
, 'x', "exclude", true },
76 { OPT_LOGLEVEL
, '\0', "loglevel", true },
77 { OPT_LOGLEVEL_ONLY
, '\0', "loglevel-only", true },
80 { OPT_USERSPACE
, 'u', "userspace", false },
81 { OPT_KERNEL
, 'k', "kernel", false },
82 { OPT_LOG4J
, 'l', "log4j", false },
83 { OPT_JUL
, 'j', "jul", false },
84 { OPT_PYTHON
, 'p', "python", false },
86 /* Event rule types */
87 { OPT_FUNCTION
, '\0', "function", true },
88 { OPT_PROBE
, '\0', "probe", true },
89 { OPT_USERSPACE_PROBE
, '\0', "userspace-probe", true },
90 { OPT_SYSCALL
, '\0', "syscall" },
91 { OPT_TRACEPOINT
, '\0', "tracepoint" },
93 /* Capture descriptor */
94 { OPT_CAPTURE
, '\0', "capture", true },
96 ARGPAR_OPT_DESCR_SENTINEL
100 bool assign_domain_type(enum lttng_domain_type
*dest
,
101 enum lttng_domain_type src
)
105 if (*dest
== LTTNG_DOMAIN_NONE
|| *dest
== src
) {
109 ERR("Multiple domains specified.");
117 bool assign_event_rule_type(enum lttng_event_rule_type
*dest
,
118 enum lttng_event_rule_type src
)
122 if (*dest
== LTTNG_EVENT_RULE_TYPE_UNKNOWN
|| *dest
== src
) {
126 ERR("Multiple event type not supported.");
134 bool assign_string(char **dest
, const char *src
, const char *opt_name
)
140 "Duplicate %s given.", opt_name
);
146 ERR("Failed to allocate %s string.", opt_name
);
160 /* This is defined in enable_events.c. */
162 int create_exclusion_list_and_validate(const char *event_name
,
163 const char *exclusions_arg
,
164 char ***exclusion_list
);
167 * Parse `str` as a log level in domain `domain_type`. Return -1 if the string
168 * is not recognized as a valid log level.
171 int parse_loglevel_string(const char *str
, enum lttng_domain_type domain_type
)
174 switch (domain_type
) {
175 case LTTNG_DOMAIN_UST
:
176 return loglevel_str_to_value(str
);
178 case LTTNG_DOMAIN_LOG4J
:
179 return loglevel_log4j_str_to_value(str
);
181 case LTTNG_DOMAIN_JUL
:
182 return loglevel_jul_str_to_value(str
);
184 case LTTNG_DOMAIN_PYTHON
:
185 return loglevel_python_str_to_value(str
);
188 /* Invalid domain type. */
193 static int parse_kernel_probe_opts(const char *source
,
194 struct lttng_kernel_probe_location
**location
)
199 char name
[LTTNG_SYMBOL_NAME_LEN
];
200 char *symbol_name
= NULL
;
203 /* Check for symbol+offset */
204 match
= sscanf(source
, "%255[^'+']+%18s", name
, s_hex
);
206 if (*s_hex
== '\0') {
207 ERR("Kernel probe symbol offset is missing.");
210 symbol_name
= strndup(name
, LTTNG_SYMBOL_NAME_LEN
);
212 ERR("Strndup kernel probe location symbol name.");
215 offset
= strtoul(s_hex
, NULL
, 0);
217 *location
= lttng_kernel_probe_location_symbol_create(
218 symbol_name
, offset
);
220 ERR("Symbol kernel probe location creation failed.");
227 /* Check for symbol */
228 if (isalpha(name
[0]) || name
[0] == '_') {
229 match
= sscanf(source
,
230 "%" LTTNG_SYMBOL_NAME_LEN_SCANF_IS_A_BROKEN_API
234 symbol_name
= strndup(name
, LTTNG_SYMBOL_NAME_LEN
);
236 ERR("Strndup kernel probe location symbol name.");
240 *location
= lttng_kernel_probe_location_symbol_create(
243 ERR("Symbol kernel probe location creation failed.");
251 /* Check for address */
252 match
= sscanf(source
, "%18s", s_hex
);
255 if (*s_hex
== '\0') {
256 ERR("Invalid kernel probe location address.");
259 address
= strtoul(s_hex
, NULL
, 0);
260 *location
= lttng_kernel_probe_location_address_create(address
);
262 ERR("Symbol kernel probe location creation failed.");
280 struct lttng_event_expr
*ir_op_load_expr_to_event_expr(
281 struct ir_load_expression
*load_exp
, const char *capture_str
)
283 struct ir_load_expression_op
*load_expr_op
= load_exp
->child
;
284 struct lttng_event_expr
*event_expr
= NULL
;
285 char *provider_name
= NULL
;
287 switch (load_expr_op
->type
) {
288 case IR_LOAD_EXPRESSION_GET_PAYLOAD_ROOT
:
290 const char *field_name
;
292 load_expr_op
= load_expr_op
->next
;
293 assert(load_expr_op
);
294 assert(load_expr_op
->type
== IR_LOAD_EXPRESSION_GET_SYMBOL
);
295 field_name
= load_expr_op
->u
.symbol
;
298 event_expr
= lttng_event_expr_event_payload_field_create(field_name
);
300 fprintf(stderr
, "Failed to create payload field event expression.\n");
307 case IR_LOAD_EXPRESSION_GET_CONTEXT_ROOT
:
309 const char *field_name
;
311 load_expr_op
= load_expr_op
->next
;
312 assert(load_expr_op
);
313 assert(load_expr_op
->type
== IR_LOAD_EXPRESSION_GET_SYMBOL
);
314 field_name
= load_expr_op
->u
.symbol
;
317 event_expr
= lttng_event_expr_channel_context_field_create(field_name
);
319 fprintf(stderr
, "Failed to create channel context field event expression.\n");
326 case IR_LOAD_EXPRESSION_GET_APP_CONTEXT_ROOT
:
328 const char *field_name
;
330 const char *type_name
;
332 load_expr_op
= load_expr_op
->next
;
333 assert(load_expr_op
);
334 assert(load_expr_op
->type
== IR_LOAD_EXPRESSION_GET_SYMBOL
);
335 field_name
= load_expr_op
->u
.symbol
;
339 * The field name needs to be of the form PROVIDER:TYPE. We
342 colon
= strchr(field_name
, ':');
344 fprintf(stderr
, "Invalid app-specific context field name: missing colon in `%s`.\n",
349 type_name
= colon
+ 1;
350 if (*type_name
== '\0') {
352 "Invalid app-specific context field name: missing type name after colon in `%s`.\n",
357 provider_name
= strndup(field_name
, colon
- field_name
);
358 if (!provider_name
) {
359 fprintf(stderr
, "Failed to allocate string.\n");
363 event_expr
= lttng_event_expr_app_specific_context_field_create(
364 provider_name
, type_name
);
367 "Failed to create app-specific context field event expression.\n");
375 fprintf(stderr
, "%s: unexpected load expr type %d.\n",
376 __func__
, load_expr_op
->type
);
380 load_expr_op
= load_expr_op
->next
;
382 /* There may be a single array index after that. */
383 if (load_expr_op
->type
== IR_LOAD_EXPRESSION_GET_INDEX
) {
384 uint64_t index
= load_expr_op
->u
.index
;
385 struct lttng_event_expr
*index_event_expr
;
387 index_event_expr
= lttng_event_expr_array_field_element_create(event_expr
, index
);
388 if (!index_event_expr
) {
389 fprintf(stderr
, "Failed to create array field element event expression.\n");
393 event_expr
= index_event_expr
;
394 load_expr_op
= load_expr_op
->next
;
397 switch (load_expr_op
->type
) {
398 case IR_LOAD_EXPRESSION_LOAD_FIELD
:
400 * This is what we expect, IR_LOAD_EXPRESSION_LOAD_FIELD is
401 * always found at the end of the chain.
404 case IR_LOAD_EXPRESSION_GET_SYMBOL
:
405 fprintf(stderr
, "Error: While parsing expression `%s`: Capturing subfields is not supported.\n",
410 fprintf(stderr
, "%s: unexpected load expression operator %s.\n",
411 __func__
, ir_load_expression_type_str(load_expr_op
->type
));
418 lttng_event_expr_destroy(event_expr
);
428 struct lttng_event_expr
*ir_op_load_to_event_expr(struct ir_op
*ir
,
429 const char *capture_str
)
431 struct lttng_event_expr
*event_expr
= NULL
;
433 assert(ir
->op
== IR_OP_LOAD
);
435 switch (ir
->data_type
) {
436 case IR_DATA_EXPRESSION
:
438 struct ir_load_expression
*ir_load_expr
= ir
->u
.load
.u
.expression
;
439 event_expr
= ir_op_load_expr_to_event_expr(ir_load_expr
, capture_str
);
444 fprintf(stderr
, "%s: unexpected data type: %s.\n", __func__
,
445 ir_data_type_str(ir
->data_type
));
453 struct lttng_event_expr
*ir_op_root_to_event_expr(struct ir_op
*ir
,
454 const char *capture_str
)
456 struct lttng_event_expr
*event_expr
= NULL
;
458 assert(ir
->op
== IR_OP_ROOT
);
459 ir
= ir
->u
.root
.child
;
463 event_expr
= ir_op_load_to_event_expr(ir
, capture_str
);
467 fprintf(stderr
, "Error: While parsing expression `%s`: Binary operators are not allowed in capture expressions.\n",
472 fprintf(stderr
, "Error: While parsing expression `%s`: Unary operators are not allowed in capture expressions.\n",
477 fprintf(stderr
, "Error: While parsing expression `%s`: Logical operators are not allowed in capture expressions.\n",
482 fprintf(stderr
, "%s: unexpected IR op type: %s.\n", __func__
,
483 ir_op_type_str(ir
->op
));
491 void destroy_event_expr(void *ptr
)
493 lttng_event_expr_destroy(ptr
);
496 struct parse_event_rule_res
{
498 struct lttng_event_rule
*er
;
500 /* Array of `struct lttng_event_expr *` */
501 struct lttng_dynamic_pointer_array capture_descriptors
;
505 struct parse_event_rule_res
parse_event_rule(int *argc
, const char ***argv
)
507 enum lttng_domain_type domain_type
= LTTNG_DOMAIN_NONE
;
508 enum lttng_event_rule_type event_rule_type
= LTTNG_EVENT_RULE_TYPE_UNKNOWN
;
509 struct argpar_state
*state
;
510 struct argpar_item
*item
= NULL
;
512 int consumed_args
= -1;
513 struct lttng_kernel_probe_location
*kernel_probe_location
= NULL
;
514 struct lttng_userspace_probe_location
*userspace_probe_location
= NULL
;
515 struct parse_event_rule_res res
= { 0 };
516 struct lttng_event_expr
*event_expr
= NULL
;
517 struct filter_parser_ctx
*parser_ctx
= NULL
;
519 /* Was the -a/--all flag provided? */
520 bool all_events
= false;
522 /* Tracepoint name (non-option argument) */
523 const char *tracepoint_name
= NULL
;
525 /* Holds the argument of --probe / --userspace-probe. */
532 char *exclude
= NULL
;
533 char **exclusion_list
= NULL
;
536 char *loglevel_str
= NULL
;
537 bool loglevel_only
= false;
539 lttng_dynamic_pointer_array_init(&res
.capture_descriptors
,
541 state
= argpar_state_create(*argc
, *argv
, event_rule_opt_descrs
);
543 ERR("Failed to allocate an argpar state.");
548 enum argpar_state_parse_next_status status
;
550 ARGPAR_ITEM_DESTROY_AND_RESET(item
);
551 status
= argpar_state_parse_next(state
, &item
, &error
);
552 if (status
== ARGPAR_STATE_PARSE_NEXT_STATUS_ERROR
) {
555 } else if (status
== ARGPAR_STATE_PARSE_NEXT_STATUS_ERROR_UNKNOWN_OPT
) {
556 /* Just stop parsing here. */
558 } else if (status
== ARGPAR_STATE_PARSE_NEXT_STATUS_END
) {
562 assert(status
== ARGPAR_STATE_PARSE_NEXT_STATUS_OK
);
564 if (item
->type
== ARGPAR_ITEM_TYPE_OPT
) {
565 struct argpar_item_opt
*item_opt
=
566 (struct argpar_item_opt
*) item
;
568 switch (item_opt
->descr
->id
) {
571 if (!assign_domain_type(&domain_type
, LTTNG_DOMAIN_UST
)) {
577 if (!assign_domain_type(&domain_type
, LTTNG_DOMAIN_KERNEL
)) {
583 if (!assign_domain_type(&domain_type
, LTTNG_DOMAIN_LOG4J
)) {
589 if (!assign_domain_type(&domain_type
, LTTNG_DOMAIN_JUL
)) {
595 if (!assign_domain_type(&domain_type
, LTTNG_DOMAIN_PYTHON
)) {
600 /* Event rule types */
602 if (!assign_event_rule_type(&event_rule_type
,
603 LTTNG_EVENT_RULE_TYPE_KRETPROBE
)) {
609 if (!assign_event_rule_type(&event_rule_type
,
610 LTTNG_EVENT_RULE_TYPE_KPROBE
)) {
614 if (!assign_string(&source
, item_opt
->arg
, "source")) {
620 case OPT_USERSPACE_PROBE
:
621 if (!assign_event_rule_type(&event_rule_type
,
622 LTTNG_EVENT_RULE_TYPE_UPROBE
)) {
626 if (!assign_string(&source
, item_opt
->arg
, "source")) {
632 if (!assign_event_rule_type(&event_rule_type
,
633 LTTNG_EVENT_RULE_TYPE_SYSCALL
)) {
639 if (!assign_event_rule_type(&event_rule_type
,
640 LTTNG_EVENT_RULE_TYPE_TRACEPOINT
)) {
650 if (!assign_string(&filter
, item_opt
->arg
, "--filter/-f")) {
656 if (!assign_string(&exclude
, item_opt
->arg
, "--exclude/-x")) {
662 case OPT_LOGLEVEL_ONLY
:
663 if (!assign_string(&loglevel_str
, item_opt
->arg
, "--loglevel/--loglevel-only")) {
667 loglevel_only
= item_opt
->descr
->id
== OPT_LOGLEVEL_ONLY
;
672 const char *capture_str
= item_opt
->arg
;
675 ret
= filter_parser_ctx_create_from_filter_expression(
676 capture_str
, &parser_ctx
);
678 fprintf(stderr
, "Failed to parse capture expression `%s`.\n", capture_str
);
682 event_expr
= ir_op_root_to_event_expr(parser_ctx
->ir_root
,
685 /* ir_op_root_to_event_expr has printed an error message. */
689 ret
= lttng_dynamic_pointer_array_add_pointer(
690 &res
.capture_descriptors
,
696 /* The ownership of event expression was transferred to the dynamic array. */
706 struct argpar_item_non_opt
*item_non_opt
=
707 (struct argpar_item_non_opt
*) item
;
710 * Don't accept two non-option arguments/tracepoint
713 if (tracepoint_name
) {
715 "Unexpected argument: %s",
720 tracepoint_name
= item_non_opt
->arg
;
724 if (event_rule_type
== LTTNG_EVENT_RULE_TYPE_UNKNOWN
) {
725 event_rule_type
= LTTNG_EVENT_RULE_TYPE_TRACEPOINT
;
729 * Option -a is applicable to event rules of type tracepoint and
730 * syscall, and it is equivalent to using "*" as the tracepoint name.
733 switch (event_rule_type
) {
734 case LTTNG_EVENT_RULE_TYPE_TRACEPOINT
:
735 case LTTNG_EVENT_RULE_TYPE_SYSCALL
:
738 ERR("Can't use -a/--all with event rule of type %s.",
739 lttng_event_rule_type_str(event_rule_type
));
743 if (tracepoint_name
) {
744 ERR("Can't provide a tracepoint name with -a/--all.");
748 /* In which case, it's equivalent to tracepoint name "*". */
749 tracepoint_name
= "*";
753 * A tracepoint name (or -a, for the event rule types that accept it)
756 if (!tracepoint_name
) {
757 ERR("Need to provide either a tracepoint name or -a/--all.");
762 * We don't support multiple tracepoint names for now.
764 if (strchr(tracepoint_name
, ',')) {
765 ERR("multiple tracepoint names are not supported at the moment.");
770 * Update *argc and *argv so our caller can keep parsing what follows.
772 consumed_args
= argpar_state_get_ingested_orig_args(state
);
773 assert(consumed_args
>= 0);
774 *argc
-= consumed_args
;
775 *argv
+= consumed_args
;
777 /* Need to specify a domain. */
778 if (domain_type
== LTTNG_DOMAIN_NONE
) {
779 ERR("Please specify a domain (-k/-u/-j).");
783 /* Validate event rule type against domain. */
784 switch (event_rule_type
) {
785 case LTTNG_EVENT_RULE_TYPE_KPROBE
:
786 case LTTNG_EVENT_RULE_TYPE_KRETPROBE
:
787 case LTTNG_EVENT_RULE_TYPE_UPROBE
:
788 case LTTNG_EVENT_RULE_TYPE_SYSCALL
:
789 if (domain_type
!= LTTNG_DOMAIN_KERNEL
) {
790 ERR("Event type not available for user-space tracing");
795 case LTTNG_EVENT_RULE_TYPE_TRACEPOINT
:
803 * Adding a filter to a probe, function or userspace-probe would be
804 * denied by the kernel tracer as it's not supported at the moment. We
805 * do an early check here to warn the user.
807 if (filter
&& domain_type
== LTTNG_DOMAIN_KERNEL
) {
808 switch (event_rule_type
) {
809 case LTTNG_EVENT_RULE_TYPE_TRACEPOINT
:
810 case LTTNG_EVENT_RULE_TYPE_SYSCALL
:
813 ERR("Filter expressions are not supported for %s events",
814 lttng_event_rule_type_str(event_rule_type
));
819 /* If --exclude/-x was passed, split it into an exclusion list. */
821 if (domain_type
!= LTTNG_DOMAIN_UST
) {
822 ERR("Event name exclusions are not yet implemented for %s events",
823 get_domain_str(domain_type
));
828 if (create_exclusion_list_and_validate(tracepoint_name
, exclude
,
829 &exclusion_list
) != 0) {
830 ERR("Failed to create exclusion list.");
835 if (loglevel_str
&& event_rule_type
!= LTTNG_EVENT_RULE_TYPE_TRACEPOINT
) {
836 ERR("Log levels are only application to tracepoint event rules.");
840 /* Finally, create the event rule object. */
841 switch (event_rule_type
) {
842 case LTTNG_EVENT_RULE_TYPE_TRACEPOINT
:
844 enum lttng_event_rule_status event_rule_status
;
846 res
.er
= lttng_event_rule_tracepoint_create(domain_type
);
848 ERR("Failed to create tracepoint event rule.");
854 lttng_event_rule_tracepoint_set_pattern(res
.er
, tracepoint_name
);
855 if (event_rule_status
!= LTTNG_EVENT_RULE_STATUS_OK
) {
856 ERR("Failed to set tracepoint pattern.");
863 lttng_event_rule_tracepoint_set_filter(
865 if (event_rule_status
!= LTTNG_EVENT_RULE_STATUS_OK
) {
866 ERR("Failed to set tracepoint filter expression.");
871 /* Set exclusion list. */
872 if (exclusion_list
) {
875 for (n
= 0; exclusion_list
[n
]; n
++) {
876 event_rule_status
= lttng_event_rule_tracepoint_add_exclusion(
879 if (event_rule_status
!=
880 LTTNG_EVENT_RULE_STATUS_OK
) {
881 ERR("Failed to set tracepoint exclusion list.");
890 if (domain_type
== LTTNG_DOMAIN_KERNEL
) {
891 ERR("Log levels are not supported by the kernel tracer.");
895 loglevel
= parse_loglevel_string(
896 loglevel_str
, domain_type
);
898 ERR("Failed to parse `%s` as a log level.", loglevel_str
);
904 lttng_event_rule_tracepoint_set_log_level(
908 lttng_event_rule_tracepoint_set_log_level_range_lower_bound(
912 if (event_rule_status
!= LTTNG_EVENT_RULE_STATUS_OK
) {
913 ERR("Failed to set log level.");
921 case LTTNG_EVENT_RULE_TYPE_KPROBE
:
924 enum lttng_event_rule_status event_rule_status
;
926 res
.er
= lttng_event_rule_kprobe_create();
928 ERR("Failed to create kprobe event rule.");
932 ret
= parse_kernel_probe_opts(source
, &kernel_probe_location
);
934 ERR("Failed to parse kernel probe location.");
938 event_rule_status
= lttng_event_rule_kprobe_set_name(res
.er
, tracepoint_name
);
939 if (event_rule_status
!= LTTNG_EVENT_RULE_STATUS_OK
) {
940 ERR("Failed to set kprobe event rule's name.");
944 assert(kernel_probe_location
);
945 event_rule_status
= lttng_event_rule_kprobe_set_location(res
.er
, kernel_probe_location
);
946 if (event_rule_status
!= LTTNG_EVENT_RULE_STATUS_OK
) {
947 ERR("Failed to set kprobe event rule's location.");
954 case LTTNG_EVENT_RULE_TYPE_UPROBE
:
957 enum lttng_event_rule_status event_rule_status
;
959 ret
= parse_userspace_probe_opts(source
, &userspace_probe_location
);
961 ERR("Failed to parse userspace probe location.");
965 res
.er
= lttng_event_rule_uprobe_create();
967 ERR("Failed to create userspace probe event rule.");
971 event_rule_status
= lttng_event_rule_uprobe_set_location(res
.er
, userspace_probe_location
);
972 if (event_rule_status
!= LTTNG_EVENT_RULE_STATUS_OK
) {
973 ERR("Failed to set userspace probe event rule's location.");
977 event_rule_status
= lttng_event_rule_uprobe_set_name(res
.er
, tracepoint_name
);
978 if (event_rule_status
!= LTTNG_EVENT_RULE_STATUS_OK
) {
979 ERR("Failed to set userspace probe event rule's name.");
986 case LTTNG_EVENT_RULE_TYPE_SYSCALL
:
988 enum lttng_event_rule_status event_rule_status
;
990 res
.er
= lttng_event_rule_syscall_create();
992 ERR("Failed to create syscall event rule.");
996 event_rule_status
= lttng_event_rule_syscall_set_pattern(res
.er
, tracepoint_name
);
997 if (event_rule_status
!= LTTNG_EVENT_RULE_STATUS_OK
) {
998 ERR("Failed to set syscall event rule's pattern.");
1003 event_rule_status
= lttng_event_rule_syscall_set_filter(
1005 if (event_rule_status
!= LTTNG_EVENT_RULE_STATUS_OK
) {
1006 ERR("Failed to set syscall event rule's filter expression.");
1015 ERR("%s: I don't support event rules of type `%s` at the moment.", __func__
,
1016 lttng_event_rule_type_str(event_rule_type
));
1023 lttng_event_rule_destroy(res
.er
);
1025 lttng_dynamic_pointer_array_reset(&res
.capture_descriptors
);
1029 filter_parser_ctx_free(parser_ctx
);
1032 lttng_event_expr_destroy(event_expr
);
1033 argpar_item_destroy(item
);
1035 argpar_state_destroy(state
);
1039 strutils_free_null_terminated_array_of_strings(exclusion_list
);
1040 lttng_kernel_probe_location_destroy(kernel_probe_location
);
1041 lttng_userspace_probe_location_destroy(userspace_probe_location
);
1046 struct lttng_condition
*handle_condition_event(int *argc
, const char ***argv
)
1048 struct parse_event_rule_res res
;
1049 struct lttng_condition
*c
;
1052 res
= parse_event_rule(argc
, argv
);
1058 c
= lttng_condition_event_rule_create(res
.er
);
1063 for (i
= 0; i
< lttng_dynamic_pointer_array_get_count(&res
.capture_descriptors
);
1065 enum lttng_condition_status status
;
1066 struct lttng_event_expr
**expr
=
1067 lttng_dynamic_array_get_element(
1068 &res
.capture_descriptors
.array
, i
);
1072 status
= lttng_condition_event_rule_append_capture_descriptor(
1074 if (status
!= LTTNG_CONDITION_STATUS_OK
) {
1075 if (status
== LTTNG_CONDITION_STATUS_UNSUPPORTED
) {
1076 ERR("The capture feature is unsupported by the event-rule type");
1081 /* Ownership of event expression moved to `c` */
1088 lttng_condition_destroy(c
);
1092 lttng_dynamic_pointer_array_reset(&res
.capture_descriptors
);
1093 lttng_event_rule_destroy(res
.er
);
1098 struct lttng_condition
*handle_condition_session_consumed_size(int *argc
, const char ***argv
)
1100 struct lttng_condition
*cond
= NULL
;
1101 struct argpar_state
*state
= NULL
;
1102 struct argpar_item
*item
= NULL
;
1103 const char *threshold_arg
= NULL
;
1104 const char *session_name_arg
= NULL
;
1107 enum lttng_condition_status condition_status
;
1109 state
= argpar_state_create(*argc
, *argv
, event_rule_opt_descrs
);
1111 ERR("Failed to allocate an argpar state.");
1116 enum argpar_state_parse_next_status status
;
1118 ARGPAR_ITEM_DESTROY_AND_RESET(item
);
1119 status
= argpar_state_parse_next(state
, &item
, &error
);
1120 if (status
== ARGPAR_STATE_PARSE_NEXT_STATUS_ERROR
) {
1123 } else if (status
== ARGPAR_STATE_PARSE_NEXT_STATUS_ERROR_UNKNOWN_OPT
) {
1124 /* Just stop parsing here. */
1126 } else if (status
== ARGPAR_STATE_PARSE_NEXT_STATUS_END
) {
1130 assert(status
== ARGPAR_STATE_PARSE_NEXT_STATUS_OK
);
1132 if (item
->type
== ARGPAR_ITEM_TYPE_OPT
) {
1133 struct argpar_item_opt
*item_opt
=
1134 (struct argpar_item_opt
*) item
;
1136 switch (item_opt
->descr
->id
) {
1141 struct argpar_item_non_opt
*item_non_opt
;
1143 assert(item
->type
== ARGPAR_ITEM_TYPE_NON_OPT
);
1145 item_non_opt
= (struct argpar_item_non_opt
*) item
;
1147 switch (item_non_opt
->non_opt_index
) {
1149 session_name_arg
= item_non_opt
->arg
;
1152 threshold_arg
= item_non_opt
->arg
;
1155 ERR("Unexpected argument `%s`.",
1162 *argc
-= argpar_state_get_ingested_orig_args(state
);
1163 *argv
+= argpar_state_get_ingested_orig_args(state
);
1165 if (!session_name_arg
) {
1166 ERR("Missing session name argument.");
1170 if (!threshold_arg
) {
1171 ERR("Missing threshold argument.");
1175 if (utils_parse_size_suffix(threshold_arg
, &threshold
) != 0) {
1176 ERR("Failed to parse `%s` as a size.", threshold_arg
);
1180 cond
= lttng_condition_session_consumed_size_create();
1182 ERR("Failed to allocate a session consumed size condition.");
1186 condition_status
= lttng_condition_session_consumed_size_set_session_name(
1187 cond
, session_name_arg
);
1188 if (condition_status
!= LTTNG_CONDITION_STATUS_OK
) {
1189 ERR("Failed to set session consumed size condition session name.");
1194 condition_status
= lttng_condition_session_consumed_size_set_threshold(
1196 if (condition_status
!= LTTNG_CONDITION_STATUS_OK
) {
1197 ERR("Failed to set session consumed size condition threshold.");
1204 lttng_condition_destroy(cond
);
1208 argpar_state_destroy(state
);
1209 argpar_item_destroy(item
);
1215 struct lttng_condition
*handle_condition_buffer_usage_high(int *argc
, const char ***argv
)
1217 struct lttng_condition
*cond
= NULL
;
1218 struct argpar_state
*state
= NULL
;
1219 struct argpar_item
*item
= NULL
;
1220 const char *threshold_arg
= NULL
;
1221 const char *session_name_arg
= NULL
;
1224 enum lttng_condition_status condition_status
;
1226 state
= argpar_state_create(*argc
, *argv
, event_rule_opt_descrs
);
1228 ERR("Failed to allocate an argpar state.");
1233 enum argpar_state_parse_next_status status
;
1235 ARGPAR_ITEM_DESTROY_AND_RESET(item
);
1236 status
= argpar_state_parse_next(state
, &item
, &error
);
1237 if (status
== ARGPAR_STATE_PARSE_NEXT_STATUS_ERROR
) {
1240 } else if (status
== ARGPAR_STATE_PARSE_NEXT_STATUS_ERROR_UNKNOWN_OPT
) {
1241 /* Just stop parsing here. */
1243 } else if (status
== ARGPAR_STATE_PARSE_NEXT_STATUS_END
) {
1247 assert(status
== ARGPAR_STATE_PARSE_NEXT_STATUS_OK
);
1249 if (item
->type
== ARGPAR_ITEM_TYPE_OPT
) {
1250 struct argpar_item_opt
*item_opt
=
1251 (struct argpar_item_opt
*) item
;
1253 switch (item_opt
->descr
->id
) {
1258 struct argpar_item_non_opt
*item_non_opt
;
1260 assert(item
->type
== ARGPAR_ITEM_TYPE_NON_OPT
);
1262 item_non_opt
= (struct argpar_item_non_opt
*) item
;
1264 switch (item_non_opt
->non_opt_index
) {
1266 session_name_arg
= item_non_opt
->arg
;
1269 threshold_arg
= item_non_opt
->arg
;
1272 ERR("Unexpected argument `%s`.",
1279 *argc
-= argpar_state_get_ingested_orig_args(state
);
1280 *argv
+= argpar_state_get_ingested_orig_args(state
);
1282 if (!session_name_arg
) {
1283 ERR("Missing session name argument.");
1287 if (!threshold_arg
) {
1288 ERR("Missing threshold argument.");
1292 if (utils_parse_size_suffix(threshold_arg
, &threshold
) != 0) {
1293 ERR("Failed to parse `%s` as a size.", threshold_arg
);
1297 cond
= lttng_condition_session_consumed_size_create();
1299 ERR("Failed to allocate a session consumed size condition.");
1303 condition_status
= lttng_condition_session_consumed_size_set_session_name(
1304 cond
, session_name_arg
);
1305 if (condition_status
!= LTTNG_CONDITION_STATUS_OK
) {
1306 ERR("Failed to set session consumed size condition session name.");
1310 condition_status
= lttng_condition_session_consumed_size_set_threshold(
1312 if (condition_status
!= LTTNG_CONDITION_STATUS_OK
) {
1313 ERR("Failed to set session consumed size condition threshold.");
1320 lttng_condition_destroy(cond
);
1324 argpar_state_destroy(state
);
1325 argpar_item_destroy(item
);
1331 struct lttng_condition
*handle_condition_buffer_usage_low(int *argc
, const char ***argv
)
1337 struct lttng_condition
*handle_condition_session_rotation_ongoing(int *argc
, const char ***argv
)
1343 struct lttng_condition
*handle_condition_session_rotation_completed(int *argc
, const char ***argv
)
1348 struct condition_descr
{
1350 struct lttng_condition
*(*handler
) (int *argc
, const char ***argv
);
1354 struct condition_descr condition_descrs
[] = {
1355 { "on-event", handle_condition_event
},
1356 { "on-session-consumed-size", handle_condition_session_consumed_size
},
1357 { "on-buffer-usage-high", handle_condition_buffer_usage_high
},
1358 { "on-buffer-usage-low", handle_condition_buffer_usage_low
},
1359 { "on-session-rotation-ongoing", handle_condition_session_rotation_ongoing
},
1360 { "on-session-rotation-completed", handle_condition_session_rotation_completed
},
1364 struct lttng_condition
*parse_condition(int *argc
, const char ***argv
)
1367 struct lttng_condition
*cond
;
1368 const char *condition_name
;
1369 const struct condition_descr
*descr
= NULL
;
1372 ERR("Missing condition name.");
1376 condition_name
= (*argv
)[0];
1381 for (i
= 0; i
< ARRAY_SIZE(condition_descrs
); i
++) {
1382 if (strcmp(condition_name
, condition_descrs
[i
].name
) == 0) {
1383 descr
= &condition_descrs
[i
];
1389 ERR("Unknown condition name: %s", condition_name
);
1393 cond
= descr
->handler(argc
, argv
);
1395 /* The handler has already printed an error message. */
1408 struct lttng_action
*handle_action_notify(int *argc
, const char ***argv
)
1410 return lttng_action_notify_create();
1413 static const struct argpar_opt_descr no_opt_descrs
[] = {
1414 ARGPAR_OPT_DESCR_SENTINEL
1418 * Generic handler for a kind of action that takes a session name as its sole
1423 struct lttng_action
*handle_action_simple_session(
1424 int *argc
, const char ***argv
,
1425 struct lttng_action
*(*create_action_cb
)(void),
1426 enum lttng_action_status (*set_session_name_cb
)(struct lttng_action
*, const char *),
1427 const char *action_name
)
1429 struct lttng_action
*action
= NULL
;
1430 struct argpar_state
*state
= NULL
;
1431 struct argpar_item
*item
= NULL
;
1432 const char *session_name_arg
= NULL
;
1434 enum lttng_action_status action_status
;
1436 state
= argpar_state_create(*argc
, *argv
, no_opt_descrs
);
1438 ERR("Failed to allocate an argpar state.");
1443 enum argpar_state_parse_next_status status
;
1444 struct argpar_item_non_opt
*item_non_opt
;
1446 ARGPAR_ITEM_DESTROY_AND_RESET(item
);
1447 status
= argpar_state_parse_next(state
, &item
, &error
);
1448 if (status
== ARGPAR_STATE_PARSE_NEXT_STATUS_ERROR
) {
1451 } else if (status
== ARGPAR_STATE_PARSE_NEXT_STATUS_ERROR_UNKNOWN_OPT
) {
1452 /* Just stop parsing here. */
1454 } else if (status
== ARGPAR_STATE_PARSE_NEXT_STATUS_END
) {
1458 assert(status
== ARGPAR_STATE_PARSE_NEXT_STATUS_OK
);
1459 assert(item
->type
== ARGPAR_ITEM_TYPE_NON_OPT
);
1461 item_non_opt
= (struct argpar_item_non_opt
*) item
;
1463 switch (item_non_opt
->non_opt_index
) {
1465 session_name_arg
= item_non_opt
->arg
;
1468 ERR("Unexpected argument `%s`.",
1474 *argc
-= argpar_state_get_ingested_orig_args(state
);
1475 *argv
+= argpar_state_get_ingested_orig_args(state
);
1477 if (!session_name_arg
) {
1478 ERR("Missing session name.");
1482 action
= create_action_cb();
1485 "Failed to allocate %s session action.", action_name
);
1489 action_status
= set_session_name_cb(action
, session_name_arg
);
1490 if (action_status
!= LTTNG_ACTION_STATUS_OK
) {
1492 "Failed to set action %s session's session name.",
1500 lttng_action_destroy(action
);
1508 struct lttng_action
*handle_action_start_session(int *argc
,
1511 return handle_action_simple_session(argc
, argv
,
1512 lttng_action_start_session_create
,
1513 lttng_action_start_session_set_session_name
,
1518 struct lttng_action
*handle_action_stop_session(int *argc
,
1521 return handle_action_simple_session(argc
, argv
,
1522 lttng_action_stop_session_create
,
1523 lttng_action_stop_session_set_session_name
,
1528 struct lttng_action
*handle_action_rotate_session(int *argc
,
1531 return handle_action_simple_session(argc
, argv
,
1532 lttng_action_rotate_session_create
,
1533 lttng_action_rotate_session_set_session_name
,
1537 static const struct argpar_opt_descr snapshot_action_opt_descrs
[] = {
1538 { OPT_NAME
, 'n', "name", true },
1539 { OPT_MAX_SIZE
, 'm', "max-size", true },
1540 { OPT_CTRL_URL
, '\0', "ctrl-url", true },
1541 { OPT_DATA_URL
, '\0', "data-url", true },
1542 ARGPAR_OPT_DESCR_SENTINEL
1546 struct lttng_action
*handle_action_snapshot_session(int *argc
,
1549 struct lttng_action
*action
= NULL
;
1550 struct argpar_state
*state
= NULL
;
1551 struct argpar_item
*item
= NULL
;
1552 const char *session_name_arg
= NULL
;
1553 char *snapshot_name_arg
= NULL
;
1554 char *ctrl_url_arg
= NULL
;
1555 char *data_url_arg
= NULL
;
1556 char *max_size_arg
= NULL
;
1557 const char *url_arg
= NULL
;
1559 enum lttng_action_status action_status
;
1560 struct lttng_snapshot_output
*snapshot_output
= NULL
;
1563 state
= argpar_state_create(*argc
, *argv
, snapshot_action_opt_descrs
);
1565 ERR("Failed to allocate an argpar state.");
1570 enum argpar_state_parse_next_status status
;
1572 ARGPAR_ITEM_DESTROY_AND_RESET(item
);
1573 status
= argpar_state_parse_next(state
, &item
, &error
);
1574 if (status
== ARGPAR_STATE_PARSE_NEXT_STATUS_ERROR
) {
1577 } else if (status
== ARGPAR_STATE_PARSE_NEXT_STATUS_ERROR_UNKNOWN_OPT
) {
1578 /* Just stop parsing here. */
1580 } else if (status
== ARGPAR_STATE_PARSE_NEXT_STATUS_END
) {
1584 assert(status
== ARGPAR_STATE_PARSE_NEXT_STATUS_OK
);
1586 if (item
->type
== ARGPAR_ITEM_TYPE_OPT
) {
1587 struct argpar_item_opt
*item_opt
=
1588 (struct argpar_item_opt
*) item
;
1590 switch (item_opt
->descr
->id
) {
1592 if (!assign_string(&snapshot_name_arg
, item_opt
->arg
, "--name/-n")) {
1598 if (!assign_string(&max_size_arg
, item_opt
->arg
, "--max-size/-m")) {
1604 if (!assign_string(&ctrl_url_arg
, item_opt
->arg
, "--ctrl-url")) {
1610 if (!assign_string(&data_url_arg
, item_opt
->arg
, "--data-url")) {
1619 struct argpar_item_non_opt
*item_non_opt
;
1621 assert(item
->type
== ARGPAR_ITEM_TYPE_NON_OPT
);
1623 item_non_opt
= (struct argpar_item_non_opt
*) item
;
1625 switch (item_non_opt
->non_opt_index
) {
1627 session_name_arg
= item_non_opt
->arg
;
1630 // FIXME: the use of a non-option argument for this is to
1631 // follow the syntax of `lttng snapshot record`. But otherwise,
1632 // I think an option argument would be best.
1634 url_arg
= item_non_opt
->arg
;
1638 ERR("Unexpected argument `%s`.",
1645 *argc
-= argpar_state_get_ingested_orig_args(state
);
1646 *argv
+= argpar_state_get_ingested_orig_args(state
);
1648 if (!session_name_arg
) {
1649 ERR("Missing session name.");
1653 /* --ctrl-url and --data-url must come in pair. */
1654 if (ctrl_url_arg
&& !data_url_arg
) {
1655 ERR("--ctrl-url is specified, but --data-url is missing.");
1659 if (!ctrl_url_arg
&& data_url_arg
) {
1660 ERR("--data-url is specified, but --ctrl-url is missing.");
1664 /* --ctrl-url/--data-url and the non-option URL are mutually exclusive. */
1665 if (ctrl_url_arg
&& url_arg
) {
1666 ERR("Both --ctrl-url/--data-url and the non-option URL argument "
1667 "can't be used together.");
1672 * Did the user specify an option that implies using a
1673 * custom/unregistered output?
1675 if (url_arg
|| ctrl_url_arg
) {
1676 snapshot_output
= lttng_snapshot_output_create();
1677 if (!snapshot_output
) {
1678 ERR("Failed to allocate a snapshot output.");
1683 action
= lttng_action_snapshot_session_create();
1686 "Failed to allocate snapshot session action.");
1690 action_status
= lttng_action_snapshot_session_set_session_name(
1691 action
, session_name_arg
);
1692 if (action_status
!= LTTNG_ACTION_STATUS_OK
) {
1694 "Failed to set action snapshot session's session name.");
1698 if (snapshot_name_arg
) {
1699 if (!snapshot_output
) {
1700 ERR("Can't provide a snapshot output name without a snapshot output destination.");
1704 ret
= lttng_snapshot_output_set_name(snapshot_name_arg
, snapshot_output
);
1706 ERR("Failed to set name of snapshot output.");
1714 if (!snapshot_output
) {
1715 ERR("Can't provide a snapshot output max size without a snapshot output destination.");
1719 ret
= utils_parse_size_suffix(max_size_arg
, &max_size
);
1721 ERR("Failed to parse `%s` as a size.", max_size_arg
);
1725 ret
= lttng_snapshot_output_set_size(max_size
, snapshot_output
);
1727 ERR("Failed to set snapshot output's max size.");
1733 /* One argument form, either net:// / net6:// or a local file path. */
1735 if (strncmp(url_arg
, "net://", strlen("net://")) == 0 ||
1736 strncmp(url_arg
, "net6://", strlen("net6://")) == 0) {
1737 ret
= lttng_snapshot_output_set_network_url(
1738 url_arg
, snapshot_output
);
1740 ERR("Failed to parse %s as a network URL.", url_arg
);
1744 ret
= lttng_snapshot_output_set_local_path(
1745 url_arg
, snapshot_output
);
1747 ERR("Failed to parse %s as a local path.", url_arg
);
1755 * Two argument form, network output with separate control and
1758 ret
= lttng_snapshot_output_set_network_urls(
1759 ctrl_url_arg
, data_url_arg
, snapshot_output
);
1761 ERR("Failed to parse `%s` and `%s` as control and data URLs.",
1762 ctrl_url_arg
, data_url_arg
);
1767 if (snapshot_output
) {
1768 action_status
= lttng_action_snapshot_session_set_output(
1769 action
, snapshot_output
);
1770 if (action_status
!= LTTNG_ACTION_STATUS_OK
) {
1771 ERR("Failed to set snapshot session action's output.");
1775 /* Ownership of `snapshot_output` has been transferred to the action. */
1776 snapshot_output
= NULL
;
1782 lttng_action_destroy(action
);
1786 free(snapshot_name_arg
);
1789 free(snapshot_output
);
1793 struct action_descr
{
1795 struct lttng_action
*(*handler
) (int *argc
, const char ***argv
);
1799 struct action_descr action_descrs
[] = {
1800 { "notify", handle_action_notify
},
1801 { "start-session", handle_action_start_session
},
1802 { "stop-session", handle_action_stop_session
},
1803 { "rotate-session", handle_action_rotate_session
},
1804 { "snapshot-session", handle_action_snapshot_session
},
1808 struct lttng_action
*parse_action(int *argc
, const char ***argv
)
1811 struct lttng_action
*action
;
1812 const char *action_name
;
1813 const struct action_descr
*descr
= NULL
;
1816 ERR("Missing action name.");
1820 action_name
= (*argv
)[0];
1825 for (i
= 0; i
< ARRAY_SIZE(action_descrs
); i
++) {
1826 if (strcmp(action_name
, action_descrs
[i
].name
) == 0) {
1827 descr
= &action_descrs
[i
];
1833 ERR("Unknown action name: %s", action_name
);
1837 action
= descr
->handler(argc
, argv
);
1839 /* The handler has already printed an error message. */
1851 struct argpar_opt_descr add_trigger_options
[] = {
1852 { OPT_HELP
, 'h', "help", false },
1853 { OPT_LIST_OPTIONS
, '\0', "list-options", false },
1854 { OPT_CONDITION
, '\0', "condition", false },
1855 { OPT_ACTION
, '\0', "action", false },
1856 { OPT_ID
, '\0', "id", true },
1857 { OPT_FIRE_ONCE_AFTER
, '\0', "fire-once-after", true },
1858 { OPT_FIRE_EVERY
, '\0', "fire-every", true },
1859 { OPT_USER_ID
, '\0', "user-id", true },
1860 ARGPAR_OPT_DESCR_SENTINEL
,
1864 void lttng_actions_destructor(void *p
)
1866 struct lttng_action
*action
= p
;
1868 lttng_action_destroy(action
);
1871 int cmd_add_trigger(int argc
, const char **argv
)
1874 int my_argc
= argc
- 1;
1875 const char **my_argv
= argv
+ 1;
1876 struct lttng_condition
*condition
= NULL
;
1877 struct lttng_dynamic_pointer_array actions
;
1878 struct argpar_state
*argpar_state
= NULL
;
1879 struct argpar_item
*argpar_item
= NULL
;
1880 struct lttng_action
*action_group
= NULL
;
1881 struct lttng_action
*action
= NULL
;
1882 struct lttng_trigger
*trigger
= NULL
;
1886 char *fire_once_after_str
= NULL
;
1887 char *fire_every_str
= NULL
;
1888 char *user_id
= NULL
;
1890 lttng_dynamic_pointer_array_init(&actions
, lttng_actions_destructor
);
1893 enum argpar_state_parse_next_status status
;
1894 struct argpar_item_opt
*item_opt
;
1897 argpar_state_destroy(argpar_state
);
1898 argpar_state
= argpar_state_create(my_argc
, my_argv
,
1899 add_trigger_options
);
1900 if (!argpar_state
) {
1901 ERR("Failed to create argpar state.");
1905 status
= argpar_state_parse_next(argpar_state
, &argpar_item
, &error
);
1907 if (status
== ARGPAR_STATE_PARSE_NEXT_STATUS_ERROR
) {
1910 } else if (status
== ARGPAR_STATE_PARSE_NEXT_STATUS_ERROR_UNKNOWN_OPT
) {
1913 } else if (status
== ARGPAR_STATE_PARSE_NEXT_STATUS_END
) {
1917 assert(status
== ARGPAR_STATE_PARSE_NEXT_STATUS_OK
);
1919 if (argpar_item
->type
== ARGPAR_ITEM_TYPE_NON_OPT
) {
1920 struct argpar_item_non_opt
*item_non_opt
=
1921 (struct argpar_item_non_opt
*) argpar_item
;
1923 ERR("Unexpected argument `%s`.",
1928 item_opt
= (struct argpar_item_opt
*) argpar_item
;
1930 ingested_args
= argpar_state_get_ingested_orig_args(
1933 my_argc
-= ingested_args
;
1934 my_argv
+= ingested_args
;
1936 switch (item_opt
->descr
->id
) {
1942 case OPT_LIST_OPTIONS
:
1943 list_cmd_options_argpar(stdout
, add_trigger_options
);
1950 ERR("A --condition was already given.");
1954 condition
= parse_condition(&my_argc
, &my_argv
);
1957 * An error message was already printed by
1968 action
= parse_action(&my_argc
, &my_argv
);
1971 * An error message was already printed by
1977 ret
= lttng_dynamic_pointer_array_add_pointer(
1980 ERR("Failed to add pointer to pointer array.");
1984 /* Ownership of the action was transferred to the group. */
1992 if (!assign_string(&id
, item_opt
->arg
, "--id")) {
1999 case OPT_FIRE_ONCE_AFTER
:
2001 if (!assign_string(&fire_once_after_str
, item_opt
->arg
,
2002 "--fire-once-after")) {
2008 case OPT_FIRE_EVERY
:
2010 if (!assign_string(&fire_every_str
, item_opt
->arg
,
2019 if (!assign_string(&user_id
, item_opt
->arg
,
2032 ERR("Missing --condition.");
2036 if (lttng_dynamic_pointer_array_get_count(&actions
) == 0) {
2037 ERR("Need at least one --action.");
2041 if (fire_every_str
&& fire_once_after_str
) {
2042 ERR("Can't specify both --fire-once-after and --fire-every.");
2046 action_group
= lttng_action_group_create();
2047 if (!action_group
) {
2051 for (i
= 0; i
< lttng_dynamic_pointer_array_get_count(&actions
); i
++) {
2052 enum lttng_action_status status
;
2054 action
= lttng_dynamic_pointer_array_steal_pointer(&actions
, i
);
2056 status
= lttng_action_group_add_action(
2057 action_group
, action
);
2058 if (status
!= LTTNG_ACTION_STATUS_OK
) {
2062 /* Ownership of the action was transferred to the group. */
2067 trigger
= lttng_trigger_create(condition
, action_group
);
2073 enum lttng_trigger_status trigger_status
=
2074 lttng_trigger_set_name(trigger
, id
);
2075 if (trigger_status
!= LTTNG_TRIGGER_STATUS_OK
) {
2076 ERR("Failed to set trigger id.");
2081 if (fire_once_after_str
) {
2082 unsigned long long threshold
;
2083 enum lttng_trigger_status trigger_status
;
2085 if (utils_parse_unsigned_long_long(fire_once_after_str
, &threshold
) != 0) {
2086 ERR("Failed to parse `%s` as an integer.", fire_once_after_str
);
2090 trigger_status
= lttng_trigger_set_firing_policy(trigger
,
2091 LTTNG_TRIGGER_FIRE_ONCE_AFTER_N
, threshold
);
2092 if (trigger_status
!= LTTNG_TRIGGER_STATUS_OK
) {
2093 ERR("Failed to set trigger's firing policy.");
2098 if (fire_every_str
) {
2099 unsigned long long threshold
;
2100 enum lttng_trigger_status trigger_status
;
2102 if (utils_parse_unsigned_long_long(fire_every_str
, &threshold
) != 0) {
2103 ERR("Failed to parse `%s` as an integer.", fire_every_str
);
2107 trigger_status
= lttng_trigger_set_firing_policy(trigger
,
2108 LTTNG_TRIGGER_FIRE_EVERY_N
, threshold
);
2109 if (trigger_status
!= LTTNG_TRIGGER_STATUS_OK
) {
2110 ERR("Failed to set trigger's firing policy.");
2116 enum lttng_trigger_status trigger_status
;
2121 uid
= strtol(user_id
, &end
, 10);
2122 if (end
== user_id
|| *end
!= '\0' || errno
!= 0) {
2123 ERR("Failed to parse `%s` as an integer.", user_id
);
2126 trigger_status
= lttng_trigger_set_user_identity(trigger
,
2128 if (trigger_status
!= LTTNG_TRIGGER_STATUS_OK
) {
2129 ERR("Failed to set trigger's user identity.");
2134 ret
= lttng_register_trigger(trigger
);
2136 ERR("Failed to register trigger: %s.",
2137 lttng_strerror(ret
));
2141 MSG("Trigger registered successfully.");
2149 argpar_state_destroy(argpar_state
);
2150 lttng_dynamic_pointer_array_reset(&actions
);
2151 lttng_condition_destroy(condition
);
2152 lttng_action_destroy(action_group
);
2153 lttng_trigger_destroy(trigger
);
2155 free(fire_once_after_str
);
2156 free(fire_every_str
);
2158 // TODO: check what else to free