Fix: miscellaneous memory handling fixes
[lttng-tools.git] / src / bin / lttng / commands / enable_events.c
CommitLineData
f3ed775e
DG
1/*
2 * Copyright (C) 2011 - David Goulet <david.goulet@polymtl.ca>
3 *
d14d33bf
AM
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.
f3ed775e
DG
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 *
d14d33bf
AM
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.
f3ed775e
DG
16 */
17
18#define _GNU_SOURCE
b2064f54 19#include <assert.h>
f3ed775e
DG
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>
5a0de755 27#include <inttypes.h>
8f0d098b 28#include <ctype.h>
f3ed775e 29
c399183f 30#include "../command.h"
42224349 31#include <src/common/sessiond-comm/sessiond-comm.h>
f3ed775e
DG
32
33static char *opt_event_list;
34static int opt_event_type;
0cda4f28
MD
35static const char *opt_loglevel;
36static int opt_loglevel_type;
6181537c 37static int opt_kernel;
5440dc42 38static char *opt_session_name;
f3ed775e 39static int opt_userspace;
b9dfb167 40static int opt_jul;
f3ed775e 41static int opt_enable_all;
cf0e5467 42static char *opt_probe;
8f0d098b
MD
43static char *opt_function;
44static char *opt_function_entry_symbol;
f3ed775e 45static char *opt_channel_name;
53a80697 46static char *opt_filter;
fac3366c 47static char *opt_exclude;
d78d6610
DG
48#if 0
49/* Not implemented yet */
50static char *opt_cmd_name;
51static pid_t opt_pid;
52#endif
f3ed775e
DG
53
54enum {
55 OPT_HELP = 1,
f3ed775e 56 OPT_TRACEPOINT,
cf0e5467 57 OPT_PROBE,
f3ed775e 58 OPT_FUNCTION,
8f0d098b 59 OPT_FUNCTION_ENTRY,
a54bd42d 60 OPT_SYSCALL,
eeac7d46 61 OPT_USERSPACE,
0cda4f28
MD
62 OPT_LOGLEVEL,
63 OPT_LOGLEVEL_ONLY,
679b4943 64 OPT_LIST_OPTIONS,
53a80697 65 OPT_FILTER,
fac3366c 66 OPT_EXCLUDE,
f3ed775e
DG
67};
68
cd80958d
DG
69static struct lttng_handle *handle;
70
f3ed775e
DG
71static struct poptOption long_options[] = {
72 /* longName, shortName, argInfo, argPtr, value, descrip, argDesc */
73 {"help", 'h', POPT_ARG_NONE, 0, OPT_HELP, 0, 0},
5440dc42 74 {"session", 's', POPT_ARG_STRING, &opt_session_name, 0, 0, 0},
e14f64a8 75 {"all", 'a', POPT_ARG_VAL, &opt_enable_all, 1, 0, 0},
f3ed775e
DG
76 {"channel", 'c', POPT_ARG_STRING, &opt_channel_name, 0, 0, 0},
77 {"kernel", 'k', POPT_ARG_VAL, &opt_kernel, 1, 0, 0},
d78d6610 78 {"userspace", 'u', POPT_ARG_NONE, 0, OPT_USERSPACE, 0, 0},
b9dfb167 79 {"jul", 'j', POPT_ARG_VAL, &opt_jul, 1, 0, 0},
f3ed775e 80 {"tracepoint", 0, POPT_ARG_NONE, 0, OPT_TRACEPOINT, 0, 0},
7ebae521 81 {"probe", 0, POPT_ARG_STRING, &opt_probe, OPT_PROBE, 0, 0},
40e9d5d3 82 {"function", 0, POPT_ARG_STRING, &opt_function, OPT_FUNCTION, 0, 0},
b213d387
MD
83#if 0
84 /*
85 * Currently removed from lttng kernel tracer. Removed from
86 * lttng UI to discourage its use.
87 */
40e9d5d3 88 {"function:entry", 0, POPT_ARG_STRING, &opt_function_entry_symbol, OPT_FUNCTION_ENTRY, 0, 0},
b213d387 89#endif
7ebae521 90 {"syscall", 0, POPT_ARG_NONE, 0, OPT_SYSCALL, 0, 0},
0cda4f28
MD
91 {"loglevel", 0, POPT_ARG_STRING, 0, OPT_LOGLEVEL, 0, 0},
92 {"loglevel-only", 0, POPT_ARG_STRING, 0, OPT_LOGLEVEL_ONLY, 0, 0},
679b4943 93 {"list-options", 0, POPT_ARG_NONE, NULL, OPT_LIST_OPTIONS, NULL, NULL},
53a80697 94 {"filter", 'f', POPT_ARG_STRING, &opt_filter, OPT_FILTER, 0, 0},
fac3366c 95 {"exclude", 'x', POPT_ARG_STRING, &opt_exclude, OPT_EXCLUDE, 0, 0},
f3ed775e
DG
96 {0, 0, 0, 0, 0, 0, 0}
97};
98
99/*
100 * usage
101 */
102static void usage(FILE *ofp)
103{
32a6298d 104 fprintf(ofp, "usage: lttng enable-event NAME[,NAME2,...] [-k|-u] [OPTIONS] \n");
f3ed775e 105 fprintf(ofp, "\n");
32a6298d 106 fprintf(ofp, "Options:\n");
f3ed775e 107 fprintf(ofp, " -h, --help Show this help\n");
679b4943 108 fprintf(ofp, " --list-options Simple listing of options\n");
32a6298d
DG
109 fprintf(ofp, " -s, --session NAME Apply to session name\n");
110 fprintf(ofp, " -c, --channel NAME Apply to this channel\n");
e08bff8d 111 fprintf(ofp, " -a, --all Enable all tracepoints and syscalls\n");
f3ed775e 112 fprintf(ofp, " -k, --kernel Apply for the kernel tracer\n");
27221701 113 fprintf(ofp, " -u, --userspace Apply to the user-space tracer\n");
b9dfb167 114 fprintf(ofp, " -j, --jul Apply for Java application using JUL\n");
f3ed775e
DG
115 fprintf(ofp, "\n");
116 fprintf(ofp, "Event options:\n");
117 fprintf(ofp, " --tracepoint Tracepoint event (default)\n");
be49af1e
MD
118 fprintf(ofp, " - userspace tracer supports wildcards at end of string.\n");
119 fprintf(ofp, " Don't forget to quote to deal with bash expansion.\n");
120 fprintf(ofp, " e.g.:\n");
121 fprintf(ofp, " \"*\"\n");
122 fprintf(ofp, " \"app_component:na*\"\n");
6a240cd9 123 fprintf(ofp, " --probe (addr | symbol | symbol+offset)\n");
cf0e5467
MD
124 fprintf(ofp, " Dynamic probe.\n");
125 fprintf(ofp, " Addr and offset can be octal (0NNN...),\n");
126 fprintf(ofp, " decimal (NNN...) or hexadecimal (0xNNN...)\n");
6a240cd9 127 fprintf(ofp, " --function (addr | symbol | symbol+offset)\n");
8f0d098b
MD
128 fprintf(ofp, " Dynamic function entry/return probe.\n");
129 fprintf(ofp, " Addr and offset can be octal (0NNN...),\n");
130 fprintf(ofp, " decimal (NNN...) or hexadecimal (0xNNN...)\n");
b213d387 131#if 0
8f0d098b
MD
132 fprintf(ofp, " --function:entry symbol\n");
133 fprintf(ofp, " Function tracer event\n");
b213d387 134#endif
a54bd42d 135 fprintf(ofp, " --syscall System call event\n");
f3ed775e 136 fprintf(ofp, "\n");
300b8fd5 137 fprintf(ofp, " --loglevel name\n");
f9e8873b
DG
138 fprintf(ofp, " Tracepoint loglevel range from 0 to loglevel.\n");
139 fprintf(ofp, " For JUL domain, see the table below for the range values.\n");
300b8fd5
MD
140 fprintf(ofp, " --loglevel-only name\n");
141 fprintf(ofp, " Tracepoint loglevel (only this loglevel)\n");
142 fprintf(ofp, "\n");
0c8477c8
MD
143 fprintf(ofp, " The loglevel or loglevel-only options should be\n");
144 fprintf(ofp, " combined with a tracepoint name or tracepoint\n");
145 fprintf(ofp, " wildcard.\n");
146 fprintf(ofp, " Available loglevels:\n");
147 fprintf(ofp, " (higher value is more verbose)\n");
46839cc2
MD
148 fprintf(ofp, " TRACE_EMERG = 0\n");
149 fprintf(ofp, " TRACE_ALERT = 1\n");
150 fprintf(ofp, " TRACE_CRIT = 2\n");
151 fprintf(ofp, " TRACE_ERR = 3\n");
152 fprintf(ofp, " TRACE_WARNING = 4\n");
153 fprintf(ofp, " TRACE_NOTICE = 5\n");
154 fprintf(ofp, " TRACE_INFO = 6\n");
155 fprintf(ofp, " TRACE_DEBUG_SYSTEM = 7\n");
156 fprintf(ofp, " TRACE_DEBUG_PROGRAM = 8\n");
157 fprintf(ofp, " TRACE_DEBUG_PROCESS = 9\n");
158 fprintf(ofp, " TRACE_DEBUG_MODULE = 10\n");
159 fprintf(ofp, " TRACE_DEBUG_UNIT = 11\n");
160 fprintf(ofp, " TRACE_DEBUG_FUNCTION = 12\n");
161 fprintf(ofp, " TRACE_DEBUG_LINE = 13\n");
162 fprintf(ofp, " TRACE_DEBUG = 14\n");
163 fprintf(ofp, " (shortcuts such as \"system\" are allowed)\n");
b2064f54
DG
164 fprintf(ofp, "\n");
165 fprintf(ofp, " Available JUL domain loglevels:\n");
166 fprintf(ofp, " JUL_OFF = INT32_MAX\n");
167 fprintf(ofp, " JUL_SEVERE = %d\n", LTTNG_LOGLEVEL_JUL_SEVERE);
168 fprintf(ofp, " JUL_WARNING = %d\n", LTTNG_LOGLEVEL_JUL_WARNING);
169 fprintf(ofp, " JUL_INFO = %d\n", LTTNG_LOGLEVEL_JUL_INFO);
170 fprintf(ofp, " JUL_CONFIG = %d\n", LTTNG_LOGLEVEL_JUL_CONFIG);
171 fprintf(ofp, " JUL_FINE = %d\n", LTTNG_LOGLEVEL_JUL_FINE);
172 fprintf(ofp, " JUL_FINER = %d\n", LTTNG_LOGLEVEL_JUL_FINER);
173 fprintf(ofp, " JUL_FINEST = %d\n", LTTNG_LOGLEVEL_JUL_FINEST);
174 fprintf(ofp, " JUL_ALL = INT32_MIN\n");
175 fprintf(ofp, " (shortcuts such as \"severe\" are allowed)\n");
176 fprintf(ofp, "\n");
f2611ab0 177 fprintf(ofp, " -f, --filter \'expression\'\n");
ee8ccafa
MD
178 fprintf(ofp, " Filter expression on event fields and context.\n");
179 fprintf(ofp, " Event recording depends on evaluation.\n");
919e300c
MD
180 fprintf(ofp, " Only specify on first activation of\n");
181 fprintf(ofp, " a given event within a session.\n");
182 fprintf(ofp, " Filter only allowed when enabling\n");
183 fprintf(ofp, " events within a session before tracing\n");
9bd578f5
MD
184 fprintf(ofp, " is started. If the filter fails to link\n");
185 fprintf(ofp, " with the event within the traced domain,\n");
186 fprintf(ofp, " the event will be discarded. Currently,\n");
187 fprintf(ofp, " filter is only implemented for the user-space\n");
188 fprintf(ofp, " tracer.\n");
189 fprintf(ofp, " Expression examples:.\n");
190 fprintf(ofp, " \n");
191 fprintf(ofp, " 'intfield > 500 && intfield < 503'\n");
6a240cd9 192 fprintf(ofp, " '(strfield == \"test\" || intfield != 10) && intfield > 33'\n");
9bd578f5
MD
193 fprintf(ofp, " 'doublefield > 1.1 && intfield < 5.3'\n");
194 fprintf(ofp, " \n");
195 fprintf(ofp, " Wildcards are allowed at the end of strings:\n");
196 fprintf(ofp, " 'seqfield1 == \"te*\"'\n");
197 fprintf(ofp, " In string literals, the escape character is '\\'.\n");
198 fprintf(ofp, " Use '\\*' for the '*' character, and '\\\\' for\n");
ee8ccafa
MD
199 fprintf(ofp, " the '\\' character. Wildcard match any sequence of,\n");
200 fprintf(ofp, " characters including an empty sub-string (match 0 or\n");
201 fprintf(ofp, " more characters).\n");
202 fprintf(ofp, "\n");
203 fprintf(ofp, " Context information can be used for filtering. The\n");
204 fprintf(ofp, " examples below show usage of context filtering on\n");
205 fprintf(ofp, " process name (with a wildcard), process ID range, and\n");
206 fprintf(ofp, " unique thread ID for filtering. The process and\n");
207 fprintf(ofp, " thread ID of running applications can be found under\n");
208 fprintf(ofp, " columns \"PID\" and \"LWP\" of the \"ps -eLf\" command.\n");
209 fprintf(ofp, "\n");
210 fprintf(ofp, " '$ctx.procname == \"demo*\"'\n");
211 fprintf(ofp, " '$ctx.vpid >= 4433 && $ctx.vpid < 4455'\n");
212 fprintf(ofp, " '$ctx.vtid == 1234'\n");
c2063d0b
JI
213 fprintf(ofp, " -x, --exclude LIST\n");
214 fprintf(ofp, " Add exclusions to UST tracepoints:\n");
215 fprintf(ofp, " Events that match any of the items\n");
216 fprintf(ofp, " in the comma-separated LIST are not\n");
217 fprintf(ofp, " enabled, even if they match a wildcard\n");
218 fprintf(ofp, " definition of the event.\n");
300b8fd5 219 fprintf(ofp, "\n");
f3ed775e
DG
220}
221
0d63dd19 222/*
6181537c 223 * Parse probe options.
0d63dd19 224 */
cf0e5467 225static int parse_probe_opts(struct lttng_event *ev, char *opt)
0d63dd19
DG
226{
227 int ret;
8ff0bbd0 228 char s_hex[19];
0d63dd19
DG
229 char name[LTTNG_SYMBOL_NAME_LEN];
230
231 if (opt == NULL) {
232 ret = -1;
8f0d098b 233 goto end;
0d63dd19
DG
234 }
235
236 /* Check for symbol+offset */
8ff0bbd0 237 ret = sscanf(opt, "%[^'+']+%s", name, s_hex);
0d63dd19 238 if (ret == 2) {
7d29a247 239 strncpy(ev->attr.probe.symbol_name, name, LTTNG_SYMBOL_NAME_LEN);
99497cd0 240 ev->attr.probe.symbol_name[LTTNG_SYMBOL_NAME_LEN - 1] = '\0';
cf0e5467 241 DBG("probe symbol %s", ev->attr.probe.symbol_name);
9d035200 242 if (*s_hex == '\0') {
8ff0bbd0 243 ERR("Invalid probe offset %s", s_hex);
0d63dd19 244 ret = -1;
8f0d098b 245 goto end;
0d63dd19 246 }
8ff0bbd0 247 ev->attr.probe.offset = strtoul(s_hex, NULL, 0);
cf0e5467 248 DBG("probe offset %" PRIu64, ev->attr.probe.offset);
3000dc78 249 ev->attr.probe.addr = 0;
8f0d098b
MD
250 goto end;
251 }
252
253 /* Check for symbol */
254 if (isalpha(name[0])) {
255 ret = sscanf(opt, "%s", name);
256 if (ret == 1) {
257 strncpy(ev->attr.probe.symbol_name, name, LTTNG_SYMBOL_NAME_LEN);
99497cd0 258 ev->attr.probe.symbol_name[LTTNG_SYMBOL_NAME_LEN - 1] = '\0';
8f0d098b
MD
259 DBG("probe symbol %s", ev->attr.probe.symbol_name);
260 ev->attr.probe.offset = 0;
261 DBG("probe offset %" PRIu64, ev->attr.probe.offset);
262 ev->attr.probe.addr = 0;
263 goto end;
264 }
0d63dd19
DG
265 }
266
267 /* Check for address */
8ff0bbd0 268 ret = sscanf(opt, "%s", s_hex);
0d63dd19 269 if (ret > 0) {
9d035200 270 if (*s_hex == '\0') {
8ff0bbd0 271 ERR("Invalid probe address %s", s_hex);
0d63dd19 272 ret = -1;
8f0d098b 273 goto end;
0d63dd19 274 }
8ff0bbd0 275 ev->attr.probe.addr = strtoul(s_hex, NULL, 0);
cf0e5467 276 DBG("probe addr %" PRIu64, ev->attr.probe.addr);
3000dc78
DG
277 ev->attr.probe.offset = 0;
278 memset(ev->attr.probe.symbol_name, 0, LTTNG_SYMBOL_NAME_LEN);
8f0d098b 279 goto end;
0d63dd19
DG
280 }
281
282 /* No match */
283 ret = -1;
284
8f0d098b 285end:
0d63dd19
DG
286 return ret;
287}
288
b2064f54
DG
289/*
290 * Maps JUL loglevel from string to value
291 */
292static int loglevel_jul_str_to_value(const char *inputstr)
293{
294 int i = 0;
295 char str[LTTNG_SYMBOL_NAME_LEN];
296
297 /*
298 * Loop up to LTTNG_SYMBOL_NAME_LEN minus one because the NULL bytes is
299 * added at the end of the loop so a the upper bound we avoid the overflow.
300 */
301 while (i < (LTTNG_SYMBOL_NAME_LEN - 1) && inputstr[i] != '\0') {
302 str[i] = toupper(inputstr[i]);
303 i++;
304 }
305 str[i] = '\0';
306
307 if (!strcmp(str, "JUL_OFF") || !strcmp(str, "OFF")) {
308 return LTTNG_LOGLEVEL_JUL_OFF;
309 } else if (!strcmp(str, "JUL_SEVERE") || !strcmp(str, "SEVERE")) {
310 return LTTNG_LOGLEVEL_JUL_SEVERE;
311 } else if (!strcmp(str, "JUL_WARNING") || !strcmp(str, "WARNING")) {
312 return LTTNG_LOGLEVEL_JUL_WARNING;
313 } else if (!strcmp(str, "JUL_INFO") || !strcmp(str, "INFO")) {
314 return LTTNG_LOGLEVEL_JUL_INFO;
315 } else if (!strcmp(str, "JUL_CONFIG") || !strcmp(str, "CONFIG")) {
316 return LTTNG_LOGLEVEL_JUL_CONFIG;
317 } else if (!strcmp(str, "JUL_FINE") || !strcmp(str, "FINE")) {
318 return LTTNG_LOGLEVEL_JUL_FINE;
319 } else if (!strcmp(str, "JUL_FINER") || !strcmp(str, "FINER")) {
320 return LTTNG_LOGLEVEL_JUL_FINER;
321 } else if (!strcmp(str, "JUL_FINEST") || !strcmp(str, "FINEST")) {
322 return LTTNG_LOGLEVEL_JUL_FINEST;
323 } else if (!strcmp(str, "JUL_ALL") || !strcmp(str, "ALL")) {
324 return LTTNG_LOGLEVEL_JUL_ALL;
325 } else {
326 return -1;
327 }
328}
329
8005f29a 330/*
0c8477c8 331 * Maps loglevel from string to value
8005f29a
MD
332 */
333static
46839cc2 334int loglevel_str_to_value(const char *inputstr)
8005f29a 335{
46839cc2
MD
336 int i = 0;
337 char str[LTTNG_SYMBOL_NAME_LEN];
338
e051e07c
DG
339 /*
340 * Loop up to LTTNG_SYMBOL_NAME_LEN minus one because the NULL bytes is
341 * added at the end of the loop so a the upper bound we avoid the overflow.
342 */
343 while (i < (LTTNG_SYMBOL_NAME_LEN - 1) && inputstr[i] != '\0') {
46839cc2
MD
344 str[i] = toupper(inputstr[i]);
345 i++;
346 }
347 str[i] = '\0';
348 if (!strcmp(str, "TRACE_EMERG") || !strcmp(str, "EMERG")) {
349 return LTTNG_LOGLEVEL_EMERG;
350 } else if (!strcmp(str, "TRACE_ALERT") || !strcmp(str, "ALERT")) {
351 return LTTNG_LOGLEVEL_ALERT;
352 } else if (!strcmp(str, "TRACE_CRIT") || !strcmp(str, "CRIT")) {
353 return LTTNG_LOGLEVEL_CRIT;
354 } else if (!strcmp(str, "TRACE_ERR") || !strcmp(str, "ERR")) {
355 return LTTNG_LOGLEVEL_ERR;
356 } else if (!strcmp(str, "TRACE_WARNING") || !strcmp(str, "WARNING")) {
357 return LTTNG_LOGLEVEL_WARNING;
358 } else if (!strcmp(str, "TRACE_NOTICE") || !strcmp(str, "NOTICE")) {
359 return LTTNG_LOGLEVEL_NOTICE;
360 } else if (!strcmp(str, "TRACE_INFO") || !strcmp(str, "INFO")) {
361 return LTTNG_LOGLEVEL_INFO;
362 } else if (!strcmp(str, "TRACE_DEBUG_SYSTEM") || !strcmp(str, "DEBUG_SYSTEM") || !strcmp(str, "SYSTEM")) {
363 return LTTNG_LOGLEVEL_DEBUG_SYSTEM;
364 } else if (!strcmp(str, "TRACE_DEBUG_PROGRAM") || !strcmp(str, "DEBUG_PROGRAM") || !strcmp(str, "PROGRAM")) {
365 return LTTNG_LOGLEVEL_DEBUG_PROGRAM;
366 } else if (!strcmp(str, "TRACE_DEBUG_PROCESS") || !strcmp(str, "DEBUG_PROCESS") || !strcmp(str, "PROCESS")) {
367 return LTTNG_LOGLEVEL_DEBUG_PROCESS;
368 } else if (!strcmp(str, "TRACE_DEBUG_MODULE") || !strcmp(str, "DEBUG_MODULE") || !strcmp(str, "MODULE")) {
369 return LTTNG_LOGLEVEL_DEBUG_MODULE;
370 } else if (!strcmp(str, "TRACE_DEBUG_UNIT") || !strcmp(str, "DEBUG_UNIT") || !strcmp(str, "UNIT")) {
371 return LTTNG_LOGLEVEL_DEBUG_UNIT;
372 } else if (!strcmp(str, "TRACE_DEBUG_FUNCTION") || !strcmp(str, "DEBUG_FUNCTION") || !strcmp(str, "FUNCTION")) {
373 return LTTNG_LOGLEVEL_DEBUG_FUNCTION;
374 } else if (!strcmp(str, "TRACE_DEBUG_LINE") || !strcmp(str, "DEBUG_LINE") || !strcmp(str, "LINE")) {
375 return LTTNG_LOGLEVEL_DEBUG_LINE;
376 } else if (!strcmp(str, "TRACE_DEBUG") || !strcmp(str, "DEBUG")) {
377 return LTTNG_LOGLEVEL_DEBUG;
8005f29a
MD
378 } else {
379 return -1;
380 }
381}
382
85076754
MD
383static
384const char *print_channel_name(const char *name)
385{
386 return name ? : DEFAULT_CHANNEL_NAME;
387}
388
389static
390const char *print_raw_channel_name(const char *name)
391{
392 return name ? : "<default>";
393}
394
9c48cab3
JI
395/*
396 * Return allocated string for pretty-printing exclusion names.
397 */
398static
399char *print_exclusions(int count, char **names)
400{
401 int length = 0;
402 int i;
403 const char *preamble = " excluding ";
404 char *ret;
405
406 if (count == 0) {
407 return strdup("");
408 }
409
410 /* calculate total required length */
411 for (i = 0; i < count; i++) {
412 length += strlen(names[i]) + 1;
413 }
414
415 /* add length of preamble + one for NUL - one for last (missing) comma */
416 length += strlen(preamble);
417 ret = malloc(length);
418 strncpy(ret, preamble, length);
419 for (i = 0; i < count; i++) {
420 strcat(ret, names[i]);
421 if (i != count - 1) {
422 strcat(ret, ",");
423 }
424 }
425 return ret;
426}
427
748bde76
JI
428/*
429 * Compare list of exclusions against an event name.
430 * Return a list of legal exclusion names.
431 * Produce an error or a warning about others (depending on the situation)
432 */
433static
434int check_exclusion_subsets(const char *event_name,
435 const char *exclusions,
436 int *exclusion_count_ptr,
437 char ***exclusion_list_ptr)
438{
439 const char *excluder_ptr;
440 const char *event_ptr;
441 const char *next_excluder;
442 int excluder_length;
443 int exclusion_count = 0;
444 char **exclusion_list = NULL;
445 int ret = CMD_SUCCESS;
446
447 if (event_name[strlen(event_name) - 1] != '*') {
448 ERR("Event %s: Excluders can only be used with wildcarded events", event_name);
449 goto error;
450 }
451
452 next_excluder = exclusions;
453 while (*next_excluder != 0) {
454 event_ptr = event_name;
455 excluder_ptr = next_excluder;
456 excluder_length = strcspn(next_excluder, ",");
457
458 /* Scan both the excluder and the event letter by letter */
459 while (1) {
460 char e, x;
461
462 e = *event_ptr;
463 x = *excluder_ptr;
464
465 if (x == '*') {
466 /* Event is a subset of the excluder */
467 ERR("Event %s: %.*s excludes all events from %s",
468 event_name,
469 excluder_length,
470 next_excluder,
471 event_name);
472 goto error;
473 }
474 if (e == '*') {
475 /* Excluder is a proper subset of event */
476 exclusion_count++;
477 exclusion_list = realloc(exclusion_list, sizeof(char **) * exclusion_count);
478 exclusion_list[exclusion_count - 1] = strndup(next_excluder, excluder_length);
479
480 break;
481 }
482 if (x != e) {
483 /* Excluder and event sets have no common elements */
484 WARN("Event %s: %.*s does not exclude any events from %s",
485 event_name,
486 excluder_length,
487 next_excluder,
488 event_name);
489 break;
490 }
491 excluder_ptr++;
492 event_ptr++;
493 }
494 /* next excluder */
495 next_excluder += excluder_length;
496 if (*next_excluder == ',') {
497 next_excluder++;
498 }
499 }
500 goto end;
501error:
502 while (exclusion_count--) {
503 free(exclusion_list[exclusion_count]);
504 }
505 if (exclusion_list != NULL) {
506 free(exclusion_list);
507 }
508 exclusion_list = NULL;
509 exclusion_count = 0;
510 ret = CMD_ERROR;
511end:
512 *exclusion_count_ptr = exclusion_count;
513 *exclusion_list_ptr = exclusion_list;
514 return ret;
515}
f3ed775e 516/*
6181537c 517 * Enabling event using the lttng API.
f3ed775e 518 */
cd80958d 519static int enable_events(char *session_name)
f3ed775e 520{
85076754 521 int ret = CMD_SUCCESS, warn = 0;
b73d0b29 522 char *event_name, *channel_name = NULL;
f3ed775e 523 struct lttng_event ev;
7d29a247 524 struct lttng_domain dom;
7ed70bc9
JI
525 int exclusion_count = 0;
526 char **exclusion_list = NULL;
f3ed775e 527
441c16a7
MD
528 memset(&ev, 0, sizeof(ev));
529 memset(&dom, 0, sizeof(dom));
530
53a80697
MD
531 if (opt_kernel) {
532 if (opt_filter) {
533 ERR("Filter not implement for kernel tracing yet");
534 ret = CMD_ERROR;
535 goto error;
536 }
67b58630
JG
537 if (opt_loglevel) {
538 WARN("Kernel loglevels are not supported.");
539 }
53a80697
MD
540 }
541
7d29a247
DG
542 /* Create lttng domain */
543 if (opt_kernel) {
544 dom.type = LTTNG_DOMAIN_KERNEL;
7972aab2 545 dom.buf_type = LTTNG_BUFFER_GLOBAL;
d78d6610 546 } else if (opt_userspace) {
2bdd86d4 547 dom.type = LTTNG_DOMAIN_UST;
7972aab2 548 /* Default. */
8692d4e5 549 dom.buf_type = LTTNG_BUFFER_PER_UID;
b9dfb167
DG
550 } else if (opt_jul) {
551 dom.type = LTTNG_DOMAIN_JUL;
552 /* Default. */
553 dom.buf_type = LTTNG_BUFFER_PER_UID;
6181537c 554 } else {
b9dfb167 555 print_missing_domain();
d16c1a4c 556 ret = CMD_ERROR;
6181537c 557 goto error;
2bdd86d4 558 }
7d29a247 559
d5dd17fd
JI
560 if (opt_kernel && opt_exclude) {
561 ERR("Event name exclusions are not yet implemented for kernel events");
562 ret = CMD_ERROR;
563 goto error;
564 }
565
85076754 566 channel_name = opt_channel_name;
ae856491 567
cd80958d
DG
568 handle = lttng_create_handle(session_name, &dom);
569 if (handle == NULL) {
570 ret = -1;
571 goto error;
572 }
1aef21b6 573
cd80958d 574 if (opt_enable_all) {
8c9ae521 575 /* Default setup for enable all */
75e8c5ab
MD
576 if (opt_kernel) {
577 ev.type = opt_event_type;
578 ev.name[0] = '\0';
300b8fd5
MD
579 /* kernel loglevels not implemented */
580 ev.loglevel_type = LTTNG_EVENT_LOGLEVEL_ALL;
75e8c5ab
MD
581 } else {
582 ev.type = LTTNG_EVENT_TRACEPOINT;
583 strcpy(ev.name, "*");
300b8fd5
MD
584 ev.loglevel_type = opt_loglevel_type;
585 if (opt_loglevel) {
b2064f54
DG
586 assert(opt_userspace || opt_jul);
587 if (opt_userspace) {
588 ev.loglevel = loglevel_str_to_value(opt_loglevel);
589 } else if (opt_jul) {
590 ev.loglevel = loglevel_jul_str_to_value(opt_loglevel);
591 }
300b8fd5
MD
592 if (ev.loglevel == -1) {
593 ERR("Unknown loglevel %s", opt_loglevel);
2f70b271 594 ret = -LTTNG_ERR_INVALID;
300b8fd5
MD
595 goto error;
596 }
22e25b71 597 } else {
b2064f54
DG
598 assert(opt_userspace || opt_jul);
599 if (opt_userspace) {
600 ev.loglevel = -1;
601 } else if (opt_jul) {
602 ev.loglevel = LTTNG_LOGLEVEL_JUL_ALL;
603 }
300b8fd5 604 }
75e8c5ab 605 }
8c9ae521 606
7ed70bc9
JI
607 if (opt_exclude) {
608 ret = check_exclusion_subsets("*", opt_exclude,
609 &exclusion_count, &exclusion_list);
610 if (ret == CMD_ERROR) {
611 goto error;
612 }
613 }
025faf73 614 if (!opt_filter) {
7ed70bc9
JI
615 ret = lttng_enable_event_with_exclusions(handle,
616 &ev, channel_name,
617 NULL,
618 exclusion_count, exclusion_list);
025faf73
DG
619 if (ret < 0) {
620 switch (-ret) {
621 case LTTNG_ERR_KERN_EVENT_EXIST:
622 WARN("Kernel events already enabled (channel %s, session %s)",
85076754 623 print_channel_name(channel_name), session_name);
025faf73
DG
624 break;
625 default:
626 ERR("Events: %s (channel %s, session %s)",
85076754
MD
627 lttng_strerror(ret),
628 ret == -LTTNG_ERR_NEED_CHANNEL_NAME
629 ? print_raw_channel_name(channel_name)
630 : print_channel_name(channel_name),
631 session_name);
025faf73
DG
632 break;
633 }
634 goto end;
42224349 635 }
8c9ae521 636
025faf73
DG
637 switch (opt_event_type) {
638 case LTTNG_EVENT_TRACEPOINT:
67b58630 639 if (opt_loglevel && dom.type != LTTNG_DOMAIN_KERNEL) {
9c48cab3
JI
640 char *exclusion_string = print_exclusions(exclusion_count, exclusion_list);
641 MSG("All %s tracepoints%s are enabled in channel %s for loglevel %s",
b9dfb167 642 get_domain_str(dom.type),
9c48cab3 643 exclusion_string,
85076754 644 print_channel_name(channel_name),
025faf73 645 opt_loglevel);
9c48cab3 646 free(exclusion_string);
025faf73 647 } else {
9c48cab3
JI
648 char *exclusion_string = print_exclusions(exclusion_count, exclusion_list);
649 MSG("All %s tracepoints%s are enabled in channel %s",
b9dfb167 650 get_domain_str(dom.type),
9c48cab3 651 exclusion_string,
85076754 652 print_channel_name(channel_name));
9c48cab3 653 free(exclusion_string);
025faf73
DG
654 }
655 break;
656 case LTTNG_EVENT_SYSCALL:
657 if (opt_kernel) {
658 MSG("All kernel system calls are enabled in channel %s",
85076754 659 print_channel_name(channel_name));
025faf73
DG
660 }
661 break;
662 case LTTNG_EVENT_ALL:
67b58630 663 if (opt_loglevel && dom.type != LTTNG_DOMAIN_KERNEL) {
9c48cab3
JI
664 char *exclusion_string = print_exclusions(exclusion_count, exclusion_list);
665 MSG("All %s events%s are enabled in channel %s for loglevel %s",
b9dfb167 666 get_domain_str(dom.type),
9c48cab3 667 exclusion_string,
85076754 668 print_channel_name(channel_name),
025faf73 669 opt_loglevel);
9c48cab3 670 free(exclusion_string);
025faf73 671 } else {
9c48cab3
JI
672 char *exclusion_string = print_exclusions(exclusion_count, exclusion_list);
673 MSG("All %s events%s are enabled in channel %s",
b9dfb167 674 get_domain_str(dom.type),
9c48cab3 675 exclusion_string,
85076754 676 print_channel_name(channel_name));
9c48cab3 677 free(exclusion_string);
025faf73
DG
678 }
679 break;
680 default:
681 /*
682 * We should not be here since lttng_enable_event should have
683 * failed on the event type.
684 */
685 goto error;
57064ada 686 }
f3ed775e 687 }
025faf73 688 if (opt_filter) {
7ed70bc9
JI
689 ret = lttng_enable_event_with_exclusions(handle, &ev, channel_name,
690 opt_filter, exclusion_count, exclusion_list);
16363652
DG
691 if (ret < 0) {
692 switch (-ret) {
693 case LTTNG_ERR_FILTER_EXIST:
85076754 694 WARN("Filter on all events is already enabled"
16363652 695 " (channel %s, session %s)",
85076754 696 print_channel_name(channel_name), session_name);
16363652
DG
697 break;
698 default:
85076754
MD
699 ERR("All events: %s (channel %s, session %s, filter \'%s\')",
700 lttng_strerror(ret),
701 ret == -LTTNG_ERR_NEED_CHANNEL_NAME
702 ? print_raw_channel_name(channel_name)
703 : print_channel_name(channel_name),
704 session_name, opt_filter);
16363652
DG
705 break;
706 }
707 goto error;
708 } else {
709 MSG("Filter '%s' successfully set", opt_filter);
710 }
711 }
8c9ae521 712 goto end;
f3ed775e
DG
713 }
714
715 /* Strip event list */
716 event_name = strtok(opt_event_list, ",");
717 while (event_name != NULL) {
6181537c
DG
718 /* Copy name and type of the event */
719 strncpy(ev.name, event_name, LTTNG_SYMBOL_NAME_LEN);
720 ev.name[LTTNG_SYMBOL_NAME_LEN - 1] = '\0';
721 ev.type = opt_event_type;
722
f3ed775e
DG
723 /* Kernel tracer action */
724 if (opt_kernel) {
725 DBG("Enabling kernel event %s for channel %s",
85076754
MD
726 event_name,
727 print_channel_name(channel_name));
f3ed775e
DG
728
729 switch (opt_event_type) {
7a3d1328
MD
730 case LTTNG_EVENT_ALL: /* Default behavior is tracepoint */
731 ev.type = LTTNG_EVENT_TRACEPOINT;
732 /* Fall-through */
e6ddca71 733 case LTTNG_EVENT_TRACEPOINT:
f3ed775e 734 break;
7d29a247 735 case LTTNG_EVENT_PROBE:
cf0e5467 736 ret = parse_probe_opts(&ev, opt_probe);
0d63dd19 737 if (ret < 0) {
cf0e5467 738 ERR("Unable to parse probe options");
0d63dd19
DG
739 ret = 0;
740 goto error;
741 }
f3ed775e
DG
742 break;
743 case LTTNG_EVENT_FUNCTION:
8f0d098b
MD
744 ret = parse_probe_opts(&ev, opt_function);
745 if (ret < 0) {
746 ERR("Unable to parse function probe options");
747 ret = 0;
748 goto error;
749 }
750 break;
751 case LTTNG_EVENT_FUNCTION_ENTRY:
6181537c
DG
752 strncpy(ev.attr.ftrace.symbol_name, opt_function_entry_symbol,
753 LTTNG_SYMBOL_NAME_LEN);
99497cd0 754 ev.attr.ftrace.symbol_name[LTTNG_SYMBOL_NAME_LEN - 1] = '\0';
f3ed775e 755 break;
a54bd42d 756 case LTTNG_EVENT_SYSCALL:
6181537c
DG
757 MSG("per-syscall selection not supported yet. Use \"-a\" "
758 "for all syscalls.");
f3ed775e 759 default:
1ab1ea0b 760 ret = CMD_UNDEFINED;
f3ed775e
DG
761 goto error;
762 }
0cda4f28 763
0cda4f28 764 /* kernel loglevels not implemented */
8005f29a 765 ev.loglevel_type = LTTNG_EVENT_LOGLEVEL_ALL;
f3ed775e 766 } else if (opt_userspace) { /* User-space tracer action */
d78d6610 767#if 0
e14f64a8
DG
768 if (opt_cmd_name != NULL || opt_pid) {
769 MSG("Only supporting tracing all UST processes (-u) for now.");
1ab1ea0b 770 ret = CMD_UNDEFINED;
2bdd86d4
MD
771 goto error;
772 }
d78d6610 773#endif
6181537c 774
300b8fd5 775 DBG("Enabling UST event %s for channel %s, loglevel %s", event_name,
85076754 776 print_channel_name(channel_name), opt_loglevel ? : "<all>");
2bdd86d4
MD
777
778 switch (opt_event_type) {
779 case LTTNG_EVENT_ALL: /* Default behavior is tracepoint */
2bdd86d4
MD
780 /* Fall-through */
781 case LTTNG_EVENT_TRACEPOINT:
e4baff1e
MD
782 /* Copy name and type of the event */
783 ev.type = LTTNG_EVENT_TRACEPOINT;
784 strncpy(ev.name, event_name, LTTNG_SYMBOL_NAME_LEN);
785 ev.name[LTTNG_SYMBOL_NAME_LEN - 1] = '\0';
2bdd86d4
MD
786 break;
787 case LTTNG_EVENT_PROBE:
788 case LTTNG_EVENT_FUNCTION:
789 case LTTNG_EVENT_FUNCTION_ENTRY:
790 case LTTNG_EVENT_SYSCALL:
791 default:
cc62c0c0 792 ERR("Event type not available for user-space tracing");
4ce78777 793 ret = CMD_UNSUPPORTED;
2bdd86d4
MD
794 goto error;
795 }
0cda4f28 796
7ed70bc9 797 if (opt_exclude) {
d5dd17fd
JI
798 if (opt_event_type != LTTNG_EVENT_ALL && opt_event_type != LTTNG_EVENT_TRACEPOINT) {
799 ERR("Exclusion option can only be used with tracepoint events");
800 ret = CMD_ERROR;
801 goto error;
802 }
7ed70bc9
JI
803 /* Free previously allocated items */
804 if (exclusion_list != NULL) {
805 while (exclusion_count--) {
806 free(exclusion_list[exclusion_count]);
807 }
808 free(exclusion_list);
809 exclusion_list = NULL;
810 }
811 /* Check for proper subsets */
812 ret = check_exclusion_subsets(event_name, opt_exclude,
813 &exclusion_count, &exclusion_list);
814 if (ret == CMD_ERROR) {
815 goto error;
816 }
817 }
818
0cda4f28 819 ev.loglevel_type = opt_loglevel_type;
ed7f4083 820 if (opt_loglevel) {
8005f29a
MD
821 ev.loglevel = loglevel_str_to_value(opt_loglevel);
822 if (ev.loglevel == -1) {
823 ERR("Unknown loglevel %s", opt_loglevel);
2f70b271 824 ret = -LTTNG_ERR_INVALID;
8005f29a
MD
825 goto error;
826 }
22e25b71
MD
827 } else {
828 ev.loglevel = -1;
ed7f4083 829 }
b9dfb167
DG
830 } else if (opt_jul) {
831 if (opt_event_type != LTTNG_EVENT_ALL &&
832 opt_event_type != LTTNG_EVENT_TRACEPOINT) {
833 ERR("Event type not supported for JUL domain.");
834 ret = CMD_UNSUPPORTED;
835 goto error;
836 }
b2064f54
DG
837
838 ev.loglevel_type = opt_loglevel_type;
839 if (opt_loglevel) {
840 ev.loglevel = loglevel_jul_str_to_value(opt_loglevel);
841 if (ev.loglevel == -1) {
842 ERR("Unknown loglevel %s", opt_loglevel);
843 ret = -LTTNG_ERR_INVALID;
844 goto error;
845 }
846 } else {
847 ev.loglevel = LTTNG_LOGLEVEL_JUL_ALL;
848 }
b9dfb167
DG
849 ev.type = LTTNG_EVENT_TRACEPOINT;
850 strncpy(ev.name, event_name, LTTNG_SYMBOL_NAME_LEN);
851 ev.name[LTTNG_SYMBOL_NAME_LEN - 1] = '\0';
f3ed775e 852 } else {
b9dfb167 853 print_missing_domain();
300b8fd5 854 ret = CMD_ERROR;
f3ed775e
DG
855 goto error;
856 }
857
025faf73 858 if (!opt_filter) {
9c48cab3
JI
859 char *exclusion_string;
860
7ed70bc9
JI
861 ret = lttng_enable_event_with_exclusions(handle,
862 &ev, channel_name,
863 NULL, exclusion_count, exclusion_list);
9c48cab3 864 exclusion_string = print_exclusions(exclusion_count, exclusion_list);
025faf73
DG
865 if (ret < 0) {
866 /* Turn ret to positive value to handle the positive error code */
867 switch (-ret) {
868 case LTTNG_ERR_KERN_EVENT_EXIST:
9c48cab3 869 WARN("Kernel event %s%s already enabled (channel %s, session %s)",
85076754 870 event_name,
9c48cab3 871 exclusion_string,
85076754 872 print_channel_name(channel_name), session_name);
025faf73
DG
873 break;
874 default:
9c48cab3
JI
875 ERR("Event %s%s: %s (channel %s, session %s)", event_name,
876 exclusion_string,
85076754
MD
877 lttng_strerror(ret),
878 ret == -LTTNG_ERR_NEED_CHANNEL_NAME
879 ? print_raw_channel_name(channel_name)
880 : print_channel_name(channel_name),
881 session_name);
025faf73
DG
882 break;
883 }
884 warn = 1;
885 } else {
9c48cab3 886 MSG("%s event %s%s created in channel %s",
b9dfb167 887 get_domain_str(dom.type), event_name,
9c48cab3 888 exclusion_string,
85076754 889 print_channel_name(channel_name));
42224349 890 }
9c48cab3 891 free(exclusion_string);
6181537c 892 }
025faf73
DG
893
894 if (opt_filter) {
9c48cab3
JI
895 char *exclusion_string;
896
7ed70bc9
JI
897 ret = lttng_enable_event_with_exclusions(handle, &ev, channel_name,
898 opt_filter, exclusion_count, exclusion_list);
9c48cab3
JI
899 exclusion_string = print_exclusions(exclusion_count, exclusion_list);
900
53a80697 901 if (ret < 0) {
7671f53c
CB
902 switch (-ret) {
903 case LTTNG_ERR_FILTER_EXIST:
9c48cab3 904 WARN("Filter on event %s%s is already enabled"
7671f53c 905 " (channel %s, session %s)",
85076754 906 event_name,
9c48cab3 907 exclusion_string,
85076754 908 print_channel_name(channel_name), session_name);
7671f53c
CB
909 break;
910 default:
9c48cab3
JI
911 ERR("Event %s%s: %s (channel %s, session %s, filter \'%s\')", ev.name,
912 exclusion_string,
85076754
MD
913 lttng_strerror(ret),
914 ret == -LTTNG_ERR_NEED_CHANNEL_NAME
915 ? print_raw_channel_name(channel_name)
916 : print_channel_name(channel_name),
917 session_name, opt_filter);
7671f53c
CB
918 break;
919 }
b69793ae 920 free(exclusion_string);
53a80697 921 goto error;
16363652 922 } else {
9c48cab3
JI
923 MSG("Event %s%s: Filter '%s' successfully set",
924 event_name, exclusion_string,
925 opt_filter);
53a80697 926 }
9c48cab3 927 free(exclusion_string);
53a80697 928 }
6181537c 929
f3ed775e
DG
930 /* Next event */
931 event_name = strtok(NULL, ",");
932 }
933
8c9ae521 934end:
f3ed775e 935error:
ae856491
DG
936 if (warn) {
937 ret = CMD_WARNING;
938 }
cd80958d
DG
939 lttng_destroy_handle(handle);
940
7ed70bc9
JI
941 if (exclusion_list != NULL) {
942 while (exclusion_count--) {
943 free(exclusion_list[exclusion_count]);
944 }
945 free(exclusion_list);
946 }
947
f3ed775e
DG
948 return ret;
949}
950
951/*
6181537c 952 * Add event to trace session
f3ed775e
DG
953 */
954int cmd_enable_events(int argc, const char **argv)
955{
ca1c3607 956 int opt, ret = CMD_SUCCESS;
f3ed775e 957 static poptContext pc;
cd80958d 958 char *session_name = NULL;
de044b7a 959 int event_type = -1;
f3ed775e
DG
960
961 pc = poptGetContext(NULL, argc, argv, long_options, 0);
962 poptReadDefaultConfig(pc, 0);
963
964 /* Default event type */
7a3d1328 965 opt_event_type = LTTNG_EVENT_ALL;
f3ed775e
DG
966
967 while ((opt = poptGetNextOpt(pc)) != -1) {
968 switch (opt) {
969 case OPT_HELP:
ca1c3607 970 usage(stdout);
f3ed775e 971 goto end;
f3ed775e 972 case OPT_TRACEPOINT:
e6ddca71 973 opt_event_type = LTTNG_EVENT_TRACEPOINT;
f3ed775e 974 break;
cf0e5467 975 case OPT_PROBE:
7d29a247 976 opt_event_type = LTTNG_EVENT_PROBE;
f3ed775e
DG
977 break;
978 case OPT_FUNCTION:
979 opt_event_type = LTTNG_EVENT_FUNCTION;
8f0d098b
MD
980 break;
981 case OPT_FUNCTION_ENTRY:
982 opt_event_type = LTTNG_EVENT_FUNCTION_ENTRY;
f3ed775e 983 break;
a54bd42d
MD
984 case OPT_SYSCALL:
985 opt_event_type = LTTNG_EVENT_SYSCALL;
0133c199 986 break;
eeac7d46
MD
987 case OPT_USERSPACE:
988 opt_userspace = 1;
eeac7d46 989 break;
0cda4f28 990 case OPT_LOGLEVEL:
8005f29a 991 opt_loglevel_type = LTTNG_EVENT_LOGLEVEL_RANGE;
0cda4f28
MD
992 opt_loglevel = poptGetOptArg(pc);
993 break;
994 case OPT_LOGLEVEL_ONLY:
8005f29a 995 opt_loglevel_type = LTTNG_EVENT_LOGLEVEL_SINGLE;
0cda4f28 996 opt_loglevel = poptGetOptArg(pc);
13dce3b7 997 break;
679b4943
SM
998 case OPT_LIST_OPTIONS:
999 list_cmd_options(stdout, long_options);
679b4943 1000 goto end;
53a80697
MD
1001 case OPT_FILTER:
1002 break;
fac3366c
JI
1003 case OPT_EXCLUDE:
1004 break;
f3ed775e
DG
1005 default:
1006 usage(stderr);
1007 ret = CMD_UNDEFINED;
1008 goto end;
1009 }
de044b7a
DG
1010
1011 /* Validate event type. Multiple event type are not supported. */
1012 if (event_type == -1) {
1013 event_type = opt_event_type;
1014 } else {
1015 if (event_type != opt_event_type) {
1016 ERR("Multiple event type not supported.");
1017 ret = CMD_ERROR;
1018 goto end;
1019 }
1020 }
f3ed775e
DG
1021 }
1022
1023 opt_event_list = (char*) poptGetArg(pc);
1024 if (opt_event_list == NULL && opt_enable_all == 0) {
1025 ERR("Missing event name(s).\n");
1026 usage(stderr);
ca1c3607 1027 ret = CMD_ERROR;
f3ed775e
DG
1028 goto end;
1029 }
1030
cd80958d
DG
1031 if (!opt_session_name) {
1032 session_name = get_session_name();
1033 if (session_name == NULL) {
ca1c3607 1034 ret = CMD_ERROR;
cd80958d
DG
1035 goto end;
1036 }
1037 } else {
1038 session_name = opt_session_name;
1039 }
1040
1041 ret = enable_events(session_name);
f3ed775e
DG
1042
1043end:
cd80958d
DG
1044 if (opt_session_name == NULL) {
1045 free(session_name);
1046 }
1047
ca1c3607 1048 poptFreeContext(pc);
f3ed775e
DG
1049 return ret;
1050}
This page took 0.099605 seconds and 5 git commands to generate.