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