2 * Copyright (C) 2011 - David Goulet <david.goulet@polymtl.ca>
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License, version 2 only,
6 * as published by the Free Software Foundation.
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
13 * You should have received a copy of the GNU General Public License along
14 * with this program; if not, write to the Free Software Foundation, Inc.,
15 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
24 #include <sys/types.h>
29 #include <common/sessiond-comm/sessiond-comm.h>
30 #include <common/compat/string.h>
31 #include <common/compat/getenv.h>
32 #include <common/string-utils/string-utils.h>
33 #include <common/utils.h>
35 #include <lttng/constant.h>
37 #include <common/mi-lttng.h>
39 #include "../command.h"
41 #if (LTTNG_SYMBOL_NAME_LEN == 256)
42 #define LTTNG_SYMBOL_NAME_LEN_SCANF_IS_A_BROKEN_API "255"
45 static char *opt_event_list
;
46 static int opt_event_type
;
47 static const char *opt_loglevel
;
48 static int opt_loglevel_type
;
49 static int opt_kernel
;
50 static char *opt_session_name
;
51 static int opt_userspace
;
54 static int opt_python
;
55 static int opt_enable_all
;
56 static char *opt_probe
;
57 static char *opt_userspace_probe
;
58 static char *opt_function
;
59 static char *opt_channel_name
;
60 static char *opt_filter
;
61 static char *opt_exclude
;
63 #ifdef LTTNG_EMBED_HELP
64 static const char help_msg
[] =
65 #include <lttng-enable-event.1.h>
84 static struct lttng_handle
*handle
;
85 static struct mi_writer
*writer
;
87 static struct poptOption long_options
[] = {
88 /* longName, shortName, argInfo, argPtr, value, descrip, argDesc */
89 {"help", 'h', POPT_ARG_NONE
, 0, OPT_HELP
, 0, 0},
90 {"session", 's', POPT_ARG_STRING
, &opt_session_name
, 0, 0, 0},
91 {"all", 'a', POPT_ARG_VAL
, &opt_enable_all
, 1, 0, 0},
92 {"channel", 'c', POPT_ARG_STRING
, &opt_channel_name
, 0, 0, 0},
93 {"kernel", 'k', POPT_ARG_VAL
, &opt_kernel
, 1, 0, 0},
94 {"userspace", 'u', POPT_ARG_NONE
, 0, OPT_USERSPACE
, 0, 0},
95 {"jul", 'j', POPT_ARG_VAL
, &opt_jul
, 1, 0, 0},
96 {"log4j", 'l', POPT_ARG_VAL
, &opt_log4j
, 1, 0, 0},
97 {"python", 'p', POPT_ARG_VAL
, &opt_python
, 1, 0, 0},
98 {"tracepoint", 0, POPT_ARG_NONE
, 0, OPT_TRACEPOINT
, 0, 0},
99 {"probe", 0, POPT_ARG_STRING
, &opt_probe
, OPT_PROBE
, 0, 0},
100 {"userspace-probe",0, POPT_ARG_STRING
, &opt_userspace_probe
, OPT_USERSPACE_PROBE
, 0, 0},
101 {"function", 0, POPT_ARG_STRING
, &opt_function
, OPT_FUNCTION
, 0, 0},
102 {"syscall", 0, POPT_ARG_NONE
, 0, OPT_SYSCALL
, 0, 0},
103 {"loglevel", 0, POPT_ARG_STRING
, 0, OPT_LOGLEVEL
, 0, 0},
104 {"loglevel-only", 0, POPT_ARG_STRING
, 0, OPT_LOGLEVEL_ONLY
, 0, 0},
105 {"list-options", 0, POPT_ARG_NONE
, NULL
, OPT_LIST_OPTIONS
, NULL
, NULL
},
106 {"filter", 'f', POPT_ARG_STRING
, &opt_filter
, OPT_FILTER
, 0, 0},
107 {"exclude", 'x', POPT_ARG_STRING
, &opt_exclude
, OPT_EXCLUDE
, 0, 0},
108 {0, 0, 0, 0, 0, 0, 0}
112 * Parse probe options.
114 static int parse_probe_opts(struct lttng_event
*ev
, char *opt
)
116 int ret
= CMD_SUCCESS
;
119 #define S_HEX_LEN_SCANF_IS_A_BROKEN_API "18" /* 18 is (19 - 1) (\0 is extra) */
120 char name
[LTTNG_SYMBOL_NAME_LEN
];
127 /* Check for symbol+offset */
128 match
= sscanf(opt
, "%" LTTNG_SYMBOL_NAME_LEN_SCANF_IS_A_BROKEN_API
129 "[^'+']+%" S_HEX_LEN_SCANF_IS_A_BROKEN_API
"s", name
, s_hex
);
131 strncpy(ev
->attr
.probe
.symbol_name
, name
, LTTNG_SYMBOL_NAME_LEN
);
132 ev
->attr
.probe
.symbol_name
[LTTNG_SYMBOL_NAME_LEN
- 1] = '\0';
133 DBG("probe symbol %s", ev
->attr
.probe
.symbol_name
);
134 if (*s_hex
== '\0') {
135 ERR("Invalid probe offset %s", s_hex
);
139 ev
->attr
.probe
.offset
= strtoul(s_hex
, NULL
, 0);
140 DBG("probe offset %" PRIu64
, ev
->attr
.probe
.offset
);
141 ev
->attr
.probe
.addr
= 0;
145 /* Check for symbol */
146 if (isalpha(name
[0])) {
147 match
= sscanf(opt
, "%" LTTNG_SYMBOL_NAME_LEN_SCANF_IS_A_BROKEN_API
"s",
150 strncpy(ev
->attr
.probe
.symbol_name
, name
, LTTNG_SYMBOL_NAME_LEN
);
151 ev
->attr
.probe
.symbol_name
[LTTNG_SYMBOL_NAME_LEN
- 1] = '\0';
152 DBG("probe symbol %s", ev
->attr
.probe
.symbol_name
);
153 ev
->attr
.probe
.offset
= 0;
154 DBG("probe offset %" PRIu64
, ev
->attr
.probe
.offset
);
155 ev
->attr
.probe
.addr
= 0;
160 /* Check for address */
161 match
= sscanf(opt
, "%" S_HEX_LEN_SCANF_IS_A_BROKEN_API
"s", s_hex
);
163 if (*s_hex
== '\0') {
164 ERR("Invalid probe address %s", s_hex
);
168 ev
->attr
.probe
.addr
= strtoul(s_hex
, NULL
, 0);
169 DBG("probe addr %" PRIu64
, ev
->attr
.probe
.addr
);
170 ev
->attr
.probe
.offset
= 0;
171 memset(ev
->attr
.probe
.symbol_name
, 0, LTTNG_SYMBOL_NAME_LEN
);
183 * Walk the directories in the PATH environment variable to find the target
184 * binary passed as parameter.
186 * On success, the full path of the binary is copied in binary_full_path out
187 * parameter. This buffer is allocated by the caller and must be at least
188 * LTTNG_PATH_MAX bytes long.
189 * On failure, returns -1;
191 static int walk_command_search_path(const char *binary
, char *binary_full_path
)
193 char *tentative_binary_path
= NULL
;
194 char *command_search_path
= NULL
;
195 char *curr_search_dir_end
= NULL
;
196 char *curr_search_dir
= NULL
;
197 struct stat stat_output
;
200 command_search_path
= lttng_secure_getenv("PATH");
201 if (!command_search_path
) {
207 * Duplicate the $PATH string as the char pointer returned by getenv() should
210 command_search_path
= strdup(command_search_path
);
211 if (!command_search_path
) {
217 * This char array is used to concatenate path to binary to look for
220 tentative_binary_path
= zmalloc(LTTNG_PATH_MAX
* sizeof(char));
221 if (!tentative_binary_path
) {
226 curr_search_dir
= command_search_path
;
229 * Split on ':'. The return value of this call points to the
230 * matching character.
232 curr_search_dir_end
= strchr(curr_search_dir
, ':');
233 if (curr_search_dir_end
!= NULL
) {
235 * Add a NULL byte to the end of the first token so it
236 * can be used as a string.
238 curr_search_dir_end
[0] = '\0';
241 /* Empty the tentative path */
242 memset(tentative_binary_path
, 0, LTTNG_PATH_MAX
* sizeof(char));
245 * Build the tentative path to the binary using the current
246 * search directory and the name of the binary.
248 ret
= snprintf(tentative_binary_path
, LTTNG_PATH_MAX
, "%s/%s",
249 curr_search_dir
, binary
);
251 goto free_binary_path
;
253 if (ret
< LTTNG_PATH_MAX
) {
255 * Use STAT(2) to see if the file exists.
257 ret
= stat(tentative_binary_path
, &stat_output
);
260 * Verify that it is a regular file or a
261 * symlink and not a special file (e.g.
264 if (S_ISREG(stat_output
.st_mode
)
265 || S_ISLNK(stat_output
.st_mode
)) {
267 * Found a match, set the out parameter
268 * and return success.
270 ret
= lttng_strncpy(binary_full_path
,
271 tentative_binary_path
,
274 ERR("Source path does not fit "
275 "in destination buffer.");
277 goto free_binary_path
;
281 /* Go to the next entry in the $PATH variable. */
282 curr_search_dir
= curr_search_dir_end
+ 1;
283 } while (curr_search_dir_end
!= NULL
);
286 free(tentative_binary_path
);
288 free(command_search_path
);
294 * Parse userspace probe options
295 * Set the userspace probe fields in the lttng_event struct and set the
296 * target_path to the path to the binary.
298 static int parse_userspace_probe_opts(struct lttng_event
*ev
, char *opt
)
300 int ret
= CMD_SUCCESS
;
303 char *target_path
= NULL
;
304 char *unescaped_target_path
= NULL
;
305 char *real_target_path
= NULL
;
306 char *symbol_name
= NULL
, *probe_name
= NULL
, *provider_name
= NULL
;
307 struct lttng_userspace_probe_location
*probe_location
= NULL
;
308 struct lttng_userspace_probe_location_lookup_method
*lookup_method
=
317 case LTTNG_EVENT_USERSPACE_PROBE
:
324 * userspace probe fields are separated by ':'.
326 tokens
= strutils_split(opt
, ':', 1);
327 num_token
= strutils_array_of_strings_len(tokens
);
330 * Early sanity check that the number of parameter is between 2 and 4
333 * std:PATH:PROVIDER_NAME:PROBE_NAME
334 * PATH:SYMBOL (same behavior as ELF)
336 if (num_token
< 2 || num_token
> 4) {
342 * Looking up the first parameter will tell the technique to use to
343 * interpret the userspace probe/function description.
347 /* When the probe type is omitted we assume ELF for now. */
349 if (num_token
== 3 && strcmp(tokens
[0], "elf") == 0) {
350 target_path
= tokens
[1];
351 symbol_name
= tokens
[2];
352 } else if (num_token
== 2) {
353 target_path
= tokens
[0];
354 symbol_name
= tokens
[1];
360 lttng_userspace_probe_location_lookup_method_function_elf_create();
361 if (!lookup_method
) {
362 WARN("Failed to create ELF lookup method");
368 if (strcmp(tokens
[0], "sdt") == 0) {
369 target_path
= tokens
[1];
370 provider_name
= tokens
[2];
371 probe_name
= tokens
[3];
377 lttng_userspace_probe_location_lookup_method_tracepoint_sdt_create();
378 if (!lookup_method
) {
379 WARN("Failed to create ELF lookup method");
389 /* strutils_unescape_string allocates a new char *. */
390 unescaped_target_path
= strutils_unescape_string(target_path
, 0);
391 if (!unescaped_target_path
) {
392 ret
= -LTTNG_ERR_INVALID
;
393 goto end_destroy_lookup_method
;
397 * If there is not forward slash in the path. Walk the $PATH else
400 if (strchr(unescaped_target_path
, '/') == NULL
) {
401 /* Walk the $PATH variable to find the targeted binary. */
402 real_target_path
= zmalloc(LTTNG_PATH_MAX
* sizeof(char));
403 if (!real_target_path
) {
404 PERROR("Error allocating path buffer");
406 goto end_destroy_lookup_method
;
408 ret
= walk_command_search_path(unescaped_target_path
, real_target_path
);
410 ERR("Binary not found.");
412 goto end_destroy_lookup_method
;
416 * Expand references to `/./` and `/../`. This function does not check
417 * if the file exists. This call returns an allocated buffer on
420 real_target_path
= utils_expand_path_keep_symlink(unescaped_target_path
);
421 if (!real_target_path
) {
422 ERR("Error expanding the path to binary.");
424 goto end_destroy_lookup_method
;
428 * Check if the file exists using access(2). If it does not, walk the
431 ret
= access(real_target_path
, F_OK
);
434 goto end_destroy_lookup_method
;
438 switch (lttng_userspace_probe_location_lookup_method_get_type(lookup_method
)) {
439 case LTTNG_USERSPACE_PROBE_LOCATION_LOOKUP_METHOD_TYPE_FUNCTION_ELF
:
440 probe_location
= lttng_userspace_probe_location_function_create(
441 real_target_path
, symbol_name
, lookup_method
);
442 if (!probe_location
) {
443 WARN("Failed to create function probe location");
445 goto end_destroy_lookup_method
;
448 /* Ownership transferred to probe_location. */
449 lookup_method
= NULL
;
451 ret
= lttng_event_set_userspace_probe_location(ev
, probe_location
);
453 WARN("Failed to set probe location on event");
455 goto end_destroy_location
;
458 case LTTNG_USERSPACE_PROBE_LOCATION_LOOKUP_METHOD_TYPE_TRACEPOINT_SDT
:
459 probe_location
= lttng_userspace_probe_location_tracepoint_create(
460 real_target_path
, provider_name
, probe_name
, lookup_method
);
461 if (!probe_location
) {
462 WARN("Failed to create function probe location");
464 goto end_destroy_lookup_method
;
467 /* Ownership transferred to probe_location. */
468 lookup_method
= NULL
;
470 ret
= lttng_event_set_userspace_probe_location(ev
, probe_location
);
472 WARN("Failed to set probe location on event");
474 goto end_destroy_location
;
479 goto end_destroy_lookup_method
;
482 /* Successful parsing, now clean up everything and return. */
485 end_destroy_location
:
486 lttng_userspace_probe_location_destroy(probe_location
);
487 end_destroy_lookup_method
:
488 lttng_userspace_probe_location_lookup_method_destroy(lookup_method
);
490 strutils_free_null_terminated_array_of_strings(tokens
);
492 * Freeing both char * here makes the error handling simplier. free()
493 * performs not action if the pointer is NULL.
495 free(real_target_path
);
496 free(unescaped_target_path
);
502 * Maps LOG4j loglevel from string to value
504 static int loglevel_log4j_str_to_value(const char *inputstr
)
507 char str
[LTTNG_SYMBOL_NAME_LEN
];
509 if (!inputstr
|| strlen(inputstr
) == 0) {
514 * Loop up to LTTNG_SYMBOL_NAME_LEN minus one because the NULL bytes is
515 * added at the end of the loop so a the upper bound we avoid the overflow.
517 while (i
< (LTTNG_SYMBOL_NAME_LEN
- 1) && inputstr
[i
] != '\0') {
518 str
[i
] = toupper(inputstr
[i
]);
523 if (!strcmp(str
, "LOG4J_OFF") || !strcmp(str
, "OFF")) {
524 return LTTNG_LOGLEVEL_LOG4J_OFF
;
525 } else if (!strcmp(str
, "LOG4J_FATAL") || !strcmp(str
, "FATAL")) {
526 return LTTNG_LOGLEVEL_LOG4J_FATAL
;
527 } else if (!strcmp(str
, "LOG4J_ERROR") || !strcmp(str
, "ERROR")) {
528 return LTTNG_LOGLEVEL_LOG4J_ERROR
;
529 } else if (!strcmp(str
, "LOG4J_WARN") || !strcmp(str
, "WARN")) {
530 return LTTNG_LOGLEVEL_LOG4J_WARN
;
531 } else if (!strcmp(str
, "LOG4J_INFO") || !strcmp(str
, "INFO")) {
532 return LTTNG_LOGLEVEL_LOG4J_INFO
;
533 } else if (!strcmp(str
, "LOG4J_DEBUG") || !strcmp(str
, "DEBUG")) {
534 return LTTNG_LOGLEVEL_LOG4J_DEBUG
;
535 } else if (!strcmp(str
, "LOG4J_TRACE") || !strcmp(str
, "TRACE")) {
536 return LTTNG_LOGLEVEL_LOG4J_TRACE
;
537 } else if (!strcmp(str
, "LOG4J_ALL") || !strcmp(str
, "ALL")) {
538 return LTTNG_LOGLEVEL_LOG4J_ALL
;
545 * Maps JUL loglevel from string to value
547 static int loglevel_jul_str_to_value(const char *inputstr
)
550 char str
[LTTNG_SYMBOL_NAME_LEN
];
552 if (!inputstr
|| strlen(inputstr
) == 0) {
557 * Loop up to LTTNG_SYMBOL_NAME_LEN minus one because the NULL bytes is
558 * added at the end of the loop so a the upper bound we avoid the overflow.
560 while (i
< (LTTNG_SYMBOL_NAME_LEN
- 1) && inputstr
[i
] != '\0') {
561 str
[i
] = toupper(inputstr
[i
]);
566 if (!strcmp(str
, "JUL_OFF") || !strcmp(str
, "OFF")) {
567 return LTTNG_LOGLEVEL_JUL_OFF
;
568 } else if (!strcmp(str
, "JUL_SEVERE") || !strcmp(str
, "SEVERE")) {
569 return LTTNG_LOGLEVEL_JUL_SEVERE
;
570 } else if (!strcmp(str
, "JUL_WARNING") || !strcmp(str
, "WARNING")) {
571 return LTTNG_LOGLEVEL_JUL_WARNING
;
572 } else if (!strcmp(str
, "JUL_INFO") || !strcmp(str
, "INFO")) {
573 return LTTNG_LOGLEVEL_JUL_INFO
;
574 } else if (!strcmp(str
, "JUL_CONFIG") || !strcmp(str
, "CONFIG")) {
575 return LTTNG_LOGLEVEL_JUL_CONFIG
;
576 } else if (!strcmp(str
, "JUL_FINE") || !strcmp(str
, "FINE")) {
577 return LTTNG_LOGLEVEL_JUL_FINE
;
578 } else if (!strcmp(str
, "JUL_FINER") || !strcmp(str
, "FINER")) {
579 return LTTNG_LOGLEVEL_JUL_FINER
;
580 } else if (!strcmp(str
, "JUL_FINEST") || !strcmp(str
, "FINEST")) {
581 return LTTNG_LOGLEVEL_JUL_FINEST
;
582 } else if (!strcmp(str
, "JUL_ALL") || !strcmp(str
, "ALL")) {
583 return LTTNG_LOGLEVEL_JUL_ALL
;
590 * Maps Python loglevel from string to value
592 static int loglevel_python_str_to_value(const char *inputstr
)
595 char str
[LTTNG_SYMBOL_NAME_LEN
];
597 if (!inputstr
|| strlen(inputstr
) == 0) {
602 * Loop up to LTTNG_SYMBOL_NAME_LEN minus one because the NULL bytes is
603 * added at the end of the loop so a the upper bound we avoid the overflow.
605 while (i
< (LTTNG_SYMBOL_NAME_LEN
- 1) && inputstr
[i
] != '\0') {
606 str
[i
] = toupper(inputstr
[i
]);
611 if (!strcmp(str
, "PYTHON_CRITICAL") || !strcmp(str
, "CRITICAL")) {
612 return LTTNG_LOGLEVEL_PYTHON_CRITICAL
;
613 } else if (!strcmp(str
, "PYTHON_ERROR") || !strcmp(str
, "ERROR")) {
614 return LTTNG_LOGLEVEL_PYTHON_ERROR
;
615 } else if (!strcmp(str
, "PYTHON_WARNING") || !strcmp(str
, "WARNING")) {
616 return LTTNG_LOGLEVEL_PYTHON_WARNING
;
617 } else if (!strcmp(str
, "PYTHON_INFO") || !strcmp(str
, "INFO")) {
618 return LTTNG_LOGLEVEL_PYTHON_INFO
;
619 } else if (!strcmp(str
, "PYTNON_DEBUG") || !strcmp(str
, "DEBUG")) {
620 return LTTNG_LOGLEVEL_PYTHON_DEBUG
;
621 } else if (!strcmp(str
, "PYTHON_NOTSET") || !strcmp(str
, "NOTSET")) {
622 return LTTNG_LOGLEVEL_PYTHON_NOTSET
;
629 * Maps loglevel from string to value
632 int loglevel_str_to_value(const char *inputstr
)
635 char str
[LTTNG_SYMBOL_NAME_LEN
];
637 if (!inputstr
|| strlen(inputstr
) == 0) {
642 * Loop up to LTTNG_SYMBOL_NAME_LEN minus one because the NULL bytes is
643 * added at the end of the loop so a the upper bound we avoid the overflow.
645 while (i
< (LTTNG_SYMBOL_NAME_LEN
- 1) && inputstr
[i
] != '\0') {
646 str
[i
] = toupper(inputstr
[i
]);
650 if (!strcmp(str
, "TRACE_EMERG") || !strcmp(str
, "EMERG")) {
651 return LTTNG_LOGLEVEL_EMERG
;
652 } else if (!strcmp(str
, "TRACE_ALERT") || !strcmp(str
, "ALERT")) {
653 return LTTNG_LOGLEVEL_ALERT
;
654 } else if (!strcmp(str
, "TRACE_CRIT") || !strcmp(str
, "CRIT")) {
655 return LTTNG_LOGLEVEL_CRIT
;
656 } else if (!strcmp(str
, "TRACE_ERR") || !strcmp(str
, "ERR")) {
657 return LTTNG_LOGLEVEL_ERR
;
658 } else if (!strcmp(str
, "TRACE_WARNING") || !strcmp(str
, "WARNING")) {
659 return LTTNG_LOGLEVEL_WARNING
;
660 } else if (!strcmp(str
, "TRACE_NOTICE") || !strcmp(str
, "NOTICE")) {
661 return LTTNG_LOGLEVEL_NOTICE
;
662 } else if (!strcmp(str
, "TRACE_INFO") || !strcmp(str
, "INFO")) {
663 return LTTNG_LOGLEVEL_INFO
;
664 } else if (!strcmp(str
, "TRACE_DEBUG_SYSTEM") || !strcmp(str
, "DEBUG_SYSTEM") || !strcmp(str
, "SYSTEM")) {
665 return LTTNG_LOGLEVEL_DEBUG_SYSTEM
;
666 } else if (!strcmp(str
, "TRACE_DEBUG_PROGRAM") || !strcmp(str
, "DEBUG_PROGRAM") || !strcmp(str
, "PROGRAM")) {
667 return LTTNG_LOGLEVEL_DEBUG_PROGRAM
;
668 } else if (!strcmp(str
, "TRACE_DEBUG_PROCESS") || !strcmp(str
, "DEBUG_PROCESS") || !strcmp(str
, "PROCESS")) {
669 return LTTNG_LOGLEVEL_DEBUG_PROCESS
;
670 } else if (!strcmp(str
, "TRACE_DEBUG_MODULE") || !strcmp(str
, "DEBUG_MODULE") || !strcmp(str
, "MODULE")) {
671 return LTTNG_LOGLEVEL_DEBUG_MODULE
;
672 } else if (!strcmp(str
, "TRACE_DEBUG_UNIT") || !strcmp(str
, "DEBUG_UNIT") || !strcmp(str
, "UNIT")) {
673 return LTTNG_LOGLEVEL_DEBUG_UNIT
;
674 } else if (!strcmp(str
, "TRACE_DEBUG_FUNCTION") || !strcmp(str
, "DEBUG_FUNCTION") || !strcmp(str
, "FUNCTION")) {
675 return LTTNG_LOGLEVEL_DEBUG_FUNCTION
;
676 } else if (!strcmp(str
, "TRACE_DEBUG_LINE") || !strcmp(str
, "DEBUG_LINE") || !strcmp(str
, "LINE")) {
677 return LTTNG_LOGLEVEL_DEBUG_LINE
;
678 } else if (!strcmp(str
, "TRACE_DEBUG") || !strcmp(str
, "DEBUG")) {
679 return LTTNG_LOGLEVEL_DEBUG
;
686 const char *print_channel_name(const char *name
)
688 return name
? : DEFAULT_CHANNEL_NAME
;
692 const char *print_raw_channel_name(const char *name
)
694 return name
? : "<default>";
698 * Mi print exlcusion list
701 int mi_print_exclusion(char **names
)
704 int count
= names
? strutils_array_of_strings_len(names
) : 0;
712 ret
= mi_lttng_writer_open_element(writer
, config_element_exclusions
);
717 for (i
= 0; i
< count
; i
++) {
718 ret
= mi_lttng_writer_write_element_string(writer
,
719 config_element_exclusion
, names
[i
]);
725 /* Close exclusions element */
726 ret
= mi_lttng_writer_close_element(writer
);
733 * Return allocated string for pretty-printing exclusion names.
736 char *print_exclusions(char **names
)
740 const char *preamble
= " excluding ";
742 int count
= names
? strutils_array_of_strings_len(names
) : 0;
748 /* calculate total required length */
749 for (i
= 0; i
< count
; i
++) {
750 length
+= strlen(names
[i
]) + 4;
753 /* add length of preamble + one for NUL - one for last (missing) comma */
754 length
+= strlen(preamble
);
755 ret
= zmalloc(length
+ 1);
759 strncpy(ret
, preamble
, length
);
760 for (i
= 0; i
< count
; i
++) {
762 strcat(ret
, names
[i
]);
764 if (i
!= count
- 1) {
773 int check_exclusion_subsets(const char *event_name
, const char *exclusion
)
777 const char *e
= event_name
;
778 const char *x
= exclusion
;
780 /* Scan both the excluder and the event letter by letter */
794 /* Event is a subset of the excluder */
795 ERR("Event %s: %s excludes all events from %s",
796 event_name
, exclusion
, event_name
);
802 * Reached the end of the event name before the
803 * end of the exclusion: this is valid.
825 WARN("Event %s: %s does not exclude any events from %s",
826 event_name
, exclusion
, event_name
);
833 int create_exclusion_list_and_validate(const char *event_name
,
834 const char *exclusions_arg
,
835 char ***exclusion_list
)
838 char **exclusions
= NULL
;
840 /* Event name must be a valid globbing pattern to allow exclusions. */
841 if (!strutils_is_star_glob_pattern(event_name
)) {
842 ERR("Event %s: Exclusions can only be used with a globbing pattern",
847 /* Split exclusions. */
848 exclusions
= strutils_split(exclusions_arg
, ',', true);
854 * If the event name is a star-at-end only globbing pattern,
855 * then we can validate the individual exclusions. Otherwise
856 * all exclusions are passed to the session daemon.
858 if (strutils_is_star_at_the_end_only_glob_pattern(event_name
)) {
859 char * const *exclusion
;
861 for (exclusion
= exclusions
; *exclusion
; exclusion
++) {
862 if (!strutils_is_star_glob_pattern(*exclusion
) ||
863 strutils_is_star_at_the_end_only_glob_pattern(*exclusion
)) {
864 ret
= check_exclusion_subsets(event_name
, *exclusion
);
872 *exclusion_list
= exclusions
;
878 strutils_free_null_terminated_array_of_strings(exclusions
);
884 static void warn_on_truncated_exclusion_names(char * const *exclusion_list
,
887 char * const *exclusion
;
889 for (exclusion
= exclusion_list
; *exclusion
; exclusion
++) {
890 if (strlen(*exclusion
) >= LTTNG_SYMBOL_NAME_LEN
) {
891 WARN("Event exclusion \"%s\" will be truncated",
899 * Enabling event using the lttng API.
900 * Note: in case of error only the last error code will be return.
902 static int enable_events(char *session_name
)
904 int ret
= CMD_SUCCESS
, command_ret
= CMD_SUCCESS
;
905 int error_holder
= CMD_SUCCESS
, warn
= 0, error
= 0, success
= 1;
906 char *event_name
, *channel_name
= NULL
;
907 struct lttng_event
*ev
;
908 struct lttng_domain dom
;
909 char **exclusion_list
= NULL
;
911 memset(&dom
, 0, sizeof(dom
));
913 ev
= lttng_event_create();
921 WARN("Kernel loglevels are not supported.");
925 /* Create lttng domain */
927 dom
.type
= LTTNG_DOMAIN_KERNEL
;
928 dom
.buf_type
= LTTNG_BUFFER_GLOBAL
;
929 } else if (opt_userspace
) {
930 dom
.type
= LTTNG_DOMAIN_UST
;
932 dom
.buf_type
= LTTNG_BUFFER_PER_UID
;
933 } else if (opt_jul
) {
934 dom
.type
= LTTNG_DOMAIN_JUL
;
936 dom
.buf_type
= LTTNG_BUFFER_PER_UID
;
937 } else if (opt_log4j
) {
938 dom
.type
= LTTNG_DOMAIN_LOG4J
;
940 dom
.buf_type
= LTTNG_BUFFER_PER_UID
;
941 } else if (opt_python
) {
942 dom
.type
= LTTNG_DOMAIN_PYTHON
;
944 dom
.buf_type
= LTTNG_BUFFER_PER_UID
;
946 /* Checked by the caller. */
952 case LTTNG_DOMAIN_KERNEL
:
953 case LTTNG_DOMAIN_JUL
:
954 case LTTNG_DOMAIN_LOG4J
:
955 case LTTNG_DOMAIN_PYTHON
:
956 ERR("Event name exclusions are not yet implemented for %s events",
957 get_domain_str(dom
.type
));
960 case LTTNG_DOMAIN_UST
:
961 /* Exclusions supported */
969 * Adding a filter to a probe, function or userspace-probe would be
970 * denied by the kernel tracer as it's not supported at the moment. We
971 * do an early check here to warn the user.
973 if (opt_filter
&& opt_kernel
) {
974 switch (opt_event_type
) {
975 case LTTNG_EVENT_ALL
:
976 case LTTNG_EVENT_TRACEPOINT
:
977 case LTTNG_EVENT_SYSCALL
:
979 case LTTNG_EVENT_PROBE
:
980 case LTTNG_EVENT_USERSPACE_PROBE
:
981 case LTTNG_EVENT_FUNCTION
:
982 ERR("Filter expressions are not supported for %s events",
983 get_event_type_str(opt_event_type
));
992 channel_name
= opt_channel_name
;
994 handle
= lttng_create_handle(session_name
, &dom
);
995 if (handle
== NULL
) {
1002 /* Open a events element */
1003 ret
= mi_lttng_writer_open_element(writer
, config_element_events
);
1010 if (opt_enable_all
) {
1011 /* Default setup for enable all */
1013 ev
->type
= opt_event_type
;
1014 strcpy(ev
->name
, "*");
1015 /* kernel loglevels not implemented */
1016 ev
->loglevel_type
= LTTNG_EVENT_LOGLEVEL_ALL
;
1018 ev
->type
= LTTNG_EVENT_TRACEPOINT
;
1019 strcpy(ev
->name
, "*");
1020 ev
->loglevel_type
= opt_loglevel_type
;
1022 assert(opt_userspace
|| opt_jul
|| opt_log4j
|| opt_python
);
1023 if (opt_userspace
) {
1024 ev
->loglevel
= loglevel_str_to_value(opt_loglevel
);
1025 } else if (opt_jul
) {
1026 ev
->loglevel
= loglevel_jul_str_to_value(opt_loglevel
);
1027 } else if (opt_log4j
) {
1028 ev
->loglevel
= loglevel_log4j_str_to_value(opt_loglevel
);
1029 } else if (opt_python
) {
1030 ev
->loglevel
= loglevel_python_str_to_value(opt_loglevel
);
1032 if (ev
->loglevel
== -1) {
1033 ERR("Unknown loglevel %s", opt_loglevel
);
1034 ret
= -LTTNG_ERR_INVALID
;
1038 assert(opt_userspace
|| opt_jul
|| opt_log4j
|| opt_python
);
1039 if (opt_userspace
) {
1041 } else if (opt_jul
) {
1042 ev
->loglevel
= LTTNG_LOGLEVEL_JUL_ALL
;
1043 } else if (opt_log4j
) {
1044 ev
->loglevel
= LTTNG_LOGLEVEL_LOG4J_ALL
;
1045 } else if (opt_python
) {
1046 ev
->loglevel
= LTTNG_LOGLEVEL_PYTHON_DEBUG
;
1052 ret
= create_exclusion_list_and_validate("*",
1053 opt_exclude
, &exclusion_list
);
1060 warn_on_truncated_exclusion_names(exclusion_list
,
1064 ret
= lttng_enable_event_with_exclusions(handle
,
1067 exclusion_list
? strutils_array_of_strings_len(exclusion_list
) : 0,
1071 case LTTNG_ERR_KERN_EVENT_EXIST
:
1072 WARN("Kernel events already enabled (channel %s, session %s)",
1073 print_channel_name(channel_name
), session_name
);
1076 case LTTNG_ERR_TRACE_ALREADY_STARTED
:
1078 const char *msg
= "The command tried to enable an event in a new domain for a session that has already been started once.";
1079 ERR("Events: %s (channel %s, session %s)",
1081 print_channel_name(channel_name
),
1087 ERR("Events: %s (channel %s, session %s)",
1088 lttng_strerror(ret
),
1089 ret
== -LTTNG_ERR_NEED_CHANNEL_NAME
1090 ? print_raw_channel_name(channel_name
)
1091 : print_channel_name(channel_name
),
1099 switch (opt_event_type
) {
1100 case LTTNG_EVENT_TRACEPOINT
:
1101 if (opt_loglevel
&& dom
.type
!= LTTNG_DOMAIN_KERNEL
) {
1102 char *exclusion_string
= print_exclusions(exclusion_list
);
1104 if (!exclusion_string
) {
1105 PERROR("Cannot allocate exclusion_string");
1109 MSG("All %s tracepoints%s are enabled in channel %s for loglevel %s",
1110 get_domain_str(dom
.type
),
1112 print_channel_name(channel_name
),
1114 free(exclusion_string
);
1116 char *exclusion_string
= print_exclusions(exclusion_list
);
1118 if (!exclusion_string
) {
1119 PERROR("Cannot allocate exclusion_string");
1123 MSG("All %s tracepoints%s are enabled in channel %s",
1124 get_domain_str(dom
.type
),
1126 print_channel_name(channel_name
));
1127 free(exclusion_string
);
1130 case LTTNG_EVENT_SYSCALL
:
1132 MSG("All %s system calls are enabled in channel %s",
1133 get_domain_str(dom
.type
),
1134 print_channel_name(channel_name
));
1137 case LTTNG_EVENT_ALL
:
1138 if (opt_loglevel
&& dom
.type
!= LTTNG_DOMAIN_KERNEL
) {
1139 char *exclusion_string
= print_exclusions(exclusion_list
);
1141 if (!exclusion_string
) {
1142 PERROR("Cannot allocate exclusion_string");
1146 MSG("All %s events%s are enabled in channel %s for loglevel %s",
1147 get_domain_str(dom
.type
),
1149 print_channel_name(channel_name
),
1151 free(exclusion_string
);
1153 char *exclusion_string
= print_exclusions(exclusion_list
);
1155 if (!exclusion_string
) {
1156 PERROR("Cannot allocate exclusion_string");
1160 MSG("All %s events%s are enabled in channel %s",
1161 get_domain_str(dom
.type
),
1163 print_channel_name(channel_name
));
1164 free(exclusion_string
);
1169 * We should not be here since lttng_enable_event should have
1170 * failed on the event type.
1177 command_ret
= lttng_enable_event_with_exclusions(handle
, ev
, channel_name
,
1179 exclusion_list
? strutils_array_of_strings_len(exclusion_list
) : 0,
1181 if (command_ret
< 0) {
1182 switch (-command_ret
) {
1183 case LTTNG_ERR_FILTER_EXIST
:
1184 WARN("Filter on all events is already enabled"
1185 " (channel %s, session %s)",
1186 print_channel_name(channel_name
), session_name
);
1189 case LTTNG_ERR_TRACE_ALREADY_STARTED
:
1191 const char *msg
= "The command tried to enable an event in a new domain for a session that has already been started once.";
1192 ERR("All events: %s (channel %s, session %s, filter \'%s\')",
1194 print_channel_name(channel_name
),
1195 session_name
, opt_filter
);
1200 ERR("All events: %s (channel %s, session %s, filter \'%s\')",
1201 lttng_strerror(command_ret
),
1202 command_ret
== -LTTNG_ERR_NEED_CHANNEL_NAME
1203 ? print_raw_channel_name(channel_name
)
1204 : print_channel_name(channel_name
),
1205 session_name
, opt_filter
);
1209 error_holder
= command_ret
;
1212 MSG("Filter '%s' successfully set", opt_filter
);
1217 /* The wildcard * is used for kernel and ust domain to
1218 * represent ALL. We copy * in event name to force the wildcard use
1221 * Note: this is strictly for semantic and printing while in
1222 * machine interface mode.
1224 strcpy(ev
->name
, "*");
1226 /* If we reach here the events are enabled */
1227 if (!error
&& !warn
) {
1233 ret
= mi_lttng_event(writer
, ev
, 1, handle
->domain
.type
);
1239 /* print exclusion */
1240 ret
= mi_print_exclusion(exclusion_list
);
1247 ret
= mi_lttng_writer_write_element_bool(writer
,
1248 mi_lttng_element_command_success
, success
);
1254 /* Close event element */
1255 ret
= mi_lttng_writer_close_element(writer
);
1265 /* Strip event list */
1266 event_name
= strtok(opt_event_list
, ",");
1267 while (event_name
!= NULL
) {
1268 /* Copy name and type of the event */
1269 strncpy(ev
->name
, event_name
, LTTNG_SYMBOL_NAME_LEN
);
1270 ev
->name
[LTTNG_SYMBOL_NAME_LEN
- 1] = '\0';
1271 ev
->type
= opt_event_type
;
1273 /* Kernel tracer action */
1275 DBG("Enabling kernel event %s for channel %s",
1277 print_channel_name(channel_name
));
1279 switch (opt_event_type
) {
1280 case LTTNG_EVENT_ALL
: /* Enable tracepoints and syscalls */
1281 /* If event name differs from *, select tracepoint. */
1282 if (strcmp(ev
->name
, "*")) {
1283 ev
->type
= LTTNG_EVENT_TRACEPOINT
;
1286 case LTTNG_EVENT_TRACEPOINT
:
1288 case LTTNG_EVENT_PROBE
:
1289 ret
= parse_probe_opts(ev
, opt_probe
);
1291 ERR("Unable to parse probe options");
1296 case LTTNG_EVENT_USERSPACE_PROBE
:
1297 ret
= parse_userspace_probe_opts(ev
, opt_userspace_probe
);
1299 ERR("Unable to parse userspace probe options");
1304 case LTTNG_EVENT_FUNCTION
:
1305 ret
= parse_probe_opts(ev
, opt_function
);
1307 ERR("Unable to parse function probe options");
1312 case LTTNG_EVENT_SYSCALL
:
1313 ev
->type
= LTTNG_EVENT_SYSCALL
;
1316 ret
= CMD_UNDEFINED
;
1320 /* kernel loglevels not implemented */
1321 ev
->loglevel_type
= LTTNG_EVENT_LOGLEVEL_ALL
;
1322 } else if (opt_userspace
) { /* User-space tracer action */
1323 DBG("Enabling UST event %s for channel %s, loglevel %s", event_name
,
1324 print_channel_name(channel_name
), opt_loglevel
? : "<all>");
1326 switch (opt_event_type
) {
1327 case LTTNG_EVENT_ALL
: /* Default behavior is tracepoint */
1329 case LTTNG_EVENT_TRACEPOINT
:
1330 /* Copy name and type of the event */
1331 ev
->type
= LTTNG_EVENT_TRACEPOINT
;
1332 strncpy(ev
->name
, event_name
, LTTNG_SYMBOL_NAME_LEN
);
1333 ev
->name
[LTTNG_SYMBOL_NAME_LEN
- 1] = '\0';
1335 case LTTNG_EVENT_PROBE
:
1336 case LTTNG_EVENT_FUNCTION
:
1337 case LTTNG_EVENT_SYSCALL
:
1338 case LTTNG_EVENT_USERSPACE_PROBE
:
1340 ERR("Event type not available for user-space tracing");
1341 ret
= CMD_UNSUPPORTED
;
1347 if (opt_event_type
!= LTTNG_EVENT_ALL
&& opt_event_type
!= LTTNG_EVENT_TRACEPOINT
) {
1348 ERR("Exclusion option can only be used with tracepoint events");
1352 /* Free previously allocated items */
1353 strutils_free_null_terminated_array_of_strings(
1355 exclusion_list
= NULL
;
1356 ret
= create_exclusion_list_and_validate(
1357 event_name
, opt_exclude
,
1364 warn_on_truncated_exclusion_names(
1365 exclusion_list
, &warn
);
1368 ev
->loglevel_type
= opt_loglevel_type
;
1370 ev
->loglevel
= loglevel_str_to_value(opt_loglevel
);
1371 if (ev
->loglevel
== -1) {
1372 ERR("Unknown loglevel %s", opt_loglevel
);
1373 ret
= -LTTNG_ERR_INVALID
;
1379 } else if (opt_jul
|| opt_log4j
|| opt_python
) {
1380 if (opt_event_type
!= LTTNG_EVENT_ALL
&&
1381 opt_event_type
!= LTTNG_EVENT_TRACEPOINT
) {
1382 ERR("Event type not supported for domain.");
1383 ret
= CMD_UNSUPPORTED
;
1387 ev
->loglevel_type
= opt_loglevel_type
;
1390 ev
->loglevel
= loglevel_jul_str_to_value(opt_loglevel
);
1391 } else if (opt_log4j
) {
1392 ev
->loglevel
= loglevel_log4j_str_to_value(opt_loglevel
);
1393 } else if (opt_python
) {
1394 ev
->loglevel
= loglevel_python_str_to_value(opt_loglevel
);
1396 if (ev
->loglevel
== -1) {
1397 ERR("Unknown loglevel %s", opt_loglevel
);
1398 ret
= -LTTNG_ERR_INVALID
;
1403 ev
->loglevel
= LTTNG_LOGLEVEL_JUL_ALL
;
1404 } else if (opt_log4j
) {
1405 ev
->loglevel
= LTTNG_LOGLEVEL_LOG4J_ALL
;
1406 } else if (opt_python
) {
1407 ev
->loglevel
= LTTNG_LOGLEVEL_PYTHON_DEBUG
;
1410 ev
->type
= LTTNG_EVENT_TRACEPOINT
;
1411 strncpy(ev
->name
, event_name
, LTTNG_SYMBOL_NAME_LEN
);
1412 ev
->name
[LTTNG_SYMBOL_NAME_LEN
- 1] = '\0';
1418 char *exclusion_string
;
1420 command_ret
= lttng_enable_event_with_exclusions(handle
,
1423 exclusion_list
? strutils_array_of_strings_len(exclusion_list
) : 0,
1425 exclusion_string
= print_exclusions(exclusion_list
);
1426 if (!exclusion_string
) {
1427 PERROR("Cannot allocate exclusion_string");
1431 if (command_ret
< 0) {
1432 /* Turn ret to positive value to handle the positive error code */
1433 switch (-command_ret
) {
1434 case LTTNG_ERR_KERN_EVENT_EXIST
:
1435 WARN("Kernel event %s%s already enabled (channel %s, session %s)",
1438 print_channel_name(channel_name
), session_name
);
1441 case LTTNG_ERR_TRACE_ALREADY_STARTED
:
1443 const char *msg
= "The command tried to enable an event in a new domain for a session that has already been started once.";
1444 ERR("Event %s%s: %s (channel %s, session %s)", event_name
,
1447 print_channel_name(channel_name
),
1452 case LTTNG_ERR_SDT_PROBE_SEMAPHORE
:
1453 ERR("SDT probes %s guarded by semaphores are not supported (channel %s, session %s)",
1454 event_name
, print_channel_name(channel_name
),
1459 ERR("Event %s%s: %s (channel %s, session %s)", event_name
,
1461 lttng_strerror(command_ret
),
1462 command_ret
== -LTTNG_ERR_NEED_CHANNEL_NAME
1463 ? print_raw_channel_name(channel_name
)
1464 : print_channel_name(channel_name
),
1469 error_holder
= command_ret
;
1472 case LTTNG_DOMAIN_KERNEL
:
1473 case LTTNG_DOMAIN_UST
:
1474 MSG("%s event %s%s created in channel %s",
1475 get_domain_str(dom
.type
),
1478 print_channel_name(channel_name
));
1480 case LTTNG_DOMAIN_JUL
:
1481 case LTTNG_DOMAIN_LOG4J
:
1482 case LTTNG_DOMAIN_PYTHON
:
1484 * Don't print the default channel
1485 * name for agent domains.
1487 MSG("%s event %s%s enabled",
1488 get_domain_str(dom
.type
),
1496 free(exclusion_string
);
1500 char *exclusion_string
;
1502 /* Filter present */
1505 command_ret
= lttng_enable_event_with_exclusions(handle
, ev
, channel_name
,
1507 exclusion_list
? strutils_array_of_strings_len(exclusion_list
) : 0,
1509 exclusion_string
= print_exclusions(exclusion_list
);
1510 if (!exclusion_string
) {
1511 PERROR("Cannot allocate exclusion_string");
1515 if (command_ret
< 0) {
1516 switch (-command_ret
) {
1517 case LTTNG_ERR_FILTER_EXIST
:
1518 WARN("Filter on event %s%s is already enabled"
1519 " (channel %s, session %s)",
1522 print_channel_name(channel_name
), session_name
);
1525 case LTTNG_ERR_TRACE_ALREADY_STARTED
:
1527 const char *msg
= "The command tried to enable an event in a new domain for a session that has already been started once.";
1528 ERR("Event %s%s: %s (channel %s, session %s, filter \'%s\')", ev
->name
,
1531 print_channel_name(channel_name
),
1532 session_name
, opt_filter
);
1537 ERR("Event %s%s: %s (channel %s, session %s, filter \'%s\')", ev
->name
,
1539 lttng_strerror(command_ret
),
1540 command_ret
== -LTTNG_ERR_NEED_CHANNEL_NAME
1541 ? print_raw_channel_name(channel_name
)
1542 : print_channel_name(channel_name
),
1543 session_name
, opt_filter
);
1547 error_holder
= command_ret
;
1550 MSG("Event %s%s: Filter '%s' successfully set",
1551 event_name
, exclusion_string
,
1554 free(exclusion_string
);
1565 ret
= mi_lttng_event(writer
, ev
, 1, handle
->domain
.type
);
1571 /* print exclusion */
1572 ret
= mi_print_exclusion(exclusion_list
);
1579 ret
= mi_lttng_writer_write_element_bool(writer
,
1580 mi_lttng_element_command_success
, success
);
1586 /* Close event element */
1587 ret
= mi_lttng_writer_close_element(writer
);
1595 event_name
= strtok(NULL
, ",");
1596 /* Reset warn, error and success */
1603 /* Close events element */
1604 ret
= mi_lttng_writer_close_element(writer
);
1617 lttng_destroy_handle(handle
);
1618 strutils_free_null_terminated_array_of_strings(exclusion_list
);
1620 /* Overwrite ret with error_holder if there was an actual error with
1621 * enabling an event.
1623 ret
= error_holder
? error_holder
: ret
;
1625 lttng_event_destroy(ev
);
1630 * Add event to trace session
1632 int cmd_enable_events(int argc
, const char **argv
)
1634 int opt
, ret
= CMD_SUCCESS
, command_ret
= CMD_SUCCESS
, success
= 1;
1635 static poptContext pc
;
1636 char *session_name
= NULL
;
1637 const char *leftover
= NULL
;
1638 int event_type
= -1;
1640 pc
= poptGetContext(NULL
, argc
, argv
, long_options
, 0);
1641 poptReadDefaultConfig(pc
, 0);
1643 /* Default event type */
1644 opt_event_type
= LTTNG_EVENT_ALL
;
1646 while ((opt
= poptGetNextOpt(pc
)) != -1) {
1651 case OPT_TRACEPOINT
:
1652 opt_event_type
= LTTNG_EVENT_TRACEPOINT
;
1655 opt_event_type
= LTTNG_EVENT_PROBE
;
1657 case OPT_USERSPACE_PROBE
:
1658 opt_event_type
= LTTNG_EVENT_USERSPACE_PROBE
;
1661 opt_event_type
= LTTNG_EVENT_FUNCTION
;
1664 opt_event_type
= LTTNG_EVENT_SYSCALL
;
1670 opt_loglevel_type
= LTTNG_EVENT_LOGLEVEL_RANGE
;
1671 opt_loglevel
= poptGetOptArg(pc
);
1673 case OPT_LOGLEVEL_ONLY
:
1674 opt_loglevel_type
= LTTNG_EVENT_LOGLEVEL_SINGLE
;
1675 opt_loglevel
= poptGetOptArg(pc
);
1677 case OPT_LIST_OPTIONS
:
1678 list_cmd_options(stdout
, long_options
);
1685 ret
= CMD_UNDEFINED
;
1689 /* Validate event type. Multiple event type are not supported. */
1690 if (event_type
== -1) {
1691 event_type
= opt_event_type
;
1693 if (event_type
!= opt_event_type
) {
1694 ERR("Multiple event type not supported.");
1701 ret
= print_missing_or_multiple_domains(
1702 opt_kernel
+ opt_userspace
+ opt_jul
+ opt_log4j
+ opt_python
);
1710 writer
= mi_lttng_writer_create(fileno(stdout
), lttng_opt_mi
);
1712 ret
= -LTTNG_ERR_NOMEM
;
1716 /* Open command element */
1717 ret
= mi_lttng_writer_command_open(writer
,
1718 mi_lttng_element_command_enable_event
);
1724 /* Open output element */
1725 ret
= mi_lttng_writer_open_element(writer
,
1726 mi_lttng_element_command_output
);
1733 opt_event_list
= (char*) poptGetArg(pc
);
1734 if (opt_event_list
== NULL
&& opt_enable_all
== 0) {
1735 ERR("Missing event name(s).\n");
1740 leftover
= poptGetArg(pc
);
1742 ERR("Unknown argument: %s", leftover
);
1747 if (!opt_session_name
) {
1748 session_name
= get_session_name();
1749 if (session_name
== NULL
) {
1750 command_ret
= CMD_ERROR
;
1755 session_name
= opt_session_name
;
1758 command_ret
= enable_events(session_name
);
1767 /* Close output element */
1768 ret
= mi_lttng_writer_close_element(writer
);
1774 ret
= mi_lttng_writer_write_element_bool(writer
,
1775 mi_lttng_element_command_success
, success
);
1781 /* Command element close */
1782 ret
= mi_lttng_writer_command_close(writer
);
1791 if (writer
&& mi_lttng_writer_destroy(writer
)) {
1792 /* Preserve original error code */
1793 ret
= ret
? ret
: LTTNG_ERR_MI_IO_FAIL
;
1796 if (opt_session_name
== NULL
) {
1800 /* Overwrite ret if an error occurred in enable_events */
1801 ret
= command_ret
? command_ret
: ret
;
1803 poptFreeContext(pc
);