tests: Make test_per_application_leaks more robust
[lttng-tools.git] / src / bin / lttng / commands / create.cpp
1 /*
2 * Copyright (C) 2011 EfficiOS Inc.
3 * Copyright (C) 2019 Jérémie Galarneau <jeremie.galarneau@efficios.com>
4 *
5 * SPDX-License-Identifier: GPL-2.0-only
6 *
7 */
8
9 #define _LGPL_SOURCE
10 #include "../command.hpp"
11 #include "../utils.hpp"
12
13 #include <common/compat/time.hpp>
14 #include <common/defaults.hpp>
15 #include <common/mi-lttng.hpp>
16 #include <common/path.hpp>
17 #include <common/sessiond-comm/sessiond-comm.hpp>
18 #include <common/uri.hpp>
19 #include <common/utils.hpp>
20
21 #include <lttng/lttng.h>
22
23 #include <ctype.h>
24 #include <popt.h>
25 #include <signal.h>
26 #include <stdio.h>
27 #include <stdlib.h>
28 #include <string.h>
29 #include <sys/stat.h>
30 #include <sys/types.h>
31 #include <sys/wait.h>
32 #include <unistd.h>
33
34 static char *opt_output_path;
35 static char *opt_url;
36 static char *opt_ctrl_url;
37 static char *opt_data_url;
38 static char *opt_shm_path;
39 static int opt_no_consumer;
40 static int opt_no_output;
41 static int opt_snapshot;
42 static uint32_t opt_live_timer;
43
44 #ifdef LTTNG_EMBED_HELP
45 static const char help_msg[] =
46 #include <lttng-create.1.h>
47 ;
48 #endif
49
50 enum {
51 OPT_HELP = 1,
52 OPT_LIST_OPTIONS,
53 OPT_LIVE_TIMER,
54 };
55
56 enum output_type {
57 OUTPUT_NONE,
58 OUTPUT_LOCAL,
59 OUTPUT_NETWORK,
60 OUTPUT_UNSPECIFIED,
61 };
62
63 static struct mi_writer *writer;
64 static struct poptOption long_options[] = {
65 /* longName, shortName, argInfo, argPtr, value, descrip, argDesc */
66 { "help", 'h', POPT_ARG_NONE, nullptr, OPT_HELP, nullptr, nullptr },
67 { "output", 'o', POPT_ARG_STRING, &opt_output_path, 0, nullptr, nullptr },
68 { "list-options", 0, POPT_ARG_NONE, nullptr, OPT_LIST_OPTIONS, nullptr, nullptr },
69 { "set-url", 'U', POPT_ARG_STRING, &opt_url, 0, nullptr, nullptr },
70 { "ctrl-url", 'C', POPT_ARG_STRING, &opt_ctrl_url, 0, nullptr, nullptr },
71 { "data-url", 'D', POPT_ARG_STRING, &opt_data_url, 0, nullptr, nullptr },
72 { "no-output", 0, POPT_ARG_VAL, &opt_no_output, 1, nullptr, nullptr },
73 { "no-consumer", 0, POPT_ARG_VAL, &opt_no_consumer, 1, nullptr, nullptr },
74 { "snapshot", 0, POPT_ARG_VAL, &opt_snapshot, 1, nullptr, nullptr },
75 { "live",
76 0,
77 POPT_ARG_INT | POPT_ARGFLAG_OPTIONAL,
78 nullptr,
79 OPT_LIVE_TIMER,
80 nullptr,
81 nullptr },
82 { "shm-path", 0, POPT_ARG_STRING, &opt_shm_path, 0, nullptr, nullptr },
83 { nullptr, 0, 0, nullptr, 0, nullptr, nullptr }
84 };
85
86 /*
87 * Retrieve the created session and mi output it based on provided argument
88 * This is currently a summary of what was pretty printed and is subject to
89 * enhancements.
90 */
91 static int mi_created_session(const char *session_name)
92 {
93 int ret, i, count, found;
94 struct lttng_session *sessions;
95
96 /* session_name should not be null */
97 LTTNG_ASSERT(session_name);
98 LTTNG_ASSERT(writer);
99
100 count = lttng_list_sessions(&sessions);
101 if (count < 0) {
102 ret = count;
103 ERR("%s", lttng_strerror(ret));
104 goto error;
105 }
106
107 if (count == 0) {
108 ERR("Error session creation failed: session %s not found", session_name);
109 ret = -LTTNG_ERR_SESS_NOT_FOUND;
110 goto end;
111 }
112
113 found = 0;
114 for (i = 0; i < count; i++) {
115 if (strncmp(sessions[i].name, session_name, NAME_MAX) == 0) {
116 found = 1;
117 ret = mi_lttng_session(writer, &sessions[i], 0);
118 if (ret) {
119 goto error;
120 }
121 break;
122 }
123 }
124
125 if (!found) {
126 ret = -LTTNG_ERR_SESS_NOT_FOUND;
127 } else {
128 ret = CMD_SUCCESS;
129 }
130
131 error:
132 free(sessions);
133 end:
134 return ret;
135 }
136
137 static struct lttng_session_descriptor *create_session_descriptor(const char *session_name)
138 {
139 ssize_t uri_count;
140 enum output_type output_type;
141 struct lttng_uri *uris = nullptr;
142 struct lttng_session_descriptor *descriptor = nullptr;
143 const char *uri_str1 = nullptr, *uri_str2 = nullptr;
144 char local_output_path[LTTNG_PATH_MAX] = {};
145
146 if (opt_no_output) {
147 output_type = OUTPUT_NONE;
148 } else if (opt_output_path) {
149 char *expanded_output_path;
150 int ret;
151
152 output_type = OUTPUT_LOCAL;
153 expanded_output_path = utils_expand_path(opt_output_path);
154 if (!expanded_output_path) {
155 ERR("Failed to expand output path.");
156 goto end;
157 }
158 ret = lttng_strncpy(
159 local_output_path, expanded_output_path, sizeof(local_output_path));
160 free(expanded_output_path);
161 if (ret) {
162 ERR("Output path exceeds the maximal supported length (%zu bytes)",
163 sizeof(local_output_path));
164 goto end;
165 }
166 } else if (opt_url || opt_ctrl_url) {
167 int ret;
168
169 uri_str1 = opt_ctrl_url ? opt_ctrl_url : opt_url;
170 uri_str2 = opt_data_url;
171
172 uri_count = uri_parse_str_urls(uri_str1, uri_str2, &uris);
173 if (uri_count != 1 && uri_count != 2) {
174 ERR("Unrecognized URL format.");
175 goto end;
176 }
177
178 switch (uri_count) {
179 case 1:
180 output_type = OUTPUT_LOCAL;
181 if (uris[0].dtype != LTTNG_DST_PATH) {
182 ERR("Unrecognized URL format.");
183 goto end;
184 }
185 ret = lttng_strncpy(
186 local_output_path, uris[0].dst.path, sizeof(local_output_path));
187 if (ret) {
188 ERR("Output path exceeds the maximal supported length (%zu bytes)",
189 sizeof(local_output_path));
190 }
191 break;
192 case 2:
193 output_type = OUTPUT_NETWORK;
194 break;
195 default:
196 /* Already checked. */
197 abort();
198 }
199 } else {
200 output_type = OUTPUT_UNSPECIFIED;
201 }
202
203 if (opt_snapshot) {
204 /* Snapshot session. */
205 switch (output_type) {
206 case OUTPUT_UNSPECIFIED:
207 case OUTPUT_LOCAL:
208 descriptor = lttng_session_descriptor_snapshot_local_create(
209 session_name,
210 output_type == OUTPUT_LOCAL ? local_output_path : nullptr);
211 break;
212 case OUTPUT_NONE:
213 descriptor = lttng_session_descriptor_snapshot_create(session_name);
214 break;
215 case OUTPUT_NETWORK:
216 descriptor = lttng_session_descriptor_snapshot_network_create(
217 session_name, uri_str1, uri_str2);
218 break;
219 default:
220 abort();
221 }
222 } else if (opt_live_timer) {
223 /* Live session. */
224 if (output_type != OUTPUT_UNSPECIFIED && output_type != OUTPUT_NETWORK) {
225 ERR("Unsupported output type specified for live session.");
226 goto end;
227 }
228 descriptor = lttng_session_descriptor_live_network_create(
229 session_name, uri_str1, uri_str2, opt_live_timer);
230 } else {
231 /* Regular session. */
232 switch (output_type) {
233 case OUTPUT_UNSPECIFIED:
234 case OUTPUT_LOCAL:
235 descriptor = lttng_session_descriptor_local_create(
236 session_name,
237 output_type == OUTPUT_LOCAL ? local_output_path : nullptr);
238 break;
239 case OUTPUT_NONE:
240 descriptor = lttng_session_descriptor_create(session_name);
241 break;
242 case OUTPUT_NETWORK:
243 descriptor = lttng_session_descriptor_network_create(
244 session_name, uri_str1, uri_str2);
245 break;
246 default:
247 abort();
248 }
249 }
250 if (!descriptor) {
251 ERR("Failed to initialize session creation command.");
252 } else {
253 /*
254 * Auto-launch the relay daemon when a live session
255 * is created using default URLs.
256 */
257 if (!opt_url && !opt_ctrl_url && !opt_data_url && opt_live_timer &&
258 !check_relayd()) {
259 int ret;
260 const char *pathname = opt_relayd_path ?: INSTALL_BIN_PATH "/lttng-relayd";
261
262 ret = spawn_relayd(pathname, 0);
263 if (ret < 0) {
264 lttng_session_descriptor_destroy(descriptor);
265 descriptor = nullptr;
266 }
267 }
268 }
269 end:
270 free(uris);
271 return descriptor;
272 }
273
274 /*
275 * Create a tracing session.
276 * If no name is specified, a default name is generated.
277 *
278 * Returns one of the CMD_* result constants.
279 */
280 static int create_session(const char *session_name)
281 {
282 int ret, i;
283 char shm_path[LTTNG_PATH_MAX] = {};
284 struct lttng_session_descriptor *session_descriptor = nullptr;
285 enum lttng_session_descriptor_status descriptor_status;
286 enum lttng_error_code ret_code;
287 struct lttng_session *sessions = nullptr;
288 const struct lttng_session *created_session = nullptr;
289 const char *created_session_name;
290
291 /* Validate options. */
292 if (session_name) {
293 if (strlen(session_name) > NAME_MAX) {
294 ERR("Session name too long. Length must be lower or equal to %d", NAME_MAX);
295 ret = CMD_ERROR;
296 goto error;
297 }
298 /*
299 * Check if the session name begins with "auto-" or is exactly "auto".
300 * Both are reserved for the default session name. See bug #449 to
301 * understand why we need to check both here.
302 */
303 if ((strncmp(session_name,
304 DEFAULT_SESSION_NAME "-",
305 strlen(DEFAULT_SESSION_NAME) + 1) == 0) ||
306 (strncmp(session_name, DEFAULT_SESSION_NAME, strlen(DEFAULT_SESSION_NAME)) ==
307 0 &&
308 strlen(session_name) == strlen(DEFAULT_SESSION_NAME))) {
309 ERR("%s is a reserved keyword for default session(s)",
310 DEFAULT_SESSION_NAME);
311 ret = CMD_ERROR;
312 goto error;
313 }
314 }
315
316 if (opt_snapshot && opt_live_timer) {
317 ERR("Snapshot and live modes are mutually exclusive.");
318 ret = CMD_ERROR;
319 goto error;
320 }
321
322 if ((!opt_ctrl_url && opt_data_url) || (opt_ctrl_url && !opt_data_url)) {
323 ERR("Both control and data URLs must be specified.");
324 ret = CMD_ERROR;
325 goto error;
326 }
327
328 session_descriptor = create_session_descriptor(session_name);
329 if (!session_descriptor) {
330 ret = CMD_ERROR;
331 goto error;
332 }
333 ret_code = lttng_create_session_ext(session_descriptor);
334 if (ret_code != LTTNG_OK) {
335 ERR("%s", lttng_strerror(-ret_code));
336 ret = CMD_ERROR;
337 goto error;
338 }
339
340 descriptor_status = lttng_session_descriptor_get_session_name(session_descriptor,
341 &created_session_name);
342 if (descriptor_status != LTTNG_SESSION_DESCRIPTOR_STATUS_OK) {
343 ERR("Failed to obtain created session name");
344 ret = CMD_ERROR;
345 goto error;
346 }
347
348 ret = lttng_list_sessions(&sessions);
349 if (ret < 0) {
350 ERR("Failed to fetch properties of created session: %s", lttng_strerror(ret));
351 ret = CMD_ERROR;
352 goto error;
353 }
354 for (i = 0; i < ret; i++) {
355 if (!strcmp(created_session_name, sessions[i].name)) {
356 created_session = &sessions[i];
357 break;
358 }
359 }
360 if (!created_session) {
361 ERR("Failed to fetch properties of created session");
362 ret = CMD_ERROR;
363 goto error;
364 }
365
366 if (opt_shm_path) {
367 char datetime_suffix[17] = {};
368
369 /*
370 * An auto-generated session name already includes the creation
371 * timestamp.
372 */
373 if (session_name) {
374 uint64_t creation_time;
375 struct tm *timeinfo;
376 time_t creation_time_t;
377 size_t strftime_ret;
378
379 ret_code = lttng_session_get_creation_time(created_session, &creation_time);
380 if (ret_code != LTTNG_OK) {
381 ERR("%s", lttng_strerror(-ret_code));
382 ret = CMD_ERROR;
383 goto error;
384 }
385 creation_time_t = (time_t) creation_time;
386 timeinfo = localtime(&creation_time_t);
387 if (!timeinfo) {
388 PERROR("Failed to interpret session creation time");
389 ret = CMD_ERROR;
390 goto error;
391 }
392 strftime_ret = strftime(datetime_suffix,
393 sizeof(datetime_suffix),
394 "-%Y%m%d-%H%M%S",
395 timeinfo);
396 if (strftime_ret == 0) {
397 ERR("Failed to format session creation time.");
398 ret = CMD_ERROR;
399 goto error;
400 }
401 }
402
403 ret = snprintf(shm_path,
404 sizeof(shm_path),
405 "%s/%s%s",
406 opt_shm_path,
407 created_session_name,
408 datetime_suffix);
409 if (ret < 0 || ret >= sizeof(shm_path)) {
410 ERR("Failed to format the shared memory path.");
411 ret = CMD_ERROR;
412 goto error;
413 }
414 ret = lttng_set_session_shm_path(created_session_name, shm_path);
415 if (ret < 0) {
416 lttng_destroy_session(created_session_name);
417 ret = CMD_ERROR;
418 goto error;
419 }
420 }
421
422 if (opt_snapshot) {
423 MSG("Snapshot session %s created.", created_session_name);
424 } else if (opt_live_timer) {
425 MSG("Live session %s created.", created_session_name);
426 } else {
427 MSG("Session %s created.", created_session_name);
428 }
429
430 if (*created_session->path && !opt_snapshot) {
431 MSG("Traces will be output to %s", created_session->path);
432
433 if (opt_live_timer) {
434 MSG("Live timer interval set to %u %s", opt_live_timer, USEC_UNIT);
435 }
436 } else if (opt_snapshot) {
437 struct lttng_snapshot_output_list *list;
438 struct lttng_snapshot_output *iter;
439 char snapshot_url[LTTNG_PATH_MAX] = {};
440
441 ret = lttng_snapshot_list_output(created_session_name, &list);
442 if (ret < 0) {
443 ERR("Failed to list snapshot outputs.");
444 ret = CMD_ERROR;
445 goto error;
446 }
447
448 while ((iter = lttng_snapshot_output_list_get_next(list))) {
449 const char *url = nullptr;
450
451 url = lttng_snapshot_output_get_ctrl_url(iter);
452 ret = lttng_strncpy(snapshot_url, url, sizeof(snapshot_url));
453 if (ret) {
454 snapshot_url[0] = '\0';
455 ERR("Failed to retrieve snapshot output destination");
456 }
457 break;
458 }
459 lttng_snapshot_output_list_destroy(list);
460
461 if (*snapshot_url) {
462 MSG("Default snapshot output set to %s", snapshot_url);
463 }
464 MSG("Every channel enabled for this session will be set to mmap output and default to overwrite mode.");
465 }
466 if (opt_shm_path) {
467 MSG("Shared memory path set to %s", shm_path);
468 }
469
470 /* Mi output */
471 if (lttng_opt_mi) {
472 ret = mi_created_session(created_session_name);
473 if (ret) {
474 ret = CMD_ERROR;
475 goto error;
476 }
477 }
478
479 /* Init lttng session config */
480 ret = config_init(created_session_name);
481 if (ret < 0) {
482 MSG("Unable to initialize configuration for created session: future commands will require the target session name explicitly");
483 ret = CMD_WARNING;
484 goto error;
485 }
486
487 ret = CMD_SUCCESS;
488 error:
489 lttng_session_descriptor_destroy(session_descriptor);
490 free(sessions);
491 return ret;
492 }
493
494 /*
495 * spawn_sessiond
496 *
497 * Spawn a session daemon by forking and execv.
498 */
499 static int spawn_sessiond(const char *pathname)
500 {
501 int ret = 0;
502 pid_t pid;
503
504 MSG("Spawning a session daemon");
505 pid = fork();
506 if (pid == 0) {
507 /*
508 * Spawn session daemon in daemon mode.
509 */
510 execlp(pathname, "lttng-sessiond", "--daemonize", NULL);
511 /* execlp only returns if error happened */
512 if (errno == ENOENT) {
513 ERR("No session daemon found. Use --sessiond-path.");
514 } else {
515 PERROR("execlp");
516 }
517 kill(getppid(), SIGTERM); /* wake parent */
518 exit(EXIT_FAILURE);
519 } else if (pid > 0) {
520 /*
521 * In daemon mode (--daemonize), sessiond only exits when
522 * it's ready to accept commands.
523 */
524 for (;;) {
525 int status;
526 pid_t wait_pid_ret = waitpid(pid, &status, 0);
527
528 if (wait_pid_ret < 0) {
529 if (errno == EINTR) {
530 continue;
531 }
532 PERROR("waitpid");
533 ret = -errno;
534 goto end;
535 }
536
537 if (WIFSIGNALED(status)) {
538 ERR("Session daemon was killed by signal %d", WTERMSIG(status));
539 ret = -1;
540 goto end;
541 } else if (WIFEXITED(status)) {
542 DBG("Session daemon terminated normally (exit status: %d)",
543 WEXITSTATUS(status));
544
545 if (WEXITSTATUS(status) != 0) {
546 ERR("Session daemon terminated with an error (exit status: %d)",
547 WEXITSTATUS(status));
548 ret = -1;
549 goto end;
550 }
551 break;
552 }
553 }
554
555 goto end;
556 } else {
557 PERROR("fork");
558 ret = -1;
559 goto end;
560 }
561
562 end:
563 return ret;
564 }
565
566 /*
567 * launch_sessiond
568 *
569 * Check if the session daemon is available using
570 * the liblttngctl API for the check. If not, try to
571 * spawn a daemon.
572 */
573 static int launch_sessiond()
574 {
575 int ret;
576 const char *pathname = nullptr;
577
578 ret = lttng_session_daemon_alive();
579 if (ret) {
580 /* Sessiond is alive, not an error */
581 ret = 0;
582 goto end;
583 }
584
585 /* Try command line option path */
586 pathname = opt_sessiond_path;
587
588 /* Try LTTNG_SESSIOND_PATH env variable */
589 if (pathname == nullptr) {
590 pathname = getenv(DEFAULT_SESSIOND_PATH_ENV);
591 }
592
593 /* Try with configured path */
594 if (pathname == nullptr) {
595 if (CONFIG_SESSIOND_BIN[0] != '\0') {
596 pathname = CONFIG_SESSIOND_BIN;
597 }
598 }
599
600 /* Try the default path */
601 if (pathname == nullptr) {
602 pathname = INSTALL_BIN_PATH "/lttng-sessiond";
603 }
604
605 DBG("Session daemon binary path: %s", pathname);
606
607 /* Check existence and permissions */
608 ret = access(pathname, F_OK | X_OK);
609 if (ret < 0) {
610 ERR("No such file or access denied: %s", pathname);
611 goto end;
612 }
613
614 ret = spawn_sessiond(pathname);
615 end:
616 if (ret) {
617 ERR("Problem occurred while launching session daemon (%s)", pathname);
618 }
619 return ret;
620 }
621
622 static int validate_url_option_combination()
623 {
624 int ret = 0;
625 int used_count = 0;
626
627 used_count += !!opt_url;
628 used_count += !!opt_output_path;
629 used_count += (opt_data_url || opt_ctrl_url);
630 if (used_count > 1) {
631 ERR("Only one of the --set-url, --ctrl-url/data-url, or --output options may be used at once.");
632 ret = -1;
633 }
634
635 return ret;
636 }
637
638 /*
639 * The 'create <options>' first level command
640 *
641 * Returns one of the CMD_* result constants.
642 */
643 int cmd_create(int argc, const char **argv)
644 {
645 int opt, ret = CMD_SUCCESS, command_ret = CMD_SUCCESS, success = 1;
646 char *opt_arg = nullptr;
647 const char *arg_session_name = nullptr;
648 const char *leftover = nullptr;
649 static poptContext pc;
650
651 pc = poptGetContext(nullptr, argc, argv, long_options, 0);
652 poptReadDefaultConfig(pc, 0);
653
654 while ((opt = poptGetNextOpt(pc)) != -1) {
655 switch (opt) {
656 case OPT_HELP:
657 SHOW_HELP();
658 goto end;
659 case OPT_LIST_OPTIONS:
660 list_cmd_options(stdout, long_options);
661 goto end;
662 case OPT_LIVE_TIMER:
663 {
664 uint64_t v;
665
666 errno = 0;
667 if (opt_arg) {
668 free(opt_arg);
669 opt_arg = nullptr;
670 }
671
672 opt_arg = poptGetOptArg(pc);
673 if (!opt_arg) {
674 /* Set up default values. */
675 opt_live_timer = (uint32_t) DEFAULT_LTTNG_LIVE_TIMER;
676 DBG("Session live timer interval set to default value %d",
677 opt_live_timer);
678 break;
679 }
680
681 if (utils_parse_time_suffix(opt_arg, &v) < 0) {
682 ERR("Wrong value for --live parameter: %s", opt_arg);
683 ret = CMD_ERROR;
684 goto end;
685 }
686
687 if (v != (uint32_t) v) {
688 ERR("32-bit overflow in --live parameter: %s", opt_arg);
689 ret = CMD_ERROR;
690 goto end;
691 }
692
693 if (v == 0) {
694 ERR("Live timer interval must be greater than zero");
695 ret = CMD_ERROR;
696 goto end;
697 }
698
699 opt_live_timer = (uint32_t) v;
700 DBG("Session live timer interval set to %d", opt_live_timer);
701 break;
702 }
703 default:
704 ret = CMD_UNDEFINED;
705 goto end;
706 }
707 }
708
709 if (opt_no_consumer) {
710 MSG("The option --no-consumer is obsolete. Use --no-output now.");
711 ret = CMD_WARNING;
712 goto end;
713 }
714
715 ret = validate_url_option_combination();
716 if (ret) {
717 ret = CMD_ERROR;
718 goto end;
719 }
720
721 /* Spawn a session daemon if needed */
722 if (!opt_no_sessiond) {
723 ret = launch_sessiond();
724 if (ret) {
725 ret = CMD_ERROR;
726 goto end;
727 }
728 }
729
730 /* MI initialization */
731 if (lttng_opt_mi) {
732 writer = mi_lttng_writer_create(fileno(stdout), lttng_opt_mi);
733 if (!writer) {
734 ret = -LTTNG_ERR_NOMEM;
735 goto end;
736 }
737
738 /* Open command element */
739 ret = mi_lttng_writer_command_open(writer, mi_lttng_element_command_create);
740 if (ret) {
741 ret = CMD_ERROR;
742 goto end;
743 }
744
745 /* Open output element */
746 ret = mi_lttng_writer_open_element(writer, mi_lttng_element_command_output);
747 if (ret) {
748 ret = CMD_ERROR;
749 goto end;
750 }
751 }
752
753 /* Get the optional session name argument. */
754 arg_session_name = poptGetArg(pc);
755
756 leftover = poptGetArg(pc);
757 if (leftover) {
758 ERR("Unknown argument: %s", leftover);
759 ret = CMD_ERROR;
760 goto end;
761 }
762
763 command_ret = create_session(arg_session_name);
764 if (command_ret) {
765 success = 0;
766 }
767
768 if (lttng_opt_mi) {
769 /* Close output element */
770 ret = mi_lttng_writer_close_element(writer);
771 if (ret) {
772 ret = CMD_ERROR;
773 goto end;
774 }
775
776 /* Success ? */
777 ret = mi_lttng_writer_write_element_bool(
778 writer, mi_lttng_element_command_success, success);
779 if (ret) {
780 ret = CMD_ERROR;
781 goto end;
782 }
783
784 /* Command element close */
785 ret = mi_lttng_writer_command_close(writer);
786 if (ret) {
787 ret = CMD_ERROR;
788 goto end;
789 }
790 }
791
792 end:
793 /* Mi clean-up */
794 if (writer && mi_lttng_writer_destroy(writer)) {
795 /* Preserve original error code */
796 ret = ret ? ret : -LTTNG_ERR_MI_IO_FAIL;
797 }
798
799 /* Overwrite ret if an error occurred in create_session() */
800 ret = command_ret ? command_ret : ret;
801
802 free(opt_arg);
803 poptFreeContext(pc);
804 return ret;
805 }
This page took 0.045961 seconds and 5 git commands to generate.