c54b6407802ed7cd0e342c057f9d3c460c05a351
[lttng-tools.git] / src / bin / lttng / commands / track-untrack.c
1 /*
2 * Copyright (C) 2011 - David Goulet <david.goulet@polymtl.ca>
3 * Copyright (C) 2015 - Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License, version 2 only,
7 * as published by the Free Software Foundation.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License along
15 * with this program; if not, write to the Free Software Foundation, Inc.,
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
17 */
18
19 #define _LGPL_SOURCE
20 #include <ctype.h>
21 #include <popt.h>
22 #include <stdio.h>
23 #include <stdlib.h>
24 #include <string.h>
25 #include <sys/stat.h>
26 #include <sys/types.h>
27 #include <unistd.h>
28 #include <assert.h>
29
30 #include <urcu/list.h>
31
32 #include <common/mi-lttng.h>
33
34 #include "../command.h"
35
36 enum cmd_type {
37 CMD_TRACK,
38 CMD_UNTRACK,
39 };
40
41 enum tracker_type_state {
42 STATE_NONE = 0,
43 STATE_PID,
44 STATE_VPID,
45 STATE_UID,
46 STATE_VUID,
47 STATE_GID,
48 STATE_VGID,
49 };
50
51 struct opt_type {
52 int used;
53 int all;
54 char *string;
55 };
56
57 struct id_list {
58 size_t nr;
59 struct lttng_tracker_id **array;
60 };
61
62 static char *opt_session_name;
63 static int opt_kernel;
64 static int opt_userspace;
65
66 static struct opt_type opt_pid, opt_vpid, opt_uid, opt_vuid, opt_gid, opt_vgid;
67
68 static enum tracker_type_state type_state;
69
70 enum {
71 OPT_HELP = 1,
72 OPT_LIST_OPTIONS,
73 OPT_SESSION,
74 OPT_PID,
75 OPT_VPID,
76 OPT_UID,
77 OPT_VUID,
78 OPT_GID,
79 OPT_VGID,
80 OPT_ALL,
81 };
82
83 static struct poptOption long_options[] = {
84 /* { longName, shortName, argInfo, argPtr, value, descrip, argDesc, } */
85 { "help", 'h', POPT_ARG_NONE, 0, OPT_HELP, 0, 0, },
86 { "session", 's', POPT_ARG_STRING, &opt_session_name, OPT_SESSION, 0, 0, },
87 { "kernel", 'k', POPT_ARG_VAL, &opt_kernel, 1, 0, 0, },
88 { "userspace", 'u', POPT_ARG_VAL, &opt_userspace, 1, 0, 0, },
89 { "pid", 'p', POPT_ARG_STRING | POPT_ARGFLAG_OPTIONAL, &opt_pid.string, OPT_PID, 0, 0, },
90 { "vpid", 0, POPT_ARG_STRING | POPT_ARGFLAG_OPTIONAL, &opt_vpid.string, OPT_VPID, 0, 0, },
91 { "uid", 0, POPT_ARG_STRING | POPT_ARGFLAG_OPTIONAL, &opt_uid.string, OPT_UID, 0, 0, },
92 { "vuid", 0, POPT_ARG_STRING | POPT_ARGFLAG_OPTIONAL, &opt_vuid.string, OPT_VUID, 0, 0, },
93 { "gid", 0, POPT_ARG_STRING | POPT_ARGFLAG_OPTIONAL, &opt_gid.string, OPT_GID, 0, 0, },
94 { "vgid", 0, POPT_ARG_STRING | POPT_ARGFLAG_OPTIONAL, &opt_vgid.string, OPT_VGID, 0, 0, },
95 { "all", 'a', POPT_ARG_NONE, 0, OPT_ALL, 0, 0, },
96 { "list-options", 0, POPT_ARG_NONE, NULL, OPT_LIST_OPTIONS, 0, 0, },
97 { 0, 0, 0, 0, 0, 0, 0, },
98 };
99
100 static struct id_list *alloc_id_list(size_t nr_items)
101 {
102 struct id_list *id_list;
103 struct lttng_tracker_id **items;
104
105 id_list = zmalloc(sizeof(*id_list));
106 if (!id_list) {
107 goto error;
108 }
109 items = zmalloc(nr_items * sizeof(*items));
110 if (!items) {
111 goto error;
112 }
113 id_list->nr = nr_items;
114 id_list->array = items;
115 return id_list;
116 error:
117 free(id_list);
118 return NULL;
119 }
120
121 static void free_id_list(struct id_list *list)
122 {
123 size_t nr_items;
124 int i;
125
126 if (!list) {
127 return;
128 }
129 nr_items = list->nr;
130 for (i = 0; i < nr_items; i++) {
131 struct lttng_tracker_id *item = list->array[i];
132 lttng_tracker_id_destroy(item);
133 }
134 free(list);
135 }
136
137 static int parse_id_string(const char *_id_string,
138 int all,
139 struct id_list **_id_list,
140 enum lttng_tracker_type tracker_type)
141 {
142 const char *one_id_str;
143 char *iter;
144 int retval = CMD_SUCCESS;
145 int count = 0;
146 struct id_list *id_list = NULL;
147 char *id_string = NULL;
148 char *endptr;
149
150 if (all && _id_string) {
151 ERR("An empty ID string is expected with --all");
152 retval = CMD_ERROR;
153 goto error;
154 }
155 if (!all && !_id_string) {
156 ERR("An ID string is expected");
157 retval = CMD_ERROR;
158 goto error;
159 }
160 if (all) {
161 enum lttng_tracker_id_status status;
162 /* Empty `ID string means all IDs */
163 id_list = alloc_id_list(1);
164 if (!id_list) {
165 ERR("Out of memory");
166 retval = CMD_ERROR;
167 goto error;
168 }
169
170 id_list->array[0] = lttng_tracker_id_create();
171 if (id_list->array[0] == NULL) {
172 ERR("Out of memory");
173 retval = CMD_ERROR;
174 goto error;
175 }
176
177 status = lttng_tracker_id_set_all(id_list->array[0]);
178 if (status != LTTNG_TRACKER_ID_STATUS_OK) {
179 ERR("Invalid value for tracker id");
180 retval = CMD_ERROR;
181 goto error;
182 }
183 goto assign;
184 }
185
186 id_string = strdup(_id_string);
187 if (!id_string) {
188 ERR("Out of memory");
189 retval = CMD_ERROR;
190 goto error;
191 }
192
193 /* Count */
194 one_id_str = strtok_r(id_string, ",", &iter);
195 while (one_id_str != NULL) {
196 unsigned long v;
197
198 if (isdigit(one_id_str[0])) {
199 errno = 0;
200 v = strtoul(one_id_str, &endptr, 10);
201 if ((v == 0 && errno == EINVAL) ||
202 (v == ULONG_MAX && errno == ERANGE) ||
203 (*one_id_str != '\0' &&
204 *endptr != '\0')) {
205 ERR("Error parsing ID %s", one_id_str);
206 retval = CMD_ERROR;
207 goto error;
208 }
209
210 if ((long) v > INT_MAX || (int) v < 0) {
211 ERR("Invalid ID value %ld", (long) v);
212 retval = CMD_ERROR;
213 goto error;
214 }
215 }
216 count++;
217
218 /* For next loop */
219 one_id_str = strtok_r(NULL, ",", &iter);
220 }
221 if (count == 0) {
222 ERR("Fatal error occurred when parsing pid string");
223 retval = CMD_ERROR;
224 goto error;
225 }
226
227 free(id_string);
228 /* Identity of delimiter has been lost in first pass. */
229 id_string = strdup(_id_string);
230 if (!id_string) {
231 ERR("Out of memory");
232 retval = CMD_ERROR;
233 goto error;
234 }
235
236 /* Allocate */
237 id_list = alloc_id_list(count);
238 if (!id_list) {
239 ERR("Out of memory");
240 retval = CMD_ERROR;
241 goto error;
242 }
243
244 /* Reparse string and populate the id list. */
245 count = 0;
246 one_id_str = strtok_r(id_string, ",", &iter);
247 while (one_id_str != NULL) {
248 enum lttng_tracker_id_status status;
249 struct lttng_tracker_id *item;
250 item = lttng_tracker_id_create();
251 if (item == NULL) {
252 ERR("Out of memory");
253 retval = CMD_ERROR;
254 goto error;
255 }
256
257 id_list->array[count++] = item;
258 if (isdigit(one_id_str[0])) {
259 unsigned long v;
260
261 v = strtoul(one_id_str, NULL, 10);
262 status = lttng_tracker_id_set_value(item, (int) v);
263 if (status == LTTNG_TRACKER_ID_STATUS_INVALID) {
264 ERR("Invalid value");
265 retval = CMD_ERROR;
266 goto error;
267 }
268 } else {
269 status = lttng_tracker_id_set_string(item, one_id_str);
270 if (status == LTTNG_TRACKER_ID_STATUS_INVALID) {
271 ERR("Failed to set ID string");
272 retval = CMD_ERROR;
273 goto error;
274 }
275 }
276
277 /* For next loop */
278 one_id_str = strtok_r(NULL, ",", &iter);
279 }
280
281 assign:
282 /* SUCCESS */
283 *_id_list = id_list;
284 goto end;
285
286 error:
287 /* ERROR */
288 free_id_list(id_list);
289 end:
290 free(id_string);
291 return retval;
292 }
293
294 static const char *get_tracker_str(enum lttng_tracker_type tracker_type)
295 {
296 switch (tracker_type) {
297 case LTTNG_TRACKER_PID:
298 return "PID";
299 case LTTNG_TRACKER_VPID:
300 return "VPID";
301 case LTTNG_TRACKER_UID:
302 return "UID";
303 case LTTNG_TRACKER_VUID:
304 return "VUID";
305 case LTTNG_TRACKER_GID:
306 return "GID";
307 case LTTNG_TRACKER_VGID:
308 return "VGID";
309 default:
310 return NULL;
311 }
312 return NULL;
313 }
314
315 static int ust_tracker_type_support(enum lttng_tracker_type *tracker_type)
316 {
317 int ret;
318
319 switch (*tracker_type) {
320 case LTTNG_TRACKER_PID:
321 *tracker_type = LTTNG_TRACKER_VPID;
322 ret = 0;
323 break;
324 case LTTNG_TRACKER_VPID:
325 case LTTNG_TRACKER_VUID:
326 case LTTNG_TRACKER_VGID:
327 ret = 0;
328 break;
329 case LTTNG_TRACKER_UID:
330 case LTTNG_TRACKER_GID:
331 ERR("The %s tracker is invalid for UST domain.",
332 get_tracker_str(*tracker_type));
333 ret = -1;
334 break;
335 default:
336 ret = -1;
337 break;
338 }
339
340 return ret;
341 }
342
343 static enum cmd_error_code track_untrack_id(enum cmd_type cmd_type,
344 const char *cmd_str,
345 const char *session_name,
346 const char *id_string,
347 int all,
348 struct mi_writer *writer,
349 enum lttng_tracker_type tracker_type)
350 {
351 int ret, success = 1 , i;
352 enum cmd_error_code retval = CMD_SUCCESS;
353 struct id_list *id_list = NULL;
354 struct lttng_domain dom;
355 struct lttng_handle *handle = NULL;
356 int (*cmd_func)(struct lttng_handle *handle,
357 enum lttng_tracker_type tracker_type,
358 const struct lttng_tracker_id *id);
359 const char *tracker_str;
360
361 switch (cmd_type) {
362 case CMD_TRACK:
363 cmd_func = lttng_track_id;
364 break;
365 case CMD_UNTRACK:
366 cmd_func = lttng_untrack_id;
367 break;
368 default:
369 ERR("Unknown command");
370 retval = CMD_ERROR;
371 goto end;
372 }
373 memset(&dom, 0, sizeof(dom));
374 if (opt_kernel) {
375 dom.type = LTTNG_DOMAIN_KERNEL;
376 } else if (opt_userspace) {
377 dom.type = LTTNG_DOMAIN_UST;
378 ret = ust_tracker_type_support(&tracker_type);
379 if (ret) {
380 ERR("Invalid parameter");
381 retval = CMD_ERROR;
382 goto end;
383 }
384 } else {
385 /* Checked by the caller. */
386 assert(0);
387 }
388 tracker_str = get_tracker_str(tracker_type);
389 if (!tracker_str) {
390 ERR("Unknown tracker type");
391 retval = CMD_ERROR;
392 goto end;
393 }
394 ret = parse_id_string(id_string, all, &id_list, tracker_type);
395 if (ret != CMD_SUCCESS) {
396 ERR("Error parsing %s string", tracker_str);
397 retval = CMD_ERROR;
398 goto end;
399 }
400
401 handle = lttng_create_handle(session_name, &dom);
402 if (handle == NULL) {
403 retval = CMD_ERROR;
404 goto end;
405 }
406
407 if (writer) {
408 /* Open tracker_id and targets elements */
409 ret = mi_lttng_id_tracker_open(writer, tracker_type);
410 if (ret) {
411 goto end;
412 }
413 }
414
415 for (i = 0; i < id_list->nr; i++) {
416 struct lttng_tracker_id *item = id_list->array[i];
417 enum lttng_tracker_id_type type =
418 lttng_tracker_id_get_type(item);
419 enum lttng_tracker_id_status status =
420 LTTNG_TRACKER_ID_STATUS_OK;
421 int value;
422 const char *value_string;
423
424 switch (type) {
425 case LTTNG_ID_ALL:
426 /* Nothing to check */
427 break;
428 case LTTNG_ID_VALUE:
429 status = lttng_tracker_id_get_value(item, &value);
430 break;
431 case LTTNG_ID_STRING:
432 status = lttng_tracker_id_get_string(
433 item, &value_string);
434 break;
435 default:
436 retval = CMD_ERROR;
437 goto end;
438 }
439
440 if (status != LTTNG_TRACKER_ID_STATUS_OK) {
441 ERR("Tracker id object is in an invalid state");
442 retval = CMD_ERROR;
443 goto end;
444 }
445
446 switch (type) {
447 case LTTNG_ID_ALL:
448 DBG("%s all IDs", cmd_str);
449 break;
450 case LTTNG_ID_VALUE:
451 DBG("%s ID %d", cmd_str, value);
452 break;
453 case LTTNG_ID_STRING:
454 DBG("%s ID '%s'", cmd_str, value_string);
455 break;
456 default:
457 retval = CMD_ERROR;
458 goto end;
459 }
460
461 ret = cmd_func(handle, tracker_type, item);
462 if (ret) {
463 char *msg = NULL;
464
465 switch (-ret) {
466 case LTTNG_ERR_ID_TRACKED:
467 msg = "already tracked";
468 success = 1;
469 retval = CMD_SUCCESS;
470 break;
471 case LTTNG_ERR_ID_NOT_TRACKED:
472 msg = "already not tracked";
473 success = 1;
474 retval = CMD_SUCCESS;
475 break;
476 default:
477 ERR("%s", lttng_strerror(ret));
478 success = 0;
479 retval = CMD_ERROR;
480 break;
481 }
482 if (msg) {
483 switch (type) {
484 case LTTNG_ID_ALL:
485 WARN("All %ss %s in session %s",
486 tracker_str, msg,
487 session_name);
488 break;
489 case LTTNG_ID_VALUE:
490 WARN("%s %i %s in session %s",
491 tracker_str, value, msg,
492 session_name);
493 break;
494 case LTTNG_ID_STRING:
495 WARN("%s '%s' %s in session %s",
496 tracker_str,
497 value_string, msg,
498 session_name);
499 break;
500 default:
501 retval = CMD_ERROR;
502 goto end;
503 }
504 }
505 } else {
506 switch (type) {
507 case LTTNG_ID_ALL:
508 MSG("All %ss %sed in session %s", tracker_str,
509 cmd_str, session_name);
510 break;
511 case LTTNG_ID_VALUE:
512 MSG("%s %i %sed in session %s", tracker_str,
513 value, cmd_str, session_name);
514 break;
515 case LTTNG_ID_STRING:
516 MSG("%s '%s' %sed in session %s", tracker_str,
517 value_string, cmd_str,
518 session_name);
519 break;
520 default:
521 retval = CMD_ERROR;
522 goto end;
523 }
524 success = 1;
525 }
526
527 /* Mi */
528 if (writer) {
529 ret = mi_lttng_id_target(writer, tracker_type, item, 1);
530 if (ret) {
531 retval = CMD_ERROR;
532 goto end;
533 }
534
535 ret = mi_lttng_writer_write_element_bool(writer,
536 mi_lttng_element_success, success);
537 if (ret) {
538 retval = CMD_ERROR;
539 goto end;
540 }
541
542 ret = mi_lttng_writer_close_element(writer);
543 if (ret) {
544 retval = CMD_ERROR;
545 goto end;
546 }
547 }
548 }
549
550 if (writer) {
551 /* Close targets and tracker_id elements */
552 ret = mi_lttng_close_multi_element(writer, 2);
553 if (ret) {
554 retval = CMD_ERROR;
555 goto end;
556 }
557 }
558
559 end:
560 if (handle) {
561 lttng_destroy_handle(handle);
562 }
563 free_id_list(id_list);
564 return retval;
565 }
566
567 static
568 const char *get_mi_element_command(enum cmd_type cmd_type)
569 {
570 switch (cmd_type) {
571 case CMD_TRACK:
572 return mi_lttng_element_command_track;
573 case CMD_UNTRACK:
574 return mi_lttng_element_command_untrack;
575 default:
576 return NULL;
577 }
578 }
579
580 static void print_err_duplicate(const char *type)
581 {
582 ERR("The --%s option can only be used once. A list of comma-separated values can be specified.",
583 type);
584 }
585
586 /*
587 * Add/remove tracker to/from session.
588 */
589 static
590 int cmd_track_untrack(enum cmd_type cmd_type, const char *cmd_str,
591 int argc, const char **argv, const char *help_msg)
592 {
593 int opt, ret = 0;
594 enum cmd_error_code command_ret = CMD_SUCCESS;
595 int success = 1;
596 static poptContext pc;
597 char *session_name = NULL;
598 struct mi_writer *writer = NULL;
599
600 if (argc < 1) {
601 command_ret = CMD_ERROR;
602 goto end;
603 }
604
605 pc = poptGetContext(NULL, argc, argv, long_options, 0);
606 poptReadDefaultConfig(pc, 0);
607
608 while ((opt = poptGetNextOpt(pc)) != -1) {
609 switch (opt) {
610 case OPT_HELP:
611 SHOW_HELP();
612 goto end;
613 case OPT_LIST_OPTIONS:
614 list_cmd_options(stdout, long_options);
615 goto end;
616 case OPT_SESSION:
617 break;
618 case OPT_PID:
619 if (opt_pid.used) {
620 print_err_duplicate("pid");
621 command_ret = CMD_ERROR;
622 goto end;
623 }
624 opt_pid.used = 1;
625 type_state = STATE_PID;
626 break;
627 case OPT_VPID:
628 if (opt_vpid.used) {
629 print_err_duplicate("vpid");
630 command_ret = CMD_ERROR;
631 goto end;
632 }
633 opt_vpid.used = 1;
634 type_state = STATE_VPID;
635 break;
636 case OPT_UID:
637 if (opt_uid.used) {
638 print_err_duplicate("uid");
639 command_ret = CMD_ERROR;
640 goto end;
641 }
642 opt_uid.used = 1;
643 type_state = STATE_UID;
644 break;
645 case OPT_VUID:
646 if (opt_vuid.used) {
647 print_err_duplicate("vuid");
648 command_ret = CMD_ERROR;
649 goto end;
650 }
651 opt_vuid.used = 1;
652 type_state = STATE_VUID;
653 break;
654 case OPT_GID:
655 if (opt_gid.used) {
656 print_err_duplicate("gid");
657 command_ret = CMD_ERROR;
658 goto end;
659 }
660 opt_gid.used = 1;
661 type_state = STATE_GID;
662 break;
663 case OPT_VGID:
664 if (opt_vgid.used) {
665 print_err_duplicate("vgid");
666 command_ret = CMD_ERROR;
667 goto end;
668 }
669 opt_vgid.used = 1;
670 type_state = STATE_VGID;
671 break;
672 case OPT_ALL:
673 switch (type_state) {
674 case STATE_PID:
675 opt_pid.all = 1;
676 break;
677 case STATE_VPID:
678 opt_vpid.all = 1;
679 break;
680 case STATE_UID:
681 opt_uid.all = 1;
682 break;
683 case STATE_VUID:
684 opt_vuid.all = 1;
685 break;
686 case STATE_GID:
687 opt_gid.all = 1;
688 break;
689 case STATE_VGID:
690 opt_vgid.all = 1;
691 break;
692 default:
693 command_ret = CMD_ERROR;
694 goto end;
695 }
696 break;
697 default:
698 command_ret = CMD_UNDEFINED;
699 goto end;
700 }
701 }
702
703 ret = print_missing_or_multiple_domains(opt_kernel + opt_userspace);
704 if (ret) {
705 command_ret = CMD_ERROR;
706 goto end;
707 }
708
709 if (!opt_session_name) {
710 session_name = get_session_name();
711 if (session_name == NULL) {
712 command_ret = CMD_ERROR;
713 goto end;
714 }
715 } else {
716 session_name = opt_session_name;
717 }
718
719 /* Mi check */
720 if (lttng_opt_mi) {
721 writer = mi_lttng_writer_create(fileno(stdout), lttng_opt_mi);
722 if (!writer) {
723 command_ret = CMD_ERROR;
724 goto end;
725 }
726 }
727
728 if (writer) {
729 /* Open command element */
730 ret = mi_lttng_writer_command_open(writer,
731 get_mi_element_command(cmd_type));
732 if (ret) {
733 command_ret = CMD_ERROR;
734 goto end;
735 }
736
737 /* Open output element */
738 ret = mi_lttng_writer_open_element(writer,
739 mi_lttng_element_command_output);
740 if (ret) {
741 command_ret = CMD_ERROR;
742 goto end;
743 }
744
745 ret = mi_lttng_trackers_open(writer);
746 if (ret) {
747 goto end;
748 }
749 }
750
751 if (opt_pid.used) {
752 command_ret = track_untrack_id(cmd_type, cmd_str, session_name,
753 opt_pid.string, opt_pid.all, writer,
754 LTTNG_TRACKER_PID);
755 if (command_ret != CMD_SUCCESS) {
756 success = 0;
757 }
758 }
759 if (opt_vpid.used) {
760 command_ret = track_untrack_id(cmd_type, cmd_str, session_name,
761 opt_vpid.string, opt_vpid.all, writer,
762 LTTNG_TRACKER_VPID);
763 if (command_ret != CMD_SUCCESS) {
764 success = 0;
765 }
766 }
767 if (opt_uid.used) {
768 command_ret = track_untrack_id(cmd_type, cmd_str, session_name,
769 opt_uid.string, opt_uid.all, writer,
770 LTTNG_TRACKER_UID);
771 if (command_ret != CMD_SUCCESS) {
772 success = 0;
773 }
774 }
775 if (opt_vuid.used) {
776 command_ret = track_untrack_id(cmd_type, cmd_str, session_name,
777 opt_vuid.string, opt_vuid.all, writer,
778 LTTNG_TRACKER_VUID);
779 if (command_ret != CMD_SUCCESS) {
780 success = 0;
781 }
782 }
783 if (opt_gid.used) {
784 command_ret = track_untrack_id(cmd_type, cmd_str, session_name,
785 opt_gid.string, opt_gid.all, writer,
786 LTTNG_TRACKER_GID);
787 if (command_ret != CMD_SUCCESS) {
788 success = 0;
789 }
790 }
791 if (opt_vgid.used) {
792 command_ret = track_untrack_id(cmd_type, cmd_str, session_name,
793 opt_vgid.string, opt_vgid.all, writer,
794 LTTNG_TRACKER_VGID);
795 if (command_ret != CMD_SUCCESS) {
796 success = 0;
797 }
798 }
799
800 /* Mi closing */
801 if (writer) {
802 /* Close trackers and output elements */
803 ret = mi_lttng_close_multi_element(writer, 2);
804 if (ret) {
805 command_ret = CMD_ERROR;
806 goto end;
807 }
808
809 /* Success ? */
810 ret = mi_lttng_writer_write_element_bool(writer,
811 mi_lttng_element_command_success, success);
812 if (ret) {
813 command_ret = CMD_ERROR;
814 goto end;
815 }
816
817 /* Command element close */
818 ret = mi_lttng_writer_command_close(writer);
819 if (ret) {
820 command_ret = CMD_ERROR;
821 goto end;
822 }
823 }
824
825 end:
826 if (!opt_session_name) {
827 free(session_name);
828 }
829
830 /* Mi clean-up */
831 if (writer && mi_lttng_writer_destroy(writer)) {
832 /* Preserve original error code */
833 command_ret = CMD_ERROR;
834 }
835
836 poptFreeContext(pc);
837 return (int) command_ret;
838 }
839
840 int cmd_track(int argc, const char **argv)
841 {
842 static const char *help_msg =
843 #ifdef LTTNG_EMBED_HELP
844 #include <lttng-track.1.h>
845 #else
846 NULL
847 #endif
848 ;
849
850 return cmd_track_untrack(CMD_TRACK, "track", argc, argv, help_msg);
851 }
852
853 int cmd_untrack(int argc, const char **argv)
854 {
855 static const char *help_msg =
856 #ifdef LTTNG_EMBED_HELP
857 #include <lttng-untrack.1.h>
858 #else
859 NULL
860 #endif
861 ;
862
863 return cmd_track_untrack(CMD_UNTRACK, "untrack", argc, argv, help_msg);
864 }
This page took 0.075889 seconds and 4 git commands to generate.