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_exp
, const char *capture_str
)
306 char *provider_name
= NULL
;
307 struct lttng_event_expr
*event_expr
= NULL
;
308 const struct ir_load_expression_op
*load_expr_op
= load_exp
->child
;
310 switch (load_expr_op
->type
) {
311 case IR_LOAD_EXPRESSION_GET_PAYLOAD_ROOT
:
312 case IR_LOAD_EXPRESSION_GET_CONTEXT_ROOT
:
314 const char *field_name
;
316 load_expr_op
= load_expr_op
->next
;
317 assert(load_expr_op
);
318 assert(load_expr_op
->type
== IR_LOAD_EXPRESSION_GET_SYMBOL
);
319 field_name
= load_expr_op
->u
.symbol
;
322 event_expr
= load_expr_op
->type
== IR_LOAD_EXPRESSION_GET_PAYLOAD_ROOT
?
323 lttng_event_expr_event_payload_field_create(field_name
) :
324 lttng_event_expr_channel_context_field_create(field_name
);
326 ERR("Failed to create %s event expression: field name = `%s`.",
327 load_expr_op
->type
== IR_LOAD_EXPRESSION_GET_PAYLOAD_ROOT
?
328 "payload field" : "channel context",
335 case IR_LOAD_EXPRESSION_GET_APP_CONTEXT_ROOT
:
338 const char *type_name
;
339 const char *field_name
;
341 load_expr_op
= load_expr_op
->next
;
342 assert(load_expr_op
);
343 assert(load_expr_op
->type
== IR_LOAD_EXPRESSION_GET_SYMBOL
);
344 field_name
= load_expr_op
->u
.symbol
;
348 * The field name needs to be of the form PROVIDER:TYPE. We
351 colon
= strchr(field_name
, ':');
353 ERR("Invalid app-specific context field name: missing colon in `%s`.",
358 type_name
= colon
+ 1;
359 if (*type_name
== '\0') {
360 ERR("Invalid app-specific context field name: missing type name after colon in `%s`.",
365 provider_name
= strndup(field_name
, colon
- field_name
);
366 if (!provider_name
) {
367 PERROR("Failed to allocate field name string");
371 event_expr
= lttng_event_expr_app_specific_context_field_create(
372 provider_name
, type_name
);
374 ERR("Failed to create app-specific context field event expression: provider name = `%s`, type name = `%s`",
375 provider_name
, type_name
);
382 ERR("%s: unexpected load expr type %d.", __func__
,
387 load_expr_op
= load_expr_op
->next
;
389 /* There may be a single array index after that. */
390 if (load_expr_op
->type
== IR_LOAD_EXPRESSION_GET_INDEX
) {
391 struct lttng_event_expr
*index_event_expr
;
392 const uint64_t index
= load_expr_op
->u
.index
;
394 index_event_expr
= lttng_event_expr_array_field_element_create(event_expr
, index
);
395 if (!index_event_expr
) {
396 ERR("Failed to create array field element event expression.");
400 event_expr
= index_event_expr
;
401 load_expr_op
= load_expr_op
->next
;
404 switch (load_expr_op
->type
) {
405 case IR_LOAD_EXPRESSION_LOAD_FIELD
:
407 * This is what we expect, IR_LOAD_EXPRESSION_LOAD_FIELD is
408 * always found at the end of the chain.
411 case IR_LOAD_EXPRESSION_GET_SYMBOL
:
412 ERR("While parsing expression `%s`: Capturing subfields is not supported.",
417 ERR("%s: unexpected load expression operator %s.", __func__
,
418 ir_load_expression_type_str(load_expr_op
->type
));
425 lttng_event_expr_destroy(event_expr
);
435 struct lttng_event_expr
*ir_op_load_to_event_expr(
436 const struct ir_op
*ir
, const char *capture_str
)
438 struct lttng_event_expr
*event_expr
= NULL
;
440 assert(ir
->op
== IR_OP_LOAD
);
442 switch (ir
->data_type
) {
443 case IR_DATA_EXPRESSION
:
445 const struct ir_load_expression
*ir_load_expr
=
446 ir
->u
.load
.u
.expression
;
448 event_expr
= ir_op_load_expr_to_event_expr(
449 ir_load_expr
, capture_str
);
453 ERR("%s: unexpected data type: %s.", __func__
,
454 ir_data_type_str(ir
->data_type
));
462 const char *ir_operator_type_human_str(enum ir_op_type op
)
484 struct lttng_event_expr
*ir_op_root_to_event_expr(const struct ir_op
*ir
,
485 const char *capture_str
)
487 struct lttng_event_expr
*event_expr
= NULL
;
489 assert(ir
->op
== IR_OP_ROOT
);
490 ir
= ir
->u
.root
.child
;
494 event_expr
= ir_op_load_to_event_expr(ir
, capture_str
);
499 ERR("While parsing expression `%s`: %s operators are not allowed in capture expressions.",
501 ir_operator_type_human_str(ir
->op
));
504 ERR("%s: unexpected IR op type: %s.", __func__
,
505 ir_op_type_str(ir
->op
));
513 void destroy_event_expr(void *ptr
)
515 lttng_event_expr_destroy(ptr
);
518 struct parse_event_rule_res
{
520 struct lttng_event_rule
*er
;
522 /* Array of `struct lttng_event_expr *` */
523 struct lttng_dynamic_pointer_array capture_descriptors
;
527 struct parse_event_rule_res
parse_event_rule(int *argc
, const char ***argv
)
529 enum lttng_domain_type domain_type
= LTTNG_DOMAIN_NONE
;
530 enum lttng_event_rule_type event_rule_type
=
531 LTTNG_EVENT_RULE_TYPE_UNKNOWN
;
532 struct argpar_state
*state
;
533 struct argpar_item
*item
= NULL
;
535 int consumed_args
= -1;
536 struct lttng_kernel_probe_location
*kernel_probe_location
= NULL
;
537 struct lttng_userspace_probe_location
*userspace_probe_location
= NULL
;
538 struct parse_event_rule_res res
= { 0 };
539 struct lttng_event_expr
*event_expr
= NULL
;
540 struct filter_parser_ctx
*parser_ctx
= NULL
;
542 /* Was the -a/--all flag provided? */
543 bool all_events
= false;
545 /* Tracepoint name (non-option argument). */
546 const char *tracepoint_name
= NULL
;
548 /* Holds the argument of --probe / --userspace-probe. */
555 char *exclude
= NULL
;
556 char **exclusion_list
= NULL
;
559 char *loglevel_str
= NULL
;
560 bool loglevel_only
= false;
562 lttng_dynamic_pointer_array_init(&res
.capture_descriptors
,
564 state
= argpar_state_create(*argc
, *argv
, event_rule_opt_descrs
);
566 ERR("Failed to allocate an argpar state.");
571 enum argpar_state_parse_next_status status
;
573 ARGPAR_ITEM_DESTROY_AND_RESET(item
);
574 status
= argpar_state_parse_next(state
, &item
, &error
);
575 if (status
== ARGPAR_STATE_PARSE_NEXT_STATUS_ERROR
) {
578 } else if (status
== ARGPAR_STATE_PARSE_NEXT_STATUS_ERROR_UNKNOWN_OPT
) {
579 /* Just stop parsing here. */
581 } else if (status
== ARGPAR_STATE_PARSE_NEXT_STATUS_END
) {
585 assert(status
== ARGPAR_STATE_PARSE_NEXT_STATUS_OK
);
587 if (item
->type
== ARGPAR_ITEM_TYPE_OPT
) {
588 const struct argpar_item_opt
*item_opt
=
589 (const struct argpar_item_opt
*) item
;
591 switch (item_opt
->descr
->id
) {
594 if (!assign_domain_type(&domain_type
, LTTNG_DOMAIN_UST
)) {
600 if (!assign_domain_type(&domain_type
, LTTNG_DOMAIN_KERNEL
)) {
606 if (!assign_domain_type(&domain_type
, LTTNG_DOMAIN_LOG4J
)) {
612 if (!assign_domain_type(&domain_type
, LTTNG_DOMAIN_JUL
)) {
618 if (!assign_domain_type(&domain_type
, LTTNG_DOMAIN_PYTHON
)) {
624 /* Event rule types */
626 if (!assign_event_rule_type(&event_rule_type
,
627 LTTNG_EVENT_RULE_TYPE_KRETPROBE
)) {
633 if (!assign_event_rule_type(&event_rule_type
,
634 LTTNG_EVENT_RULE_TYPE_KPROBE
)) {
638 if (!assign_string(&source
, item_opt
->arg
, "source")) {
643 case OPT_USERSPACE_PROBE
:
644 if (!assign_event_rule_type(&event_rule_type
,
645 LTTNG_EVENT_RULE_TYPE_UPROBE
)) {
649 if (!assign_string(&source
, item_opt
->arg
, "source")) {
655 if (!assign_event_rule_type(&event_rule_type
,
656 LTTNG_EVENT_RULE_TYPE_SYSCALL
)) {
662 if (!assign_event_rule_type(&event_rule_type
,
663 LTTNG_EVENT_RULE_TYPE_TRACEPOINT
)) {
672 if (!assign_string(&filter
, item_opt
->arg
,
679 if (!assign_string(&exclude
, item_opt
->arg
,
686 case OPT_LOGLEVEL_ONLY
:
687 if (!assign_string(&loglevel_str
, item_opt
->arg
,
688 "--loglevel/--loglevel-only")) {
692 loglevel_only
= item_opt
->descr
->id
==
698 const char *capture_str
= item_opt
->arg
;
700 ret
= filter_parser_ctx_create_from_filter_expression(
701 capture_str
, &parser_ctx
);
703 ERR("Failed to parse capture expression `%s`.",
708 event_expr
= ir_op_root_to_event_expr(
713 * ir_op_root_to_event_expr has printed
719 ret
= lttng_dynamic_pointer_array_add_pointer(
720 &res
.capture_descriptors
,
727 * The ownership of event expression was
728 * transferred to the dynamic array.
738 const struct argpar_item_non_opt
*item_non_opt
=
739 (const struct argpar_item_non_opt
*)
743 * Don't accept two non-option arguments/tracepoint
746 if (tracepoint_name
) {
747 ERR("Unexpected argument '%s'",
752 tracepoint_name
= item_non_opt
->arg
;
756 if (event_rule_type
== LTTNG_EVENT_RULE_TYPE_UNKNOWN
) {
757 event_rule_type
= LTTNG_EVENT_RULE_TYPE_TRACEPOINT
;
761 * Option -a is applicable to event rules of type tracepoint and
762 * syscall, and it is equivalent to using "*" as the tracepoint name.
765 switch (event_rule_type
) {
766 case LTTNG_EVENT_RULE_TYPE_TRACEPOINT
:
767 case LTTNG_EVENT_RULE_TYPE_SYSCALL
:
770 ERR("Can't use -a/--all with %s event rules.",
771 lttng_event_rule_type_str(event_rule_type
));
775 if (tracepoint_name
) {
776 ERR("Can't provide a tracepoint name with -a/--all.");
780 /* In which case, it's equivalent to tracepoint name "*". */
781 tracepoint_name
= "*";
785 * A tracepoint name (or -a, for the event rule types that accept it)
788 if (!tracepoint_name
) {
789 ERR("Need to provide either a tracepoint name or -a/--all.");
794 * We don't support multiple tracepoint names for now.
796 if (strchr(tracepoint_name
, ',')) {
797 ERR("Comma separated tracepoint names are not supported.");
802 * Update *argc and *argv so our caller can keep parsing what follows.
804 consumed_args
= argpar_state_get_ingested_orig_args(state
);
805 assert(consumed_args
>= 0);
806 *argc
-= consumed_args
;
807 *argv
+= consumed_args
;
809 /* Need to specify a domain. */
810 if (domain_type
== LTTNG_DOMAIN_NONE
) {
811 ERR("Please specify a domain (--kernel/--userspace/--jul/--log4j/--python).");
815 /* Validate event rule type against domain. */
816 switch (event_rule_type
) {
817 case LTTNG_EVENT_RULE_TYPE_KPROBE
:
818 case LTTNG_EVENT_RULE_TYPE_KRETPROBE
:
819 case LTTNG_EVENT_RULE_TYPE_UPROBE
:
820 case LTTNG_EVENT_RULE_TYPE_SYSCALL
:
821 if (domain_type
!= LTTNG_DOMAIN_KERNEL
) {
822 ERR("Event type not available for user-space tracing.");
827 case LTTNG_EVENT_RULE_TYPE_TRACEPOINT
:
835 * Adding a filter to a probe, function or userspace-probe would be
836 * denied by the kernel tracer as it's not supported at the moment. We
837 * do an early check here to warn the user.
839 if (filter
&& domain_type
== LTTNG_DOMAIN_KERNEL
) {
840 switch (event_rule_type
) {
841 case LTTNG_EVENT_RULE_TYPE_TRACEPOINT
:
842 case LTTNG_EVENT_RULE_TYPE_SYSCALL
:
845 ERR("Filter expressions are not supported for %s event rules.",
846 lttng_event_rule_type_str(event_rule_type
));
851 /* If --exclude/-x was passed, split it into an exclusion list. */
853 if (domain_type
!= LTTNG_DOMAIN_UST
) {
854 ERR("Event name exclusions are not yet implemented for %s event rules.",
855 get_domain_str(domain_type
));
860 if (create_exclusion_list_and_validate(tracepoint_name
, exclude
,
861 &exclusion_list
) != 0) {
862 ERR("Failed to create exclusion list.");
867 if (loglevel_str
&& event_rule_type
!= LTTNG_EVENT_RULE_TYPE_TRACEPOINT
) {
868 ERR("Log levels are only applicable to tracepoint event rules.");
872 /* Finally, create the event rule object. */
873 switch (event_rule_type
) {
874 case LTTNG_EVENT_RULE_TYPE_TRACEPOINT
:
876 enum lttng_event_rule_status event_rule_status
;
878 res
.er
= lttng_event_rule_tracepoint_create(domain_type
);
880 ERR("Failed to create tracepoint event rule.");
885 event_rule_status
= lttng_event_rule_tracepoint_set_pattern(
886 res
.er
, tracepoint_name
);
887 if (event_rule_status
!= LTTNG_EVENT_RULE_STATUS_OK
) {
888 ERR("Failed to set tracepoint event rule's pattern to '%s'.",
895 event_rule_status
= lttng_event_rule_tracepoint_set_filter(
897 if (event_rule_status
!= LTTNG_EVENT_RULE_STATUS_OK
) {
898 ERR("Failed to set tracepoint event rule's filter to '%s'.",
904 /* Set exclusion list. */
905 if (exclusion_list
) {
908 for (n
= 0; exclusion_list
[n
]; n
++) {
909 event_rule_status
= lttng_event_rule_tracepoint_add_exclusion(
912 if (event_rule_status
!=
913 LTTNG_EVENT_RULE_STATUS_OK
) {
914 ERR("Failed to set tracepoint exclusion list element '%s'",
924 if (domain_type
== LTTNG_DOMAIN_KERNEL
) {
925 ERR("Log levels are not supported by the kernel tracer.");
929 loglevel
= parse_loglevel_string(
930 loglevel_str
, domain_type
);
932 ERR("Failed to parse `%s` as a log level.",
938 event_rule_status
= lttng_event_rule_tracepoint_set_log_level(
942 event_rule_status
= lttng_event_rule_tracepoint_set_log_level_range_lower_bound(
947 if (event_rule_status
!= LTTNG_EVENT_RULE_STATUS_OK
) {
948 ERR("Failed to set log level on event fule.");
955 case LTTNG_EVENT_RULE_TYPE_KPROBE
:
958 enum lttng_event_rule_status event_rule_status
;
960 res
.er
= lttng_event_rule_kprobe_create();
962 ERR("Failed to create kprobe event rule.");
966 ret
= parse_kernel_probe_opts(source
, &kernel_probe_location
);
968 ERR("Failed to parse kernel probe location.");
972 event_rule_status
= lttng_event_rule_kprobe_set_name(res
.er
, tracepoint_name
);
973 if (event_rule_status
!= LTTNG_EVENT_RULE_STATUS_OK
) {
974 ERR("Failed to set kprobe event rule's name to '%s'.", tracepoint_name
);
978 assert(kernel_probe_location
);
979 event_rule_status
= lttng_event_rule_kprobe_set_location(res
.er
, kernel_probe_location
);
980 if (event_rule_status
!= LTTNG_EVENT_RULE_STATUS_OK
) {
981 ERR("Failed to set kprobe event rule's location.");
987 case LTTNG_EVENT_RULE_TYPE_UPROBE
:
990 enum lttng_event_rule_status event_rule_status
;
992 ret
= parse_userspace_probe_opts(
993 source
, &userspace_probe_location
);
995 ERR("Failed to parse user space probe location.");
999 res
.er
= lttng_event_rule_uprobe_create();
1001 ERR("Failed to create userspace probe event rule.");
1005 event_rule_status
= lttng_event_rule_uprobe_set_location(
1006 res
.er
, userspace_probe_location
);
1007 if (event_rule_status
!= LTTNG_EVENT_RULE_STATUS_OK
) {
1008 ERR("Failed to set user space probe event rule's location.");
1012 event_rule_status
= lttng_event_rule_uprobe_set_name(
1013 res
.er
, tracepoint_name
);
1014 if (event_rule_status
!= LTTNG_EVENT_RULE_STATUS_OK
) {
1015 ERR("Failed to set user space probe event rule's name to '%s'.",
1022 case LTTNG_EVENT_RULE_TYPE_SYSCALL
:
1024 enum lttng_event_rule_status event_rule_status
;
1026 res
.er
= lttng_event_rule_syscall_create();
1028 ERR("Failed to create syscall event rule.");
1032 event_rule_status
= lttng_event_rule_syscall_set_pattern(
1033 res
.er
, tracepoint_name
);
1034 if (event_rule_status
!= LTTNG_EVENT_RULE_STATUS_OK
) {
1035 ERR("Failed to set syscall event rule's pattern to '%s'.",
1041 event_rule_status
= lttng_event_rule_syscall_set_filter(
1043 if (event_rule_status
!= LTTNG_EVENT_RULE_STATUS_OK
) {
1044 ERR("Failed to set syscall event rule's filter to '%s'.",
1060 lttng_event_rule_destroy(res
.er
);
1062 lttng_dynamic_pointer_array_reset(&res
.capture_descriptors
);
1066 filter_parser_ctx_free(parser_ctx
);
1069 lttng_event_expr_destroy(event_expr
);
1070 argpar_item_destroy(item
);
1072 argpar_state_destroy(state
);
1077 strutils_free_null_terminated_array_of_strings(exclusion_list
);
1078 lttng_kernel_probe_location_destroy(kernel_probe_location
);
1079 lttng_userspace_probe_location_destroy(userspace_probe_location
);
1084 struct lttng_condition
*handle_condition_event(int *argc
, const char ***argv
)
1086 struct parse_event_rule_res res
;
1087 struct lttng_condition
*c
;
1090 res
= parse_event_rule(argc
, argv
);
1096 c
= lttng_condition_event_rule_create(res
.er
);
1097 lttng_event_rule_destroy(res
.er
);
1103 for (i
= 0; i
< lttng_dynamic_pointer_array_get_count(&res
.capture_descriptors
);
1105 enum lttng_condition_status status
;
1106 struct lttng_event_expr
**expr
=
1107 lttng_dynamic_array_get_element(
1108 &res
.capture_descriptors
.array
, i
);
1112 status
= lttng_condition_event_rule_append_capture_descriptor(
1114 if (status
!= LTTNG_CONDITION_STATUS_OK
) {
1118 /* Ownership of event expression moved to `c` */
1125 lttng_condition_destroy(c
);
1129 lttng_dynamic_pointer_array_reset(&res
.capture_descriptors
);
1130 lttng_event_rule_destroy(res
.er
);
1135 struct lttng_condition
*handle_condition_session_consumed_size(int *argc
, const char ***argv
)
1137 struct lttng_condition
*cond
= NULL
;
1138 struct argpar_state
*state
= NULL
;
1139 struct argpar_item
*item
= NULL
;
1140 const char *threshold_arg
= NULL
;
1141 const char *session_name_arg
= NULL
;
1144 enum lttng_condition_status condition_status
;
1146 state
= argpar_state_create(*argc
, *argv
, event_rule_opt_descrs
);
1148 ERR("Failed to allocate an argpar state.");
1153 enum argpar_state_parse_next_status status
;
1155 ARGPAR_ITEM_DESTROY_AND_RESET(item
);
1156 status
= argpar_state_parse_next(state
, &item
, &error
);
1157 if (status
== ARGPAR_STATE_PARSE_NEXT_STATUS_ERROR
) {
1160 } else if (status
== ARGPAR_STATE_PARSE_NEXT_STATUS_ERROR_UNKNOWN_OPT
) {
1161 /* Just stop parsing here. */
1163 } else if (status
== ARGPAR_STATE_PARSE_NEXT_STATUS_END
) {
1167 assert(status
== ARGPAR_STATE_PARSE_NEXT_STATUS_OK
);
1169 if (item
->type
== ARGPAR_ITEM_TYPE_OPT
) {
1170 const struct argpar_item_opt
*item_opt
=
1171 (const struct argpar_item_opt
*) item
;
1173 switch (item_opt
->descr
->id
) {
1178 const struct argpar_item_non_opt
*item_non_opt
;
1180 assert(item
->type
== ARGPAR_ITEM_TYPE_NON_OPT
);
1182 item_non_opt
= (const struct argpar_item_non_opt
*) item
;
1184 switch (item_non_opt
->non_opt_index
) {
1186 session_name_arg
= item_non_opt
->arg
;
1189 threshold_arg
= item_non_opt
->arg
;
1192 ERR("Unexpected argument `%s`.",
1199 *argc
-= argpar_state_get_ingested_orig_args(state
);
1200 *argv
+= argpar_state_get_ingested_orig_args(state
);
1202 if (!session_name_arg
) {
1203 ERR("Missing session name argument.");
1207 if (!threshold_arg
) {
1208 ERR("Missing threshold argument.");
1212 if (utils_parse_size_suffix(threshold_arg
, &threshold
) != 0) {
1213 ERR("Failed to parse `%s` as a size.", threshold_arg
);
1217 cond
= lttng_condition_session_consumed_size_create();
1219 ERR("Failed to allocate a session consumed size condition.");
1223 condition_status
= lttng_condition_session_consumed_size_set_session_name(
1224 cond
, session_name_arg
);
1225 if (condition_status
!= LTTNG_CONDITION_STATUS_OK
) {
1226 ERR("Failed to set session consumed size condition's session name to '%s'.",
1231 condition_status
= lttng_condition_session_consumed_size_set_threshold(
1233 if (condition_status
!= LTTNG_CONDITION_STATUS_OK
) {
1234 ERR("Failed to set session consumed size condition threshold.");
1241 lttng_condition_destroy(cond
);
1245 argpar_state_destroy(state
);
1246 argpar_item_destroy(item
);
1252 struct lttng_condition
*handle_condition_buffer_usage_high(int *argc
, const char ***argv
)
1254 ERR("High buffer usage threshold conditions are unsupported for the moment.");
1259 struct lttng_condition
*handle_condition_buffer_usage_low(int *argc
, const char ***argv
)
1261 ERR("Low buffer usage threshold conditions are unsupported for the moment.");
1266 struct lttng_condition
*handle_condition_session_rotation_ongoing(int *argc
, const char ***argv
)
1268 ERR("Session rotation ongoing conditions are unsupported for the moment.");
1273 struct lttng_condition
*handle_condition_session_rotation_completed(int *argc
, const char ***argv
)
1275 ERR("Session rotation completed conditions are unsupported for the moment.");
1279 struct condition_descr
{
1281 struct lttng_condition
*(*handler
) (int *argc
, const char ***argv
);
1285 struct condition_descr condition_descrs
[] = {
1286 { "on-event", handle_condition_event
},
1287 { "on-session-consumed-size", handle_condition_session_consumed_size
},
1288 { "on-buffer-usage-high", handle_condition_buffer_usage_high
},
1289 { "on-buffer-usage-low", handle_condition_buffer_usage_low
},
1290 { "on-session-rotation-ongoing", handle_condition_session_rotation_ongoing
},
1291 { "on-session-rotation-completed", handle_condition_session_rotation_completed
},
1295 struct lttng_condition
*parse_condition(int *argc
, const char ***argv
)
1298 struct lttng_condition
*cond
;
1299 const char *condition_name
;
1300 const struct condition_descr
*descr
= NULL
;
1303 ERR("Missing condition name.");
1307 condition_name
= (*argv
)[0];
1312 for (i
= 0; i
< ARRAY_SIZE(condition_descrs
); i
++) {
1313 if (strcmp(condition_name
, condition_descrs
[i
].name
) == 0) {
1314 descr
= &condition_descrs
[i
];
1320 ERR("Unknown condition name '%s'", condition_name
);
1324 cond
= descr
->handler(argc
, argv
);
1326 /* The handler has already printed an error message. */
1339 struct lttng_action
*handle_action_notify(int *argc
, const char ***argv
)
1341 return lttng_action_notify_create();
1344 static const struct argpar_opt_descr no_opt_descrs
[] = {
1345 ARGPAR_OPT_DESCR_SENTINEL
1349 * Generic handler for a kind of action that takes a session name as its sole
1354 struct lttng_action
*handle_action_simple_session(
1355 int *argc
, const char ***argv
,
1356 struct lttng_action
*(*create_action_cb
)(void),
1357 enum lttng_action_status (*set_session_name_cb
)(struct lttng_action
*, const char *),
1358 const char *action_name
)
1360 struct lttng_action
*action
= NULL
;
1361 struct argpar_state
*state
= NULL
;
1362 struct argpar_item
*item
= NULL
;
1363 const char *session_name_arg
= NULL
;
1365 enum lttng_action_status action_status
;
1367 state
= argpar_state_create(*argc
, *argv
, no_opt_descrs
);
1369 ERR("Failed to allocate an argpar state.");
1374 enum argpar_state_parse_next_status status
;
1375 const struct argpar_item_non_opt
*item_non_opt
;
1377 ARGPAR_ITEM_DESTROY_AND_RESET(item
);
1378 status
= argpar_state_parse_next(state
, &item
, &error
);
1379 if (status
== ARGPAR_STATE_PARSE_NEXT_STATUS_ERROR
) {
1382 } else if (status
== ARGPAR_STATE_PARSE_NEXT_STATUS_ERROR_UNKNOWN_OPT
) {
1383 /* Just stop parsing here. */
1385 } else if (status
== ARGPAR_STATE_PARSE_NEXT_STATUS_END
) {
1389 assert(status
== ARGPAR_STATE_PARSE_NEXT_STATUS_OK
);
1390 assert(item
->type
== ARGPAR_ITEM_TYPE_NON_OPT
);
1392 item_non_opt
= (const struct argpar_item_non_opt
*) item
;
1394 switch (item_non_opt
->non_opt_index
) {
1396 session_name_arg
= item_non_opt
->arg
;
1399 ERR("Unexpected argument `%s`.", item_non_opt
->arg
);
1404 *argc
-= argpar_state_get_ingested_orig_args(state
);
1405 *argv
+= argpar_state_get_ingested_orig_args(state
);
1407 if (!session_name_arg
) {
1408 ERR("Missing session name.");
1412 action
= create_action_cb();
1414 ERR("Failed to allocate %s session action.", action_name
);
1418 action_status
= set_session_name_cb(action
, session_name_arg
);
1419 if (action_status
!= LTTNG_ACTION_STATUS_OK
) {
1420 ERR("Failed to set action %s session's session name to '%s'.",
1421 action_name
, session_name_arg
);
1428 lttng_action_destroy(action
);
1430 argpar_item_destroy(item
);
1433 argpar_state_destroy(state
);
1438 struct lttng_action
*handle_action_start_session(int *argc
,
1441 return handle_action_simple_session(argc
, argv
,
1442 lttng_action_start_session_create
,
1443 lttng_action_start_session_set_session_name
,
1448 struct lttng_action
*handle_action_stop_session(int *argc
,
1451 return handle_action_simple_session(argc
, argv
,
1452 lttng_action_stop_session_create
,
1453 lttng_action_stop_session_set_session_name
,
1458 struct lttng_action
*handle_action_rotate_session(int *argc
,
1461 return handle_action_simple_session(argc
, argv
,
1462 lttng_action_rotate_session_create
,
1463 lttng_action_rotate_session_set_session_name
,
1467 static const struct argpar_opt_descr snapshot_action_opt_descrs
[] = {
1468 { OPT_NAME
, 'n', "name", true },
1469 { OPT_MAX_SIZE
, 'm', "max-size", true },
1470 { OPT_CTRL_URL
, '\0', "ctrl-url", true },
1471 { OPT_DATA_URL
, '\0', "data-url", true },
1472 { OPT_URL
, '\0', "url", true },
1473 { OPT_PATH
, '\0', "path", true },
1474 ARGPAR_OPT_DESCR_SENTINEL
1478 struct lttng_action
*handle_action_snapshot_session(int *argc
,
1481 struct lttng_action
*action
= NULL
;
1482 struct argpar_state
*state
= NULL
;
1483 struct argpar_item
*item
= NULL
;
1484 const char *session_name_arg
= NULL
;
1485 char *snapshot_name_arg
= NULL
;
1486 char *ctrl_url_arg
= NULL
;
1487 char *data_url_arg
= NULL
;
1488 char *max_size_arg
= NULL
;
1489 char *url_arg
= NULL
;
1490 char *path_arg
= NULL
;
1492 enum lttng_action_status action_status
;
1493 struct lttng_snapshot_output
*snapshot_output
= NULL
;
1495 unsigned int locations_specified
= 0;
1497 state
= argpar_state_create(*argc
, *argv
, snapshot_action_opt_descrs
);
1499 ERR("Failed to allocate an argpar state.");
1504 enum argpar_state_parse_next_status status
;
1506 ARGPAR_ITEM_DESTROY_AND_RESET(item
);
1507 status
= argpar_state_parse_next(state
, &item
, &error
);
1508 if (status
== ARGPAR_STATE_PARSE_NEXT_STATUS_ERROR
) {
1511 } else if (status
== ARGPAR_STATE_PARSE_NEXT_STATUS_ERROR_UNKNOWN_OPT
) {
1512 /* Just stop parsing here. */
1514 } else if (status
== ARGPAR_STATE_PARSE_NEXT_STATUS_END
) {
1518 assert(status
== ARGPAR_STATE_PARSE_NEXT_STATUS_OK
);
1520 if (item
->type
== ARGPAR_ITEM_TYPE_OPT
) {
1521 const struct argpar_item_opt
*item_opt
=
1522 (const struct argpar_item_opt
*) item
;
1524 switch (item_opt
->descr
->id
) {
1526 if (!assign_string(&snapshot_name_arg
, item_opt
->arg
, "--name/-n")) {
1532 if (!assign_string(&max_size_arg
, item_opt
->arg
, "--max-size/-m")) {
1538 if (!assign_string(&ctrl_url_arg
, item_opt
->arg
, "--ctrl-url")) {
1544 if (!assign_string(&data_url_arg
, item_opt
->arg
, "--data-url")) {
1550 if (!assign_string(&url_arg
, item_opt
->arg
, "--url")) {
1556 if (!assign_string(&path_arg
, item_opt
->arg
, "--path")) {
1565 const struct argpar_item_non_opt
*item_non_opt
;
1567 assert(item
->type
== ARGPAR_ITEM_TYPE_NON_OPT
);
1569 item_non_opt
= (const struct argpar_item_non_opt
*) item
;
1571 switch (item_non_opt
->non_opt_index
) {
1573 session_name_arg
= item_non_opt
->arg
;
1576 ERR("Unexpected argument `%s`.",
1583 *argc
-= argpar_state_get_ingested_orig_args(state
);
1584 *argv
+= argpar_state_get_ingested_orig_args(state
);
1586 if (!session_name_arg
) {
1587 ERR("Missing session name.");
1591 /* --ctrl-url and --data-url must come in pair. */
1592 if (ctrl_url_arg
&& !data_url_arg
) {
1593 ERR("--ctrl-url is specified, but --data-url is missing.");
1597 if (!ctrl_url_arg
&& data_url_arg
) {
1598 ERR("--data-url is specified, but --ctrl-url is missing.");
1602 locations_specified
+= !!(ctrl_url_arg
|| data_url_arg
);
1603 locations_specified
+= !!url_arg
;
1604 locations_specified
+= !!path_arg
;
1606 /* --ctrl-url/--data-url, --url and --path are mutually exclusive. */
1607 if (locations_specified
> 1) {
1608 ERR("The --ctrl-url/--data-url, --url, and --path options can't be used together.");
1613 * Did the user specify an option that implies using a
1614 * custom/unregistered output?
1616 if (url_arg
|| ctrl_url_arg
|| path_arg
) {
1617 snapshot_output
= lttng_snapshot_output_create();
1618 if (!snapshot_output
) {
1619 ERR("Failed to allocate a snapshot output.");
1624 action
= lttng_action_snapshot_session_create();
1626 ERR("Failed to allocate snapshot session action.");
1630 action_status
= lttng_action_snapshot_session_set_session_name(
1631 action
, session_name_arg
);
1632 if (action_status
!= LTTNG_ACTION_STATUS_OK
) {
1633 ERR("Failed to set action snapshot session's session name to '%s'.",
1638 if (snapshot_name_arg
) {
1639 if (!snapshot_output
) {
1640 ERR("Can't provide a snapshot output name without a snapshot output destination.");
1644 ret
= lttng_snapshot_output_set_name(
1645 snapshot_name_arg
, snapshot_output
);
1647 ERR("Failed to set name of snapshot output.");
1655 if (!snapshot_output
) {
1656 ERR("Can't provide a snapshot output max size without a snapshot output destination.");
1660 ret
= utils_parse_size_suffix(max_size_arg
, &max_size
);
1662 ERR("Failed to parse `%s` as a size.", max_size_arg
);
1666 ret
= lttng_snapshot_output_set_size(max_size
, snapshot_output
);
1668 ERR("Failed to set snapshot output's max size to %" PRIu64
" bytes.",
1676 struct lttng_uri
*uris
;
1678 if (!strstr(url_arg
, "://")) {
1679 ERR("Failed to parse '%s' as an URL.", url_arg
);
1683 num_uris
= uri_parse_str_urls(url_arg
, NULL
, &uris
);
1685 ERR("Failed to parse '%s' as an URL.", url_arg
);
1689 if (uris
[0].dtype
== LTTNG_DST_PATH
) {
1690 ret
= lttng_snapshot_output_set_local_path(
1691 uris
[0].dst
.path
, snapshot_output
);
1694 ERR("Failed to assign '%s' as a local destination.",
1699 ret
= lttng_snapshot_output_set_network_url(
1700 url_arg
, snapshot_output
);
1703 ERR("Failed to assign '%s' as a network URL.",
1711 ret
= lttng_snapshot_output_set_local_path(
1712 path_arg
, snapshot_output
);
1714 ERR("Failed to parse '%s' as a local path.", path_arg
);
1721 * Two argument form, network output with separate control and
1724 ret
= lttng_snapshot_output_set_network_urls(
1725 ctrl_url_arg
, data_url_arg
, snapshot_output
);
1727 ERR("Failed to parse `%s` and `%s` as control and data URLs.",
1728 ctrl_url_arg
, data_url_arg
);
1733 if (snapshot_output
) {
1734 action_status
= lttng_action_snapshot_session_set_output(
1735 action
, snapshot_output
);
1736 if (action_status
!= LTTNG_ACTION_STATUS_OK
) {
1737 ERR("Failed to set snapshot session action's output.");
1741 /* Ownership of `snapshot_output` has been transferred to the action. */
1742 snapshot_output
= NULL
;
1748 lttng_action_destroy(action
);
1752 free(snapshot_name_arg
);
1757 free(snapshot_output
);
1759 argpar_state_destroy(state
);
1760 argpar_item_destroy(item
);
1764 struct action_descr
{
1766 struct lttng_action
*(*handler
) (int *argc
, const char ***argv
);
1770 struct action_descr action_descrs
[] = {
1771 { "notify", handle_action_notify
},
1772 { "start-session", handle_action_start_session
},
1773 { "stop-session", handle_action_stop_session
},
1774 { "rotate-session", handle_action_rotate_session
},
1775 { "snapshot-session", handle_action_snapshot_session
},
1779 struct lttng_action
*parse_action(int *argc
, const char ***argv
)
1782 struct lttng_action
*action
;
1783 const char *action_name
;
1784 const struct action_descr
*descr
= NULL
;
1787 ERR("Missing action name.");
1791 action_name
= (*argv
)[0];
1796 for (i
= 0; i
< ARRAY_SIZE(action_descrs
); i
++) {
1797 if (strcmp(action_name
, action_descrs
[i
].name
) == 0) {
1798 descr
= &action_descrs
[i
];
1804 ERR("Unknown action name: %s", action_name
);
1808 action
= descr
->handler(argc
, argv
);
1810 /* The handler has already printed an error message. */
1822 struct argpar_opt_descr add_trigger_options
[] = {
1823 { OPT_HELP
, 'h', "help", false },
1824 { OPT_LIST_OPTIONS
, '\0', "list-options", false },
1825 { OPT_CONDITION
, '\0', "condition", false },
1826 { OPT_ACTION
, '\0', "action", false },
1827 { OPT_ID
, '\0', "id", true },
1828 { OPT_FIRE_ONCE_AFTER
, '\0', "fire-once-after", true },
1829 { OPT_FIRE_EVERY
, '\0', "fire-every", true },
1830 { OPT_USER_ID
, '\0', "user-id", true },
1831 ARGPAR_OPT_DESCR_SENTINEL
,
1835 void lttng_actions_destructor(void *p
)
1837 struct lttng_action
*action
= p
;
1839 lttng_action_destroy(action
);
1842 int cmd_add_trigger(int argc
, const char **argv
)
1845 int my_argc
= argc
- 1;
1846 const char **my_argv
= argv
+ 1;
1847 struct lttng_condition
*condition
= NULL
;
1848 struct lttng_dynamic_pointer_array actions
;
1849 struct argpar_state
*argpar_state
= NULL
;
1850 struct argpar_item
*argpar_item
= NULL
;
1851 struct lttng_action
*action_group
= NULL
;
1852 struct lttng_action
*action
= NULL
;
1853 struct lttng_trigger
*trigger
= NULL
;
1857 char *fire_once_after_str
= NULL
;
1858 char *fire_every_str
= NULL
;
1859 char *user_id
= NULL
;
1861 lttng_dynamic_pointer_array_init(&actions
, lttng_actions_destructor
);
1864 enum argpar_state_parse_next_status status
;
1865 const struct argpar_item_opt
*item_opt
;
1868 argpar_state_destroy(argpar_state
);
1869 argpar_state
= argpar_state_create(my_argc
, my_argv
,
1870 add_trigger_options
);
1871 if (!argpar_state
) {
1872 ERR("Failed to create argpar state.");
1876 ARGPAR_ITEM_DESTROY_AND_RESET(argpar_item
);
1877 status
= argpar_state_parse_next(argpar_state
, &argpar_item
, &error
);
1878 if (status
== ARGPAR_STATE_PARSE_NEXT_STATUS_ERROR
) {
1881 } else if (status
== ARGPAR_STATE_PARSE_NEXT_STATUS_ERROR_UNKNOWN_OPT
) {
1884 } else if (status
== ARGPAR_STATE_PARSE_NEXT_STATUS_END
) {
1888 assert(status
== ARGPAR_STATE_PARSE_NEXT_STATUS_OK
);
1890 if (argpar_item
->type
== ARGPAR_ITEM_TYPE_NON_OPT
) {
1891 const struct argpar_item_non_opt
*item_non_opt
=
1892 (const struct argpar_item_non_opt
*)
1895 ERR("Unexpected argument `%s`.", item_non_opt
->arg
);
1899 item_opt
= (const struct argpar_item_opt
*) argpar_item
;
1901 ingested_args
= argpar_state_get_ingested_orig_args(
1904 my_argc
-= ingested_args
;
1905 my_argv
+= ingested_args
;
1907 switch (item_opt
->descr
->id
) {
1912 case OPT_LIST_OPTIONS
:
1913 list_cmd_options_argpar(stdout
, add_trigger_options
);
1919 ERR("A --condition was already given.");
1923 condition
= parse_condition(&my_argc
, &my_argv
);
1926 * An error message was already printed by
1936 action
= parse_action(&my_argc
, &my_argv
);
1939 * An error message was already printed by
1945 ret
= lttng_dynamic_pointer_array_add_pointer(
1948 ERR("Failed to add pointer to pointer array.");
1952 /* Ownership of the action was transferred to the group. */
1959 if (!assign_string(&id
, item_opt
->arg
, "--id")) {
1965 case OPT_FIRE_ONCE_AFTER
:
1967 if (!assign_string(&fire_once_after_str
, item_opt
->arg
,
1968 "--fire-once-after")) {
1974 case OPT_FIRE_EVERY
:
1976 if (!assign_string(&fire_every_str
, item_opt
->arg
,
1985 if (!assign_string(&user_id
, item_opt
->arg
,
1998 ERR("Missing --condition.");
2002 if (lttng_dynamic_pointer_array_get_count(&actions
) == 0) {
2003 ERR("Need at least one --action.");
2007 if (fire_every_str
&& fire_once_after_str
) {
2008 ERR("Can't specify both --fire-once-after and --fire-every.");
2012 action_group
= lttng_action_group_create();
2013 if (!action_group
) {
2017 for (i
= 0; i
< lttng_dynamic_pointer_array_get_count(&actions
); i
++) {
2018 enum lttng_action_status status
;
2020 action
= lttng_dynamic_pointer_array_steal_pointer(&actions
, i
);
2022 status
= lttng_action_group_add_action(action_group
, action
);
2023 if (status
!= LTTNG_ACTION_STATUS_OK
) {
2028 * The `lttng_action_group_add_action()` takes a reference to
2029 * the action. We can destroy ours.
2031 lttng_action_destroy(action
);
2035 trigger
= lttng_trigger_create(condition
, action_group
);
2041 enum lttng_trigger_status trigger_status
=
2042 lttng_trigger_set_name(trigger
, id
);
2044 if (trigger_status
!= LTTNG_TRIGGER_STATUS_OK
) {
2045 ERR("Failed to set trigger id.");
2050 if (fire_once_after_str
) {
2051 unsigned long long threshold
;
2052 enum lttng_trigger_status trigger_status
;
2054 if (utils_parse_unsigned_long_long(fire_once_after_str
, &threshold
) != 0) {
2055 ERR("Failed to parse `%s` as an integer.", fire_once_after_str
);
2059 trigger_status
= lttng_trigger_set_firing_policy(trigger
,
2060 LTTNG_TRIGGER_FIRING_POLICY_ONCE_AFTER_N
,
2062 if (trigger_status
!= LTTNG_TRIGGER_STATUS_OK
) {
2063 ERR("Failed to set trigger's policy to `fire once after N`.");
2068 if (fire_every_str
) {
2069 unsigned long long threshold
;
2070 enum lttng_trigger_status trigger_status
;
2072 if (utils_parse_unsigned_long_long(fire_every_str
, &threshold
) != 0) {
2073 ERR("Failed to parse `%s` as an integer.", fire_every_str
);
2077 trigger_status
= lttng_trigger_set_firing_policy(trigger
,
2078 LTTNG_TRIGGER_FIRING_POLICY_EVERY_N
, threshold
);
2079 if (trigger_status
!= LTTNG_TRIGGER_STATUS_OK
) {
2080 ERR("Failed to set trigger's policy to `fire every N`.");
2086 enum lttng_trigger_status trigger_status
;
2091 uid
= strtol(user_id
, &end
, 10);
2092 if (end
== user_id
|| *end
!= '\0' || errno
!= 0) {
2093 ERR("Failed to parse `%s` as a user id.", user_id
);
2096 trigger_status
= lttng_trigger_set_owner_uid(trigger
, uid
);
2097 if (trigger_status
!= LTTNG_TRIGGER_STATUS_OK
) {
2098 ERR("Failed to set trigger's user identity.");
2103 ret
= lttng_register_trigger(trigger
);
2105 ERR("Failed to register trigger: %s.", lttng_strerror(ret
));
2109 MSG("Trigger registered successfully.");
2117 argpar_state_destroy(argpar_state
);
2118 argpar_item_destroy(argpar_item
);
2119 lttng_dynamic_pointer_array_reset(&actions
);
2120 lttng_condition_destroy(condition
);
2121 lttng_action_destroy(action_group
);
2122 lttng_action_destroy(action
);
2123 lttng_trigger_destroy(trigger
);
2126 free(fire_once_after_str
);
2127 free(fire_every_str
);