Commit | Line | Data |
---|---|---|
4624dad0 SM |
1 | /* |
2 | * Copyright (C) 2021 Simon Marchi <simon.marchi@efficios.com> | |
3 | * | |
4 | * SPDX-License-Identifier: GPL-2.0-only | |
5 | * | |
6 | */ | |
7 | ||
8 | #include <ctype.h> | |
9 | #include <stdio.h> | |
10 | ||
11 | #include "../command.h" | |
12 | #include "../loglevel.h" | |
13 | #include "../uprobe.h" | |
14 | ||
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> | |
20a01d15 SM |
22 | #include "common/filter/filter-ast.h" |
23 | #include "common/filter/filter-ir.h" | |
24 | #include "common/dynamic-array.h" | |
4624dad0 SM |
25 | |
26 | #if (LTTNG_SYMBOL_NAME_LEN == 256) | |
27 | #define LTTNG_SYMBOL_NAME_LEN_SCANF_IS_A_BROKEN_API "255" | |
28 | #endif | |
29 | ||
30 | #ifdef LTTNG_EMBED_HELP | |
31 | static const char help_msg[] = | |
32 | #include <lttng-add-trigger.1.h> | |
33 | ; | |
34 | #endif | |
35 | ||
36 | enum { | |
37 | OPT_HELP, | |
38 | OPT_LIST_OPTIONS, | |
39 | ||
40 | OPT_CONDITION, | |
41 | OPT_ACTION, | |
42 | OPT_ID, | |
4624dad0 | 43 | OPT_USER_ID, |
bbadb5e0 | 44 | OPT_RATE_POLICY, |
4624dad0 | 45 | |
50ad0862 | 46 | OPT_NAME, |
4624dad0 | 47 | OPT_FILTER, |
50ad0862 SM |
48 | OPT_EXCLUDE_NAMES, |
49 | OPT_EVENT_NAME, | |
949f049b | 50 | OPT_LOG_LEVEL, |
4624dad0 | 51 | |
64c34630 | 52 | OPT_DOMAIN, |
24de704e SM |
53 | OPT_TYPE, |
54 | OPT_LOCATION, | |
4624dad0 | 55 | |
4624dad0 SM |
56 | OPT_MAX_SIZE, |
57 | OPT_DATA_URL, | |
58 | OPT_CTRL_URL, | |
59 | OPT_URL, | |
60 | OPT_PATH, | |
20a01d15 SM |
61 | |
62 | OPT_CAPTURE, | |
4624dad0 SM |
63 | }; |
64 | ||
65 | static const struct argpar_opt_descr event_rule_opt_descrs[] = { | |
4624dad0 | 66 | { OPT_FILTER, 'f', "filter", true }, |
50ad0862 SM |
67 | { OPT_NAME, 'n', "name", true }, |
68 | { OPT_EXCLUDE_NAMES, 'x', "exclude-names", true }, | |
949f049b | 69 | { OPT_LOG_LEVEL, 'l', "log-level", true }, |
50ad0862 | 70 | { OPT_EVENT_NAME, 'E', "event-name", true }, |
4624dad0 | 71 | |
64c34630 | 72 | { OPT_DOMAIN, 'd', "domain", true }, |
24de704e SM |
73 | { OPT_TYPE, 't', "type", true }, |
74 | { OPT_LOCATION, 'L', "location", true }, | |
4624dad0 | 75 | |
20a01d15 SM |
76 | /* Capture descriptor */ |
77 | { OPT_CAPTURE, '\0', "capture", true }, | |
78 | ||
4624dad0 SM |
79 | ARGPAR_OPT_DESCR_SENTINEL |
80 | }; | |
81 | ||
82 | static | |
64c34630 | 83 | bool assign_domain_type(enum lttng_domain_type *dest, const char *arg) |
4624dad0 SM |
84 | { |
85 | bool ret; | |
86 | ||
64c34630 SM |
87 | if (*dest != LTTNG_DOMAIN_NONE) { |
88 | ERR("More than one `--domain` was specified."); | |
89 | goto error; | |
90 | } | |
91 | ||
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; | |
4624dad0 | 102 | } else { |
64c34630 SM |
103 | ERR("Invalid `--domain` value: %s", arg); |
104 | goto error; | |
4624dad0 SM |
105 | } |
106 | ||
64c34630 SM |
107 | ret = true; |
108 | goto end; | |
109 | ||
110 | error: | |
111 | ret = false; | |
112 | ||
113 | end: | |
4624dad0 SM |
114 | return ret; |
115 | } | |
116 | ||
117 | static | |
24de704e | 118 | bool assign_event_rule_type(enum lttng_event_rule_type *dest, const char *arg) |
4624dad0 SM |
119 | { |
120 | bool ret; | |
121 | ||
24de704e SM |
122 | if (*dest != LTTNG_EVENT_RULE_TYPE_UNKNOWN) { |
123 | ERR("More than one `--type` was specified."); | |
124 | goto error; | |
125 | } | |
126 | ||
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; | |
4624dad0 | 137 | } else { |
24de704e SM |
138 | ERR("Invalid `--type` value: %s", arg); |
139 | goto error; | |
4624dad0 SM |
140 | } |
141 | ||
24de704e SM |
142 | ret = true; |
143 | goto end; | |
144 | ||
145 | error: | |
146 | ret = false; | |
147 | ||
148 | end: | |
4624dad0 SM |
149 | return ret; |
150 | } | |
151 | ||
152 | static | |
153 | bool assign_string(char **dest, const char *src, const char *opt_name) | |
154 | { | |
155 | bool ret; | |
156 | ||
157 | if (*dest) { | |
158 | ERR("Duplicate '%s' given.", opt_name); | |
159 | goto error; | |
160 | } | |
161 | ||
162 | *dest = strdup(src); | |
163 | if (!*dest) { | |
164 | PERROR("Failed to allocate string '%s'.", opt_name); | |
165 | goto error; | |
166 | } | |
167 | ||
168 | ret = true; | |
169 | goto end; | |
170 | ||
171 | error: | |
172 | ret = false; | |
173 | ||
174 | end: | |
175 | return ret; | |
176 | } | |
177 | ||
178 | /* This is defined in enable_events.c. */ | |
179 | LTTNG_HIDDEN | |
180 | int create_exclusion_list_and_validate(const char *event_name, | |
181 | const char *exclusions_arg, | |
182 | char ***exclusion_list); | |
183 | ||
184 | /* | |
949f049b SM |
185 | * Parse `str` as a log level in domain `domain_type`. |
186 | * | |
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 | |
189 | * this log level. | |
190 | * | |
191 | * Return true if the string was successfully parsed as a log level string. | |
4624dad0 | 192 | */ |
949f049b SM |
193 | static bool parse_log_level_string(const char *str, |
194 | enum lttng_domain_type domain_type, | |
195 | int *log_level, | |
196 | bool *log_level_only) | |
4624dad0 | 197 | { |
949f049b SM |
198 | bool ret; |
199 | ||
4624dad0 SM |
200 | switch (domain_type) { |
201 | case LTTNG_DOMAIN_UST: | |
202 | { | |
949f049b SM |
203 | enum lttng_loglevel log_level_min, log_level_max; |
204 | if (!loglevel_parse_range_string( | |
205 | str, &log_level_min, &log_level_max)) { | |
206 | goto error; | |
207 | } | |
4624dad0 | 208 | |
949f049b SM |
209 | /* Only support VAL and VAL.. for now. */ |
210 | if (log_level_min != log_level_max && | |
211 | log_level_max != LTTNG_LOGLEVEL_EMERG) { | |
212 | goto error; | |
213 | } | |
214 | ||
215 | *log_level = (int) log_level_min; | |
216 | *log_level_only = log_level_min == log_level_max; | |
217 | break; | |
4624dad0 SM |
218 | } |
219 | case LTTNG_DOMAIN_LOG4J: | |
220 | { | |
949f049b SM |
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)) { | |
224 | goto error; | |
225 | } | |
4624dad0 | 226 | |
949f049b SM |
227 | /* Only support VAL and VAL.. for now. */ |
228 | if (log_level_min != log_level_max && | |
229 | log_level_max != LTTNG_LOGLEVEL_LOG4J_FATAL) { | |
230 | goto error; | |
231 | } | |
232 | ||
233 | *log_level = (int) log_level_min; | |
234 | *log_level_only = log_level_min == log_level_max; | |
235 | break; | |
4624dad0 SM |
236 | } |
237 | case LTTNG_DOMAIN_JUL: | |
238 | { | |
949f049b SM |
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)) { | |
242 | goto error; | |
243 | } | |
4624dad0 | 244 | |
949f049b SM |
245 | /* Only support VAL and VAL.. for now. */ |
246 | if (log_level_min != log_level_max && | |
247 | log_level_max != LTTNG_LOGLEVEL_JUL_SEVERE) { | |
248 | goto error; | |
249 | } | |
250 | ||
251 | *log_level = (int) log_level_min; | |
252 | *log_level_only = log_level_min == log_level_max; | |
253 | break; | |
4624dad0 SM |
254 | } |
255 | case LTTNG_DOMAIN_PYTHON: | |
256 | { | |
949f049b SM |
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)) { | |
260 | goto error; | |
261 | } | |
4624dad0 | 262 | |
949f049b SM |
263 | /* Only support VAL and VAL.. for now. */ |
264 | if (log_level_min != log_level_max && | |
265 | log_level_max != | |
266 | LTTNG_LOGLEVEL_PYTHON_CRITICAL) { | |
267 | goto error; | |
268 | } | |
269 | ||
270 | *log_level = (int) log_level_min; | |
271 | *log_level_only = log_level_min == log_level_max; | |
272 | break; | |
4624dad0 SM |
273 | } |
274 | default: | |
275 | /* Invalid domain type. */ | |
276 | abort(); | |
277 | } | |
949f049b SM |
278 | |
279 | ret = true; | |
280 | goto end; | |
281 | ||
282 | error: | |
283 | ret = false; | |
284 | ||
285 | end: | |
286 | return ret; | |
4624dad0 SM |
287 | } |
288 | ||
289 | static int parse_kernel_probe_opts(const char *source, | |
290 | struct lttng_kernel_probe_location **location) | |
291 | { | |
292 | int ret = 0; | |
293 | int match; | |
294 | char s_hex[19]; | |
295 | char name[LTTNG_SYMBOL_NAME_LEN]; | |
296 | char *symbol_name = NULL; | |
297 | uint64_t offset; | |
298 | ||
299 | /* Check for symbol+offset. */ | |
300 | match = sscanf(source, | |
301 | "%" LTTNG_SYMBOL_NAME_LEN_SCANF_IS_A_BROKEN_API | |
302 | "[^'+']+%18s", | |
303 | name, s_hex); | |
304 | if (match == 2) { | |
305 | if (*s_hex == '\0') { | |
306 | ERR("Kernel probe symbol offset is missing."); | |
307 | goto error; | |
308 | } | |
309 | ||
310 | symbol_name = strndup(name, LTTNG_SYMBOL_NAME_LEN); | |
311 | if (!symbol_name) { | |
312 | PERROR("Failed to copy kernel probe location symbol name."); | |
313 | goto error; | |
314 | } | |
315 | offset = strtoul(s_hex, NULL, 0); | |
316 | ||
317 | *location = lttng_kernel_probe_location_symbol_create( | |
318 | symbol_name, offset); | |
f6e30a8a | 319 | if (!*location) { |
4624dad0 SM |
320 | ERR("Failed to create symbol kernel probe location."); |
321 | goto error; | |
322 | } | |
323 | ||
324 | goto end; | |
325 | } | |
326 | ||
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 | |
331 | "s", | |
332 | name); | |
333 | if (match == 1) { | |
334 | symbol_name = strndup(name, LTTNG_SYMBOL_NAME_LEN); | |
335 | if (!symbol_name) { | |
336 | ERR("Failed to copy kernel probe location symbol name."); | |
337 | goto error; | |
338 | } | |
339 | ||
340 | *location = lttng_kernel_probe_location_symbol_create( | |
341 | symbol_name, 0); | |
14f27f79 | 342 | if (!*location) { |
4624dad0 SM |
343 | ERR("Failed to create symbol kernel probe location."); |
344 | goto error; | |
345 | } | |
346 | ||
347 | goto end; | |
348 | } | |
349 | } | |
350 | ||
351 | /* Check for address. */ | |
352 | match = sscanf(source, "%18s", s_hex); | |
353 | if (match > 0) { | |
354 | uint64_t address; | |
355 | ||
356 | if (*s_hex == '\0') { | |
357 | ERR("Invalid kernel probe location address."); | |
358 | goto error; | |
359 | } | |
360 | ||
361 | address = strtoul(s_hex, NULL, 0); | |
362 | *location = lttng_kernel_probe_location_address_create(address); | |
5c6ca809 | 363 | if (!*location) { |
4624dad0 SM |
364 | ERR("Failed to create symbol kernel probe location."); |
365 | goto error; | |
366 | } | |
367 | ||
368 | goto end; | |
369 | } | |
370 | ||
371 | error: | |
372 | /* No match */ | |
373 | ret = -1; | |
374 | *location = NULL; | |
375 | ||
376 | end: | |
377 | free(symbol_name); | |
378 | return ret; | |
379 | } | |
380 | ||
20a01d15 SM |
381 | static |
382 | struct lttng_event_expr *ir_op_load_expr_to_event_expr( | |
3363a4c3 JG |
383 | const struct ir_load_expression *load_expr, |
384 | const char *capture_str) | |
20a01d15 SM |
385 | { |
386 | char *provider_name = NULL; | |
387 | struct lttng_event_expr *event_expr = NULL; | |
3363a4c3 JG |
388 | const struct ir_load_expression_op *load_expr_op = load_expr->child; |
389 | const enum ir_load_expression_type load_expr_child_type = | |
390 | load_expr_op->type; | |
20a01d15 | 391 | |
3363a4c3 | 392 | switch (load_expr_child_type) { |
20a01d15 SM |
393 | case IR_LOAD_EXPRESSION_GET_PAYLOAD_ROOT: |
394 | case IR_LOAD_EXPRESSION_GET_CONTEXT_ROOT: | |
395 | { | |
396 | const char *field_name; | |
397 | ||
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; | |
402 | assert(field_name); | |
403 | ||
3363a4c3 | 404 | event_expr = load_expr_child_type == IR_LOAD_EXPRESSION_GET_PAYLOAD_ROOT ? |
20a01d15 SM |
405 | lttng_event_expr_event_payload_field_create(field_name) : |
406 | lttng_event_expr_channel_context_field_create(field_name); | |
407 | if (!event_expr) { | |
408 | ERR("Failed to create %s event expression: field name = `%s`.", | |
3363a4c3 | 409 | load_expr_child_type == IR_LOAD_EXPRESSION_GET_PAYLOAD_ROOT ? |
20a01d15 SM |
410 | "payload field" : "channel context", |
411 | field_name); | |
412 | goto error; | |
413 | } | |
414 | ||
415 | break; | |
416 | } | |
417 | case IR_LOAD_EXPRESSION_GET_APP_CONTEXT_ROOT: | |
418 | { | |
419 | const char *colon; | |
420 | const char *type_name; | |
421 | const char *field_name; | |
422 | ||
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; | |
427 | assert(field_name); | |
428 | ||
429 | /* | |
430 | * The field name needs to be of the form PROVIDER:TYPE. We | |
431 | * split it here. | |
432 | */ | |
433 | colon = strchr(field_name, ':'); | |
434 | if (!colon) { | |
435 | ERR("Invalid app-specific context field name: missing colon in `%s`.", | |
436 | field_name); | |
437 | goto error; | |
438 | } | |
439 | ||
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`.", | |
443 | field_name); | |
444 | goto error; | |
445 | } | |
446 | ||
447 | provider_name = strndup(field_name, colon - field_name); | |
448 | if (!provider_name) { | |
449 | PERROR("Failed to allocate field name string"); | |
450 | goto error; | |
451 | } | |
452 | ||
453 | event_expr = lttng_event_expr_app_specific_context_field_create( | |
454 | provider_name, type_name); | |
455 | if (!event_expr) { | |
456 | ERR("Failed to create app-specific context field event expression: provider name = `%s`, type name = `%s`", | |
457 | provider_name, type_name); | |
458 | goto error; | |
459 | } | |
460 | ||
461 | break; | |
462 | } | |
463 | default: | |
464 | ERR("%s: unexpected load expr type %d.", __func__, | |
465 | load_expr_op->type); | |
466 | abort(); | |
467 | } | |
468 | ||
469 | load_expr_op = load_expr_op->next; | |
470 | ||
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; | |
475 | ||
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."); | |
479 | goto error; | |
480 | } | |
481 | ||
482 | event_expr = index_event_expr; | |
483 | load_expr_op = load_expr_op->next; | |
484 | } | |
485 | ||
486 | switch (load_expr_op->type) { | |
487 | case IR_LOAD_EXPRESSION_LOAD_FIELD: | |
488 | /* | |
489 | * This is what we expect, IR_LOAD_EXPRESSION_LOAD_FIELD is | |
490 | * always found at the end of the chain. | |
491 | */ | |
492 | break; | |
493 | case IR_LOAD_EXPRESSION_GET_SYMBOL: | |
494 | ERR("While parsing expression `%s`: Capturing subfields is not supported.", | |
495 | capture_str); | |
496 | goto error; | |
497 | ||
498 | default: | |
499 | ERR("%s: unexpected load expression operator %s.", __func__, | |
500 | ir_load_expression_type_str(load_expr_op->type)); | |
501 | abort(); | |
502 | } | |
503 | ||
504 | goto end; | |
505 | ||
506 | error: | |
507 | lttng_event_expr_destroy(event_expr); | |
508 | event_expr = NULL; | |
509 | ||
510 | end: | |
511 | free(provider_name); | |
512 | ||
513 | return event_expr; | |
514 | } | |
515 | ||
516 | static | |
517 | struct lttng_event_expr *ir_op_load_to_event_expr( | |
518 | const struct ir_op *ir, const char *capture_str) | |
519 | { | |
520 | struct lttng_event_expr *event_expr = NULL; | |
521 | ||
522 | assert(ir->op == IR_OP_LOAD); | |
523 | ||
524 | switch (ir->data_type) { | |
525 | case IR_DATA_EXPRESSION: | |
526 | { | |
527 | const struct ir_load_expression *ir_load_expr = | |
528 | ir->u.load.u.expression; | |
529 | ||
530 | event_expr = ir_op_load_expr_to_event_expr( | |
531 | ir_load_expr, capture_str); | |
532 | break; | |
533 | } | |
534 | default: | |
535 | ERR("%s: unexpected data type: %s.", __func__, | |
536 | ir_data_type_str(ir->data_type)); | |
537 | abort(); | |
538 | } | |
539 | ||
540 | return event_expr; | |
541 | } | |
542 | ||
543 | static | |
544 | const char *ir_operator_type_human_str(enum ir_op_type op) | |
545 | { | |
546 | const char *name; | |
547 | ||
548 | switch (op) { | |
549 | case IR_OP_BINARY: | |
550 | name = "Binary"; | |
551 | break; | |
552 | case IR_OP_UNARY: | |
553 | name = "Unary"; | |
554 | break; | |
555 | case IR_OP_LOGICAL: | |
556 | name = "Logical"; | |
557 | break; | |
558 | default: | |
559 | abort(); | |
560 | } | |
561 | ||
562 | return name; | |
563 | } | |
564 | ||
565 | static | |
566 | struct lttng_event_expr *ir_op_root_to_event_expr(const struct ir_op *ir, | |
567 | const char *capture_str) | |
568 | { | |
569 | struct lttng_event_expr *event_expr = NULL; | |
570 | ||
571 | assert(ir->op == IR_OP_ROOT); | |
572 | ir = ir->u.root.child; | |
573 | ||
574 | switch (ir->op) { | |
575 | case IR_OP_LOAD: | |
576 | event_expr = ir_op_load_to_event_expr(ir, capture_str); | |
577 | break; | |
578 | case IR_OP_BINARY: | |
579 | case IR_OP_UNARY: | |
580 | case IR_OP_LOGICAL: | |
581 | ERR("While parsing expression `%s`: %s operators are not allowed in capture expressions.", | |
582 | capture_str, | |
583 | ir_operator_type_human_str(ir->op)); | |
584 | break; | |
585 | default: | |
586 | ERR("%s: unexpected IR op type: %s.", __func__, | |
587 | ir_op_type_str(ir->op)); | |
588 | abort(); | |
589 | } | |
590 | ||
591 | return event_expr; | |
592 | } | |
593 | ||
594 | static | |
595 | void destroy_event_expr(void *ptr) | |
596 | { | |
597 | lttng_event_expr_destroy(ptr); | |
598 | } | |
599 | ||
600 | struct parse_event_rule_res { | |
601 | /* Owned by this. */ | |
602 | struct lttng_event_rule *er; | |
603 | ||
604 | /* Array of `struct lttng_event_expr *` */ | |
605 | struct lttng_dynamic_pointer_array capture_descriptors; | |
606 | }; | |
607 | ||
608 | static | |
609 | struct parse_event_rule_res parse_event_rule(int *argc, const char ***argv) | |
4624dad0 | 610 | { |
4624dad0 SM |
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; | |
616 | char *error = 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; | |
20a01d15 SM |
620 | struct parse_event_rule_res res = { 0 }; |
621 | struct lttng_event_expr *event_expr = NULL; | |
622 | struct filter_parser_ctx *parser_ctx = NULL; | |
85b05318 | 623 | struct lttng_log_level_rule *log_level_rule = NULL; |
4624dad0 | 624 | |
50ad0862 SM |
625 | /* Tracepoint and syscall options. */ |
626 | char *name = NULL; | |
627 | char *exclude_names = NULL; | |
628 | char **exclusion_list = NULL; | |
4624dad0 | 629 | |
24de704e SM |
630 | /* For userspace / kernel probe and function. */ |
631 | char *location = NULL; | |
632 | char *event_name = NULL; | |
4624dad0 SM |
633 | |
634 | /* Filter. */ | |
635 | char *filter = NULL; | |
636 | ||
4624dad0 | 637 | /* Log level. */ |
949f049b | 638 | char *log_level_str = NULL; |
4624dad0 | 639 | |
20a01d15 SM |
640 | lttng_dynamic_pointer_array_init(&res.capture_descriptors, |
641 | destroy_event_expr); | |
4624dad0 SM |
642 | state = argpar_state_create(*argc, *argv, event_rule_opt_descrs); |
643 | if (!state) { | |
644 | ERR("Failed to allocate an argpar state."); | |
645 | goto error; | |
646 | } | |
647 | ||
648 | while (true) { | |
649 | enum argpar_state_parse_next_status status; | |
650 | ||
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) { | |
654 | ERR("%s", error); | |
655 | goto error; | |
656 | } else if (status == ARGPAR_STATE_PARSE_NEXT_STATUS_ERROR_UNKNOWN_OPT) { | |
657 | /* Just stop parsing here. */ | |
658 | break; | |
659 | } else if (status == ARGPAR_STATE_PARSE_NEXT_STATUS_END) { | |
660 | break; | |
661 | } | |
662 | ||
663 | assert(status == ARGPAR_STATE_PARSE_NEXT_STATUS_OK); | |
664 | ||
665 | if (item->type == ARGPAR_ITEM_TYPE_OPT) { | |
666 | const struct argpar_item_opt *item_opt = | |
667 | (const struct argpar_item_opt *) item; | |
668 | ||
669 | switch (item_opt->descr->id) { | |
670 | /* Domains. */ | |
64c34630 | 671 | case OPT_DOMAIN: |
24de704e SM |
672 | if (!assign_domain_type(&domain_type, |
673 | item_opt->arg)) { | |
4624dad0 SM |
674 | goto error; |
675 | } | |
676 | ||
677 | break; | |
24de704e | 678 | case OPT_TYPE: |
4624dad0 | 679 | if (!assign_event_rule_type(&event_rule_type, |
24de704e | 680 | item_opt->arg)) { |
4624dad0 SM |
681 | goto error; |
682 | } | |
683 | ||
684 | break; | |
24de704e SM |
685 | case OPT_LOCATION: |
686 | if (!assign_string(&location, | |
687 | item_opt->arg, | |
688 | "--location/-L")) { | |
50ad0862 SM |
689 | goto error; |
690 | } | |
691 | ||
692 | break; | |
693 | case OPT_EVENT_NAME: | |
24de704e | 694 | if (!assign_string(&event_name, |
50ad0862 SM |
695 | item_opt->arg, |
696 | "--event-name/-E")) { | |
697 | goto error; | |
4624dad0 SM |
698 | } |
699 | ||
4624dad0 SM |
700 | break; |
701 | case OPT_FILTER: | |
702 | if (!assign_string(&filter, item_opt->arg, | |
703 | "--filter/-f")) { | |
704 | goto error; | |
705 | } | |
706 | ||
707 | break; | |
50ad0862 SM |
708 | case OPT_NAME: |
709 | if (!assign_string(&name, item_opt->arg, | |
710 | "--name/-n")) { | |
711 | goto error; | |
712 | } | |
713 | ||
714 | break; | |
715 | case OPT_EXCLUDE_NAMES: | |
716 | if (!assign_string(&exclude_names, | |
717 | item_opt->arg, | |
718 | "--exclude-names/-x")) { | |
4624dad0 SM |
719 | goto error; |
720 | } | |
721 | ||
722 | break; | |
949f049b SM |
723 | case OPT_LOG_LEVEL: |
724 | if (!assign_string(&log_level_str, | |
725 | item_opt->arg, "--log-level/-l")) { | |
4624dad0 SM |
726 | goto error; |
727 | } | |
728 | ||
4624dad0 | 729 | break; |
20a01d15 SM |
730 | case OPT_CAPTURE: |
731 | { | |
732 | int ret; | |
733 | const char *capture_str = item_opt->arg; | |
734 | ||
735 | ret = filter_parser_ctx_create_from_filter_expression( | |
736 | capture_str, &parser_ctx); | |
737 | if (ret) { | |
738 | ERR("Failed to parse capture expression `%s`.", | |
739 | capture_str); | |
740 | goto error; | |
741 | } | |
742 | ||
743 | event_expr = ir_op_root_to_event_expr( | |
744 | parser_ctx->ir_root, | |
745 | capture_str); | |
746 | if (!event_expr) { | |
747 | /* | |
748 | * ir_op_root_to_event_expr has printed | |
749 | * an error message. | |
750 | */ | |
751 | goto error; | |
752 | } | |
753 | ||
754 | ret = lttng_dynamic_pointer_array_add_pointer( | |
755 | &res.capture_descriptors, | |
756 | event_expr); | |
757 | if (ret) { | |
758 | goto error; | |
759 | } | |
760 | ||
761 | /* | |
762 | * The ownership of event expression was | |
763 | * transferred to the dynamic array. | |
764 | */ | |
765 | event_expr = NULL; | |
766 | ||
767 | break; | |
768 | } | |
4624dad0 SM |
769 | default: |
770 | abort(); | |
771 | } | |
772 | } else { | |
773 | const struct argpar_item_non_opt *item_non_opt = | |
774 | (const struct argpar_item_non_opt *) | |
775 | item; | |
776 | ||
50ad0862 SM |
777 | /* Don't accept non-option arguments. */ |
778 | ERR("Unexpected argument '%s'", item_non_opt->arg); | |
779 | goto error; | |
4624dad0 SM |
780 | } |
781 | } | |
782 | ||
783 | if (event_rule_type == LTTNG_EVENT_RULE_TYPE_UNKNOWN) { | |
784 | event_rule_type = LTTNG_EVENT_RULE_TYPE_TRACEPOINT; | |
785 | } | |
786 | ||
787 | /* | |
50ad0862 SM |
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 "*". | |
4624dad0 | 791 | */ |
50ad0862 SM |
792 | switch (event_rule_type) { |
793 | case LTTNG_EVENT_RULE_TYPE_TRACEPOINT: | |
794 | case LTTNG_EVENT_RULE_TYPE_SYSCALL: | |
795 | if (!name) { | |
796 | name = strdup("*"); | |
4624dad0 | 797 | } |
50ad0862 | 798 | break; |
4624dad0 | 799 | |
50ad0862 SM |
800 | default: |
801 | if (name) { | |
802 | ERR("Can't use --name with %s event rules.", | |
803 | lttng_event_rule_type_str( | |
804 | event_rule_type)); | |
4624dad0 SM |
805 | goto error; |
806 | } | |
807 | ||
50ad0862 SM |
808 | if (exclude_names) { |
809 | ERR("Can't use --exclude-names/-x with %s event rules.", | |
810 | lttng_event_rule_type_str( | |
811 | event_rule_type)); | |
812 | goto error; | |
813 | } | |
4624dad0 SM |
814 | } |
815 | ||
816 | /* | |
24de704e SM |
817 | * Option --location is only applicable to (and mandatory for) event |
818 | * rules of type {k,u}probe and function. | |
819 | * | |
50ad0862 | 820 | * Option --event-name is only applicable to event rules of type probe. |
24de704e | 821 | * If omitted, it defaults to the location. |
4624dad0 | 822 | */ |
50ad0862 SM |
823 | switch (event_rule_type) { |
824 | case LTTNG_EVENT_RULE_TYPE_KERNEL_PROBE: | |
825 | case LTTNG_EVENT_RULE_TYPE_USERSPACE_PROBE: | |
24de704e SM |
826 | case LTTNG_EVENT_RULE_TYPE_KERNEL_FUNCTION: |
827 | if (!location) { | |
828 | ERR("Event rule of type %s requires a --location.", | |
829 | lttng_event_rule_type_str(event_rule_type)); | |
830 | goto error; | |
831 | } | |
832 | ||
833 | if (!event_name) { | |
834 | event_name = strdup(location); | |
50ad0862 | 835 | } |
4624dad0 | 836 | |
50ad0862 SM |
837 | break; |
838 | ||
839 | default: | |
24de704e SM |
840 | if (location) { |
841 | ERR("Can't use --location with %s event rules.", | |
842 | lttng_event_rule_type_str(event_rule_type)); | |
843 | goto error; | |
844 | } | |
845 | ||
846 | if (event_name) { | |
50ad0862 SM |
847 | ERR("Can't use --event-name with %s event rules.", |
848 | lttng_event_rule_type_str( | |
849 | event_rule_type)); | |
850 | goto error; | |
851 | } | |
4624dad0 SM |
852 | } |
853 | ||
854 | /* | |
855 | * Update *argc and *argv so our caller can keep parsing what follows. | |
856 | */ | |
857 | consumed_args = argpar_state_get_ingested_orig_args(state); | |
858 | assert(consumed_args >= 0); | |
859 | *argc -= consumed_args; | |
860 | *argv += consumed_args; | |
861 | ||
862 | /* Need to specify a domain. */ | |
863 | if (domain_type == LTTNG_DOMAIN_NONE) { | |
64c34630 | 864 | ERR("Please specify a domain (--domain=(kernel,user,jul,log4j,python))."); |
4624dad0 SM |
865 | goto error; |
866 | } | |
867 | ||
868 | /* Validate event rule type against domain. */ | |
869 | switch (event_rule_type) { | |
f2791161 | 870 | case LTTNG_EVENT_RULE_TYPE_KERNEL_PROBE: |
f2d09181 | 871 | case LTTNG_EVENT_RULE_TYPE_KERNEL_FUNCTION: |
1f1567a5 | 872 | case LTTNG_EVENT_RULE_TYPE_USERSPACE_PROBE: |
4624dad0 SM |
873 | case LTTNG_EVENT_RULE_TYPE_SYSCALL: |
874 | if (domain_type != LTTNG_DOMAIN_KERNEL) { | |
875 | ERR("Event type not available for user-space tracing."); | |
876 | goto error; | |
877 | } | |
878 | break; | |
879 | ||
880 | case LTTNG_EVENT_RULE_TYPE_TRACEPOINT: | |
881 | break; | |
882 | ||
883 | default: | |
884 | abort(); | |
885 | } | |
886 | ||
887 | /* | |
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. | |
891 | */ | |
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: | |
896 | break; | |
897 | default: | |
898 | ERR("Filter expressions are not supported for %s event rules.", | |
899 | lttng_event_rule_type_str(event_rule_type)); | |
900 | goto error; | |
901 | } | |
902 | } | |
903 | ||
904 | /* If --exclude/-x was passed, split it into an exclusion list. */ | |
50ad0862 | 905 | if (exclude_names) { |
4624dad0 SM |
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)); | |
909 | goto error; | |
910 | } | |
911 | ||
50ad0862 SM |
912 | if (create_exclusion_list_and_validate(name, |
913 | exclude_names, &exclusion_list) != 0) { | |
4624dad0 SM |
914 | ERR("Failed to create exclusion list."); |
915 | goto error; | |
916 | } | |
917 | } | |
918 | ||
949f049b SM |
919 | if (log_level_str) { |
920 | if (event_rule_type != LTTNG_EVENT_RULE_TYPE_TRACEPOINT) { | |
921 | ERR("Log levels are only applicable to tracepoint event rules."); | |
922 | goto error; | |
923 | } | |
924 | ||
925 | if (domain_type == LTTNG_DOMAIN_KERNEL) { | |
926 | ERR("Log levels are not supported by the kernel tracer."); | |
927 | goto error; | |
928 | } | |
4624dad0 SM |
929 | } |
930 | ||
931 | /* Finally, create the event rule object. */ | |
932 | switch (event_rule_type) { | |
933 | case LTTNG_EVENT_RULE_TYPE_TRACEPOINT: | |
934 | { | |
935 | enum lttng_event_rule_status event_rule_status; | |
936 | ||
20a01d15 SM |
937 | res.er = lttng_event_rule_tracepoint_create(domain_type); |
938 | if (!res.er) { | |
4624dad0 SM |
939 | ERR("Failed to create tracepoint event rule."); |
940 | goto error; | |
941 | } | |
942 | ||
943 | /* Set pattern. */ | |
944 | event_rule_status = lttng_event_rule_tracepoint_set_pattern( | |
50ad0862 | 945 | res.er, name); |
4624dad0 SM |
946 | if (event_rule_status != LTTNG_EVENT_RULE_STATUS_OK) { |
947 | ERR("Failed to set tracepoint event rule's pattern to '%s'.", | |
50ad0862 | 948 | name); |
4624dad0 SM |
949 | goto error; |
950 | } | |
951 | ||
952 | /* Set filter. */ | |
953 | if (filter) { | |
954 | event_rule_status = lttng_event_rule_tracepoint_set_filter( | |
20a01d15 | 955 | res.er, filter); |
4624dad0 SM |
956 | if (event_rule_status != LTTNG_EVENT_RULE_STATUS_OK) { |
957 | ERR("Failed to set tracepoint event rule's filter to '%s'.", | |
958 | filter); | |
959 | goto error; | |
960 | } | |
961 | } | |
962 | ||
963 | /* Set exclusion list. */ | |
964 | if (exclusion_list) { | |
965 | int n; | |
966 | ||
967 | for (n = 0; exclusion_list[n]; n++) { | |
968 | event_rule_status = lttng_event_rule_tracepoint_add_exclusion( | |
20a01d15 | 969 | res.er, |
4624dad0 SM |
970 | exclusion_list[n]); |
971 | if (event_rule_status != | |
972 | LTTNG_EVENT_RULE_STATUS_OK) { | |
973 | ERR("Failed to set tracepoint exclusion list element '%s'", | |
974 | exclusion_list[n]); | |
975 | goto error; | |
976 | } | |
977 | } | |
978 | } | |
979 | ||
949f049b SM |
980 | /* |
981 | * ".." is the same as passing no log level option and | |
982 | * correspond the the "ANY" case. | |
983 | */ | |
984 | if (log_level_str && strcmp(log_level_str, "..") != 0) { | |
985 | int log_level; | |
986 | bool log_level_only; | |
987 | ||
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`.", | |
991 | log_level_str); | |
4624dad0 SM |
992 | goto error; |
993 | } | |
994 | ||
949f049b SM |
995 | if (log_level_only) { |
996 | log_level_rule = lttng_log_level_rule_exactly_create(log_level); | |
4624dad0 | 997 | } else { |
949f049b | 998 | log_level_rule = lttng_log_level_rule_at_least_as_severe_as_create(log_level); |
85b05318 JR |
999 | } |
1000 | ||
1001 | if (log_level_rule == NULL) { | |
1002 | ERR("Failed to create log level rule object."); | |
1003 | goto error; | |
4624dad0 SM |
1004 | } |
1005 | ||
85b05318 JR |
1006 | event_rule_status = |
1007 | lttng_event_rule_tracepoint_set_log_level_rule( | |
1008 | res.er, log_level_rule); | |
1009 | ||
4624dad0 SM |
1010 | if (event_rule_status != LTTNG_EVENT_RULE_STATUS_OK) { |
1011 | ERR("Failed to set log level on event fule."); | |
1012 | goto error; | |
1013 | } | |
1014 | } | |
1015 | ||
1016 | break; | |
1017 | } | |
f2791161 | 1018 | case LTTNG_EVENT_RULE_TYPE_KERNEL_PROBE: |
4624dad0 SM |
1019 | { |
1020 | int ret; | |
1021 | enum lttng_event_rule_status event_rule_status; | |
1022 | ||
50ad0862 | 1023 | ret = parse_kernel_probe_opts( |
24de704e | 1024 | location, &kernel_probe_location); |
4624dad0 SM |
1025 | if (ret) { |
1026 | ERR("Failed to parse kernel probe location."); | |
1027 | goto error; | |
1028 | } | |
1029 | ||
602a6d40 JR |
1030 | assert(kernel_probe_location); |
1031 | res.er = lttng_event_rule_kernel_probe_create(kernel_probe_location); | |
1032 | if (!res.er) { | |
1033 | ERR("Failed to create kprobe event rule."); | |
4624dad0 SM |
1034 | goto error; |
1035 | } | |
1036 | ||
50ad0862 SM |
1037 | event_rule_status = |
1038 | lttng_event_rule_kernel_probe_set_event_name( | |
24de704e | 1039 | res.er, event_name); |
4624dad0 | 1040 | if (event_rule_status != LTTNG_EVENT_RULE_STATUS_OK) { |
50ad0862 | 1041 | ERR("Failed to set kprobe event rule's name to '%s'.", |
24de704e | 1042 | event_name); |
4624dad0 SM |
1043 | goto error; |
1044 | } | |
1045 | ||
1046 | break; | |
1047 | } | |
1f1567a5 | 1048 | case LTTNG_EVENT_RULE_TYPE_USERSPACE_PROBE: |
4624dad0 SM |
1049 | { |
1050 | int ret; | |
1051 | enum lttng_event_rule_status event_rule_status; | |
1052 | ||
1053 | ret = parse_userspace_probe_opts( | |
24de704e | 1054 | location, &userspace_probe_location); |
4624dad0 SM |
1055 | if (ret) { |
1056 | ERR("Failed to parse user space probe location."); | |
1057 | goto error; | |
1058 | } | |
1059 | ||
10685de6 | 1060 | res.er = lttng_event_rule_userspace_probe_create(userspace_probe_location); |
20a01d15 SM |
1061 | if (!res.er) { |
1062 | ERR("Failed to create userspace probe event rule."); | |
4624dad0 SM |
1063 | goto error; |
1064 | } | |
1065 | ||
50ad0862 SM |
1066 | event_rule_status = |
1067 | lttng_event_rule_userspace_probe_set_event_name( | |
24de704e | 1068 | res.er, event_name); |
4624dad0 SM |
1069 | if (event_rule_status != LTTNG_EVENT_RULE_STATUS_OK) { |
1070 | ERR("Failed to set user space probe event rule's name to '%s'.", | |
24de704e | 1071 | event_name); |
4624dad0 SM |
1072 | goto error; |
1073 | } | |
1074 | ||
1075 | break; | |
1076 | } | |
1077 | case LTTNG_EVENT_RULE_TYPE_SYSCALL: | |
1078 | { | |
1079 | enum lttng_event_rule_status event_rule_status; | |
1080 | ||
20a01d15 SM |
1081 | res.er = lttng_event_rule_syscall_create(); |
1082 | if (!res.er) { | |
4624dad0 SM |
1083 | ERR("Failed to create syscall event rule."); |
1084 | goto error; | |
1085 | } | |
1086 | ||
1087 | event_rule_status = lttng_event_rule_syscall_set_pattern( | |
50ad0862 | 1088 | res.er, name); |
4624dad0 SM |
1089 | if (event_rule_status != LTTNG_EVENT_RULE_STATUS_OK) { |
1090 | ERR("Failed to set syscall event rule's pattern to '%s'.", | |
50ad0862 | 1091 | name); |
4624dad0 SM |
1092 | goto error; |
1093 | } | |
1094 | ||
1095 | if (filter) { | |
1096 | event_rule_status = lttng_event_rule_syscall_set_filter( | |
20a01d15 | 1097 | res.er, filter); |
4624dad0 SM |
1098 | if (event_rule_status != LTTNG_EVENT_RULE_STATUS_OK) { |
1099 | ERR("Failed to set syscall event rule's filter to '%s'.", | |
1100 | filter); | |
1101 | goto error; | |
1102 | } | |
1103 | } | |
1104 | ||
1105 | break; | |
1106 | } | |
1107 | default: | |
1108 | abort(); | |
1109 | goto error; | |
1110 | } | |
1111 | ||
1112 | goto end; | |
1113 | ||
1114 | error: | |
20a01d15 SM |
1115 | lttng_event_rule_destroy(res.er); |
1116 | res.er = NULL; | |
1117 | lttng_dynamic_pointer_array_reset(&res.capture_descriptors); | |
4624dad0 SM |
1118 | |
1119 | end: | |
20a01d15 SM |
1120 | if (parser_ctx) { |
1121 | filter_parser_ctx_free(parser_ctx); | |
1122 | } | |
1123 | ||
1124 | lttng_event_expr_destroy(event_expr); | |
4624dad0 SM |
1125 | argpar_item_destroy(item); |
1126 | free(error); | |
1127 | argpar_state_destroy(state); | |
1128 | free(filter); | |
50ad0862 SM |
1129 | free(name); |
1130 | free(exclude_names); | |
949f049b | 1131 | free(log_level_str); |
24de704e SM |
1132 | free(location); |
1133 | free(event_name); | |
50ad0862 | 1134 | |
4624dad0 SM |
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); | |
85b05318 | 1138 | lttng_log_level_rule_destroy(log_level_rule); |
20a01d15 | 1139 | return res; |
4624dad0 SM |
1140 | } |
1141 | ||
1142 | static | |
1143 | struct lttng_condition *handle_condition_event(int *argc, const char ***argv) | |
1144 | { | |
20a01d15 | 1145 | struct parse_event_rule_res res; |
4624dad0 | 1146 | struct lttng_condition *c; |
20a01d15 | 1147 | size_t i; |
4624dad0 | 1148 | |
20a01d15 SM |
1149 | res = parse_event_rule(argc, argv); |
1150 | if (!res.er) { | |
4624dad0 | 1151 | c = NULL; |
20a01d15 | 1152 | goto error; |
4624dad0 SM |
1153 | } |
1154 | ||
d602bd6a | 1155 | c = lttng_condition_on_event_create(res.er); |
20a01d15 SM |
1156 | lttng_event_rule_destroy(res.er); |
1157 | res.er = NULL; | |
4624dad0 | 1158 | if (!c) { |
20a01d15 SM |
1159 | goto error; |
1160 | } | |
1161 | ||
1162 | for (i = 0; i < lttng_dynamic_pointer_array_get_count(&res.capture_descriptors); | |
1163 | i++) { | |
1164 | enum lttng_condition_status status; | |
1165 | struct lttng_event_expr **expr = | |
1166 | lttng_dynamic_array_get_element( | |
1167 | &res.capture_descriptors.array, i); | |
1168 | ||
1169 | assert(expr); | |
1170 | assert(*expr); | |
d602bd6a | 1171 | status = lttng_condition_on_event_append_capture_descriptor( |
20a01d15 SM |
1172 | c, *expr); |
1173 | if (status != LTTNG_CONDITION_STATUS_OK) { | |
81d566c9 JR |
1174 | if (status == LTTNG_CONDITION_STATUS_UNSUPPORTED) { |
1175 | ERR("The capture feature is unsupported by the event-rule condition type"); | |
1176 | } | |
1177 | ||
20a01d15 SM |
1178 | goto error; |
1179 | } | |
1180 | ||
1181 | /* Ownership of event expression moved to `c` */ | |
1182 | *expr = NULL; | |
4624dad0 SM |
1183 | } |
1184 | ||
20a01d15 SM |
1185 | goto end; |
1186 | ||
1187 | error: | |
1188 | lttng_condition_destroy(c); | |
1189 | c = NULL; | |
1190 | ||
4624dad0 | 1191 | end: |
20a01d15 SM |
1192 | lttng_dynamic_pointer_array_reset(&res.capture_descriptors); |
1193 | lttng_event_rule_destroy(res.er); | |
4624dad0 SM |
1194 | return c; |
1195 | } | |
1196 | ||
1197 | static | |
1198 | struct lttng_condition *handle_condition_session_consumed_size(int *argc, const char ***argv) | |
1199 | { | |
1200 | struct lttng_condition *cond = NULL; | |
1201 | struct argpar_state *state = NULL; | |
1202 | struct argpar_item *item = NULL; | |
1203 | const char *threshold_arg = NULL; | |
1204 | const char *session_name_arg = NULL; | |
1205 | uint64_t threshold; | |
1206 | char *error = NULL; | |
1207 | enum lttng_condition_status condition_status; | |
1208 | ||
1209 | state = argpar_state_create(*argc, *argv, event_rule_opt_descrs); | |
1210 | if (!state) { | |
1211 | ERR("Failed to allocate an argpar state."); | |
1212 | goto error; | |
1213 | } | |
1214 | ||
1215 | while (true) { | |
1216 | enum argpar_state_parse_next_status status; | |
1217 | ||
1218 | ARGPAR_ITEM_DESTROY_AND_RESET(item); | |
1219 | status = argpar_state_parse_next(state, &item, &error); | |
1220 | if (status == ARGPAR_STATE_PARSE_NEXT_STATUS_ERROR) { | |
1221 | ERR("%s", error); | |
1222 | goto error; | |
1223 | } else if (status == ARGPAR_STATE_PARSE_NEXT_STATUS_ERROR_UNKNOWN_OPT) { | |
1224 | /* Just stop parsing here. */ | |
1225 | break; | |
1226 | } else if (status == ARGPAR_STATE_PARSE_NEXT_STATUS_END) { | |
1227 | break; | |
1228 | } | |
1229 | ||
1230 | assert(status == ARGPAR_STATE_PARSE_NEXT_STATUS_OK); | |
1231 | ||
1232 | if (item->type == ARGPAR_ITEM_TYPE_OPT) { | |
1233 | const struct argpar_item_opt *item_opt = | |
1234 | (const struct argpar_item_opt *) item; | |
1235 | ||
1236 | switch (item_opt->descr->id) { | |
1237 | default: | |
1238 | abort(); | |
1239 | } | |
1240 | } else { | |
1241 | const struct argpar_item_non_opt *item_non_opt; | |
1242 | ||
1243 | assert(item->type == ARGPAR_ITEM_TYPE_NON_OPT); | |
1244 | ||
1245 | item_non_opt = (const struct argpar_item_non_opt *) item; | |
1246 | ||
1247 | switch (item_non_opt->non_opt_index) { | |
1248 | case 0: | |
1249 | session_name_arg = item_non_opt->arg; | |
1250 | break; | |
1251 | case 1: | |
1252 | threshold_arg = item_non_opt->arg; | |
1253 | break; | |
1254 | default: | |
1255 | ERR("Unexpected argument `%s`.", | |
1256 | item_non_opt->arg); | |
1257 | goto error; | |
1258 | } | |
1259 | } | |
1260 | } | |
1261 | ||
1262 | *argc -= argpar_state_get_ingested_orig_args(state); | |
1263 | *argv += argpar_state_get_ingested_orig_args(state); | |
1264 | ||
1265 | if (!session_name_arg) { | |
1266 | ERR("Missing session name argument."); | |
1267 | goto error; | |
1268 | } | |
1269 | ||
1270 | if (!threshold_arg) { | |
1271 | ERR("Missing threshold argument."); | |
1272 | goto error; | |
1273 | } | |
1274 | ||
1275 | if (utils_parse_size_suffix(threshold_arg, &threshold) != 0) { | |
1276 | ERR("Failed to parse `%s` as a size.", threshold_arg); | |
1277 | goto error; | |
1278 | } | |
1279 | ||
1280 | cond = lttng_condition_session_consumed_size_create(); | |
1281 | if (!cond) { | |
1282 | ERR("Failed to allocate a session consumed size condition."); | |
1283 | goto error; | |
1284 | } | |
1285 | ||
1286 | condition_status = lttng_condition_session_consumed_size_set_session_name( | |
1287 | cond, session_name_arg); | |
1288 | if (condition_status != LTTNG_CONDITION_STATUS_OK) { | |
1289 | ERR("Failed to set session consumed size condition's session name to '%s'.", | |
1290 | session_name_arg); | |
1291 | goto error; | |
1292 | } | |
1293 | ||
1294 | condition_status = lttng_condition_session_consumed_size_set_threshold( | |
1295 | cond, threshold); | |
1296 | if (condition_status != LTTNG_CONDITION_STATUS_OK) { | |
1297 | ERR("Failed to set session consumed size condition threshold."); | |
1298 | goto error; | |
1299 | } | |
1300 | ||
1301 | goto end; | |
1302 | ||
1303 | error: | |
1304 | lttng_condition_destroy(cond); | |
1305 | cond = NULL; | |
1306 | ||
1307 | end: | |
1308 | argpar_state_destroy(state); | |
1309 | argpar_item_destroy(item); | |
1310 | free(error); | |
1311 | return cond; | |
1312 | } | |
1313 | ||
1314 | static | |
1315 | struct lttng_condition *handle_condition_buffer_usage_high(int *argc, const char ***argv) | |
1316 | { | |
1317 | ERR("High buffer usage threshold conditions are unsupported for the moment."); | |
1318 | return NULL; | |
1319 | } | |
1320 | ||
1321 | static | |
1322 | struct lttng_condition *handle_condition_buffer_usage_low(int *argc, const char ***argv) | |
1323 | { | |
1324 | ERR("Low buffer usage threshold conditions are unsupported for the moment."); | |
1325 | return NULL; | |
1326 | } | |
1327 | ||
1328 | static | |
1329 | struct lttng_condition *handle_condition_session_rotation_ongoing(int *argc, const char ***argv) | |
1330 | { | |
1331 | ERR("Session rotation ongoing conditions are unsupported for the moment."); | |
1332 | return NULL; | |
1333 | } | |
1334 | ||
1335 | static | |
1336 | struct lttng_condition *handle_condition_session_rotation_completed(int *argc, const char ***argv) | |
1337 | { | |
1338 | ERR("Session rotation completed conditions are unsupported for the moment."); | |
1339 | return NULL; | |
1340 | } | |
1341 | ||
1342 | struct condition_descr { | |
1343 | const char *name; | |
1344 | struct lttng_condition *(*handler) (int *argc, const char ***argv); | |
1345 | }; | |
1346 | ||
1347 | static const | |
1348 | struct condition_descr condition_descrs[] = { | |
665db063 | 1349 | { "event-rule-matches", handle_condition_event }, |
4624dad0 SM |
1350 | { "on-session-consumed-size", handle_condition_session_consumed_size }, |
1351 | { "on-buffer-usage-high", handle_condition_buffer_usage_high }, | |
1352 | { "on-buffer-usage-low", handle_condition_buffer_usage_low }, | |
1353 | { "on-session-rotation-ongoing", handle_condition_session_rotation_ongoing }, | |
1354 | { "on-session-rotation-completed", handle_condition_session_rotation_completed }, | |
1355 | }; | |
1356 | ||
1357 | static | |
29bcf415 SM |
1358 | struct lttng_condition *parse_condition(const char *condition_name, int *argc, |
1359 | const char ***argv) | |
4624dad0 SM |
1360 | { |
1361 | int i; | |
1362 | struct lttng_condition *cond; | |
4624dad0 SM |
1363 | const struct condition_descr *descr = NULL; |
1364 | ||
4624dad0 SM |
1365 | for (i = 0; i < ARRAY_SIZE(condition_descrs); i++) { |
1366 | if (strcmp(condition_name, condition_descrs[i].name) == 0) { | |
1367 | descr = &condition_descrs[i]; | |
1368 | break; | |
1369 | } | |
1370 | } | |
1371 | ||
1372 | if (!descr) { | |
1373 | ERR("Unknown condition name '%s'", condition_name); | |
1374 | goto error; | |
1375 | } | |
1376 | ||
1377 | cond = descr->handler(argc, argv); | |
1378 | if (!cond) { | |
1379 | /* The handler has already printed an error message. */ | |
1380 | goto error; | |
1381 | } | |
1382 | ||
1383 | goto end; | |
1384 | error: | |
1385 | cond = NULL; | |
1386 | end: | |
1387 | return cond; | |
1388 | } | |
bbadb5e0 JR |
1389 | |
1390 | static struct lttng_rate_policy *parse_rate_policy(const char *policy_str) | |
1391 | { | |
1392 | int num_token; | |
1393 | char **tokens = NULL; | |
1394 | struct lttng_rate_policy *policy = NULL; | |
1395 | enum lttng_rate_policy_type policy_type; | |
1396 | unsigned long long value; | |
1397 | char *policy_type_str; | |
1398 | char *policy_value_str; | |
1399 | ||
1400 | assert(policy_str); | |
1401 | ||
1402 | /* | |
1403 | * rate policy fields are separated by ':'. | |
1404 | */ | |
1405 | tokens = strutils_split(policy_str, ':', 1); | |
1406 | num_token = strutils_array_of_strings_len(tokens); | |
1407 | ||
1408 | /* | |
1409 | * Early sanity check that the number of parameter is exactly 2. | |
1410 | * i.e : type:value | |
1411 | */ | |
1412 | if (num_token != 2) { | |
1413 | ERR("Rate policy format is invalid."); | |
1414 | goto end; | |
1415 | } | |
1416 | ||
1417 | policy_type_str = tokens[0]; | |
1418 | policy_value_str = tokens[1]; | |
1419 | ||
1420 | /* Parse the type. */ | |
1421 | if (strcmp(policy_type_str, "once-after") == 0) { | |
1422 | policy_type = LTTNG_RATE_POLICY_TYPE_ONCE_AFTER_N; | |
1423 | } else if (strcmp(policy_type_str, "every") == 0) { | |
1424 | policy_type = LTTNG_RATE_POLICY_TYPE_EVERY_N; | |
1425 | } else { | |
1426 | ERR("Rate policy type `%s` unknown.", policy_type_str); | |
1427 | goto end; | |
1428 | } | |
1429 | ||
1430 | /* Parse the value. */ | |
1431 | if (utils_parse_unsigned_long_long(policy_value_str, &value) != 0) { | |
1432 | ERR("Failed to parse rate policy value `%s` as an integer.", | |
1433 | policy_value_str); | |
1434 | goto end; | |
1435 | } | |
1436 | ||
1437 | if (value == 0) { | |
1438 | ERR("Rate policy value `%s` must be > 0.", policy_value_str); | |
1439 | goto end; | |
1440 | } | |
1441 | ||
1442 | switch (policy_type) { | |
1443 | case LTTNG_RATE_POLICY_TYPE_EVERY_N: | |
1444 | policy = lttng_rate_policy_every_n_create(value); | |
1445 | break; | |
1446 | case LTTNG_RATE_POLICY_TYPE_ONCE_AFTER_N: | |
1447 | policy = lttng_rate_policy_once_after_n_create(value); | |
1448 | break; | |
1449 | default: | |
1450 | abort(); | |
1451 | } | |
1452 | ||
1453 | if (policy == NULL) { | |
1454 | ERR("Failed to create rate policy `%s`.", policy_str); | |
1455 | } | |
1456 | ||
1457 | end: | |
1458 | strutils_free_null_terminated_array_of_strings(tokens); | |
1459 | return policy; | |
1460 | } | |
1461 | ||
e45dd625 | 1462 | static const struct argpar_opt_descr notify_action_opt_descrs[] = { |
bbadb5e0 | 1463 | { OPT_RATE_POLICY, '\0', "rate-policy", true }, |
e45dd625 JR |
1464 | ARGPAR_OPT_DESCR_SENTINEL |
1465 | }; | |
4624dad0 | 1466 | |
4624dad0 SM |
1467 | static |
1468 | struct lttng_action *handle_action_notify(int *argc, const char ***argv) | |
1469 | { | |
e45dd625 JR |
1470 | struct lttng_action *action = NULL; |
1471 | struct argpar_state *state = NULL; | |
1472 | struct argpar_item *item = NULL; | |
1473 | char *error = NULL; | |
7f4d5b07 | 1474 | struct lttng_rate_policy *policy = NULL; |
4624dad0 | 1475 | |
e45dd625 JR |
1476 | state = argpar_state_create(*argc, *argv, notify_action_opt_descrs); |
1477 | if (!state) { | |
1478 | ERR("Failed to allocate an argpar state."); | |
1479 | goto error; | |
1480 | } | |
1481 | ||
1482 | while (true) { | |
1483 | enum argpar_state_parse_next_status status; | |
1484 | ||
1485 | ARGPAR_ITEM_DESTROY_AND_RESET(item); | |
1486 | status = argpar_state_parse_next(state, &item, &error); | |
1487 | if (status == ARGPAR_STATE_PARSE_NEXT_STATUS_ERROR) { | |
1488 | ERR("%s", error); | |
1489 | goto error; | |
1490 | } else if (status == ARGPAR_STATE_PARSE_NEXT_STATUS_ERROR_UNKNOWN_OPT) { | |
1491 | /* Just stop parsing here. */ | |
1492 | break; | |
1493 | } else if (status == ARGPAR_STATE_PARSE_NEXT_STATUS_END) { | |
1494 | break; | |
1495 | } | |
1496 | ||
1497 | assert(status == ARGPAR_STATE_PARSE_NEXT_STATUS_OK); | |
1498 | ||
1499 | if (item->type == ARGPAR_ITEM_TYPE_OPT) { | |
1500 | const struct argpar_item_opt *item_opt = | |
1501 | (const struct argpar_item_opt *) item; | |
1502 | ||
1503 | switch (item_opt->descr->id) { | |
bbadb5e0 | 1504 | case OPT_RATE_POLICY: |
e45dd625 | 1505 | { |
bbadb5e0 JR |
1506 | policy = parse_rate_policy(item_opt->arg); |
1507 | if (!policy) { | |
e45dd625 JR |
1508 | goto error; |
1509 | } | |
e45dd625 JR |
1510 | break; |
1511 | } | |
e45dd625 JR |
1512 | default: |
1513 | abort(); | |
1514 | } | |
1515 | } else { | |
1516 | const struct argpar_item_non_opt *item_non_opt; | |
1517 | ||
1518 | assert(item->type == ARGPAR_ITEM_TYPE_NON_OPT); | |
1519 | ||
1520 | item_non_opt = (const struct argpar_item_non_opt *) item; | |
1521 | ||
1522 | switch (item_non_opt->non_opt_index) { | |
1523 | default: | |
1524 | ERR("Unexpected argument `%s`.", | |
1525 | item_non_opt->arg); | |
1526 | goto error; | |
1527 | } | |
1528 | } | |
1529 | } | |
1530 | ||
1531 | *argc -= argpar_state_get_ingested_orig_args(state); | |
1532 | *argv += argpar_state_get_ingested_orig_args(state); | |
1533 | ||
e45dd625 JR |
1534 | action = lttng_action_notify_create(); |
1535 | if (!action) { | |
1536 | ERR("Failed to create notify action"); | |
1537 | goto error; | |
1538 | } | |
1539 | ||
1540 | if (policy) { | |
1541 | enum lttng_action_status status; | |
7f4d5b07 | 1542 | status = lttng_action_notify_set_rate_policy(action, policy); |
e45dd625 | 1543 | if (status != LTTNG_ACTION_STATUS_OK) { |
7f4d5b07 | 1544 | ERR("Failed to set rate policy"); |
e45dd625 JR |
1545 | goto error; |
1546 | } | |
1547 | } | |
1548 | ||
1549 | goto end; | |
1550 | ||
1551 | error: | |
1552 | lttng_action_destroy(action); | |
1553 | action = NULL; | |
e45dd625 | 1554 | end: |
55c6294d | 1555 | free(error); |
7f4d5b07 | 1556 | lttng_rate_policy_destroy(policy); |
e45dd625 JR |
1557 | argpar_state_destroy(state); |
1558 | argpar_item_destroy(item); | |
1559 | return action; | |
1560 | } | |
4624dad0 SM |
1561 | |
1562 | /* | |
e45dd625 | 1563 | * Generic handler for a kind of action that takes a session name and an |
7f4d5b07 | 1564 | * optional rate policy. |
4624dad0 SM |
1565 | */ |
1566 | ||
e45dd625 JR |
1567 | static struct lttng_action *handle_action_simple_session_with_policy(int *argc, |
1568 | const char ***argv, | |
4624dad0 | 1569 | struct lttng_action *(*create_action_cb)(void), |
e45dd625 JR |
1570 | enum lttng_action_status (*set_session_name_cb)( |
1571 | struct lttng_action *, const char *), | |
7f4d5b07 | 1572 | enum lttng_action_status (*set_rate_policy_cb)( |
e45dd625 | 1573 | struct lttng_action *, |
7f4d5b07 | 1574 | const struct lttng_rate_policy *), |
4624dad0 SM |
1575 | const char *action_name) |
1576 | { | |
1577 | struct lttng_action *action = NULL; | |
1578 | struct argpar_state *state = NULL; | |
1579 | struct argpar_item *item = NULL; | |
1580 | const char *session_name_arg = NULL; | |
1581 | char *error = NULL; | |
1582 | enum lttng_action_status action_status; | |
7f4d5b07 | 1583 | struct lttng_rate_policy *policy = NULL; |
e45dd625 JR |
1584 | |
1585 | assert(set_session_name_cb); | |
7f4d5b07 | 1586 | assert(set_rate_policy_cb); |
e45dd625 | 1587 | |
7f4d5b07 | 1588 | const struct argpar_opt_descr rate_policy_opt_descrs[] = { |
bbadb5e0 | 1589 | { OPT_RATE_POLICY, '\0', "rate-policy", true }, |
e45dd625 JR |
1590 | ARGPAR_OPT_DESCR_SENTINEL |
1591 | }; | |
1592 | ||
7f4d5b07 | 1593 | state = argpar_state_create(*argc, *argv, rate_policy_opt_descrs); |
4624dad0 SM |
1594 | if (!state) { |
1595 | ERR("Failed to allocate an argpar state."); | |
1596 | goto error; | |
1597 | } | |
1598 | ||
1599 | while (true) { | |
1600 | enum argpar_state_parse_next_status status; | |
4624dad0 SM |
1601 | |
1602 | ARGPAR_ITEM_DESTROY_AND_RESET(item); | |
1603 | status = argpar_state_parse_next(state, &item, &error); | |
1604 | if (status == ARGPAR_STATE_PARSE_NEXT_STATUS_ERROR) { | |
1605 | ERR("%s", error); | |
1606 | goto error; | |
e45dd625 JR |
1607 | } else if (status == |
1608 | ARGPAR_STATE_PARSE_NEXT_STATUS_ERROR_UNKNOWN_OPT) { | |
4624dad0 SM |
1609 | /* Just stop parsing here. */ |
1610 | break; | |
1611 | } else if (status == ARGPAR_STATE_PARSE_NEXT_STATUS_END) { | |
1612 | break; | |
1613 | } | |
1614 | ||
1615 | assert(status == ARGPAR_STATE_PARSE_NEXT_STATUS_OK); | |
e45dd625 JR |
1616 | if (item->type == ARGPAR_ITEM_TYPE_OPT) { |
1617 | const struct argpar_item_opt *item_opt = | |
1618 | (const struct argpar_item_opt *) item; | |
4624dad0 | 1619 | |
e45dd625 | 1620 | switch (item_opt->descr->id) { |
bbadb5e0 | 1621 | case OPT_RATE_POLICY: |
e45dd625 | 1622 | { |
bbadb5e0 JR |
1623 | policy = parse_rate_policy(item_opt->arg); |
1624 | if (!policy) { | |
e45dd625 JR |
1625 | goto error; |
1626 | } | |
e45dd625 JR |
1627 | break; |
1628 | } | |
e45dd625 JR |
1629 | default: |
1630 | abort(); | |
1631 | } | |
1632 | } else { | |
1633 | const struct argpar_item_non_opt *item_non_opt; | |
1634 | item_non_opt = (const struct argpar_item_non_opt *) item; | |
1635 | ||
1636 | switch (item_non_opt->non_opt_index) { | |
1637 | case 0: | |
1638 | session_name_arg = item_non_opt->arg; | |
1639 | break; | |
1640 | default: | |
1641 | ERR("Unexpected argument `%s`.", | |
1642 | item_non_opt->arg); | |
1643 | goto error; | |
1644 | } | |
4624dad0 SM |
1645 | } |
1646 | } | |
1647 | ||
1648 | *argc -= argpar_state_get_ingested_orig_args(state); | |
1649 | *argv += argpar_state_get_ingested_orig_args(state); | |
1650 | ||
1651 | if (!session_name_arg) { | |
1652 | ERR("Missing session name."); | |
1653 | goto error; | |
1654 | } | |
1655 | ||
1656 | action = create_action_cb(); | |
1657 | if (!action) { | |
1658 | ERR("Failed to allocate %s session action.", action_name); | |
1659 | goto error; | |
1660 | } | |
1661 | ||
1662 | action_status = set_session_name_cb(action, session_name_arg); | |
1663 | if (action_status != LTTNG_ACTION_STATUS_OK) { | |
1664 | ERR("Failed to set action %s session's session name to '%s'.", | |
1665 | action_name, session_name_arg); | |
1666 | goto error; | |
1667 | } | |
1668 | ||
e45dd625 | 1669 | if (policy) { |
7f4d5b07 | 1670 | action_status = set_rate_policy_cb(action, policy); |
e45dd625 | 1671 | if (action_status != LTTNG_ACTION_STATUS_OK) { |
7f4d5b07 | 1672 | ERR("Failed to set rate policy"); |
e45dd625 JR |
1673 | goto error; |
1674 | } | |
1675 | } | |
1676 | ||
4624dad0 SM |
1677 | goto end; |
1678 | ||
1679 | error: | |
1680 | lttng_action_destroy(action); | |
1681 | action = NULL; | |
97abbc84 | 1682 | argpar_item_destroy(item); |
4624dad0 | 1683 | end: |
7f4d5b07 | 1684 | lttng_rate_policy_destroy(policy); |
cb1b81ea | 1685 | free(error); |
b78ef509 | 1686 | argpar_state_destroy(state); |
4624dad0 SM |
1687 | return action; |
1688 | } | |
1689 | ||
1690 | static | |
1691 | struct lttng_action *handle_action_start_session(int *argc, | |
1692 | const char ***argv) | |
1693 | { | |
e45dd625 JR |
1694 | return handle_action_simple_session_with_policy(argc, argv, |
1695 | lttng_action_start_session_create, | |
1696 | lttng_action_start_session_set_session_name, | |
7f4d5b07 | 1697 | lttng_action_start_session_set_rate_policy, "start"); |
4624dad0 SM |
1698 | } |
1699 | ||
1700 | static | |
1701 | struct lttng_action *handle_action_stop_session(int *argc, | |
1702 | const char ***argv) | |
1703 | { | |
e45dd625 JR |
1704 | return handle_action_simple_session_with_policy(argc, argv, |
1705 | lttng_action_stop_session_create, | |
1706 | lttng_action_stop_session_set_session_name, | |
7f4d5b07 | 1707 | lttng_action_stop_session_set_rate_policy, "stop"); |
4624dad0 SM |
1708 | } |
1709 | ||
1710 | static | |
1711 | struct lttng_action *handle_action_rotate_session(int *argc, | |
1712 | const char ***argv) | |
1713 | { | |
e45dd625 | 1714 | return handle_action_simple_session_with_policy(argc, argv, |
4624dad0 SM |
1715 | lttng_action_rotate_session_create, |
1716 | lttng_action_rotate_session_set_session_name, | |
7f4d5b07 | 1717 | lttng_action_rotate_session_set_rate_policy, |
4624dad0 SM |
1718 | "rotate"); |
1719 | } | |
1720 | ||
1721 | static const struct argpar_opt_descr snapshot_action_opt_descrs[] = { | |
1722 | { OPT_NAME, 'n', "name", true }, | |
1723 | { OPT_MAX_SIZE, 'm', "max-size", true }, | |
1724 | { OPT_CTRL_URL, '\0', "ctrl-url", true }, | |
1725 | { OPT_DATA_URL, '\0', "data-url", true }, | |
1726 | { OPT_URL, '\0', "url", true }, | |
1727 | { OPT_PATH, '\0', "path", true }, | |
bbadb5e0 | 1728 | { OPT_RATE_POLICY, '\0', "rate-policy", true }, |
4624dad0 SM |
1729 | ARGPAR_OPT_DESCR_SENTINEL |
1730 | }; | |
1731 | ||
1732 | static | |
1733 | struct lttng_action *handle_action_snapshot_session(int *argc, | |
1734 | const char ***argv) | |
1735 | { | |
1736 | struct lttng_action *action = NULL; | |
1737 | struct argpar_state *state = NULL; | |
1738 | struct argpar_item *item = NULL; | |
1739 | const char *session_name_arg = NULL; | |
1740 | char *snapshot_name_arg = NULL; | |
1741 | char *ctrl_url_arg = NULL; | |
1742 | char *data_url_arg = NULL; | |
1743 | char *max_size_arg = NULL; | |
1744 | char *url_arg = NULL; | |
1745 | char *path_arg = NULL; | |
1746 | char *error = NULL; | |
1747 | enum lttng_action_status action_status; | |
1748 | struct lttng_snapshot_output *snapshot_output = NULL; | |
7f4d5b07 | 1749 | struct lttng_rate_policy *policy = NULL; |
4624dad0 SM |
1750 | int ret; |
1751 | unsigned int locations_specified = 0; | |
1752 | ||
1753 | state = argpar_state_create(*argc, *argv, snapshot_action_opt_descrs); | |
1754 | if (!state) { | |
1755 | ERR("Failed to allocate an argpar state."); | |
1756 | goto error; | |
1757 | } | |
1758 | ||
1759 | while (true) { | |
1760 | enum argpar_state_parse_next_status status; | |
1761 | ||
1762 | ARGPAR_ITEM_DESTROY_AND_RESET(item); | |
1763 | status = argpar_state_parse_next(state, &item, &error); | |
1764 | if (status == ARGPAR_STATE_PARSE_NEXT_STATUS_ERROR) { | |
1765 | ERR("%s", error); | |
1766 | goto error; | |
1767 | } else if (status == ARGPAR_STATE_PARSE_NEXT_STATUS_ERROR_UNKNOWN_OPT) { | |
1768 | /* Just stop parsing here. */ | |
1769 | break; | |
1770 | } else if (status == ARGPAR_STATE_PARSE_NEXT_STATUS_END) { | |
1771 | break; | |
1772 | } | |
1773 | ||
1774 | assert(status == ARGPAR_STATE_PARSE_NEXT_STATUS_OK); | |
1775 | ||
1776 | if (item->type == ARGPAR_ITEM_TYPE_OPT) { | |
1777 | const struct argpar_item_opt *item_opt = | |
1778 | (const struct argpar_item_opt *) item; | |
1779 | ||
1780 | switch (item_opt->descr->id) { | |
1781 | case OPT_NAME: | |
1782 | if (!assign_string(&snapshot_name_arg, item_opt->arg, "--name/-n")) { | |
1783 | goto error; | |
1784 | } | |
1785 | ||
1786 | break; | |
1787 | case OPT_MAX_SIZE: | |
1788 | if (!assign_string(&max_size_arg, item_opt->arg, "--max-size/-m")) { | |
1789 | goto error; | |
1790 | } | |
1791 | ||
1792 | break; | |
1793 | case OPT_CTRL_URL: | |
1794 | if (!assign_string(&ctrl_url_arg, item_opt->arg, "--ctrl-url")) { | |
1795 | goto error; | |
1796 | } | |
1797 | ||
1798 | break; | |
1799 | case OPT_DATA_URL: | |
1800 | if (!assign_string(&data_url_arg, item_opt->arg, "--data-url")) { | |
1801 | goto error; | |
1802 | } | |
1803 | ||
1804 | break; | |
1805 | case OPT_URL: | |
1806 | if (!assign_string(&url_arg, item_opt->arg, "--url")) { | |
1807 | goto error; | |
1808 | } | |
1809 | ||
1810 | break; | |
1811 | case OPT_PATH: | |
1812 | if (!assign_string(&path_arg, item_opt->arg, "--path")) { | |
1813 | goto error; | |
1814 | } | |
1815 | ||
1816 | break; | |
bbadb5e0 | 1817 | case OPT_RATE_POLICY: |
e45dd625 | 1818 | { |
bbadb5e0 JR |
1819 | policy = parse_rate_policy(item_opt->arg); |
1820 | if (!policy) { | |
e45dd625 JR |
1821 | goto error; |
1822 | } | |
e45dd625 JR |
1823 | break; |
1824 | } | |
4624dad0 SM |
1825 | default: |
1826 | abort(); | |
1827 | } | |
1828 | } else { | |
1829 | const struct argpar_item_non_opt *item_non_opt; | |
1830 | ||
1831 | assert(item->type == ARGPAR_ITEM_TYPE_NON_OPT); | |
1832 | ||
1833 | item_non_opt = (const struct argpar_item_non_opt *) item; | |
1834 | ||
1835 | switch (item_non_opt->non_opt_index) { | |
1836 | case 0: | |
1837 | session_name_arg = item_non_opt->arg; | |
1838 | break; | |
1839 | default: | |
1840 | ERR("Unexpected argument `%s`.", | |
1841 | item_non_opt->arg); | |
1842 | goto error; | |
1843 | } | |
1844 | } | |
1845 | } | |
1846 | ||
1847 | *argc -= argpar_state_get_ingested_orig_args(state); | |
1848 | *argv += argpar_state_get_ingested_orig_args(state); | |
1849 | ||
1850 | if (!session_name_arg) { | |
1851 | ERR("Missing session name."); | |
1852 | goto error; | |
1853 | } | |
1854 | ||
1855 | /* --ctrl-url and --data-url must come in pair. */ | |
1856 | if (ctrl_url_arg && !data_url_arg) { | |
1857 | ERR("--ctrl-url is specified, but --data-url is missing."); | |
1858 | goto error; | |
1859 | } | |
1860 | ||
1861 | if (!ctrl_url_arg && data_url_arg) { | |
1862 | ERR("--data-url is specified, but --ctrl-url is missing."); | |
1863 | goto error; | |
1864 | } | |
1865 | ||
1866 | locations_specified += !!(ctrl_url_arg || data_url_arg); | |
1867 | locations_specified += !!url_arg; | |
1868 | locations_specified += !!path_arg; | |
1869 | ||
1870 | /* --ctrl-url/--data-url, --url and --path are mutually exclusive. */ | |
1871 | if (locations_specified > 1) { | |
1872 | ERR("The --ctrl-url/--data-url, --url, and --path options can't be used together."); | |
1873 | goto error; | |
1874 | } | |
1875 | ||
1876 | /* | |
1877 | * Did the user specify an option that implies using a | |
1878 | * custom/unregistered output? | |
1879 | */ | |
1880 | if (url_arg || ctrl_url_arg || path_arg) { | |
1881 | snapshot_output = lttng_snapshot_output_create(); | |
1882 | if (!snapshot_output) { | |
1883 | ERR("Failed to allocate a snapshot output."); | |
1884 | goto error; | |
1885 | } | |
1886 | } | |
1887 | ||
1888 | action = lttng_action_snapshot_session_create(); | |
1889 | if (!action) { | |
1890 | ERR("Failed to allocate snapshot session action."); | |
1891 | goto error; | |
1892 | } | |
1893 | ||
1894 | action_status = lttng_action_snapshot_session_set_session_name( | |
1895 | action, session_name_arg); | |
1896 | if (action_status != LTTNG_ACTION_STATUS_OK) { | |
1897 | ERR("Failed to set action snapshot session's session name to '%s'.", | |
1898 | session_name_arg); | |
1899 | goto error; | |
1900 | } | |
1901 | ||
1902 | if (snapshot_name_arg) { | |
1903 | if (!snapshot_output) { | |
1904 | ERR("Can't provide a snapshot output name without a snapshot output destination."); | |
1905 | goto error; | |
1906 | } | |
1907 | ||
1908 | ret = lttng_snapshot_output_set_name( | |
1909 | snapshot_name_arg, snapshot_output); | |
1910 | if (ret != 0) { | |
1911 | ERR("Failed to set name of snapshot output."); | |
1912 | goto error; | |
1913 | } | |
1914 | } | |
1915 | ||
1916 | if (max_size_arg) { | |
1917 | uint64_t max_size; | |
1918 | ||
1919 | if (!snapshot_output) { | |
1920 | ERR("Can't provide a snapshot output max size without a snapshot output destination."); | |
1921 | goto error; | |
1922 | } | |
1923 | ||
1924 | ret = utils_parse_size_suffix(max_size_arg, &max_size); | |
1925 | if (ret != 0) { | |
1926 | ERR("Failed to parse `%s` as a size.", max_size_arg); | |
1927 | goto error; | |
1928 | } | |
1929 | ||
1930 | ret = lttng_snapshot_output_set_size(max_size, snapshot_output); | |
1931 | if (ret != 0) { | |
1932 | ERR("Failed to set snapshot output's max size to %" PRIu64 " bytes.", | |
1933 | max_size); | |
1934 | goto error; | |
1935 | } | |
1936 | } | |
1937 | ||
1938 | if (url_arg) { | |
1939 | int num_uris; | |
1940 | struct lttng_uri *uris; | |
1941 | ||
1942 | if (!strstr(url_arg, "://")) { | |
1943 | ERR("Failed to parse '%s' as an URL.", url_arg); | |
1944 | goto error; | |
1945 | } | |
1946 | ||
1947 | num_uris = uri_parse_str_urls(url_arg, NULL, &uris); | |
1948 | if (num_uris < 1) { | |
1949 | ERR("Failed to parse '%s' as an URL.", url_arg); | |
1950 | goto error; | |
1951 | } | |
1952 | ||
1953 | if (uris[0].dtype == LTTNG_DST_PATH) { | |
1954 | ret = lttng_snapshot_output_set_local_path( | |
1955 | uris[0].dst.path, snapshot_output); | |
1956 | free(uris); | |
1957 | if (ret != 0) { | |
1958 | ERR("Failed to assign '%s' as a local destination.", | |
1959 | url_arg); | |
1960 | goto error; | |
1961 | } | |
1962 | } else { | |
1963 | ret = lttng_snapshot_output_set_network_url( | |
1964 | url_arg, snapshot_output); | |
1965 | free(uris); | |
1966 | if (ret != 0) { | |
1967 | ERR("Failed to assign '%s' as a network URL.", | |
1968 | url_arg); | |
1969 | goto error; | |
1970 | } | |
1971 | } | |
1972 | } | |
1973 | ||
1974 | if (path_arg) { | |
1975 | ret = lttng_snapshot_output_set_local_path( | |
1976 | path_arg, snapshot_output); | |
1977 | if (ret != 0) { | |
1978 | ERR("Failed to parse '%s' as a local path.", path_arg); | |
1979 | goto error; | |
1980 | } | |
1981 | } | |
1982 | ||
1983 | if (ctrl_url_arg) { | |
1984 | /* | |
1985 | * Two argument form, network output with separate control and | |
1986 | * data URLs. | |
1987 | */ | |
1988 | ret = lttng_snapshot_output_set_network_urls( | |
1989 | ctrl_url_arg, data_url_arg, snapshot_output); | |
1990 | if (ret != 0) { | |
1991 | ERR("Failed to parse `%s` and `%s` as control and data URLs.", | |
1992 | ctrl_url_arg, data_url_arg); | |
1993 | goto error; | |
1994 | } | |
1995 | } | |
1996 | ||
1997 | if (snapshot_output) { | |
1998 | action_status = lttng_action_snapshot_session_set_output( | |
1999 | action, snapshot_output); | |
2000 | if (action_status != LTTNG_ACTION_STATUS_OK) { | |
2001 | ERR("Failed to set snapshot session action's output."); | |
2002 | goto error; | |
2003 | } | |
2004 | ||
2005 | /* Ownership of `snapshot_output` has been transferred to the action. */ | |
2006 | snapshot_output = NULL; | |
2007 | } | |
2008 | ||
e45dd625 JR |
2009 | if (policy) { |
2010 | enum lttng_action_status status; | |
7f4d5b07 | 2011 | status = lttng_action_snapshot_session_set_rate_policy( |
e45dd625 JR |
2012 | action, policy); |
2013 | if (status != LTTNG_ACTION_STATUS_OK) { | |
7f4d5b07 | 2014 | ERR("Failed to set rate policy"); |
e45dd625 JR |
2015 | goto error; |
2016 | } | |
2017 | } | |
2018 | ||
4624dad0 SM |
2019 | goto end; |
2020 | ||
2021 | error: | |
2022 | lttng_action_destroy(action); | |
2023 | action = NULL; | |
2024 | free(error); | |
2025 | end: | |
2026 | free(snapshot_name_arg); | |
2027 | free(path_arg); | |
2028 | free(url_arg); | |
2029 | free(ctrl_url_arg); | |
2030 | free(data_url_arg); | |
2031 | free(snapshot_output); | |
f6b73530 | 2032 | free(max_size_arg); |
7f4d5b07 | 2033 | lttng_rate_policy_destroy(policy); |
4624dad0 | 2034 | argpar_state_destroy(state); |
97abbc84 | 2035 | argpar_item_destroy(item); |
4624dad0 SM |
2036 | return action; |
2037 | } | |
2038 | ||
2039 | struct action_descr { | |
2040 | const char *name; | |
2041 | struct lttng_action *(*handler) (int *argc, const char ***argv); | |
2042 | }; | |
2043 | ||
2044 | static const | |
2045 | struct action_descr action_descrs[] = { | |
2046 | { "notify", handle_action_notify }, | |
2047 | { "start-session", handle_action_start_session }, | |
2048 | { "stop-session", handle_action_stop_session }, | |
2049 | { "rotate-session", handle_action_rotate_session }, | |
2050 | { "snapshot-session", handle_action_snapshot_session }, | |
2051 | }; | |
2052 | ||
2053 | static | |
29bcf415 | 2054 | struct lttng_action *parse_action(const char *action_name, int *argc, const char ***argv) |
4624dad0 SM |
2055 | { |
2056 | int i; | |
2057 | struct lttng_action *action; | |
4624dad0 SM |
2058 | const struct action_descr *descr = NULL; |
2059 | ||
4624dad0 SM |
2060 | for (i = 0; i < ARRAY_SIZE(action_descrs); i++) { |
2061 | if (strcmp(action_name, action_descrs[i].name) == 0) { | |
2062 | descr = &action_descrs[i]; | |
2063 | break; | |
2064 | } | |
2065 | } | |
2066 | ||
2067 | if (!descr) { | |
2068 | ERR("Unknown action name: %s", action_name); | |
2069 | goto error; | |
2070 | } | |
2071 | ||
2072 | action = descr->handler(argc, argv); | |
2073 | if (!action) { | |
2074 | /* The handler has already printed an error message. */ | |
2075 | goto error; | |
2076 | } | |
2077 | ||
2078 | goto end; | |
2079 | error: | |
2080 | action = NULL; | |
2081 | end: | |
2082 | return action; | |
2083 | } | |
2084 | ||
2085 | static const | |
2086 | struct argpar_opt_descr add_trigger_options[] = { | |
2087 | { OPT_HELP, 'h', "help", false }, | |
2088 | { OPT_LIST_OPTIONS, '\0', "list-options", false }, | |
29bcf415 SM |
2089 | { OPT_CONDITION, '\0', "condition", true }, |
2090 | { OPT_ACTION, '\0', "action", true }, | |
1d4b59f2 | 2091 | { OPT_NAME, '\0', "name", true }, |
4624dad0 SM |
2092 | { OPT_USER_ID, '\0', "user-id", true }, |
2093 | ARGPAR_OPT_DESCR_SENTINEL, | |
2094 | }; | |
2095 | ||
2096 | static | |
2097 | void lttng_actions_destructor(void *p) | |
2098 | { | |
2099 | struct lttng_action *action = p; | |
2100 | ||
2101 | lttng_action_destroy(action); | |
2102 | } | |
2103 | ||
2104 | int cmd_add_trigger(int argc, const char **argv) | |
2105 | { | |
2106 | int ret; | |
2107 | int my_argc = argc - 1; | |
2108 | const char **my_argv = argv + 1; | |
2109 | struct lttng_condition *condition = NULL; | |
2110 | struct lttng_dynamic_pointer_array actions; | |
2111 | struct argpar_state *argpar_state = NULL; | |
2112 | struct argpar_item *argpar_item = NULL; | |
2113 | struct lttng_action *action_group = NULL; | |
2114 | struct lttng_action *action = NULL; | |
2115 | struct lttng_trigger *trigger = NULL; | |
2116 | char *error = NULL; | |
1d4b59f2 | 2117 | char *name = NULL; |
4624dad0 | 2118 | int i; |
4624dad0 SM |
2119 | char *user_id = NULL; |
2120 | ||
2121 | lttng_dynamic_pointer_array_init(&actions, lttng_actions_destructor); | |
2122 | ||
2123 | while (true) { | |
2124 | enum argpar_state_parse_next_status status; | |
2125 | const struct argpar_item_opt *item_opt; | |
2126 | int ingested_args; | |
2127 | ||
2128 | argpar_state_destroy(argpar_state); | |
2129 | argpar_state = argpar_state_create(my_argc, my_argv, | |
2130 | add_trigger_options); | |
2131 | if (!argpar_state) { | |
2132 | ERR("Failed to create argpar state."); | |
2133 | goto error; | |
2134 | } | |
2135 | ||
2136 | ARGPAR_ITEM_DESTROY_AND_RESET(argpar_item); | |
2137 | status = argpar_state_parse_next(argpar_state, &argpar_item, &error); | |
2138 | if (status == ARGPAR_STATE_PARSE_NEXT_STATUS_ERROR) { | |
2139 | ERR("%s", error); | |
2140 | goto error; | |
2141 | } else if (status == ARGPAR_STATE_PARSE_NEXT_STATUS_ERROR_UNKNOWN_OPT) { | |
2142 | ERR("%s", error); | |
2143 | goto error; | |
2144 | } else if (status == ARGPAR_STATE_PARSE_NEXT_STATUS_END) { | |
2145 | break; | |
2146 | } | |
2147 | ||
2148 | assert(status == ARGPAR_STATE_PARSE_NEXT_STATUS_OK); | |
2149 | ||
2150 | if (argpar_item->type == ARGPAR_ITEM_TYPE_NON_OPT) { | |
2151 | const struct argpar_item_non_opt *item_non_opt = | |
2152 | (const struct argpar_item_non_opt *) | |
2153 | argpar_item; | |
2154 | ||
2155 | ERR("Unexpected argument `%s`.", item_non_opt->arg); | |
2156 | goto error; | |
2157 | } | |
2158 | ||
2159 | item_opt = (const struct argpar_item_opt *) argpar_item; | |
2160 | ||
2161 | ingested_args = argpar_state_get_ingested_orig_args( | |
2162 | argpar_state); | |
2163 | ||
2164 | my_argc -= ingested_args; | |
2165 | my_argv += ingested_args; | |
2166 | ||
2167 | switch (item_opt->descr->id) { | |
2168 | case OPT_HELP: | |
2169 | SHOW_HELP(); | |
2170 | ret = 0; | |
2171 | goto end; | |
2172 | case OPT_LIST_OPTIONS: | |
2173 | list_cmd_options_argpar(stdout, add_trigger_options); | |
2174 | ret = 0; | |
2175 | goto end; | |
2176 | case OPT_CONDITION: | |
2177 | { | |
2178 | if (condition) { | |
2179 | ERR("A --condition was already given."); | |
2180 | goto error; | |
2181 | } | |
2182 | ||
29bcf415 | 2183 | condition = parse_condition(item_opt->arg, &my_argc, &my_argv); |
4624dad0 SM |
2184 | if (!condition) { |
2185 | /* | |
2186 | * An error message was already printed by | |
2187 | * parse_condition. | |
2188 | */ | |
2189 | goto error; | |
2190 | } | |
2191 | ||
2192 | break; | |
2193 | } | |
2194 | case OPT_ACTION: | |
2195 | { | |
29bcf415 | 2196 | action = parse_action(item_opt->arg, &my_argc, &my_argv); |
4624dad0 SM |
2197 | if (!action) { |
2198 | /* | |
2199 | * An error message was already printed by | |
2200 | * parse_condition. | |
2201 | */ | |
2202 | goto error; | |
2203 | } | |
2204 | ||
2205 | ret = lttng_dynamic_pointer_array_add_pointer( | |
2206 | &actions, action); | |
2207 | if (ret) { | |
2208 | ERR("Failed to add pointer to pointer array."); | |
2209 | goto error; | |
2210 | } | |
2211 | ||
2212 | /* Ownership of the action was transferred to the group. */ | |
2213 | action = NULL; | |
2214 | ||
2215 | break; | |
2216 | } | |
1d4b59f2 | 2217 | case OPT_NAME: |
4624dad0 | 2218 | { |
1d4b59f2 | 2219 | if (!assign_string(&name, item_opt->arg, "--name")) { |
4624dad0 SM |
2220 | goto error; |
2221 | } | |
2222 | ||
2223 | break; | |
2224 | } | |
4624dad0 SM |
2225 | case OPT_USER_ID: |
2226 | { | |
2227 | if (!assign_string(&user_id, item_opt->arg, | |
2228 | "--user-id")) { | |
2229 | goto error; | |
2230 | } | |
2231 | ||
2232 | break; | |
2233 | } | |
2234 | default: | |
2235 | abort(); | |
2236 | } | |
2237 | } | |
2238 | ||
2239 | if (!condition) { | |
2240 | ERR("Missing --condition."); | |
2241 | goto error; | |
2242 | } | |
2243 | ||
2244 | if (lttng_dynamic_pointer_array_get_count(&actions) == 0) { | |
2245 | ERR("Need at least one --action."); | |
2246 | goto error; | |
2247 | } | |
2248 | ||
4624dad0 SM |
2249 | action_group = lttng_action_group_create(); |
2250 | if (!action_group) { | |
2251 | goto error; | |
2252 | } | |
2253 | ||
2254 | for (i = 0; i < lttng_dynamic_pointer_array_get_count(&actions); i++) { | |
2255 | enum lttng_action_status status; | |
2256 | ||
2257 | action = lttng_dynamic_pointer_array_steal_pointer(&actions, i); | |
2258 | ||
2259 | status = lttng_action_group_add_action(action_group, action); | |
2260 | if (status != LTTNG_ACTION_STATUS_OK) { | |
2261 | goto error; | |
2262 | } | |
2263 | ||
2264 | /* | |
2265 | * The `lttng_action_group_add_action()` takes a reference to | |
2266 | * the action. We can destroy ours. | |
2267 | */ | |
2268 | lttng_action_destroy(action); | |
2269 | action = NULL; | |
2270 | } | |
2271 | ||
2272 | trigger = lttng_trigger_create(condition, action_group); | |
2273 | if (!trigger) { | |
2274 | goto error; | |
2275 | } | |
2276 | ||
1d4b59f2 | 2277 | if (name) { |
4624dad0 | 2278 | enum lttng_trigger_status trigger_status = |
1d4b59f2 | 2279 | lttng_trigger_set_name(trigger, name); |
4624dad0 SM |
2280 | |
2281 | if (trigger_status != LTTNG_TRIGGER_STATUS_OK) { | |
1d4b59f2 | 2282 | ERR("Failed to set trigger name."); |
4624dad0 SM |
2283 | goto error; |
2284 | } | |
2285 | } | |
2286 | ||
4624dad0 SM |
2287 | if (user_id) { |
2288 | enum lttng_trigger_status trigger_status; | |
2289 | char *end; | |
2290 | long long uid; | |
2291 | ||
2292 | errno = 0; | |
2293 | uid = strtol(user_id, &end, 10); | |
2294 | if (end == user_id || *end != '\0' || errno != 0) { | |
2295 | ERR("Failed to parse `%s` as a user id.", user_id); | |
2296 | } | |
2297 | ||
2298 | trigger_status = lttng_trigger_set_owner_uid(trigger, uid); | |
2299 | if (trigger_status != LTTNG_TRIGGER_STATUS_OK) { | |
2300 | ERR("Failed to set trigger's user identity."); | |
2301 | goto error; | |
2302 | } | |
2303 | } | |
2304 | ||
2305 | ret = lttng_register_trigger(trigger); | |
2306 | if (ret) { | |
2307 | ERR("Failed to register trigger: %s.", lttng_strerror(ret)); | |
2308 | goto error; | |
2309 | } | |
2310 | ||
2311 | MSG("Trigger registered successfully."); | |
2312 | ||
2313 | goto end; | |
2314 | ||
2315 | error: | |
2316 | ret = 1; | |
2317 | ||
2318 | end: | |
2319 | argpar_state_destroy(argpar_state); | |
2320 | argpar_item_destroy(argpar_item); | |
2321 | lttng_dynamic_pointer_array_reset(&actions); | |
2322 | lttng_condition_destroy(condition); | |
2323 | lttng_action_destroy(action_group); | |
2324 | lttng_action_destroy(action); | |
2325 | lttng_trigger_destroy(trigger); | |
2326 | free(error); | |
1d4b59f2 | 2327 | free(name); |
4624dad0 SM |
2328 | free(user_id); |
2329 | return ret; | |
2330 | } |