Fix mi: use of wrong variable for error propagation
[lttng-tools.git] / src / bin / lttng / commands / enable_events.c
... / ...
CommitLineData
1/*
2 * Copyright (C) 2011 - David Goulet <david.goulet@polymtl.ca>
3 *
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.
7 *
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.
12 *
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.
16 */
17
18#define _GNU_SOURCE
19#include <assert.h>
20#include <popt.h>
21#include <stdio.h>
22#include <stdlib.h>
23#include <string.h>
24#include <sys/stat.h>
25#include <sys/types.h>
26#include <unistd.h>
27#include <inttypes.h>
28#include <ctype.h>
29
30#include <src/common/sessiond-comm/sessiond-comm.h>
31
32/* Mi dependancy */
33#include <common/mi-lttng.h>
34
35#include "../command.h"
36
37#if (LTTNG_SYMBOL_NAME_LEN == 256)
38#define LTTNG_SYMBOL_NAME_LEN_SCANF_IS_A_BROKEN_API "255"
39#endif
40
41static char *opt_event_list;
42static int opt_event_type;
43static const char *opt_loglevel;
44static int opt_loglevel_type;
45static int opt_kernel;
46static char *opt_session_name;
47static int opt_userspace;
48static int opt_jul;
49static int opt_enable_all;
50static char *opt_probe;
51static char *opt_function;
52static char *opt_function_entry_symbol;
53static char *opt_channel_name;
54static char *opt_filter;
55static char *opt_exclude;
56#if 0
57/* Not implemented yet */
58static char *opt_cmd_name;
59static pid_t opt_pid;
60#endif
61
62enum {
63 OPT_HELP = 1,
64 OPT_TRACEPOINT,
65 OPT_PROBE,
66 OPT_FUNCTION,
67 OPT_FUNCTION_ENTRY,
68 OPT_SYSCALL,
69 OPT_USERSPACE,
70 OPT_LOGLEVEL,
71 OPT_LOGLEVEL_ONLY,
72 OPT_LIST_OPTIONS,
73 OPT_FILTER,
74 OPT_EXCLUDE,
75};
76
77static struct lttng_handle *handle;
78static struct mi_writer *writer;
79
80static struct poptOption long_options[] = {
81 /* longName, shortName, argInfo, argPtr, value, descrip, argDesc */
82 {"help", 'h', POPT_ARG_NONE, 0, OPT_HELP, 0, 0},
83 {"session", 's', POPT_ARG_STRING, &opt_session_name, 0, 0, 0},
84 {"all", 'a', POPT_ARG_VAL, &opt_enable_all, 1, 0, 0},
85 {"channel", 'c', POPT_ARG_STRING, &opt_channel_name, 0, 0, 0},
86 {"kernel", 'k', POPT_ARG_VAL, &opt_kernel, 1, 0, 0},
87 {"userspace", 'u', POPT_ARG_NONE, 0, OPT_USERSPACE, 0, 0},
88 {"jul", 'j', POPT_ARG_VAL, &opt_jul, 1, 0, 0},
89 {"tracepoint", 0, POPT_ARG_NONE, 0, OPT_TRACEPOINT, 0, 0},
90 {"probe", 0, POPT_ARG_STRING, &opt_probe, OPT_PROBE, 0, 0},
91 {"function", 0, POPT_ARG_STRING, &opt_function, OPT_FUNCTION, 0, 0},
92#if 0
93 /*
94 * Currently removed from lttng kernel tracer. Removed from
95 * lttng UI to discourage its use.
96 */
97 {"function:entry", 0, POPT_ARG_STRING, &opt_function_entry_symbol, OPT_FUNCTION_ENTRY, 0, 0},
98#endif
99 {"syscall", 0, POPT_ARG_NONE, 0, OPT_SYSCALL, 0, 0},
100 {"loglevel", 0, POPT_ARG_STRING, 0, OPT_LOGLEVEL, 0, 0},
101 {"loglevel-only", 0, POPT_ARG_STRING, 0, OPT_LOGLEVEL_ONLY, 0, 0},
102 {"list-options", 0, POPT_ARG_NONE, NULL, OPT_LIST_OPTIONS, NULL, NULL},
103 {"filter", 'f', POPT_ARG_STRING, &opt_filter, OPT_FILTER, 0, 0},
104 {"exclude", 'x', POPT_ARG_STRING, &opt_exclude, OPT_EXCLUDE, 0, 0},
105 {0, 0, 0, 0, 0, 0, 0}
106};
107
108/*
109 * usage
110 */
111static void usage(FILE *ofp)
112{
113 fprintf(ofp, "usage: lttng enable-event NAME[,NAME2,...] [-k|-u] [OPTIONS] \n");
114 fprintf(ofp, "\n");
115 fprintf(ofp, "Options:\n");
116 fprintf(ofp, " -h, --help Show this help\n");
117 fprintf(ofp, " --list-options Simple listing of options\n");
118 fprintf(ofp, " -s, --session NAME Apply to session name\n");
119 fprintf(ofp, " -c, --channel NAME Apply to this channel\n");
120 fprintf(ofp, " -a, --all Enable all tracepoints and syscalls\n");
121 fprintf(ofp, " -k, --kernel Apply for the kernel tracer\n");
122 fprintf(ofp, " -u, --userspace Apply to the user-space tracer\n");
123 fprintf(ofp, " -j, --jul Apply for Java application using JUL\n");
124 fprintf(ofp, "\n");
125 fprintf(ofp, "Event options:\n");
126 fprintf(ofp, " --tracepoint Tracepoint event (default)\n");
127 fprintf(ofp, " - userspace tracer supports wildcards at end of string.\n");
128 fprintf(ofp, " Don't forget to quote to deal with bash expansion.\n");
129 fprintf(ofp, " e.g.:\n");
130 fprintf(ofp, " \"*\"\n");
131 fprintf(ofp, " \"app_component:na*\"\n");
132 fprintf(ofp, " --probe (addr | symbol | symbol+offset)\n");
133 fprintf(ofp, " Dynamic probe.\n");
134 fprintf(ofp, " Addr and offset can be octal (0NNN...),\n");
135 fprintf(ofp, " decimal (NNN...) or hexadecimal (0xNNN...)\n");
136 fprintf(ofp, " --function (addr | symbol | symbol+offset)\n");
137 fprintf(ofp, " Dynamic function entry/return probe.\n");
138 fprintf(ofp, " Addr and offset can be octal (0NNN...),\n");
139 fprintf(ofp, " decimal (NNN...) or hexadecimal (0xNNN...)\n");
140#if 0
141 fprintf(ofp, " --function:entry symbol\n");
142 fprintf(ofp, " Function tracer event\n");
143#endif
144 fprintf(ofp, " --syscall System call event\n");
145 fprintf(ofp, "\n");
146 fprintf(ofp, " --loglevel name\n");
147 fprintf(ofp, " Tracepoint loglevel range from 0 to loglevel.\n");
148 fprintf(ofp, " For JUL domain, see the table below for the range values.\n");
149 fprintf(ofp, " --loglevel-only name\n");
150 fprintf(ofp, " Tracepoint loglevel (only this loglevel)\n");
151 fprintf(ofp, "\n");
152 fprintf(ofp, " The loglevel or loglevel-only options should be\n");
153 fprintf(ofp, " combined with a tracepoint name or tracepoint\n");
154 fprintf(ofp, " wildcard.\n");
155 fprintf(ofp, " Available loglevels:\n");
156 fprintf(ofp, " (higher value is more verbose)\n");
157 fprintf(ofp, " TRACE_EMERG = 0\n");
158 fprintf(ofp, " TRACE_ALERT = 1\n");
159 fprintf(ofp, " TRACE_CRIT = 2\n");
160 fprintf(ofp, " TRACE_ERR = 3\n");
161 fprintf(ofp, " TRACE_WARNING = 4\n");
162 fprintf(ofp, " TRACE_NOTICE = 5\n");
163 fprintf(ofp, " TRACE_INFO = 6\n");
164 fprintf(ofp, " TRACE_DEBUG_SYSTEM = 7\n");
165 fprintf(ofp, " TRACE_DEBUG_PROGRAM = 8\n");
166 fprintf(ofp, " TRACE_DEBUG_PROCESS = 9\n");
167 fprintf(ofp, " TRACE_DEBUG_MODULE = 10\n");
168 fprintf(ofp, " TRACE_DEBUG_UNIT = 11\n");
169 fprintf(ofp, " TRACE_DEBUG_FUNCTION = 12\n");
170 fprintf(ofp, " TRACE_DEBUG_LINE = 13\n");
171 fprintf(ofp, " TRACE_DEBUG = 14\n");
172 fprintf(ofp, " (shortcuts such as \"system\" are allowed)\n");
173 fprintf(ofp, "\n");
174 fprintf(ofp, " Available JUL domain loglevels:\n");
175 fprintf(ofp, " JUL_OFF = INT32_MAX\n");
176 fprintf(ofp, " JUL_SEVERE = %d\n", LTTNG_LOGLEVEL_JUL_SEVERE);
177 fprintf(ofp, " JUL_WARNING = %d\n", LTTNG_LOGLEVEL_JUL_WARNING);
178 fprintf(ofp, " JUL_INFO = %d\n", LTTNG_LOGLEVEL_JUL_INFO);
179 fprintf(ofp, " JUL_CONFIG = %d\n", LTTNG_LOGLEVEL_JUL_CONFIG);
180 fprintf(ofp, " JUL_FINE = %d\n", LTTNG_LOGLEVEL_JUL_FINE);
181 fprintf(ofp, " JUL_FINER = %d\n", LTTNG_LOGLEVEL_JUL_FINER);
182 fprintf(ofp, " JUL_FINEST = %d\n", LTTNG_LOGLEVEL_JUL_FINEST);
183 fprintf(ofp, " JUL_ALL = INT32_MIN\n");
184 fprintf(ofp, " (shortcuts such as \"severe\" are allowed)\n");
185 fprintf(ofp, "\n");
186 fprintf(ofp, " -f, --filter \'expression\'\n");
187 fprintf(ofp, " Filter expression on event fields and context.\n");
188 fprintf(ofp, " Event recording depends on evaluation.\n");
189 fprintf(ofp, " Only specify on first activation of\n");
190 fprintf(ofp, " a given event within a session.\n");
191 fprintf(ofp, " Filter only allowed when enabling\n");
192 fprintf(ofp, " events within a session before tracing\n");
193 fprintf(ofp, " is started. If the filter fails to link\n");
194 fprintf(ofp, " with the event within the traced domain,\n");
195 fprintf(ofp, " the event will be discarded. Currently,\n");
196 fprintf(ofp, " filter is only implemented for the user-space\n");
197 fprintf(ofp, " tracer.\n");
198 fprintf(ofp, " Expression examples:.\n");
199 fprintf(ofp, " \n");
200 fprintf(ofp, " 'intfield > 500 && intfield < 503'\n");
201 fprintf(ofp, " '(strfield == \"test\" || intfield != 10) && intfield > 33'\n");
202 fprintf(ofp, " 'doublefield > 1.1 && intfield < 5.3'\n");
203 fprintf(ofp, " \n");
204 fprintf(ofp, " Wildcards are allowed at the end of strings:\n");
205 fprintf(ofp, " 'seqfield1 == \"te*\"'\n");
206 fprintf(ofp, " In string literals, the escape character is '\\'.\n");
207 fprintf(ofp, " Use '\\*' for the '*' character, and '\\\\' for\n");
208 fprintf(ofp, " the '\\' character. Wildcard match any sequence of,\n");
209 fprintf(ofp, " characters including an empty sub-string (match 0 or\n");
210 fprintf(ofp, " more characters).\n");
211 fprintf(ofp, "\n");
212 fprintf(ofp, " Context information can be used for filtering. The\n");
213 fprintf(ofp, " examples below show usage of context filtering on\n");
214 fprintf(ofp, " process name (with a wildcard), process ID range, and\n");
215 fprintf(ofp, " unique thread ID for filtering. The process and\n");
216 fprintf(ofp, " thread ID of running applications can be found under\n");
217 fprintf(ofp, " columns \"PID\" and \"LWP\" of the \"ps -eLf\" command.\n");
218 fprintf(ofp, "\n");
219 fprintf(ofp, " '$ctx.procname == \"demo*\"'\n");
220 fprintf(ofp, " '$ctx.vpid >= 4433 && $ctx.vpid < 4455'\n");
221 fprintf(ofp, " '$ctx.vtid == 1234'\n");
222 fprintf(ofp, " -x, --exclude LIST\n");
223 fprintf(ofp, " Add exclusions to UST tracepoints:\n");
224 fprintf(ofp, " Events that match any of the items\n");
225 fprintf(ofp, " in the comma-separated LIST are not\n");
226 fprintf(ofp, " enabled, even if they match a wildcard\n");
227 fprintf(ofp, " definition of the event.\n");
228 fprintf(ofp, "\n");
229}
230
231/*
232 * Parse probe options.
233 */
234static int parse_probe_opts(struct lttng_event *ev, char *opt)
235{
236 int ret;
237 char s_hex[19];
238#define S_HEX_LEN_SCANF_IS_A_BROKEN_API "18" /* 18 is (19 - 1) (\0 is extra) */
239 char name[LTTNG_SYMBOL_NAME_LEN];
240
241 if (opt == NULL) {
242 ret = -1;
243 goto end;
244 }
245
246 /* Check for symbol+offset */
247 ret = sscanf(opt, "%" LTTNG_SYMBOL_NAME_LEN_SCANF_IS_A_BROKEN_API
248 "[^'+']+%" S_HEX_LEN_SCANF_IS_A_BROKEN_API "s", name, s_hex);
249 if (ret == 2) {
250 strncpy(ev->attr.probe.symbol_name, name, LTTNG_SYMBOL_NAME_LEN);
251 ev->attr.probe.symbol_name[LTTNG_SYMBOL_NAME_LEN - 1] = '\0';
252 DBG("probe symbol %s", ev->attr.probe.symbol_name);
253 if (*s_hex == '\0') {
254 ERR("Invalid probe offset %s", s_hex);
255 ret = -1;
256 goto end;
257 }
258 ev->attr.probe.offset = strtoul(s_hex, NULL, 0);
259 DBG("probe offset %" PRIu64, ev->attr.probe.offset);
260 ev->attr.probe.addr = 0;
261 goto end;
262 }
263
264 /* Check for symbol */
265 if (isalpha(name[0])) {
266 ret = sscanf(opt, "%" LTTNG_SYMBOL_NAME_LEN_SCANF_IS_A_BROKEN_API "s",
267 name);
268 if (ret == 1) {
269 strncpy(ev->attr.probe.symbol_name, name, LTTNG_SYMBOL_NAME_LEN);
270 ev->attr.probe.symbol_name[LTTNG_SYMBOL_NAME_LEN - 1] = '\0';
271 DBG("probe symbol %s", ev->attr.probe.symbol_name);
272 ev->attr.probe.offset = 0;
273 DBG("probe offset %" PRIu64, ev->attr.probe.offset);
274 ev->attr.probe.addr = 0;
275 goto end;
276 }
277 }
278
279 /* Check for address */
280 ret = sscanf(opt, "%" S_HEX_LEN_SCANF_IS_A_BROKEN_API "s", s_hex);
281 if (ret > 0) {
282 if (*s_hex == '\0') {
283 ERR("Invalid probe address %s", s_hex);
284 ret = -1;
285 goto end;
286 }
287 ev->attr.probe.addr = strtoul(s_hex, NULL, 0);
288 DBG("probe addr %" PRIu64, ev->attr.probe.addr);
289 ev->attr.probe.offset = 0;
290 memset(ev->attr.probe.symbol_name, 0, LTTNG_SYMBOL_NAME_LEN);
291 goto end;
292 }
293
294 /* No match */
295 ret = -1;
296
297end:
298 return ret;
299}
300
301/*
302 * Maps JUL loglevel from string to value
303 */
304static int loglevel_jul_str_to_value(const char *inputstr)
305{
306 int i = 0;
307 char str[LTTNG_SYMBOL_NAME_LEN];
308
309 /*
310 * Loop up to LTTNG_SYMBOL_NAME_LEN minus one because the NULL bytes is
311 * added at the end of the loop so a the upper bound we avoid the overflow.
312 */
313 while (i < (LTTNG_SYMBOL_NAME_LEN - 1) && inputstr[i] != '\0') {
314 str[i] = toupper(inputstr[i]);
315 i++;
316 }
317 str[i] = '\0';
318
319 if (!strcmp(str, "JUL_OFF") || !strcmp(str, "OFF")) {
320 return LTTNG_LOGLEVEL_JUL_OFF;
321 } else if (!strcmp(str, "JUL_SEVERE") || !strcmp(str, "SEVERE")) {
322 return LTTNG_LOGLEVEL_JUL_SEVERE;
323 } else if (!strcmp(str, "JUL_WARNING") || !strcmp(str, "WARNING")) {
324 return LTTNG_LOGLEVEL_JUL_WARNING;
325 } else if (!strcmp(str, "JUL_INFO") || !strcmp(str, "INFO")) {
326 return LTTNG_LOGLEVEL_JUL_INFO;
327 } else if (!strcmp(str, "JUL_CONFIG") || !strcmp(str, "CONFIG")) {
328 return LTTNG_LOGLEVEL_JUL_CONFIG;
329 } else if (!strcmp(str, "JUL_FINE") || !strcmp(str, "FINE")) {
330 return LTTNG_LOGLEVEL_JUL_FINE;
331 } else if (!strcmp(str, "JUL_FINER") || !strcmp(str, "FINER")) {
332 return LTTNG_LOGLEVEL_JUL_FINER;
333 } else if (!strcmp(str, "JUL_FINEST") || !strcmp(str, "FINEST")) {
334 return LTTNG_LOGLEVEL_JUL_FINEST;
335 } else if (!strcmp(str, "JUL_ALL") || !strcmp(str, "ALL")) {
336 return LTTNG_LOGLEVEL_JUL_ALL;
337 } else {
338 return -1;
339 }
340}
341
342/*
343 * Maps loglevel from string to value
344 */
345static
346int loglevel_str_to_value(const char *inputstr)
347{
348 int i = 0;
349 char str[LTTNG_SYMBOL_NAME_LEN];
350
351 /*
352 * Loop up to LTTNG_SYMBOL_NAME_LEN minus one because the NULL bytes is
353 * added at the end of the loop so a the upper bound we avoid the overflow.
354 */
355 while (i < (LTTNG_SYMBOL_NAME_LEN - 1) && inputstr[i] != '\0') {
356 str[i] = toupper(inputstr[i]);
357 i++;
358 }
359 str[i] = '\0';
360 if (!strcmp(str, "TRACE_EMERG") || !strcmp(str, "EMERG")) {
361 return LTTNG_LOGLEVEL_EMERG;
362 } else if (!strcmp(str, "TRACE_ALERT") || !strcmp(str, "ALERT")) {
363 return LTTNG_LOGLEVEL_ALERT;
364 } else if (!strcmp(str, "TRACE_CRIT") || !strcmp(str, "CRIT")) {
365 return LTTNG_LOGLEVEL_CRIT;
366 } else if (!strcmp(str, "TRACE_ERR") || !strcmp(str, "ERR")) {
367 return LTTNG_LOGLEVEL_ERR;
368 } else if (!strcmp(str, "TRACE_WARNING") || !strcmp(str, "WARNING")) {
369 return LTTNG_LOGLEVEL_WARNING;
370 } else if (!strcmp(str, "TRACE_NOTICE") || !strcmp(str, "NOTICE")) {
371 return LTTNG_LOGLEVEL_NOTICE;
372 } else if (!strcmp(str, "TRACE_INFO") || !strcmp(str, "INFO")) {
373 return LTTNG_LOGLEVEL_INFO;
374 } else if (!strcmp(str, "TRACE_DEBUG_SYSTEM") || !strcmp(str, "DEBUG_SYSTEM") || !strcmp(str, "SYSTEM")) {
375 return LTTNG_LOGLEVEL_DEBUG_SYSTEM;
376 } else if (!strcmp(str, "TRACE_DEBUG_PROGRAM") || !strcmp(str, "DEBUG_PROGRAM") || !strcmp(str, "PROGRAM")) {
377 return LTTNG_LOGLEVEL_DEBUG_PROGRAM;
378 } else if (!strcmp(str, "TRACE_DEBUG_PROCESS") || !strcmp(str, "DEBUG_PROCESS") || !strcmp(str, "PROCESS")) {
379 return LTTNG_LOGLEVEL_DEBUG_PROCESS;
380 } else if (!strcmp(str, "TRACE_DEBUG_MODULE") || !strcmp(str, "DEBUG_MODULE") || !strcmp(str, "MODULE")) {
381 return LTTNG_LOGLEVEL_DEBUG_MODULE;
382 } else if (!strcmp(str, "TRACE_DEBUG_UNIT") || !strcmp(str, "DEBUG_UNIT") || !strcmp(str, "UNIT")) {
383 return LTTNG_LOGLEVEL_DEBUG_UNIT;
384 } else if (!strcmp(str, "TRACE_DEBUG_FUNCTION") || !strcmp(str, "DEBUG_FUNCTION") || !strcmp(str, "FUNCTION")) {
385 return LTTNG_LOGLEVEL_DEBUG_FUNCTION;
386 } else if (!strcmp(str, "TRACE_DEBUG_LINE") || !strcmp(str, "DEBUG_LINE") || !strcmp(str, "LINE")) {
387 return LTTNG_LOGLEVEL_DEBUG_LINE;
388 } else if (!strcmp(str, "TRACE_DEBUG") || !strcmp(str, "DEBUG")) {
389 return LTTNG_LOGLEVEL_DEBUG;
390 } else {
391 return -1;
392 }
393}
394
395static
396const char *print_channel_name(const char *name)
397{
398 return name ? : DEFAULT_CHANNEL_NAME;
399}
400
401static
402const char *print_raw_channel_name(const char *name)
403{
404 return name ? : "<default>";
405}
406
407/*
408 * Mi print exlcusion list
409 */
410static
411int mi_print_exclusion(int count, char **names)
412{
413 int i, ret;
414
415 assert(writer);
416
417 if (count == 0) {
418 ret = 0;
419 goto end;
420 }
421 ret = mi_lttng_writer_open_element(writer, config_element_exclusions);
422 if (ret) {
423 goto end;
424 }
425
426 for (i = 0; i < count; i++) {
427 ret = mi_lttng_writer_write_element_string(writer,
428 config_element_exclusion, names[i]);
429 if (ret) {
430 goto end;
431 }
432 }
433
434 /* Close exclusions element */
435 ret = mi_lttng_writer_close_element(writer);
436
437end:
438 return ret;
439}
440
441/*
442 * Return allocated string for pretty-printing exclusion names.
443 */
444static
445char *print_exclusions(int count, char **names)
446{
447 int length = 0;
448 int i;
449 const char *preamble = " excluding ";
450 char *ret;
451
452 if (count == 0) {
453 return strdup("");
454 }
455
456 /* calculate total required length */
457 for (i = 0; i < count; i++) {
458 length += strlen(names[i]) + 1;
459 }
460
461 /* add length of preamble + one for NUL - one for last (missing) comma */
462 length += strlen(preamble);
463 ret = malloc(length);
464 strncpy(ret, preamble, length);
465 for (i = 0; i < count; i++) {
466 strcat(ret, names[i]);
467 if (i != count - 1) {
468 strcat(ret, ",");
469 }
470 }
471
472 return ret;
473}
474
475/*
476 * Compare list of exclusions against an event name.
477 * Return a list of legal exclusion names.
478 * Produce an error or a warning about others (depending on the situation)
479 */
480static
481int check_exclusion_subsets(const char *event_name,
482 const char *exclusions,
483 int *exclusion_count_ptr,
484 char ***exclusion_list_ptr)
485{
486 const char *excluder_ptr;
487 const char *event_ptr;
488 const char *next_excluder;
489 int excluder_length;
490 int exclusion_count = 0;
491 char **exclusion_list = NULL;
492 int ret = CMD_SUCCESS;
493
494 if (event_name[strlen(event_name) - 1] != '*') {
495 ERR("Event %s: Excluders can only be used with wildcarded events", event_name);
496 goto error;
497 }
498
499 next_excluder = exclusions;
500 while (*next_excluder != 0) {
501 event_ptr = event_name;
502 excluder_ptr = next_excluder;
503 excluder_length = strcspn(next_excluder, ",");
504
505 /* Scan both the excluder and the event letter by letter */
506 while (1) {
507 char e, x;
508
509 e = *event_ptr;
510 x = *excluder_ptr;
511
512 if (x == '*') {
513 /* Event is a subset of the excluder */
514 ERR("Event %s: %.*s excludes all events from %s",
515 event_name,
516 excluder_length,
517 next_excluder,
518 event_name);
519 goto error;
520 }
521 if (e == '*') {
522 /* Excluder is a proper subset of event */
523 exclusion_count++;
524 exclusion_list = realloc(exclusion_list, sizeof(char **) * exclusion_count);
525 exclusion_list[exclusion_count - 1] = strndup(next_excluder, excluder_length);
526
527 break;
528 }
529 if (x != e) {
530 /* Excluder and event sets have no common elements */
531 WARN("Event %s: %.*s does not exclude any events from %s",
532 event_name,
533 excluder_length,
534 next_excluder,
535 event_name);
536 break;
537 }
538 excluder_ptr++;
539 event_ptr++;
540 }
541 /* next excluder */
542 next_excluder += excluder_length;
543 if (*next_excluder == ',') {
544 next_excluder++;
545 }
546 }
547 goto end;
548error:
549 while (exclusion_count--) {
550 free(exclusion_list[exclusion_count]);
551 }
552 if (exclusion_list != NULL) {
553 free(exclusion_list);
554 }
555 exclusion_list = NULL;
556 exclusion_count = 0;
557 ret = CMD_ERROR;
558end:
559 *exclusion_count_ptr = exclusion_count;
560 *exclusion_list_ptr = exclusion_list;
561 return ret;
562}
563/*
564 * Enabling event using the lttng API.
565 * Note: in case of error only the last error code will be return.
566 */
567static int enable_events(char *session_name)
568{
569 int ret = CMD_SUCCESS, command_ret = CMD_SUCCESS;
570 int error_holder = CMD_SUCCESS, warn = 0, error = 0, success = 1;
571 char *event_name, *channel_name = NULL;
572 struct lttng_event ev;
573 struct lttng_domain dom;
574 int exclusion_count = 0;
575 char **exclusion_list = NULL;
576
577 memset(&ev, 0, sizeof(ev));
578 memset(&dom, 0, sizeof(dom));
579
580 if (opt_kernel) {
581 if (opt_filter) {
582 ERR("Filter not implement for kernel tracing yet");
583 ret = CMD_ERROR;
584 goto error;
585 }
586 if (opt_loglevel) {
587 WARN("Kernel loglevels are not supported.");
588 }
589 }
590
591 /* Create lttng domain */
592 if (opt_kernel) {
593 dom.type = LTTNG_DOMAIN_KERNEL;
594 dom.buf_type = LTTNG_BUFFER_GLOBAL;
595 } else if (opt_userspace) {
596 dom.type = LTTNG_DOMAIN_UST;
597 /* Default. */
598 dom.buf_type = LTTNG_BUFFER_PER_UID;
599 } else if (opt_jul) {
600 dom.type = LTTNG_DOMAIN_JUL;
601 /* Default. */
602 dom.buf_type = LTTNG_BUFFER_PER_UID;
603 } else {
604 print_missing_domain();
605 ret = CMD_ERROR;
606 goto error;
607 }
608
609 if (opt_kernel && opt_exclude) {
610 ERR("Event name exclusions are not yet implemented for kernel events");
611 ret = CMD_ERROR;
612 goto error;
613 }
614
615 channel_name = opt_channel_name;
616
617 handle = lttng_create_handle(session_name, &dom);
618 if (handle == NULL) {
619 ret = -1;
620 goto error;
621 }
622
623 /* Prepare Mi */
624 if (lttng_opt_mi) {
625 /* Open a events element */
626 ret = mi_lttng_writer_open_element(writer, config_element_events);
627 if (ret) {
628 ret = CMD_ERROR;
629 goto error;
630 }
631 }
632
633 if (opt_enable_all) {
634 /* Default setup for enable all */
635 if (opt_kernel) {
636 ev.type = opt_event_type;
637 ev.name[0] = '\0';
638 /* kernel loglevels not implemented */
639 ev.loglevel_type = LTTNG_EVENT_LOGLEVEL_ALL;
640 } else {
641 ev.type = LTTNG_EVENT_TRACEPOINT;
642 strcpy(ev.name, "*");
643 ev.loglevel_type = opt_loglevel_type;
644 if (opt_loglevel) {
645 assert(opt_userspace || opt_jul);
646 if (opt_userspace) {
647 ev.loglevel = loglevel_str_to_value(opt_loglevel);
648 } else if (opt_jul) {
649 ev.loglevel = loglevel_jul_str_to_value(opt_loglevel);
650 }
651 if (ev.loglevel == -1) {
652 ERR("Unknown loglevel %s", opt_loglevel);
653 ret = -LTTNG_ERR_INVALID;
654 goto error;
655 }
656 } else {
657 assert(opt_userspace || opt_jul);
658 if (opt_userspace) {
659 ev.loglevel = -1;
660 } else if (opt_jul) {
661 ev.loglevel = LTTNG_LOGLEVEL_JUL_ALL;
662 }
663 }
664 }
665
666 if (opt_exclude) {
667 ret = check_exclusion_subsets("*", opt_exclude,
668 &exclusion_count, &exclusion_list);
669 if (ret == CMD_ERROR) {
670 goto error;
671 }
672 ev.exclusion = 1;
673 }
674 if (!opt_filter) {
675 ret = lttng_enable_event_with_exclusions(handle,
676 &ev, channel_name,
677 NULL,
678 exclusion_count, exclusion_list);
679 if (ret < 0) {
680 switch (-ret) {
681 case LTTNG_ERR_KERN_EVENT_EXIST:
682 WARN("Kernel events already enabled (channel %s, session %s)",
683 print_channel_name(channel_name), session_name);
684 warn = 1;
685 break;
686 default:
687 ERR("Events: %s (channel %s, session %s)",
688 lttng_strerror(ret),
689 ret == -LTTNG_ERR_NEED_CHANNEL_NAME
690 ? print_raw_channel_name(channel_name)
691 : print_channel_name(channel_name),
692 session_name);
693 error = 1;
694 break;
695 }
696 goto end;
697 }
698
699 switch (opt_event_type) {
700 case LTTNG_EVENT_TRACEPOINT:
701 if (opt_loglevel && dom.type != LTTNG_DOMAIN_KERNEL) {
702 char *exclusion_string = print_exclusions(exclusion_count, exclusion_list);
703 MSG("All %s tracepoints%s are enabled in channel %s for loglevel %s",
704 get_domain_str(dom.type),
705 exclusion_string,
706 print_channel_name(channel_name),
707 opt_loglevel);
708 free(exclusion_string);
709 } else {
710 char *exclusion_string = print_exclusions(exclusion_count, exclusion_list);
711 MSG("All %s tracepoints%s are enabled in channel %s",
712 get_domain_str(dom.type),
713 exclusion_string,
714 print_channel_name(channel_name));
715 free(exclusion_string);
716 }
717 break;
718 case LTTNG_EVENT_SYSCALL:
719 if (opt_kernel) {
720 MSG("All kernel system calls are enabled in channel %s",
721 print_channel_name(channel_name));
722 }
723 break;
724 case LTTNG_EVENT_ALL:
725 if (opt_loglevel && dom.type != LTTNG_DOMAIN_KERNEL) {
726 char *exclusion_string = print_exclusions(exclusion_count, exclusion_list);
727 MSG("All %s events%s are enabled in channel %s for loglevel %s",
728 get_domain_str(dom.type),
729 exclusion_string,
730 print_channel_name(channel_name),
731 opt_loglevel);
732 free(exclusion_string);
733 } else {
734 char *exclusion_string = print_exclusions(exclusion_count, exclusion_list);
735 MSG("All %s events%s are enabled in channel %s",
736 get_domain_str(dom.type),
737 exclusion_string,
738 print_channel_name(channel_name));
739 free(exclusion_string);
740 }
741 break;
742 default:
743 /*
744 * We should not be here since lttng_enable_event should have
745 * failed on the event type.
746 */
747 goto error;
748 }
749 }
750
751 if (opt_filter) {
752 command_ret = lttng_enable_event_with_exclusions(handle, &ev, channel_name,
753 opt_filter, exclusion_count, exclusion_list);
754 if (command_ret < 0) {
755 switch (-command_ret) {
756 case LTTNG_ERR_FILTER_EXIST:
757 WARN("Filter on all events is already enabled"
758 " (channel %s, session %s)",
759 print_channel_name(channel_name), session_name);
760 warn = 1;
761 break;
762 default:
763 ERR("All events: %s (channel %s, session %s, filter \'%s\')",
764 lttng_strerror(command_ret),
765 command_ret == -LTTNG_ERR_NEED_CHANNEL_NAME
766 ? print_raw_channel_name(channel_name)
767 : print_channel_name(channel_name),
768 session_name, opt_filter);
769 error = 1;
770 break;
771 }
772 error_holder = command_ret;
773 } else {
774 ev.filter = 1;
775 MSG("Filter '%s' successfully set", opt_filter);
776 }
777 }
778
779 if (lttng_opt_mi) {
780 /* The wildcard * is used for kernel and ust domain to
781 * represent ALL. We copy * in event name to force the wildcard use
782 * for kernel domain
783 *
784 * Note: this is strictly for semantic and printing while in
785 * machine interface mode.
786 */
787 strcpy(ev.name, "*");
788
789 /* If we reach here the events are enabled */
790 if (!error && !warn) {
791 ev.enabled = 1;
792 } else {
793 ev.enabled = 0;
794 success = 0;
795 }
796 ret = mi_lttng_event(writer, &ev, 1);
797 if (ret) {
798 ret = CMD_ERROR;
799 goto error;
800 }
801
802 /* print exclusion */
803 ret = mi_print_exclusion(exclusion_count, exclusion_list);
804 if (ret) {
805 ret = CMD_ERROR;
806 goto error;
807 }
808
809 /* Success ? */
810 ret = mi_lttng_writer_write_element_bool(writer,
811 mi_lttng_element_command_success, success);
812 if (ret) {
813 ret = CMD_ERROR;
814 goto error;
815 }
816
817 /* Close event element */
818 ret = mi_lttng_writer_close_element(writer);
819 if (ret) {
820 ret = CMD_ERROR;
821 goto error;
822 }
823 }
824
825 goto end;
826 }
827
828 /* Strip event list */
829 event_name = strtok(opt_event_list, ",");
830 while (event_name != NULL) {
831 /* Copy name and type of the event */
832 strncpy(ev.name, event_name, LTTNG_SYMBOL_NAME_LEN);
833 ev.name[LTTNG_SYMBOL_NAME_LEN - 1] = '\0';
834 ev.type = opt_event_type;
835
836 /* Kernel tracer action */
837 if (opt_kernel) {
838 DBG("Enabling kernel event %s for channel %s",
839 event_name,
840 print_channel_name(channel_name));
841
842 switch (opt_event_type) {
843 case LTTNG_EVENT_ALL: /* Default behavior is tracepoint */
844 ev.type = LTTNG_EVENT_TRACEPOINT;
845 /* Fall-through */
846 case LTTNG_EVENT_TRACEPOINT:
847 break;
848 case LTTNG_EVENT_PROBE:
849 ret = parse_probe_opts(&ev, opt_probe);
850 if (ret < 0) {
851 ERR("Unable to parse probe options");
852 ret = 0;
853 goto error;
854 }
855 break;
856 case LTTNG_EVENT_FUNCTION:
857 ret = parse_probe_opts(&ev, opt_function);
858 if (ret < 0) {
859 ERR("Unable to parse function probe options");
860 ret = 0;
861 goto error;
862 }
863 break;
864 case LTTNG_EVENT_FUNCTION_ENTRY:
865 strncpy(ev.attr.ftrace.symbol_name, opt_function_entry_symbol,
866 LTTNG_SYMBOL_NAME_LEN);
867 ev.attr.ftrace.symbol_name[LTTNG_SYMBOL_NAME_LEN - 1] = '\0';
868 break;
869 case LTTNG_EVENT_SYSCALL:
870 MSG("per-syscall selection not supported yet. Use \"-a\" "
871 "for all syscalls.");
872 default:
873 ret = CMD_UNDEFINED;
874 goto error;
875 }
876
877 /* kernel loglevels not implemented */
878 ev.loglevel_type = LTTNG_EVENT_LOGLEVEL_ALL;
879 } else if (opt_userspace) { /* User-space tracer action */
880#if 0
881 if (opt_cmd_name != NULL || opt_pid) {
882 MSG("Only supporting tracing all UST processes (-u) for now.");
883 ret = CMD_UNDEFINED;
884 goto error;
885 }
886#endif
887
888 DBG("Enabling UST event %s for channel %s, loglevel %s", event_name,
889 print_channel_name(channel_name), opt_loglevel ? : "<all>");
890
891 switch (opt_event_type) {
892 case LTTNG_EVENT_ALL: /* Default behavior is tracepoint */
893 /* Fall-through */
894 case LTTNG_EVENT_TRACEPOINT:
895 /* Copy name and type of the event */
896 ev.type = LTTNG_EVENT_TRACEPOINT;
897 strncpy(ev.name, event_name, LTTNG_SYMBOL_NAME_LEN);
898 ev.name[LTTNG_SYMBOL_NAME_LEN - 1] = '\0';
899 break;
900 case LTTNG_EVENT_PROBE:
901 case LTTNG_EVENT_FUNCTION:
902 case LTTNG_EVENT_FUNCTION_ENTRY:
903 case LTTNG_EVENT_SYSCALL:
904 default:
905 ERR("Event type not available for user-space tracing");
906 ret = CMD_UNSUPPORTED;
907 goto error;
908 }
909
910 if (opt_exclude) {
911 ev.exclusion = 1;
912 if (opt_event_type != LTTNG_EVENT_ALL && opt_event_type != LTTNG_EVENT_TRACEPOINT) {
913 ERR("Exclusion option can only be used with tracepoint events");
914 ret = CMD_ERROR;
915 goto error;
916 }
917 /* Free previously allocated items */
918 if (exclusion_list != NULL) {
919 while (exclusion_count--) {
920 free(exclusion_list[exclusion_count]);
921 }
922 free(exclusion_list);
923 exclusion_list = NULL;
924 }
925 /* Check for proper subsets */
926 ret = check_exclusion_subsets(event_name, opt_exclude,
927 &exclusion_count, &exclusion_list);
928 if (ret == CMD_ERROR) {
929 goto error;
930 }
931 }
932
933 ev.loglevel_type = opt_loglevel_type;
934 if (opt_loglevel) {
935 ev.loglevel = loglevel_str_to_value(opt_loglevel);
936 if (ev.loglevel == -1) {
937 ERR("Unknown loglevel %s", opt_loglevel);
938 ret = -LTTNG_ERR_INVALID;
939 goto error;
940 }
941 } else {
942 ev.loglevel = -1;
943 }
944 } else if (opt_jul) {
945 if (opt_event_type != LTTNG_EVENT_ALL &&
946 opt_event_type != LTTNG_EVENT_TRACEPOINT) {
947 ERR("Event type not supported for JUL domain.");
948 ret = CMD_UNSUPPORTED;
949 goto error;
950 }
951
952 ev.loglevel_type = opt_loglevel_type;
953 if (opt_loglevel) {
954 ev.loglevel = loglevel_jul_str_to_value(opt_loglevel);
955 if (ev.loglevel == -1) {
956 ERR("Unknown loglevel %s", opt_loglevel);
957 ret = -LTTNG_ERR_INVALID;
958 goto error;
959 }
960 } else {
961 ev.loglevel = LTTNG_LOGLEVEL_JUL_ALL;
962 }
963 ev.type = LTTNG_EVENT_TRACEPOINT;
964 strncpy(ev.name, event_name, LTTNG_SYMBOL_NAME_LEN);
965 ev.name[LTTNG_SYMBOL_NAME_LEN - 1] = '\0';
966 } else {
967 print_missing_domain();
968 ret = CMD_ERROR;
969 goto error;
970 }
971
972 if (!opt_filter) {
973 char *exclusion_string;
974
975 command_ret = lttng_enable_event_with_exclusions(handle,
976 &ev, channel_name,
977 NULL, exclusion_count, exclusion_list);
978 exclusion_string = print_exclusions(exclusion_count, exclusion_list);
979 if (command_ret < 0) {
980 /* Turn ret to positive value to handle the positive error code */
981 switch (-command_ret) {
982 case LTTNG_ERR_KERN_EVENT_EXIST:
983 WARN("Kernel event %s%s already enabled (channel %s, session %s)",
984 event_name,
985 exclusion_string,
986 print_channel_name(channel_name), session_name);
987 warn = 1;
988 break;
989 default:
990 ERR("Event %s%s: %s (channel %s, session %s)", event_name,
991 exclusion_string,
992 lttng_strerror(command_ret),
993 command_ret == -LTTNG_ERR_NEED_CHANNEL_NAME
994 ? print_raw_channel_name(channel_name)
995 : print_channel_name(channel_name),
996 session_name);
997 error = 1;
998 break;
999 }
1000 error_holder = command_ret;
1001 } else {
1002 /* So we don't print the default channel name for JUL. */
1003 if (dom.type == LTTNG_DOMAIN_JUL) {
1004 MSG("%s event %s%s enabled.",
1005 get_domain_str(dom.type), event_name,
1006 exclusion_string);
1007 } else {
1008 MSG("%s event %s%s created in channel %s",
1009 get_domain_str(dom.type), event_name,
1010 exclusion_string,
1011 print_channel_name(channel_name));
1012 }
1013 }
1014 free(exclusion_string);
1015 }
1016
1017 if (opt_filter) {
1018 char *exclusion_string;
1019
1020 /* Filter present */
1021 ev.filter = 1;
1022
1023 command_ret = lttng_enable_event_with_exclusions(handle, &ev, channel_name,
1024 opt_filter, exclusion_count, exclusion_list);
1025 exclusion_string = print_exclusions(exclusion_count, exclusion_list);
1026
1027 if (command_ret < 0) {
1028 switch (-command_ret) {
1029 case LTTNG_ERR_FILTER_EXIST:
1030 WARN("Filter on event %s%s is already enabled"
1031 " (channel %s, session %s)",
1032 event_name,
1033 exclusion_string,
1034 print_channel_name(channel_name), session_name);
1035 warn = 1;
1036 break;
1037 default:
1038 ERR("Event %s%s: %s (channel %s, session %s, filter \'%s\')", ev.name,
1039 exclusion_string,
1040 lttng_strerror(command_ret),
1041 command_ret == -LTTNG_ERR_NEED_CHANNEL_NAME
1042 ? print_raw_channel_name(channel_name)
1043 : print_channel_name(channel_name),
1044 session_name, opt_filter);
1045 error = 1;
1046 break;
1047 }
1048 error_holder = command_ret;
1049
1050 } else {
1051 MSG("Event %s%s: Filter '%s' successfully set",
1052 event_name, exclusion_string,
1053 opt_filter);
1054 }
1055 free(exclusion_string);
1056 }
1057
1058 if (lttng_opt_mi) {
1059 if (command_ret) {
1060 success = 0;
1061 ev.enabled = 0;
1062 } else {
1063 ev.enabled = 1;
1064 }
1065
1066 ret = mi_lttng_event(writer, &ev, 1);
1067 if (ret) {
1068 ret = CMD_ERROR;
1069 goto error;
1070 }
1071
1072 /* print exclusion */
1073 ret = mi_print_exclusion(exclusion_count, exclusion_list);
1074 if (ret) {
1075 ret = CMD_ERROR;
1076 goto error;
1077 }
1078
1079 /* Success ? */
1080 ret = mi_lttng_writer_write_element_bool(writer,
1081 mi_lttng_element_command_success, success);
1082 if (ret) {
1083 ret = CMD_ERROR;
1084 goto end;
1085 }
1086
1087 /* Close event element */
1088 ret = mi_lttng_writer_close_element(writer);
1089 if (ret) {
1090 ret = CMD_ERROR;
1091 goto end;
1092 }
1093 }
1094
1095 /* Next event */
1096 event_name = strtok(NULL, ",");
1097 /* Reset warn, error and success */
1098 success = 1;
1099 }
1100
1101end:
1102 /* Close Mi */
1103 if (lttng_opt_mi) {
1104 /* Close events element */
1105 ret = mi_lttng_writer_close_element(writer);
1106 if (ret) {
1107 ret = CMD_ERROR;
1108 goto error;
1109 }
1110 }
1111error:
1112 if (warn) {
1113 ret = CMD_WARNING;
1114 }
1115 if (error) {
1116 ret = CMD_ERROR;
1117 }
1118 lttng_destroy_handle(handle);
1119
1120 if (exclusion_list != NULL) {
1121 while (exclusion_count--) {
1122 free(exclusion_list[exclusion_count]);
1123 }
1124 free(exclusion_list);
1125 }
1126
1127 /* Overwrite ret with error_holder if there was an actual error with
1128 * enabling an event.
1129 */
1130 ret = error_holder ? error_holder : ret;
1131
1132 return ret;
1133}
1134
1135/*
1136 * Add event to trace session
1137 */
1138int cmd_enable_events(int argc, const char **argv)
1139{
1140 int opt, ret = CMD_SUCCESS, command_ret = CMD_SUCCESS, success = 1;
1141 static poptContext pc;
1142 char *session_name = NULL;
1143 int event_type = -1;
1144
1145 pc = poptGetContext(NULL, argc, argv, long_options, 0);
1146 poptReadDefaultConfig(pc, 0);
1147
1148 /* Default event type */
1149 opt_event_type = LTTNG_EVENT_ALL;
1150
1151 while ((opt = poptGetNextOpt(pc)) != -1) {
1152 switch (opt) {
1153 case OPT_HELP:
1154 usage(stdout);
1155 goto end;
1156 case OPT_TRACEPOINT:
1157 opt_event_type = LTTNG_EVENT_TRACEPOINT;
1158 break;
1159 case OPT_PROBE:
1160 opt_event_type = LTTNG_EVENT_PROBE;
1161 break;
1162 case OPT_FUNCTION:
1163 opt_event_type = LTTNG_EVENT_FUNCTION;
1164 break;
1165 case OPT_FUNCTION_ENTRY:
1166 opt_event_type = LTTNG_EVENT_FUNCTION_ENTRY;
1167 break;
1168 case OPT_SYSCALL:
1169 opt_event_type = LTTNG_EVENT_SYSCALL;
1170 break;
1171 case OPT_USERSPACE:
1172 opt_userspace = 1;
1173 break;
1174 case OPT_LOGLEVEL:
1175 opt_loglevel_type = LTTNG_EVENT_LOGLEVEL_RANGE;
1176 opt_loglevel = poptGetOptArg(pc);
1177 break;
1178 case OPT_LOGLEVEL_ONLY:
1179 opt_loglevel_type = LTTNG_EVENT_LOGLEVEL_SINGLE;
1180 opt_loglevel = poptGetOptArg(pc);
1181 break;
1182 case OPT_LIST_OPTIONS:
1183 list_cmd_options(stdout, long_options);
1184 goto end;
1185 case OPT_FILTER:
1186 break;
1187 case OPT_EXCLUDE:
1188 break;
1189 default:
1190 usage(stderr);
1191 ret = CMD_UNDEFINED;
1192 goto end;
1193 }
1194
1195 /* Validate event type. Multiple event type are not supported. */
1196 if (event_type == -1) {
1197 event_type = opt_event_type;
1198 } else {
1199 if (event_type != opt_event_type) {
1200 ERR("Multiple event type not supported.");
1201 ret = CMD_ERROR;
1202 goto end;
1203 }
1204 }
1205 }
1206
1207 /* Mi check */
1208 if (lttng_opt_mi) {
1209 writer = mi_lttng_writer_create(fileno(stdout), lttng_opt_mi);
1210 if (!writer) {
1211 ret = -LTTNG_ERR_NOMEM;
1212 goto end;
1213 }
1214
1215 /* Open command element */
1216 ret = mi_lttng_writer_command_open(writer,
1217 mi_lttng_element_command_enable_event);
1218 if (ret) {
1219 ret = CMD_ERROR;
1220 goto end;
1221 }
1222
1223 /* Open output element */
1224 ret = mi_lttng_writer_open_element(writer,
1225 mi_lttng_element_command_output);
1226 if (ret) {
1227 ret = CMD_ERROR;
1228 goto end;
1229 }
1230 }
1231
1232 opt_event_list = (char*) poptGetArg(pc);
1233 if (opt_event_list == NULL && opt_enable_all == 0) {
1234 ERR("Missing event name(s).\n");
1235 usage(stderr);
1236 ret = CMD_ERROR;
1237 goto end;
1238 }
1239
1240 if (!opt_session_name) {
1241 session_name = get_session_name();
1242 if (session_name == NULL) {
1243 command_ret = CMD_ERROR;
1244 success = 0;
1245 goto mi_closing;
1246 }
1247 } else {
1248 session_name = opt_session_name;
1249 }
1250
1251 command_ret = enable_events(session_name);
1252 if (command_ret) {
1253 success = 0;
1254 goto mi_closing;
1255 }
1256
1257mi_closing:
1258 /* Mi closing */
1259 if (lttng_opt_mi) {
1260 /* Close output element */
1261 ret = mi_lttng_writer_close_element(writer);
1262 if (ret) {
1263 ret = CMD_ERROR;
1264 goto end;
1265 }
1266
1267 ret = mi_lttng_writer_write_element_bool(writer,
1268 mi_lttng_element_command_success, success);
1269 if (ret) {
1270 ret = CMD_ERROR;
1271 goto end;
1272 }
1273
1274 /* Command element close */
1275 ret = mi_lttng_writer_command_close(writer);
1276 if (ret) {
1277 ret = CMD_ERROR;
1278 goto end;
1279 }
1280 }
1281
1282end:
1283 /* Mi clean-up */
1284 if (writer && mi_lttng_writer_destroy(writer)) {
1285 /* Preserve original error code */
1286 ret = ret ? ret : LTTNG_ERR_MI_IO_FAIL;
1287 }
1288
1289 if (opt_session_name == NULL) {
1290 free(session_name);
1291 }
1292
1293 /* Overwrite ret if an error occurred in enable_events */
1294 ret = command_ret ? command_ret : ret;
1295
1296 poptFreeContext(pc);
1297 return ret;
1298}
This page took 0.027029 seconds and 4 git commands to generate.