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 * userspace probe fields are separated by ':'.
319 tokens
= strutils_split(opt
, ':', 1);
320 num_token
= strutils_array_of_strings_len(tokens
);
323 * Early sanity check that the number of parameter is between 2 and 4
326 * std:PATH:PROVIDER_NAME:PROBE_NAME
327 * PATH:SYMBOL (same behavior as ELF)
329 if (num_token
< 2 || num_token
> 4) {
335 * Looking up the first parameter will tell the technique to use to
336 * interpret the userspace probe/function description.
340 /* When the probe type is omitted we assume ELF for now. */
342 if (num_token
== 3 && strcmp(tokens
[0], "elf") == 0) {
343 target_path
= tokens
[1];
344 symbol_name
= tokens
[2];
345 } else if (num_token
== 2) {
346 target_path
= tokens
[0];
347 symbol_name
= tokens
[1];
353 lttng_userspace_probe_location_lookup_method_function_elf_create();
354 if (!lookup_method
) {
355 WARN("Failed to create ELF lookup method");
361 if (strcmp(tokens
[0], "sdt") == 0) {
362 target_path
= tokens
[1];
363 provider_name
= tokens
[2];
364 probe_name
= tokens
[3];
370 lttng_userspace_probe_location_lookup_method_tracepoint_sdt_create();
371 if (!lookup_method
) {
372 WARN("Failed to create ELF lookup method");
382 /* strutils_unescape_string allocates a new char *. */
383 unescaped_target_path
= strutils_unescape_string(target_path
, 0);
384 if (!unescaped_target_path
) {
385 ret
= -LTTNG_ERR_INVALID
;
390 * If there is not forward slash in the path. Walk the $PATH else
393 if (strchr(target_path
, '/') == NULL
) {
394 /* Walk the $PATH variable to find the targeted binary. */
395 real_target_path
= zmalloc(LTTNG_PATH_MAX
* sizeof(char));
396 if (!real_target_path
) {
397 PERROR("Error allocating path buffer");
399 goto end_unescaped_string
;
401 ret
= walk_command_search_path(target_path
, real_target_path
);
403 ERR("Binary not found.");
409 * Expand references to `/./` and `/../`. This function does not check
410 * if the file exists.
412 real_target_path
= utils_expand_path_keep_symlink(target_path
);
413 if (!real_target_path
) {
414 ERR("Error expanding the path to binary.");
420 * Check if the file exists using access(2). If it does not, walk the
423 ret
= access(real_target_path
, F_OK
);
430 switch (lttng_userspace_probe_location_lookup_method_get_type(lookup_method
)) {
431 case LTTNG_USERSPACE_PROBE_LOCATION_LOOKUP_METHOD_TYPE_FUNCTION_ELF
:
432 probe_location
= lttng_userspace_probe_location_function_create(
433 real_target_path
, symbol_name
, lookup_method
);
434 if (!probe_location
) {
435 WARN("Failed to create function probe location");
437 goto end_destroy_lookup_method
;
440 /* Ownership transferred to probe_location. */
441 lookup_method
= NULL
;
443 ret
= lttng_event_set_userspace_probe_location(ev
, probe_location
);
445 WARN("Failed to set probe location on event");
447 goto end_destroy_location
;
450 case LTTNG_USERSPACE_PROBE_LOCATION_LOOKUP_METHOD_TYPE_TRACEPOINT_SDT
:
451 probe_location
= lttng_userspace_probe_location_tracepoint_create(
452 real_target_path
, provider_name
, probe_name
, lookup_method
);
453 if (!probe_location
) {
454 WARN("Failed to create function probe location");
456 goto end_destroy_lookup_method
;
459 /* Ownership transferred to probe_location. */
460 lookup_method
= NULL
;
462 ret
= lttng_event_set_userspace_probe_location(ev
, probe_location
);
464 WARN("Failed to set probe location on event");
466 goto end_destroy_location
;
475 case LTTNG_EVENT_USERSPACE_PROBE
:
483 end_destroy_location
:
484 lttng_userspace_probe_location_destroy(probe_location
);
485 end_destroy_lookup_method
:
486 lttng_userspace_probe_location_lookup_method_destroy(lookup_method
);
489 * Free path that was allocated by the call to realpath() or when walking
492 free(real_target_path
);
493 end_unescaped_string
:
494 free(unescaped_target_path
);
496 strutils_free_null_terminated_array_of_strings(tokens
);
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 */
968 channel_name
= opt_channel_name
;
970 handle
= lttng_create_handle(session_name
, &dom
);
971 if (handle
== NULL
) {
978 /* Open a events element */
979 ret
= mi_lttng_writer_open_element(writer
, config_element_events
);
986 if (opt_enable_all
) {
987 /* Default setup for enable all */
989 ev
->type
= opt_event_type
;
990 strcpy(ev
->name
, "*");
991 /* kernel loglevels not implemented */
992 ev
->loglevel_type
= LTTNG_EVENT_LOGLEVEL_ALL
;
994 ev
->type
= LTTNG_EVENT_TRACEPOINT
;
995 strcpy(ev
->name
, "*");
996 ev
->loglevel_type
= opt_loglevel_type
;
998 assert(opt_userspace
|| opt_jul
|| opt_log4j
|| opt_python
);
1000 ev
->loglevel
= loglevel_str_to_value(opt_loglevel
);
1001 } else if (opt_jul
) {
1002 ev
->loglevel
= loglevel_jul_str_to_value(opt_loglevel
);
1003 } else if (opt_log4j
) {
1004 ev
->loglevel
= loglevel_log4j_str_to_value(opt_loglevel
);
1005 } else if (opt_python
) {
1006 ev
->loglevel
= loglevel_python_str_to_value(opt_loglevel
);
1008 if (ev
->loglevel
== -1) {
1009 ERR("Unknown loglevel %s", opt_loglevel
);
1010 ret
= -LTTNG_ERR_INVALID
;
1014 assert(opt_userspace
|| opt_jul
|| opt_log4j
|| opt_python
);
1015 if (opt_userspace
) {
1017 } else if (opt_jul
) {
1018 ev
->loglevel
= LTTNG_LOGLEVEL_JUL_ALL
;
1019 } else if (opt_log4j
) {
1020 ev
->loglevel
= LTTNG_LOGLEVEL_LOG4J_ALL
;
1021 } else if (opt_python
) {
1022 ev
->loglevel
= LTTNG_LOGLEVEL_PYTHON_DEBUG
;
1028 ret
= create_exclusion_list_and_validate("*",
1029 opt_exclude
, &exclusion_list
);
1036 warn_on_truncated_exclusion_names(exclusion_list
,
1040 ret
= lttng_enable_event_with_exclusions(handle
,
1043 exclusion_list
? strutils_array_of_strings_len(exclusion_list
) : 0,
1047 case LTTNG_ERR_KERN_EVENT_EXIST
:
1048 WARN("Kernel events already enabled (channel %s, session %s)",
1049 print_channel_name(channel_name
), session_name
);
1052 case LTTNG_ERR_TRACE_ALREADY_STARTED
:
1054 const char *msg
= "The command tried to enable an event in a new domain for a session that has already been started once.";
1055 ERR("Events: %s (channel %s, session %s)",
1057 print_channel_name(channel_name
),
1063 ERR("Events: %s (channel %s, session %s)",
1064 lttng_strerror(ret
),
1065 ret
== -LTTNG_ERR_NEED_CHANNEL_NAME
1066 ? print_raw_channel_name(channel_name
)
1067 : print_channel_name(channel_name
),
1075 switch (opt_event_type
) {
1076 case LTTNG_EVENT_TRACEPOINT
:
1077 if (opt_loglevel
&& dom
.type
!= LTTNG_DOMAIN_KERNEL
) {
1078 char *exclusion_string
= print_exclusions(exclusion_list
);
1080 if (!exclusion_string
) {
1081 PERROR("Cannot allocate exclusion_string");
1085 MSG("All %s tracepoints%s are enabled in channel %s for loglevel %s",
1086 get_domain_str(dom
.type
),
1088 print_channel_name(channel_name
),
1090 free(exclusion_string
);
1092 char *exclusion_string
= print_exclusions(exclusion_list
);
1094 if (!exclusion_string
) {
1095 PERROR("Cannot allocate exclusion_string");
1099 MSG("All %s tracepoints%s are enabled in channel %s",
1100 get_domain_str(dom
.type
),
1102 print_channel_name(channel_name
));
1103 free(exclusion_string
);
1106 case LTTNG_EVENT_SYSCALL
:
1108 MSG("All %s system calls are enabled in channel %s",
1109 get_domain_str(dom
.type
),
1110 print_channel_name(channel_name
));
1113 case LTTNG_EVENT_ALL
:
1114 if (opt_loglevel
&& dom
.type
!= LTTNG_DOMAIN_KERNEL
) {
1115 char *exclusion_string
= print_exclusions(exclusion_list
);
1117 if (!exclusion_string
) {
1118 PERROR("Cannot allocate exclusion_string");
1122 MSG("All %s events%s are enabled in channel %s for loglevel %s",
1123 get_domain_str(dom
.type
),
1125 print_channel_name(channel_name
),
1127 free(exclusion_string
);
1129 char *exclusion_string
= print_exclusions(exclusion_list
);
1131 if (!exclusion_string
) {
1132 PERROR("Cannot allocate exclusion_string");
1136 MSG("All %s events%s are enabled in channel %s",
1137 get_domain_str(dom
.type
),
1139 print_channel_name(channel_name
));
1140 free(exclusion_string
);
1145 * We should not be here since lttng_enable_event should have
1146 * failed on the event type.
1153 command_ret
= lttng_enable_event_with_exclusions(handle
, ev
, channel_name
,
1155 exclusion_list
? strutils_array_of_strings_len(exclusion_list
) : 0,
1157 if (command_ret
< 0) {
1158 switch (-command_ret
) {
1159 case LTTNG_ERR_FILTER_EXIST
:
1160 WARN("Filter on all events is already enabled"
1161 " (channel %s, session %s)",
1162 print_channel_name(channel_name
), session_name
);
1165 case LTTNG_ERR_TRACE_ALREADY_STARTED
:
1167 const char *msg
= "The command tried to enable an event in a new domain for a session that has already been started once.";
1168 ERR("All events: %s (channel %s, session %s, filter \'%s\')",
1170 print_channel_name(channel_name
),
1171 session_name
, opt_filter
);
1176 ERR("All events: %s (channel %s, session %s, filter \'%s\')",
1177 lttng_strerror(command_ret
),
1178 command_ret
== -LTTNG_ERR_NEED_CHANNEL_NAME
1179 ? print_raw_channel_name(channel_name
)
1180 : print_channel_name(channel_name
),
1181 session_name
, opt_filter
);
1185 error_holder
= command_ret
;
1188 MSG("Filter '%s' successfully set", opt_filter
);
1193 /* The wildcard * is used for kernel and ust domain to
1194 * represent ALL. We copy * in event name to force the wildcard use
1197 * Note: this is strictly for semantic and printing while in
1198 * machine interface mode.
1200 strcpy(ev
->name
, "*");
1202 /* If we reach here the events are enabled */
1203 if (!error
&& !warn
) {
1209 ret
= mi_lttng_event(writer
, ev
, 1, handle
->domain
.type
);
1215 /* print exclusion */
1216 ret
= mi_print_exclusion(exclusion_list
);
1223 ret
= mi_lttng_writer_write_element_bool(writer
,
1224 mi_lttng_element_command_success
, success
);
1230 /* Close event element */
1231 ret
= mi_lttng_writer_close_element(writer
);
1241 /* Strip event list */
1242 event_name
= strtok(opt_event_list
, ",");
1243 while (event_name
!= NULL
) {
1244 /* Copy name and type of the event */
1245 strncpy(ev
->name
, event_name
, LTTNG_SYMBOL_NAME_LEN
);
1246 ev
->name
[LTTNG_SYMBOL_NAME_LEN
- 1] = '\0';
1247 ev
->type
= opt_event_type
;
1249 /* Kernel tracer action */
1251 DBG("Enabling kernel event %s for channel %s",
1253 print_channel_name(channel_name
));
1255 switch (opt_event_type
) {
1256 case LTTNG_EVENT_ALL
: /* Enable tracepoints and syscalls */
1257 /* If event name differs from *, select tracepoint. */
1258 if (strcmp(ev
->name
, "*")) {
1259 ev
->type
= LTTNG_EVENT_TRACEPOINT
;
1262 case LTTNG_EVENT_TRACEPOINT
:
1264 case LTTNG_EVENT_PROBE
:
1265 ret
= parse_probe_opts(ev
, opt_probe
);
1267 ERR("Unable to parse probe options");
1272 case LTTNG_EVENT_USERSPACE_PROBE
:
1273 ret
= parse_userspace_probe_opts(ev
, opt_userspace_probe
);
1275 ERR("Unable to parse userspace probe options");
1280 case LTTNG_EVENT_FUNCTION
:
1281 ret
= parse_probe_opts(ev
, opt_function
);
1283 ERR("Unable to parse function probe options");
1288 case LTTNG_EVENT_SYSCALL
:
1289 ev
->type
= LTTNG_EVENT_SYSCALL
;
1292 ret
= CMD_UNDEFINED
;
1296 /* kernel loglevels not implemented */
1297 ev
->loglevel_type
= LTTNG_EVENT_LOGLEVEL_ALL
;
1298 } else if (opt_userspace
) { /* User-space tracer action */
1299 DBG("Enabling UST event %s for channel %s, loglevel %s", event_name
,
1300 print_channel_name(channel_name
), opt_loglevel
? : "<all>");
1302 switch (opt_event_type
) {
1303 case LTTNG_EVENT_ALL
: /* Default behavior is tracepoint */
1305 case LTTNG_EVENT_TRACEPOINT
:
1306 /* Copy name and type of the event */
1307 ev
->type
= LTTNG_EVENT_TRACEPOINT
;
1308 strncpy(ev
->name
, event_name
, LTTNG_SYMBOL_NAME_LEN
);
1309 ev
->name
[LTTNG_SYMBOL_NAME_LEN
- 1] = '\0';
1311 case LTTNG_EVENT_PROBE
:
1312 case LTTNG_EVENT_FUNCTION
:
1313 case LTTNG_EVENT_SYSCALL
:
1314 case LTTNG_EVENT_USERSPACE_PROBE
:
1316 ERR("Event type not available for user-space tracing");
1317 ret
= CMD_UNSUPPORTED
;
1323 if (opt_event_type
!= LTTNG_EVENT_ALL
&& opt_event_type
!= LTTNG_EVENT_TRACEPOINT
) {
1324 ERR("Exclusion option can only be used with tracepoint events");
1328 /* Free previously allocated items */
1329 strutils_free_null_terminated_array_of_strings(
1331 exclusion_list
= NULL
;
1332 ret
= create_exclusion_list_and_validate(
1333 event_name
, opt_exclude
,
1340 warn_on_truncated_exclusion_names(
1341 exclusion_list
, &warn
);
1344 ev
->loglevel_type
= opt_loglevel_type
;
1346 ev
->loglevel
= loglevel_str_to_value(opt_loglevel
);
1347 if (ev
->loglevel
== -1) {
1348 ERR("Unknown loglevel %s", opt_loglevel
);
1349 ret
= -LTTNG_ERR_INVALID
;
1355 } else if (opt_jul
|| opt_log4j
|| opt_python
) {
1356 if (opt_event_type
!= LTTNG_EVENT_ALL
&&
1357 opt_event_type
!= LTTNG_EVENT_TRACEPOINT
) {
1358 ERR("Event type not supported for domain.");
1359 ret
= CMD_UNSUPPORTED
;
1363 ev
->loglevel_type
= opt_loglevel_type
;
1366 ev
->loglevel
= loglevel_jul_str_to_value(opt_loglevel
);
1367 } else if (opt_log4j
) {
1368 ev
->loglevel
= loglevel_log4j_str_to_value(opt_loglevel
);
1369 } else if (opt_python
) {
1370 ev
->loglevel
= loglevel_python_str_to_value(opt_loglevel
);
1372 if (ev
->loglevel
== -1) {
1373 ERR("Unknown loglevel %s", opt_loglevel
);
1374 ret
= -LTTNG_ERR_INVALID
;
1379 ev
->loglevel
= LTTNG_LOGLEVEL_JUL_ALL
;
1380 } else if (opt_log4j
) {
1381 ev
->loglevel
= LTTNG_LOGLEVEL_LOG4J_ALL
;
1382 } else if (opt_python
) {
1383 ev
->loglevel
= LTTNG_LOGLEVEL_PYTHON_DEBUG
;
1386 ev
->type
= LTTNG_EVENT_TRACEPOINT
;
1387 strncpy(ev
->name
, event_name
, LTTNG_SYMBOL_NAME_LEN
);
1388 ev
->name
[LTTNG_SYMBOL_NAME_LEN
- 1] = '\0';
1394 char *exclusion_string
;
1396 command_ret
= lttng_enable_event_with_exclusions(handle
,
1399 exclusion_list
? strutils_array_of_strings_len(exclusion_list
) : 0,
1401 exclusion_string
= print_exclusions(exclusion_list
);
1402 if (!exclusion_string
) {
1403 PERROR("Cannot allocate exclusion_string");
1407 if (command_ret
< 0) {
1408 /* Turn ret to positive value to handle the positive error code */
1409 switch (-command_ret
) {
1410 case LTTNG_ERR_KERN_EVENT_EXIST
:
1411 WARN("Kernel event %s%s already enabled (channel %s, session %s)",
1414 print_channel_name(channel_name
), session_name
);
1417 case LTTNG_ERR_TRACE_ALREADY_STARTED
:
1419 const char *msg
= "The command tried to enable an event in a new domain for a session that has already been started once.";
1420 ERR("Event %s%s: %s (channel %s, session %s)", event_name
,
1423 print_channel_name(channel_name
),
1428 case LTTNG_ERR_SDT_PROBE_SEMAPHORE
:
1429 ERR("SDT probes %s guarded by semaphores are not supported (channel %s, session %s)",
1430 event_name
, print_channel_name(channel_name
),
1435 ERR("Event %s%s: %s (channel %s, session %s)", event_name
,
1437 lttng_strerror(command_ret
),
1438 command_ret
== -LTTNG_ERR_NEED_CHANNEL_NAME
1439 ? print_raw_channel_name(channel_name
)
1440 : print_channel_name(channel_name
),
1445 error_holder
= command_ret
;
1448 case LTTNG_DOMAIN_KERNEL
:
1449 case LTTNG_DOMAIN_UST
:
1450 MSG("%s event %s%s created in channel %s",
1451 get_domain_str(dom
.type
),
1454 print_channel_name(channel_name
));
1456 case LTTNG_DOMAIN_JUL
:
1457 case LTTNG_DOMAIN_LOG4J
:
1458 case LTTNG_DOMAIN_PYTHON
:
1460 * Don't print the default channel
1461 * name for agent domains.
1463 MSG("%s event %s%s enabled",
1464 get_domain_str(dom
.type
),
1472 free(exclusion_string
);
1476 char *exclusion_string
;
1478 /* Filter present */
1481 command_ret
= lttng_enable_event_with_exclusions(handle
, ev
, channel_name
,
1483 exclusion_list
? strutils_array_of_strings_len(exclusion_list
) : 0,
1485 exclusion_string
= print_exclusions(exclusion_list
);
1486 if (!exclusion_string
) {
1487 PERROR("Cannot allocate exclusion_string");
1491 if (command_ret
< 0) {
1492 switch (-command_ret
) {
1493 case LTTNG_ERR_FILTER_EXIST
:
1494 WARN("Filter on event %s%s is already enabled"
1495 " (channel %s, session %s)",
1498 print_channel_name(channel_name
), session_name
);
1501 case LTTNG_ERR_TRACE_ALREADY_STARTED
:
1503 const char *msg
= "The command tried to enable an event in a new domain for a session that has already been started once.";
1504 ERR("Event %s%s: %s (channel %s, session %s, filter \'%s\')", ev
->name
,
1507 print_channel_name(channel_name
),
1508 session_name
, opt_filter
);
1513 ERR("Event %s%s: %s (channel %s, session %s, filter \'%s\')", ev
->name
,
1515 lttng_strerror(command_ret
),
1516 command_ret
== -LTTNG_ERR_NEED_CHANNEL_NAME
1517 ? print_raw_channel_name(channel_name
)
1518 : print_channel_name(channel_name
),
1519 session_name
, opt_filter
);
1523 error_holder
= command_ret
;
1526 MSG("Event %s%s: Filter '%s' successfully set",
1527 event_name
, exclusion_string
,
1530 free(exclusion_string
);
1541 ret
= mi_lttng_event(writer
, ev
, 1, handle
->domain
.type
);
1547 /* print exclusion */
1548 ret
= mi_print_exclusion(exclusion_list
);
1555 ret
= mi_lttng_writer_write_element_bool(writer
,
1556 mi_lttng_element_command_success
, success
);
1562 /* Close event element */
1563 ret
= mi_lttng_writer_close_element(writer
);
1571 event_name
= strtok(NULL
, ",");
1572 /* Reset warn, error and success */
1579 /* Close events element */
1580 ret
= mi_lttng_writer_close_element(writer
);
1593 lttng_destroy_handle(handle
);
1594 strutils_free_null_terminated_array_of_strings(exclusion_list
);
1596 /* Overwrite ret with error_holder if there was an actual error with
1597 * enabling an event.
1599 ret
= error_holder
? error_holder
: ret
;
1601 lttng_event_destroy(ev
);
1606 * Add event to trace session
1608 int cmd_enable_events(int argc
, const char **argv
)
1610 int opt
, ret
= CMD_SUCCESS
, command_ret
= CMD_SUCCESS
, success
= 1;
1611 static poptContext pc
;
1612 char *session_name
= NULL
;
1613 const char *leftover
= NULL
;
1614 int event_type
= -1;
1616 pc
= poptGetContext(NULL
, argc
, argv
, long_options
, 0);
1617 poptReadDefaultConfig(pc
, 0);
1619 /* Default event type */
1620 opt_event_type
= LTTNG_EVENT_ALL
;
1622 while ((opt
= poptGetNextOpt(pc
)) != -1) {
1627 case OPT_TRACEPOINT
:
1628 opt_event_type
= LTTNG_EVENT_TRACEPOINT
;
1631 opt_event_type
= LTTNG_EVENT_PROBE
;
1633 case OPT_USERSPACE_PROBE
:
1634 opt_event_type
= LTTNG_EVENT_USERSPACE_PROBE
;
1637 opt_event_type
= LTTNG_EVENT_FUNCTION
;
1640 opt_event_type
= LTTNG_EVENT_SYSCALL
;
1646 opt_loglevel_type
= LTTNG_EVENT_LOGLEVEL_RANGE
;
1647 opt_loglevel
= poptGetOptArg(pc
);
1649 case OPT_LOGLEVEL_ONLY
:
1650 opt_loglevel_type
= LTTNG_EVENT_LOGLEVEL_SINGLE
;
1651 opt_loglevel
= poptGetOptArg(pc
);
1653 case OPT_LIST_OPTIONS
:
1654 list_cmd_options(stdout
, long_options
);
1661 ret
= CMD_UNDEFINED
;
1665 /* Validate event type. Multiple event type are not supported. */
1666 if (event_type
== -1) {
1667 event_type
= opt_event_type
;
1669 if (event_type
!= opt_event_type
) {
1670 ERR("Multiple event type not supported.");
1677 ret
= print_missing_or_multiple_domains(
1678 opt_kernel
+ opt_userspace
+ opt_jul
+ opt_log4j
+ opt_python
);
1686 writer
= mi_lttng_writer_create(fileno(stdout
), lttng_opt_mi
);
1688 ret
= -LTTNG_ERR_NOMEM
;
1692 /* Open command element */
1693 ret
= mi_lttng_writer_command_open(writer
,
1694 mi_lttng_element_command_enable_event
);
1700 /* Open output element */
1701 ret
= mi_lttng_writer_open_element(writer
,
1702 mi_lttng_element_command_output
);
1709 opt_event_list
= (char*) poptGetArg(pc
);
1710 if (opt_event_list
== NULL
&& opt_enable_all
== 0) {
1711 ERR("Missing event name(s).\n");
1716 leftover
= poptGetArg(pc
);
1718 ERR("Unknown argument: %s", leftover
);
1723 if (!opt_session_name
) {
1724 session_name
= get_session_name();
1725 if (session_name
== NULL
) {
1726 command_ret
= CMD_ERROR
;
1731 session_name
= opt_session_name
;
1734 command_ret
= enable_events(session_name
);
1743 /* Close output element */
1744 ret
= mi_lttng_writer_close_element(writer
);
1750 ret
= mi_lttng_writer_write_element_bool(writer
,
1751 mi_lttng_element_command_success
, success
);
1757 /* Command element close */
1758 ret
= mi_lttng_writer_command_close(writer
);
1767 if (writer
&& mi_lttng_writer_destroy(writer
)) {
1768 /* Preserve original error code */
1769 ret
= ret
? ret
: LTTNG_ERR_MI_IO_FAIL
;
1772 if (opt_session_name
== NULL
) {
1776 /* Overwrite ret if an error occurred in enable_events */
1777 ret
= command_ret
? command_ret
: ret
;
1779 poptFreeContext(pc
);