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>
65 static const struct argpar_opt_descr event_rule_opt_descrs
[] = {
66 { OPT_FILTER
, 'f', "filter", true },
67 { OPT_NAME
, 'n', "name", true },
68 { OPT_EXCLUDE_NAMES
, 'x', "exclude-names", true },
69 { OPT_LOG_LEVEL
, 'l', "log-level", true },
70 { OPT_EVENT_NAME
, 'E', "event-name", true },
72 { OPT_DOMAIN
, 'd', "domain", true },
73 { OPT_TYPE
, 't', "type", true },
74 { OPT_LOCATION
, 'L', "location", true },
76 /* Capture descriptor */
77 { OPT_CAPTURE
, '\0', "capture", true },
79 ARGPAR_OPT_DESCR_SENTINEL
83 bool assign_domain_type(enum lttng_domain_type
*dest
, const char *arg
)
87 if (*dest
!= LTTNG_DOMAIN_NONE
) {
88 ERR("More than one `--domain` was specified.");
92 if (strcmp(arg
, "kernel") == 0) {
93 *dest
= LTTNG_DOMAIN_KERNEL
;
94 } else if (strcmp(arg
, "user") == 0 || strcmp(arg
, "userspace") == 0) {
95 *dest
= LTTNG_DOMAIN_UST
;
96 } else if (strcmp(arg
, "jul") == 0) {
97 *dest
= LTTNG_DOMAIN_JUL
;
98 } else if (strcmp(arg
, "log4j") == 0) {
99 *dest
= LTTNG_DOMAIN_LOG4J
;
100 } else if (strcmp(arg
, "python") == 0) {
101 *dest
= LTTNG_DOMAIN_PYTHON
;
103 ERR("Invalid `--domain` value: %s", arg
);
118 bool assign_event_rule_type(enum lttng_event_rule_type
*dest
, const char *arg
)
122 if (*dest
!= LTTNG_EVENT_RULE_TYPE_UNKNOWN
) {
123 ERR("More than one `--type` was specified.");
127 if (strcmp(arg
, "tracepoint") == 0 || strcmp(arg
, "logging") == 0) {
128 *dest
= LTTNG_EVENT_RULE_TYPE_TRACEPOINT
;
129 } else if (strcmp (arg
, "kprobe") == 0 || strcmp(arg
, "kernel-probe") == 0) {
130 *dest
= LTTNG_EVENT_RULE_TYPE_KERNEL_PROBE
;
131 } else if (strcmp (arg
, "uprobe") == 0 || strcmp(arg
, "userspace-probe") == 0) {
132 *dest
= LTTNG_EVENT_RULE_TYPE_USERSPACE_PROBE
;
133 } else if (strcmp (arg
, "function") == 0) {
134 *dest
= LTTNG_EVENT_RULE_TYPE_KERNEL_FUNCTION
;
135 } else if (strcmp (arg
, "syscall") == 0) {
136 *dest
= LTTNG_EVENT_RULE_TYPE_SYSCALL
;
138 ERR("Invalid `--type` value: %s", arg
);
153 bool assign_string(char **dest
, const char *src
, const char *opt_name
)
158 ERR("Duplicate '%s' given.", opt_name
);
164 PERROR("Failed to allocate string '%s'.", opt_name
);
178 /* This is defined in enable_events.c. */
180 int create_exclusion_list_and_validate(const char *event_name
,
181 const char *exclusions_arg
,
182 char ***exclusion_list
);
185 * Parse `str` as a log level in domain `domain_type`.
187 * Return the log level in `*log_level`. Return true in `*log_level_only` if
188 * the string specifies exactly this log level, false if it specifies at least
191 * Return true if the string was successfully parsed as a log level string.
193 static bool parse_log_level_string(const char *str
,
194 enum lttng_domain_type domain_type
,
196 bool *log_level_only
)
200 switch (domain_type
) {
201 case LTTNG_DOMAIN_UST
:
203 enum lttng_loglevel log_level_min
, log_level_max
;
204 if (!loglevel_parse_range_string(
205 str
, &log_level_min
, &log_level_max
)) {
209 /* Only support VAL and VAL.. for now. */
210 if (log_level_min
!= log_level_max
&&
211 log_level_max
!= LTTNG_LOGLEVEL_EMERG
) {
215 *log_level
= (int) log_level_min
;
216 *log_level_only
= log_level_min
== log_level_max
;
219 case LTTNG_DOMAIN_LOG4J
:
221 enum lttng_loglevel_log4j log_level_min
, log_level_max
;
222 if (!loglevel_log4j_parse_range_string(
223 str
, &log_level_min
, &log_level_max
)) {
227 /* Only support VAL and VAL.. for now. */
228 if (log_level_min
!= log_level_max
&&
229 log_level_max
!= LTTNG_LOGLEVEL_LOG4J_FATAL
) {
233 *log_level
= (int) log_level_min
;
234 *log_level_only
= log_level_min
== log_level_max
;
237 case LTTNG_DOMAIN_JUL
:
239 enum lttng_loglevel_jul log_level_min
, log_level_max
;
240 if (!loglevel_jul_parse_range_string(
241 str
, &log_level_min
, &log_level_max
)) {
245 /* Only support VAL and VAL.. for now. */
246 if (log_level_min
!= log_level_max
&&
247 log_level_max
!= LTTNG_LOGLEVEL_JUL_SEVERE
) {
251 *log_level
= (int) log_level_min
;
252 *log_level_only
= log_level_min
== log_level_max
;
255 case LTTNG_DOMAIN_PYTHON
:
257 enum lttng_loglevel_python log_level_min
, log_level_max
;
258 if (!loglevel_python_parse_range_string(
259 str
, &log_level_min
, &log_level_max
)) {
263 /* Only support VAL and VAL.. for now. */
264 if (log_level_min
!= log_level_max
&&
266 LTTNG_LOGLEVEL_PYTHON_CRITICAL
) {
270 *log_level
= (int) log_level_min
;
271 *log_level_only
= log_level_min
== log_level_max
;
275 /* Invalid domain type. */
289 static int parse_kernel_probe_opts(const char *source
,
290 struct lttng_kernel_probe_location
**location
)
295 char name
[LTTNG_SYMBOL_NAME_LEN
];
296 char *symbol_name
= NULL
;
299 /* Check for symbol+offset. */
300 match
= sscanf(source
,
301 "%" LTTNG_SYMBOL_NAME_LEN_SCANF_IS_A_BROKEN_API
305 if (*s_hex
== '\0') {
306 ERR("Kernel probe symbol offset is missing.");
310 symbol_name
= strndup(name
, LTTNG_SYMBOL_NAME_LEN
);
312 PERROR("Failed to copy kernel probe location symbol name.");
315 offset
= strtoul(s_hex
, NULL
, 0);
317 *location
= lttng_kernel_probe_location_symbol_create(
318 symbol_name
, offset
);
320 ERR("Failed to create symbol kernel probe location.");
327 /* Check for symbol. */
328 if (isalpha(name
[0]) || name
[0] == '_') {
329 match
= sscanf(source
,
330 "%" LTTNG_SYMBOL_NAME_LEN_SCANF_IS_A_BROKEN_API
334 symbol_name
= strndup(name
, LTTNG_SYMBOL_NAME_LEN
);
336 ERR("Failed to copy kernel probe location symbol name.");
340 *location
= lttng_kernel_probe_location_symbol_create(
343 ERR("Failed to create symbol kernel probe location.");
351 /* Check for address. */
352 match
= sscanf(source
, "%18s", s_hex
);
356 if (*s_hex
== '\0') {
357 ERR("Invalid kernel probe location address.");
361 address
= strtoul(s_hex
, NULL
, 0);
362 *location
= lttng_kernel_probe_location_address_create(address
);
364 ERR("Failed to create symbol kernel probe location.");
382 struct lttng_event_expr
*ir_op_load_expr_to_event_expr(
383 const struct ir_load_expression
*load_expr
,
384 const char *capture_str
)
386 char *provider_name
= NULL
;
387 struct lttng_event_expr
*event_expr
= NULL
;
388 const struct ir_load_expression_op
*load_expr_op
= load_expr
->child
;
389 const enum ir_load_expression_type load_expr_child_type
=
392 switch (load_expr_child_type
) {
393 case IR_LOAD_EXPRESSION_GET_PAYLOAD_ROOT
:
394 case IR_LOAD_EXPRESSION_GET_CONTEXT_ROOT
:
396 const char *field_name
;
398 load_expr_op
= load_expr_op
->next
;
399 assert(load_expr_op
);
400 assert(load_expr_op
->type
== IR_LOAD_EXPRESSION_GET_SYMBOL
);
401 field_name
= load_expr_op
->u
.symbol
;
404 event_expr
= load_expr_child_type
== IR_LOAD_EXPRESSION_GET_PAYLOAD_ROOT
?
405 lttng_event_expr_event_payload_field_create(field_name
) :
406 lttng_event_expr_channel_context_field_create(field_name
);
408 ERR("Failed to create %s event expression: field name = `%s`.",
409 load_expr_child_type
== IR_LOAD_EXPRESSION_GET_PAYLOAD_ROOT
?
410 "payload field" : "channel context",
417 case IR_LOAD_EXPRESSION_GET_APP_CONTEXT_ROOT
:
420 const char *type_name
;
421 const char *field_name
;
423 load_expr_op
= load_expr_op
->next
;
424 assert(load_expr_op
);
425 assert(load_expr_op
->type
== IR_LOAD_EXPRESSION_GET_SYMBOL
);
426 field_name
= load_expr_op
->u
.symbol
;
430 * The field name needs to be of the form PROVIDER:TYPE. We
433 colon
= strchr(field_name
, ':');
435 ERR("Invalid app-specific context field name: missing colon in `%s`.",
440 type_name
= colon
+ 1;
441 if (*type_name
== '\0') {
442 ERR("Invalid app-specific context field name: missing type name after colon in `%s`.",
447 provider_name
= strndup(field_name
, colon
- field_name
);
448 if (!provider_name
) {
449 PERROR("Failed to allocate field name string");
453 event_expr
= lttng_event_expr_app_specific_context_field_create(
454 provider_name
, type_name
);
456 ERR("Failed to create app-specific context field event expression: provider name = `%s`, type name = `%s`",
457 provider_name
, type_name
);
464 ERR("%s: unexpected load expr type %d.", __func__
,
469 load_expr_op
= load_expr_op
->next
;
471 /* There may be a single array index after that. */
472 if (load_expr_op
->type
== IR_LOAD_EXPRESSION_GET_INDEX
) {
473 struct lttng_event_expr
*index_event_expr
;
474 const uint64_t index
= load_expr_op
->u
.index
;
476 index_event_expr
= lttng_event_expr_array_field_element_create(event_expr
, index
);
477 if (!index_event_expr
) {
478 ERR("Failed to create array field element event expression.");
482 event_expr
= index_event_expr
;
483 load_expr_op
= load_expr_op
->next
;
486 switch (load_expr_op
->type
) {
487 case IR_LOAD_EXPRESSION_LOAD_FIELD
:
489 * This is what we expect, IR_LOAD_EXPRESSION_LOAD_FIELD is
490 * always found at the end of the chain.
493 case IR_LOAD_EXPRESSION_GET_SYMBOL
:
494 ERR("While parsing expression `%s`: Capturing subfields is not supported.",
499 ERR("%s: unexpected load expression operator %s.", __func__
,
500 ir_load_expression_type_str(load_expr_op
->type
));
507 lttng_event_expr_destroy(event_expr
);
517 struct lttng_event_expr
*ir_op_load_to_event_expr(
518 const struct ir_op
*ir
, const char *capture_str
)
520 struct lttng_event_expr
*event_expr
= NULL
;
522 assert(ir
->op
== IR_OP_LOAD
);
524 switch (ir
->data_type
) {
525 case IR_DATA_EXPRESSION
:
527 const struct ir_load_expression
*ir_load_expr
=
528 ir
->u
.load
.u
.expression
;
530 event_expr
= ir_op_load_expr_to_event_expr(
531 ir_load_expr
, capture_str
);
535 ERR("%s: unexpected data type: %s.", __func__
,
536 ir_data_type_str(ir
->data_type
));
544 const char *ir_operator_type_human_str(enum ir_op_type op
)
566 struct lttng_event_expr
*ir_op_root_to_event_expr(const struct ir_op
*ir
,
567 const char *capture_str
)
569 struct lttng_event_expr
*event_expr
= NULL
;
571 assert(ir
->op
== IR_OP_ROOT
);
572 ir
= ir
->u
.root
.child
;
576 event_expr
= ir_op_load_to_event_expr(ir
, capture_str
);
581 ERR("While parsing expression `%s`: %s operators are not allowed in capture expressions.",
583 ir_operator_type_human_str(ir
->op
));
586 ERR("%s: unexpected IR op type: %s.", __func__
,
587 ir_op_type_str(ir
->op
));
595 void destroy_event_expr(void *ptr
)
597 lttng_event_expr_destroy(ptr
);
600 struct parse_event_rule_res
{
602 struct lttng_event_rule
*er
;
604 /* Array of `struct lttng_event_expr *` */
605 struct lttng_dynamic_pointer_array capture_descriptors
;
609 struct parse_event_rule_res
parse_event_rule(int *argc
, const char ***argv
)
611 enum lttng_domain_type domain_type
= LTTNG_DOMAIN_NONE
;
612 enum lttng_event_rule_type event_rule_type
=
613 LTTNG_EVENT_RULE_TYPE_UNKNOWN
;
614 struct argpar_state
*state
;
615 struct argpar_item
*item
= NULL
;
617 int consumed_args
= -1;
618 struct lttng_kernel_probe_location
*kernel_probe_location
= NULL
;
619 struct lttng_userspace_probe_location
*userspace_probe_location
= NULL
;
620 struct parse_event_rule_res res
= { 0 };
621 struct lttng_event_expr
*event_expr
= NULL
;
622 struct filter_parser_ctx
*parser_ctx
= NULL
;
623 struct lttng_log_level_rule
*log_level_rule
= NULL
;
625 /* Tracepoint and syscall options. */
627 char *exclude_names
= NULL
;
628 char **exclusion_list
= NULL
;
630 /* For userspace / kernel probe and function. */
631 char *location
= NULL
;
632 char *event_name
= NULL
;
638 char *log_level_str
= NULL
;
640 lttng_dynamic_pointer_array_init(&res
.capture_descriptors
,
642 state
= argpar_state_create(*argc
, *argv
, event_rule_opt_descrs
);
644 ERR("Failed to allocate an argpar state.");
649 enum argpar_state_parse_next_status status
;
651 ARGPAR_ITEM_DESTROY_AND_RESET(item
);
652 status
= argpar_state_parse_next(state
, &item
, &error
);
653 if (status
== ARGPAR_STATE_PARSE_NEXT_STATUS_ERROR
) {
656 } else if (status
== ARGPAR_STATE_PARSE_NEXT_STATUS_ERROR_UNKNOWN_OPT
) {
657 /* Just stop parsing here. */
659 } else if (status
== ARGPAR_STATE_PARSE_NEXT_STATUS_END
) {
663 assert(status
== ARGPAR_STATE_PARSE_NEXT_STATUS_OK
);
665 if (item
->type
== ARGPAR_ITEM_TYPE_OPT
) {
666 const struct argpar_item_opt
*item_opt
=
667 (const struct argpar_item_opt
*) item
;
669 switch (item_opt
->descr
->id
) {
672 if (!assign_domain_type(&domain_type
,
679 if (!assign_event_rule_type(&event_rule_type
,
686 if (!assign_string(&location
,
694 if (!assign_string(&event_name
,
696 "--event-name/-E")) {
702 if (!assign_string(&filter
, item_opt
->arg
,
709 if (!assign_string(&name
, item_opt
->arg
,
715 case OPT_EXCLUDE_NAMES
:
716 if (!assign_string(&exclude_names
,
718 "--exclude-names/-x")) {
724 if (!assign_string(&log_level_str
,
725 item_opt
->arg
, "--log-level/-l")) {
733 const char *capture_str
= item_opt
->arg
;
735 ret
= filter_parser_ctx_create_from_filter_expression(
736 capture_str
, &parser_ctx
);
738 ERR("Failed to parse capture expression `%s`.",
743 event_expr
= ir_op_root_to_event_expr(
748 * ir_op_root_to_event_expr has printed
754 ret
= lttng_dynamic_pointer_array_add_pointer(
755 &res
.capture_descriptors
,
762 * The ownership of event expression was
763 * transferred to the dynamic array.
773 const struct argpar_item_non_opt
*item_non_opt
=
774 (const struct argpar_item_non_opt
*)
777 /* Don't accept non-option arguments. */
778 ERR("Unexpected argument '%s'", item_non_opt
->arg
);
783 if (event_rule_type
== LTTNG_EVENT_RULE_TYPE_UNKNOWN
) {
784 event_rule_type
= LTTNG_EVENT_RULE_TYPE_TRACEPOINT
;
788 * Option --name is applicable to event rules of type tracepoint
789 * and syscall. For tracepoint and syscall rules, if --name is
790 * omitted, it is implicitly "*".
792 switch (event_rule_type
) {
793 case LTTNG_EVENT_RULE_TYPE_TRACEPOINT
:
794 case LTTNG_EVENT_RULE_TYPE_SYSCALL
:
802 ERR("Can't use --name with %s event rules.",
803 lttng_event_rule_type_str(
809 ERR("Can't use --exclude-names/-x with %s event rules.",
810 lttng_event_rule_type_str(
817 * Option --location is only applicable to (and mandatory for) event
818 * rules of type {k,u}probe and function.
820 * Option --event-name is only applicable to event rules of type probe.
821 * If omitted, it defaults to the location.
823 switch (event_rule_type
) {
824 case LTTNG_EVENT_RULE_TYPE_KERNEL_PROBE
:
825 case LTTNG_EVENT_RULE_TYPE_USERSPACE_PROBE
:
826 case LTTNG_EVENT_RULE_TYPE_KERNEL_FUNCTION
:
828 ERR("Event rule of type %s requires a --location.",
829 lttng_event_rule_type_str(event_rule_type
));
834 event_name
= strdup(location
);
841 ERR("Can't use --location with %s event rules.",
842 lttng_event_rule_type_str(event_rule_type
));
847 ERR("Can't use --event-name with %s event rules.",
848 lttng_event_rule_type_str(
855 * Update *argc and *argv so our caller can keep parsing what follows.
857 consumed_args
= argpar_state_get_ingested_orig_args(state
);
858 assert(consumed_args
>= 0);
859 *argc
-= consumed_args
;
860 *argv
+= consumed_args
;
862 /* Need to specify a domain. */
863 if (domain_type
== LTTNG_DOMAIN_NONE
) {
864 ERR("Please specify a domain (--domain=(kernel,user,jul,log4j,python)).");
868 /* Validate event rule type against domain. */
869 switch (event_rule_type
) {
870 case LTTNG_EVENT_RULE_TYPE_KERNEL_PROBE
:
871 case LTTNG_EVENT_RULE_TYPE_KERNEL_FUNCTION
:
872 case LTTNG_EVENT_RULE_TYPE_USERSPACE_PROBE
:
873 case LTTNG_EVENT_RULE_TYPE_SYSCALL
:
874 if (domain_type
!= LTTNG_DOMAIN_KERNEL
) {
875 ERR("Event type not available for user-space tracing.");
880 case LTTNG_EVENT_RULE_TYPE_TRACEPOINT
:
888 * Adding a filter to a probe, function or userspace-probe would be
889 * denied by the kernel tracer as it's not supported at the moment. We
890 * do an early check here to warn the user.
892 if (filter
&& domain_type
== LTTNG_DOMAIN_KERNEL
) {
893 switch (event_rule_type
) {
894 case LTTNG_EVENT_RULE_TYPE_TRACEPOINT
:
895 case LTTNG_EVENT_RULE_TYPE_SYSCALL
:
898 ERR("Filter expressions are not supported for %s event rules.",
899 lttng_event_rule_type_str(event_rule_type
));
904 /* If --exclude/-x was passed, split it into an exclusion list. */
906 if (domain_type
!= LTTNG_DOMAIN_UST
) {
907 ERR("Event name exclusions are not yet implemented for %s event rules.",
908 get_domain_str(domain_type
));
912 if (create_exclusion_list_and_validate(name
,
913 exclude_names
, &exclusion_list
) != 0) {
914 ERR("Failed to create exclusion list.");
920 if (event_rule_type
!= LTTNG_EVENT_RULE_TYPE_TRACEPOINT
) {
921 ERR("Log levels are only applicable to tracepoint event rules.");
925 if (domain_type
== LTTNG_DOMAIN_KERNEL
) {
926 ERR("Log levels are not supported by the kernel tracer.");
931 /* Finally, create the event rule object. */
932 switch (event_rule_type
) {
933 case LTTNG_EVENT_RULE_TYPE_TRACEPOINT
:
935 enum lttng_event_rule_status event_rule_status
;
937 res
.er
= lttng_event_rule_tracepoint_create(domain_type
);
939 ERR("Failed to create tracepoint event rule.");
944 event_rule_status
= lttng_event_rule_tracepoint_set_pattern(
946 if (event_rule_status
!= LTTNG_EVENT_RULE_STATUS_OK
) {
947 ERR("Failed to set tracepoint event rule's pattern to '%s'.",
954 event_rule_status
= lttng_event_rule_tracepoint_set_filter(
956 if (event_rule_status
!= LTTNG_EVENT_RULE_STATUS_OK
) {
957 ERR("Failed to set tracepoint event rule's filter to '%s'.",
963 /* Set exclusion list. */
964 if (exclusion_list
) {
967 for (n
= 0; exclusion_list
[n
]; n
++) {
968 event_rule_status
= lttng_event_rule_tracepoint_add_exclusion(
971 if (event_rule_status
!=
972 LTTNG_EVENT_RULE_STATUS_OK
) {
973 ERR("Failed to set tracepoint exclusion list element '%s'",
981 * ".." is the same as passing no log level option and
982 * correspond the the "ANY" case.
984 if (log_level_str
&& strcmp(log_level_str
, "..") != 0) {
988 if (!parse_log_level_string(log_level_str
, domain_type
,
989 &log_level
, &log_level_only
)) {
990 ERR("Failed to parse log level string `%s`.",
995 if (log_level_only
) {
996 log_level_rule
= lttng_log_level_rule_exactly_create(log_level
);
998 log_level_rule
= lttng_log_level_rule_at_least_as_severe_as_create(log_level
);
1001 if (log_level_rule
== NULL
) {
1002 ERR("Failed to create log level rule object.");
1007 lttng_event_rule_tracepoint_set_log_level_rule(
1008 res
.er
, log_level_rule
);
1010 if (event_rule_status
!= LTTNG_EVENT_RULE_STATUS_OK
) {
1011 ERR("Failed to set log level on event fule.");
1018 case LTTNG_EVENT_RULE_TYPE_KERNEL_PROBE
:
1021 enum lttng_event_rule_status event_rule_status
;
1023 ret
= parse_kernel_probe_opts(
1024 location
, &kernel_probe_location
);
1026 ERR("Failed to parse kernel probe location.");
1030 assert(kernel_probe_location
);
1031 res
.er
= lttng_event_rule_kernel_probe_create(kernel_probe_location
);
1033 ERR("Failed to create kprobe event rule.");
1038 lttng_event_rule_kernel_probe_set_event_name(
1039 res
.er
, event_name
);
1040 if (event_rule_status
!= LTTNG_EVENT_RULE_STATUS_OK
) {
1041 ERR("Failed to set kprobe event rule's name to '%s'.",
1048 case LTTNG_EVENT_RULE_TYPE_USERSPACE_PROBE
:
1051 enum lttng_event_rule_status event_rule_status
;
1053 ret
= parse_userspace_probe_opts(
1054 location
, &userspace_probe_location
);
1056 ERR("Failed to parse user space probe location.");
1060 res
.er
= lttng_event_rule_userspace_probe_create(userspace_probe_location
);
1062 ERR("Failed to create userspace probe event rule.");
1067 lttng_event_rule_userspace_probe_set_event_name(
1068 res
.er
, event_name
);
1069 if (event_rule_status
!= LTTNG_EVENT_RULE_STATUS_OK
) {
1070 ERR("Failed to set user space probe event rule's name to '%s'.",
1077 case LTTNG_EVENT_RULE_TYPE_SYSCALL
:
1079 enum lttng_event_rule_status event_rule_status
;
1081 res
.er
= lttng_event_rule_syscall_create();
1083 ERR("Failed to create syscall event rule.");
1087 event_rule_status
= lttng_event_rule_syscall_set_pattern(
1089 if (event_rule_status
!= LTTNG_EVENT_RULE_STATUS_OK
) {
1090 ERR("Failed to set syscall event rule's pattern to '%s'.",
1096 event_rule_status
= lttng_event_rule_syscall_set_filter(
1098 if (event_rule_status
!= LTTNG_EVENT_RULE_STATUS_OK
) {
1099 ERR("Failed to set syscall event rule's filter to '%s'.",
1115 lttng_event_rule_destroy(res
.er
);
1117 lttng_dynamic_pointer_array_reset(&res
.capture_descriptors
);
1121 filter_parser_ctx_free(parser_ctx
);
1124 lttng_event_expr_destroy(event_expr
);
1125 argpar_item_destroy(item
);
1127 argpar_state_destroy(state
);
1130 free(exclude_names
);
1131 free(log_level_str
);
1135 strutils_free_null_terminated_array_of_strings(exclusion_list
);
1136 lttng_kernel_probe_location_destroy(kernel_probe_location
);
1137 lttng_userspace_probe_location_destroy(userspace_probe_location
);
1138 lttng_log_level_rule_destroy(log_level_rule
);
1143 struct lttng_condition
*handle_condition_event(int *argc
, const char ***argv
)
1145 struct parse_event_rule_res res
;
1146 struct lttng_condition
*c
;
1149 res
= parse_event_rule(argc
, argv
);
1155 c
= lttng_condition_on_event_create(res
.er
);
1156 lttng_event_rule_destroy(res
.er
);
1162 for (i
= 0; i
< lttng_dynamic_pointer_array_get_count(&res
.capture_descriptors
);
1164 enum lttng_condition_status status
;
1165 struct lttng_event_expr
**expr
=
1166 lttng_dynamic_array_get_element(
1167 &res
.capture_descriptors
.array
, i
);
1171 status
= lttng_condition_on_event_append_capture_descriptor(
1173 if (status
!= LTTNG_CONDITION_STATUS_OK
) {
1174 if (status
== LTTNG_CONDITION_STATUS_UNSUPPORTED
) {
1175 ERR("The capture feature is unsupported by the event-rule condition type");
1181 /* Ownership of event expression moved to `c` */
1188 lttng_condition_destroy(c
);
1192 lttng_dynamic_pointer_array_reset(&res
.capture_descriptors
);
1193 lttng_event_rule_destroy(res
.er
);
1197 struct condition_descr
{
1199 struct lttng_condition
*(*handler
) (int *argc
, const char ***argv
);
1203 struct condition_descr condition_descrs
[] = {
1204 { "event-rule-matches", handle_condition_event
},
1208 struct lttng_condition
*parse_condition(const char *condition_name
, int *argc
,
1212 struct lttng_condition
*cond
;
1213 const struct condition_descr
*descr
= NULL
;
1215 for (i
= 0; i
< ARRAY_SIZE(condition_descrs
); i
++) {
1216 if (strcmp(condition_name
, condition_descrs
[i
].name
) == 0) {
1217 descr
= &condition_descrs
[i
];
1223 ERR("Unknown condition name '%s'", condition_name
);
1227 cond
= descr
->handler(argc
, argv
);
1229 /* The handler has already printed an error message. */
1240 static struct lttng_rate_policy
*parse_rate_policy(const char *policy_str
)
1243 char **tokens
= NULL
;
1244 struct lttng_rate_policy
*policy
= NULL
;
1245 enum lttng_rate_policy_type policy_type
;
1246 unsigned long long value
;
1247 char *policy_type_str
;
1248 char *policy_value_str
;
1253 * rate policy fields are separated by ':'.
1255 tokens
= strutils_split(policy_str
, ':', 1);
1256 num_token
= strutils_array_of_strings_len(tokens
);
1259 * Early sanity check that the number of parameter is exactly 2.
1262 if (num_token
!= 2) {
1263 ERR("Rate policy format is invalid.");
1267 policy_type_str
= tokens
[0];
1268 policy_value_str
= tokens
[1];
1270 /* Parse the type. */
1271 if (strcmp(policy_type_str
, "once-after") == 0) {
1272 policy_type
= LTTNG_RATE_POLICY_TYPE_ONCE_AFTER_N
;
1273 } else if (strcmp(policy_type_str
, "every") == 0) {
1274 policy_type
= LTTNG_RATE_POLICY_TYPE_EVERY_N
;
1276 ERR("Rate policy type `%s` unknown.", policy_type_str
);
1280 /* Parse the value. */
1281 if (utils_parse_unsigned_long_long(policy_value_str
, &value
) != 0) {
1282 ERR("Failed to parse rate policy value `%s` as an integer.",
1288 ERR("Rate policy value `%s` must be > 0.", policy_value_str
);
1292 switch (policy_type
) {
1293 case LTTNG_RATE_POLICY_TYPE_EVERY_N
:
1294 policy
= lttng_rate_policy_every_n_create(value
);
1296 case LTTNG_RATE_POLICY_TYPE_ONCE_AFTER_N
:
1297 policy
= lttng_rate_policy_once_after_n_create(value
);
1303 if (policy
== NULL
) {
1304 ERR("Failed to create rate policy `%s`.", policy_str
);
1308 strutils_free_null_terminated_array_of_strings(tokens
);
1312 static const struct argpar_opt_descr notify_action_opt_descrs
[] = {
1313 { OPT_RATE_POLICY
, '\0', "rate-policy", true },
1314 ARGPAR_OPT_DESCR_SENTINEL
1318 struct lttng_action
*handle_action_notify(int *argc
, const char ***argv
)
1320 struct lttng_action
*action
= NULL
;
1321 struct argpar_state
*state
= NULL
;
1322 struct argpar_item
*item
= NULL
;
1324 struct lttng_rate_policy
*policy
= NULL
;
1326 state
= argpar_state_create(*argc
, *argv
, notify_action_opt_descrs
);
1328 ERR("Failed to allocate an argpar state.");
1333 enum argpar_state_parse_next_status status
;
1335 ARGPAR_ITEM_DESTROY_AND_RESET(item
);
1336 status
= argpar_state_parse_next(state
, &item
, &error
);
1337 if (status
== ARGPAR_STATE_PARSE_NEXT_STATUS_ERROR
) {
1340 } else if (status
== ARGPAR_STATE_PARSE_NEXT_STATUS_ERROR_UNKNOWN_OPT
) {
1341 /* Just stop parsing here. */
1343 } else if (status
== ARGPAR_STATE_PARSE_NEXT_STATUS_END
) {
1347 assert(status
== ARGPAR_STATE_PARSE_NEXT_STATUS_OK
);
1349 if (item
->type
== ARGPAR_ITEM_TYPE_OPT
) {
1350 const struct argpar_item_opt
*item_opt
=
1351 (const struct argpar_item_opt
*) item
;
1353 switch (item_opt
->descr
->id
) {
1354 case OPT_RATE_POLICY
:
1356 policy
= parse_rate_policy(item_opt
->arg
);
1366 const struct argpar_item_non_opt
*item_non_opt
;
1368 assert(item
->type
== ARGPAR_ITEM_TYPE_NON_OPT
);
1370 item_non_opt
= (const struct argpar_item_non_opt
*) item
;
1372 switch (item_non_opt
->non_opt_index
) {
1374 ERR("Unexpected argument `%s`.",
1381 *argc
-= argpar_state_get_ingested_orig_args(state
);
1382 *argv
+= argpar_state_get_ingested_orig_args(state
);
1384 action
= lttng_action_notify_create();
1386 ERR("Failed to create notify action");
1391 enum lttng_action_status status
;
1392 status
= lttng_action_notify_set_rate_policy(action
, policy
);
1393 if (status
!= LTTNG_ACTION_STATUS_OK
) {
1394 ERR("Failed to set rate policy");
1402 lttng_action_destroy(action
);
1406 lttng_rate_policy_destroy(policy
);
1407 argpar_state_destroy(state
);
1408 argpar_item_destroy(item
);
1413 * Generic handler for a kind of action that takes a session name and an
1414 * optional rate policy.
1417 static struct lttng_action
*handle_action_simple_session_with_policy(int *argc
,
1419 struct lttng_action
*(*create_action_cb
)(void),
1420 enum lttng_action_status (*set_session_name_cb
)(
1421 struct lttng_action
*, const char *),
1422 enum lttng_action_status (*set_rate_policy_cb
)(
1423 struct lttng_action
*,
1424 const struct lttng_rate_policy
*),
1425 const char *action_name
)
1427 struct lttng_action
*action
= NULL
;
1428 struct argpar_state
*state
= NULL
;
1429 struct argpar_item
*item
= NULL
;
1430 const char *session_name_arg
= NULL
;
1432 enum lttng_action_status action_status
;
1433 struct lttng_rate_policy
*policy
= NULL
;
1435 assert(set_session_name_cb
);
1436 assert(set_rate_policy_cb
);
1438 const struct argpar_opt_descr rate_policy_opt_descrs
[] = {
1439 { OPT_RATE_POLICY
, '\0', "rate-policy", true },
1440 ARGPAR_OPT_DESCR_SENTINEL
1443 state
= argpar_state_create(*argc
, *argv
, rate_policy_opt_descrs
);
1445 ERR("Failed to allocate an argpar state.");
1450 enum argpar_state_parse_next_status status
;
1452 ARGPAR_ITEM_DESTROY_AND_RESET(item
);
1453 status
= argpar_state_parse_next(state
, &item
, &error
);
1454 if (status
== ARGPAR_STATE_PARSE_NEXT_STATUS_ERROR
) {
1457 } else if (status
==
1458 ARGPAR_STATE_PARSE_NEXT_STATUS_ERROR_UNKNOWN_OPT
) {
1459 /* Just stop parsing here. */
1461 } else if (status
== ARGPAR_STATE_PARSE_NEXT_STATUS_END
) {
1465 assert(status
== ARGPAR_STATE_PARSE_NEXT_STATUS_OK
);
1466 if (item
->type
== ARGPAR_ITEM_TYPE_OPT
) {
1467 const struct argpar_item_opt
*item_opt
=
1468 (const struct argpar_item_opt
*) item
;
1470 switch (item_opt
->descr
->id
) {
1471 case OPT_RATE_POLICY
:
1473 policy
= parse_rate_policy(item_opt
->arg
);
1483 const struct argpar_item_non_opt
*item_non_opt
;
1484 item_non_opt
= (const struct argpar_item_non_opt
*) item
;
1486 switch (item_non_opt
->non_opt_index
) {
1488 session_name_arg
= item_non_opt
->arg
;
1491 ERR("Unexpected argument `%s`.",
1498 *argc
-= argpar_state_get_ingested_orig_args(state
);
1499 *argv
+= argpar_state_get_ingested_orig_args(state
);
1501 if (!session_name_arg
) {
1502 ERR("Missing session name.");
1506 action
= create_action_cb();
1508 ERR("Failed to allocate %s session action.", action_name
);
1512 action_status
= set_session_name_cb(action
, session_name_arg
);
1513 if (action_status
!= LTTNG_ACTION_STATUS_OK
) {
1514 ERR("Failed to set action %s session's session name to '%s'.",
1515 action_name
, session_name_arg
);
1520 action_status
= set_rate_policy_cb(action
, policy
);
1521 if (action_status
!= LTTNG_ACTION_STATUS_OK
) {
1522 ERR("Failed to set rate policy");
1530 lttng_action_destroy(action
);
1532 argpar_item_destroy(item
);
1534 lttng_rate_policy_destroy(policy
);
1536 argpar_state_destroy(state
);
1541 struct lttng_action
*handle_action_start_session(int *argc
,
1544 return handle_action_simple_session_with_policy(argc
, argv
,
1545 lttng_action_start_session_create
,
1546 lttng_action_start_session_set_session_name
,
1547 lttng_action_start_session_set_rate_policy
, "start");
1551 struct lttng_action
*handle_action_stop_session(int *argc
,
1554 return handle_action_simple_session_with_policy(argc
, argv
,
1555 lttng_action_stop_session_create
,
1556 lttng_action_stop_session_set_session_name
,
1557 lttng_action_stop_session_set_rate_policy
, "stop");
1561 struct lttng_action
*handle_action_rotate_session(int *argc
,
1564 return handle_action_simple_session_with_policy(argc
, argv
,
1565 lttng_action_rotate_session_create
,
1566 lttng_action_rotate_session_set_session_name
,
1567 lttng_action_rotate_session_set_rate_policy
,
1571 static const struct argpar_opt_descr snapshot_action_opt_descrs
[] = {
1572 { OPT_NAME
, 'n', "name", true },
1573 { OPT_MAX_SIZE
, 'm', "max-size", true },
1574 { OPT_CTRL_URL
, '\0', "ctrl-url", true },
1575 { OPT_DATA_URL
, '\0', "data-url", true },
1576 { OPT_URL
, '\0', "url", true },
1577 { OPT_PATH
, '\0', "path", true },
1578 { OPT_RATE_POLICY
, '\0', "rate-policy", true },
1579 ARGPAR_OPT_DESCR_SENTINEL
1583 struct lttng_action
*handle_action_snapshot_session(int *argc
,
1586 struct lttng_action
*action
= NULL
;
1587 struct argpar_state
*state
= NULL
;
1588 struct argpar_item
*item
= NULL
;
1589 const char *session_name_arg
= NULL
;
1590 char *snapshot_name_arg
= NULL
;
1591 char *ctrl_url_arg
= NULL
;
1592 char *data_url_arg
= NULL
;
1593 char *max_size_arg
= NULL
;
1594 char *url_arg
= NULL
;
1595 char *path_arg
= NULL
;
1597 enum lttng_action_status action_status
;
1598 struct lttng_snapshot_output
*snapshot_output
= NULL
;
1599 struct lttng_rate_policy
*policy
= NULL
;
1601 unsigned int locations_specified
= 0;
1603 state
= argpar_state_create(*argc
, *argv
, snapshot_action_opt_descrs
);
1605 ERR("Failed to allocate an argpar state.");
1610 enum argpar_state_parse_next_status status
;
1612 ARGPAR_ITEM_DESTROY_AND_RESET(item
);
1613 status
= argpar_state_parse_next(state
, &item
, &error
);
1614 if (status
== ARGPAR_STATE_PARSE_NEXT_STATUS_ERROR
) {
1617 } else if (status
== ARGPAR_STATE_PARSE_NEXT_STATUS_ERROR_UNKNOWN_OPT
) {
1618 /* Just stop parsing here. */
1620 } else if (status
== ARGPAR_STATE_PARSE_NEXT_STATUS_END
) {
1624 assert(status
== ARGPAR_STATE_PARSE_NEXT_STATUS_OK
);
1626 if (item
->type
== ARGPAR_ITEM_TYPE_OPT
) {
1627 const struct argpar_item_opt
*item_opt
=
1628 (const struct argpar_item_opt
*) item
;
1630 switch (item_opt
->descr
->id
) {
1632 if (!assign_string(&snapshot_name_arg
, item_opt
->arg
, "--name/-n")) {
1638 if (!assign_string(&max_size_arg
, item_opt
->arg
, "--max-size/-m")) {
1644 if (!assign_string(&ctrl_url_arg
, item_opt
->arg
, "--ctrl-url")) {
1650 if (!assign_string(&data_url_arg
, item_opt
->arg
, "--data-url")) {
1656 if (!assign_string(&url_arg
, item_opt
->arg
, "--url")) {
1662 if (!assign_string(&path_arg
, item_opt
->arg
, "--path")) {
1667 case OPT_RATE_POLICY
:
1669 policy
= parse_rate_policy(item_opt
->arg
);
1679 const struct argpar_item_non_opt
*item_non_opt
;
1681 assert(item
->type
== ARGPAR_ITEM_TYPE_NON_OPT
);
1683 item_non_opt
= (const struct argpar_item_non_opt
*) item
;
1685 switch (item_non_opt
->non_opt_index
) {
1687 session_name_arg
= item_non_opt
->arg
;
1690 ERR("Unexpected argument `%s`.",
1697 *argc
-= argpar_state_get_ingested_orig_args(state
);
1698 *argv
+= argpar_state_get_ingested_orig_args(state
);
1700 if (!session_name_arg
) {
1701 ERR("Missing session name.");
1705 /* --ctrl-url and --data-url must come in pair. */
1706 if (ctrl_url_arg
&& !data_url_arg
) {
1707 ERR("--ctrl-url is specified, but --data-url is missing.");
1711 if (!ctrl_url_arg
&& data_url_arg
) {
1712 ERR("--data-url is specified, but --ctrl-url is missing.");
1716 locations_specified
+= !!(ctrl_url_arg
|| data_url_arg
);
1717 locations_specified
+= !!url_arg
;
1718 locations_specified
+= !!path_arg
;
1720 /* --ctrl-url/--data-url, --url and --path are mutually exclusive. */
1721 if (locations_specified
> 1) {
1722 ERR("The --ctrl-url/--data-url, --url, and --path options can't be used together.");
1727 * Did the user specify an option that implies using a
1728 * custom/unregistered output?
1730 if (url_arg
|| ctrl_url_arg
|| path_arg
) {
1731 snapshot_output
= lttng_snapshot_output_create();
1732 if (!snapshot_output
) {
1733 ERR("Failed to allocate a snapshot output.");
1738 action
= lttng_action_snapshot_session_create();
1740 ERR("Failed to allocate snapshot session action.");
1744 action_status
= lttng_action_snapshot_session_set_session_name(
1745 action
, session_name_arg
);
1746 if (action_status
!= LTTNG_ACTION_STATUS_OK
) {
1747 ERR("Failed to set action snapshot session's session name to '%s'.",
1752 if (snapshot_name_arg
) {
1753 if (!snapshot_output
) {
1754 ERR("Can't provide a snapshot output name without a snapshot output destination.");
1758 ret
= lttng_snapshot_output_set_name(
1759 snapshot_name_arg
, snapshot_output
);
1761 ERR("Failed to set name of snapshot output.");
1769 if (!snapshot_output
) {
1770 ERR("Can't provide a snapshot output max size without a snapshot output destination.");
1774 ret
= utils_parse_size_suffix(max_size_arg
, &max_size
);
1776 ERR("Failed to parse `%s` as a size.", max_size_arg
);
1780 ret
= lttng_snapshot_output_set_size(max_size
, snapshot_output
);
1782 ERR("Failed to set snapshot output's max size to %" PRIu64
" bytes.",
1790 struct lttng_uri
*uris
;
1792 if (!strstr(url_arg
, "://")) {
1793 ERR("Failed to parse '%s' as an URL.", url_arg
);
1797 num_uris
= uri_parse_str_urls(url_arg
, NULL
, &uris
);
1799 ERR("Failed to parse '%s' as an URL.", url_arg
);
1803 if (uris
[0].dtype
== LTTNG_DST_PATH
) {
1804 ret
= lttng_snapshot_output_set_local_path(
1805 uris
[0].dst
.path
, snapshot_output
);
1808 ERR("Failed to assign '%s' as a local destination.",
1813 ret
= lttng_snapshot_output_set_network_url(
1814 url_arg
, snapshot_output
);
1817 ERR("Failed to assign '%s' as a network URL.",
1825 ret
= lttng_snapshot_output_set_local_path(
1826 path_arg
, snapshot_output
);
1828 ERR("Failed to parse '%s' as a local path.", path_arg
);
1835 * Two argument form, network output with separate control and
1838 ret
= lttng_snapshot_output_set_network_urls(
1839 ctrl_url_arg
, data_url_arg
, snapshot_output
);
1841 ERR("Failed to parse `%s` and `%s` as control and data URLs.",
1842 ctrl_url_arg
, data_url_arg
);
1847 if (snapshot_output
) {
1848 action_status
= lttng_action_snapshot_session_set_output(
1849 action
, snapshot_output
);
1850 if (action_status
!= LTTNG_ACTION_STATUS_OK
) {
1851 ERR("Failed to set snapshot session action's output.");
1855 /* Ownership of `snapshot_output` has been transferred to the action. */
1856 snapshot_output
= NULL
;
1860 enum lttng_action_status status
;
1861 status
= lttng_action_snapshot_session_set_rate_policy(
1863 if (status
!= LTTNG_ACTION_STATUS_OK
) {
1864 ERR("Failed to set rate policy");
1872 lttng_action_destroy(action
);
1876 free(snapshot_name_arg
);
1881 free(snapshot_output
);
1883 lttng_rate_policy_destroy(policy
);
1884 argpar_state_destroy(state
);
1885 argpar_item_destroy(item
);
1889 struct action_descr
{
1891 struct lttng_action
*(*handler
) (int *argc
, const char ***argv
);
1895 struct action_descr action_descrs
[] = {
1896 { "notify", handle_action_notify
},
1897 { "start-session", handle_action_start_session
},
1898 { "stop-session", handle_action_stop_session
},
1899 { "rotate-session", handle_action_rotate_session
},
1900 { "snapshot-session", handle_action_snapshot_session
},
1904 struct lttng_action
*parse_action(const char *action_name
, int *argc
, const char ***argv
)
1907 struct lttng_action
*action
;
1908 const struct action_descr
*descr
= NULL
;
1910 for (i
= 0; i
< ARRAY_SIZE(action_descrs
); i
++) {
1911 if (strcmp(action_name
, action_descrs
[i
].name
) == 0) {
1912 descr
= &action_descrs
[i
];
1918 ERR("Unknown action name: %s", action_name
);
1922 action
= descr
->handler(argc
, argv
);
1924 /* The handler has already printed an error message. */
1936 struct argpar_opt_descr add_trigger_options
[] = {
1937 { OPT_HELP
, 'h', "help", false },
1938 { OPT_LIST_OPTIONS
, '\0', "list-options", false },
1939 { OPT_CONDITION
, '\0', "condition", true },
1940 { OPT_ACTION
, '\0', "action", true },
1941 { OPT_NAME
, '\0', "name", true },
1942 { OPT_OWNER_UID
, '\0', "owner-uid", true },
1943 ARGPAR_OPT_DESCR_SENTINEL
,
1947 void lttng_actions_destructor(void *p
)
1949 struct lttng_action
*action
= p
;
1951 lttng_action_destroy(action
);
1954 int cmd_add_trigger(int argc
, const char **argv
)
1957 int my_argc
= argc
- 1;
1958 const char **my_argv
= argv
+ 1;
1959 struct lttng_condition
*condition
= NULL
;
1960 struct lttng_dynamic_pointer_array actions
;
1961 struct argpar_state
*argpar_state
= NULL
;
1962 struct argpar_item
*argpar_item
= NULL
;
1963 struct lttng_action
*action_group
= NULL
;
1964 struct lttng_action
*action
= NULL
;
1965 struct lttng_trigger
*trigger
= NULL
;
1969 char *owner_uid
= NULL
;
1971 lttng_dynamic_pointer_array_init(&actions
, lttng_actions_destructor
);
1974 enum argpar_state_parse_next_status status
;
1975 const struct argpar_item_opt
*item_opt
;
1978 argpar_state_destroy(argpar_state
);
1979 argpar_state
= argpar_state_create(my_argc
, my_argv
,
1980 add_trigger_options
);
1981 if (!argpar_state
) {
1982 ERR("Failed to create argpar state.");
1986 ARGPAR_ITEM_DESTROY_AND_RESET(argpar_item
);
1987 status
= argpar_state_parse_next(argpar_state
, &argpar_item
, &error
);
1988 if (status
== ARGPAR_STATE_PARSE_NEXT_STATUS_ERROR
) {
1991 } else if (status
== ARGPAR_STATE_PARSE_NEXT_STATUS_ERROR_UNKNOWN_OPT
) {
1994 } else if (status
== ARGPAR_STATE_PARSE_NEXT_STATUS_END
) {
1998 assert(status
== ARGPAR_STATE_PARSE_NEXT_STATUS_OK
);
2000 if (argpar_item
->type
== ARGPAR_ITEM_TYPE_NON_OPT
) {
2001 const struct argpar_item_non_opt
*item_non_opt
=
2002 (const struct argpar_item_non_opt
*)
2005 ERR("Unexpected argument `%s`.", item_non_opt
->arg
);
2009 item_opt
= (const struct argpar_item_opt
*) argpar_item
;
2011 ingested_args
= argpar_state_get_ingested_orig_args(
2014 my_argc
-= ingested_args
;
2015 my_argv
+= ingested_args
;
2017 switch (item_opt
->descr
->id
) {
2022 case OPT_LIST_OPTIONS
:
2023 list_cmd_options_argpar(stdout
, add_trigger_options
);
2029 ERR("A --condition was already given.");
2033 condition
= parse_condition(item_opt
->arg
, &my_argc
, &my_argv
);
2036 * An error message was already printed by
2046 action
= parse_action(item_opt
->arg
, &my_argc
, &my_argv
);
2049 * An error message was already printed by
2055 ret
= lttng_dynamic_pointer_array_add_pointer(
2058 ERR("Failed to add pointer to pointer array.");
2062 /* Ownership of the action was transferred to the group. */
2069 if (!assign_string(&name
, item_opt
->arg
, "--name")) {
2077 if (!assign_string(&owner_uid
, item_opt
->arg
,
2090 ERR("Missing --condition.");
2094 if (lttng_dynamic_pointer_array_get_count(&actions
) == 0) {
2095 ERR("Need at least one --action.");
2099 action_group
= lttng_action_group_create();
2100 if (!action_group
) {
2104 for (i
= 0; i
< lttng_dynamic_pointer_array_get_count(&actions
); i
++) {
2105 enum lttng_action_status status
;
2107 action
= lttng_dynamic_pointer_array_steal_pointer(&actions
, i
);
2109 status
= lttng_action_group_add_action(action_group
, action
);
2110 if (status
!= LTTNG_ACTION_STATUS_OK
) {
2115 * The `lttng_action_group_add_action()` takes a reference to
2116 * the action. We can destroy ours.
2118 lttng_action_destroy(action
);
2122 trigger
= lttng_trigger_create(condition
, action_group
);
2128 enum lttng_trigger_status trigger_status
=
2129 lttng_trigger_set_name(trigger
, name
);
2131 if (trigger_status
!= LTTNG_TRIGGER_STATUS_OK
) {
2132 ERR("Failed to set trigger name.");
2138 enum lttng_trigger_status trigger_status
;
2143 uid
= strtol(owner_uid
, &end
, 10);
2144 if (end
== owner_uid
|| *end
!= '\0' || errno
!= 0) {
2145 ERR("Failed to parse `%s` as a user id.", owner_uid
);
2148 trigger_status
= lttng_trigger_set_owner_uid(trigger
, uid
);
2149 if (trigger_status
!= LTTNG_TRIGGER_STATUS_OK
) {
2150 ERR("Failed to set trigger's user identity.");
2155 ret
= lttng_register_trigger(trigger
);
2157 ERR("Failed to register trigger: %s.", lttng_strerror(ret
));
2161 MSG("Trigger registered successfully.");
2169 argpar_state_destroy(argpar_state
);
2170 argpar_item_destroy(argpar_item
);
2171 lttng_dynamic_pointer_array_reset(&actions
);
2172 lttng_condition_destroy(condition
);
2173 lttng_action_destroy(action_group
);
2174 lttng_action_destroy(action
);
2175 lttng_trigger_destroy(trigger
);