Generate session name and default output on sessiond's end
[lttng-tools.git] / src / bin / lttng / commands / create.c
CommitLineData
f3ed775e
DG
1/*
2 * Copyright (C) 2011 - David Goulet <david.goulet@polymtl.ca>
b178f53e 3 * Copyright (C) 2019 - Jérémie Galarneau <jeremie.galarneau@efficios.com>
f3ed775e 4 *
d14d33bf
AM
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.
f3ed775e
DG
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 *
d14d33bf
AM
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.
f3ed775e
DG
17 */
18
6c1c0768 19#define _LGPL_SOURCE
a4b92340 20#include <assert.h>
ecc48a90 21#include <ctype.h>
f3ed775e
DG
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>
389fbf04 28#include <common/compat/time.h>
f3ed775e 29#include <unistd.h>
92360082 30#include <signal.h>
bbd44cae 31#include <sys/wait.h>
f3ed775e 32
37d03ff7
JRJ
33#include <common/mi-lttng.h>
34
c399183f 35#include "../command.h"
679b4943 36#include "../utils.h"
f3ed775e 37
00e2e675 38#include <common/defaults.h>
42224349 39#include <common/sessiond-comm/sessiond-comm.h>
00e2e675 40#include <common/uri.h>
81b86775 41#include <common/utils.h>
16f6f820 42#include <lttng/snapshot.h>
b178f53e 43#include <lttng/session-descriptor.h>
42224349 44
f3ed775e
DG
45static char *opt_output_path;
46static char *opt_session_name;
a4b92340
DG
47static char *opt_url;
48static char *opt_ctrl_url;
49static char *opt_data_url;
d7ba1388 50static char *opt_shm_path;
a4b92340 51static int opt_no_consumer;
96fe6b8d 52static int opt_no_output;
16f6f820 53static int opt_snapshot;
c7219617 54static uint32_t opt_live_timer;
f3ed775e 55
4fc83d94
PP
56#ifdef LTTNG_EMBED_HELP
57static const char help_msg[] =
58#include <lttng-create.1.h>
59;
60#endif
61
f3ed775e
DG
62enum {
63 OPT_HELP = 1,
679b4943 64 OPT_LIST_OPTIONS,
ecc48a90 65 OPT_LIVE_TIMER,
f3ed775e
DG
66};
67
b178f53e
JG
68enum output_type {
69 OUTPUT_NONE,
70 OUTPUT_LOCAL,
71 OUTPUT_NETWORK,
72 OUTPUT_UNSPECIFIED,
73};
37d03ff7 74
b178f53e 75static struct mi_writer *writer;
f3ed775e
DG
76static struct poptOption long_options[] = {
77 /* longName, shortName, argInfo, argPtr, value, descrip, argDesc */
679b4943
SM
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},
23d14dff
DG
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},
96fe6b8d 84 {"no-output", 0, POPT_ARG_VAL, &opt_no_output, 1, 0, 0},
2bba9e53 85 {"no-consumer", 0, POPT_ARG_VAL, &opt_no_consumer, 1, 0, 0},
16f6f820 86 {"snapshot", 0, POPT_ARG_VAL, &opt_snapshot, 1, 0, 0},
d73c5802 87 {"live", 0, POPT_ARG_INT | POPT_ARGFLAG_OPTIONAL, 0, OPT_LIVE_TIMER, 0, 0},
d7ba1388 88 {"shm-path", 0, POPT_ARG_STRING, &opt_shm_path, 0, 0, 0},
f3ed775e
DG
89 {0, 0, 0, 0, 0, 0, 0}
90};
91
37d03ff7 92/*
485ca16f 93 * Retrieve the created session and mi output it based on provided argument
37d03ff7
JRJ
94 * This is currently a summary of what was pretty printed and is subject to
95 * enhancements.
37d03ff7
JRJ
96 */
97static 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
137error:
138 free(sessions);
139end:
140 return ret;
141}
142
b178f53e
JG
143static
144struct lttng_session_descriptor *create_session_descriptor(void)
16f6f820
DG
145{
146 int ret;
b178f53e
JG
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 }
16f6f820 182
b178f53e
JG
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;
16f6f820
DG
206 }
207
b178f53e
JG
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();
16f6f820 228 }
b178f53e
JG
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);
16f6f820 239
b178f53e
JG
240 } else {
241 /* Regular session. */
242 switch (output_type) {
243 case OUTPUT_UNSPECIFIED:
244 case OUTPUT_LOCAL:
245 descriptor = lttng_session_descriptor_local_create(
246 opt_session_name,
247 output_type == OUTPUT_LOCAL ?
248 local_output_path : NULL);
249 break;
250 case OUTPUT_NONE:
251 descriptor = lttng_session_descriptor_create(
252 opt_session_name);
253 break;
254 case OUTPUT_NETWORK:
255 descriptor = lttng_session_descriptor_network_create(
256 opt_session_name, uri_str1, uri_str2);
257 break;
258 default:
259 abort();
16f6f820
DG
260 }
261 }
b178f53e
JG
262 if (!descriptor) {
263 ERR("Failed to initialize session creation command.");
16f6f820 264 }
b178f53e
JG
265end:
266 free(uris);
267 return descriptor;
16f6f820
DG
268}
269
f3ed775e 270/*
1c8d13c8
TD
271 * Create a tracing session.
272 * If no name is specified, a default name is generated.
f3ed775e 273 *
1c8d13c8 274 * Returns one of the CMD_* result constants.
f3ed775e 275 */
a4b92340 276static int create_session(void)
f3ed775e 277{
b178f53e
JG
278 int ret, i;
279 char shm_path[LTTNG_PATH_MAX] = {};
280 struct lttng_session_descriptor *session_descriptor = NULL;
281 enum lttng_session_descriptor_status descriptor_status;
282 enum lttng_error_code ret_code;
283 struct lttng_session *sessions = NULL;
284 const struct lttng_session *created_session = NULL;
285 const char *created_session_name;
286
287 /* Validate options. */
288 if (opt_session_name) {
487b253b
DG
289 if (strlen(opt_session_name) > NAME_MAX) {
290 ERR("Session name too long. Length must be lower or equal to %d",
291 NAME_MAX);
b178f53e 292 ret = CMD_ERROR;
487b253b
DG
293 goto error;
294 }
4b861950
DG
295 /*
296 * Check if the session name begins with "auto-" or is exactly "auto".
297 * Both are reserved for the default session name. See bug #449 to
298 * understand why we need to check both here.
299 */
300 if ((strncmp(opt_session_name, DEFAULT_SESSION_NAME "-",
301 strlen(DEFAULT_SESSION_NAME) + 1) == 0) ||
302 (strncmp(opt_session_name, DEFAULT_SESSION_NAME,
61b35a5a 303 strlen(DEFAULT_SESSION_NAME)) == 0 &&
4b861950 304 strlen(opt_session_name) == strlen(DEFAULT_SESSION_NAME))) {
61b35a5a
DG
305 ERR("%s is a reserved keyword for default session(s)",
306 DEFAULT_SESSION_NAME);
307 ret = CMD_ERROR;
308 goto error;
309 }
f3ed775e
DG
310 }
311
b178f53e
JG
312 if (opt_snapshot && opt_live_timer) {
313 ERR("Snapshot and live modes are mutually exclusive.");
1a241656
DG
314 ret = CMD_ERROR;
315 goto error;
316 }
317
b178f53e
JG
318 if ((!opt_ctrl_url && opt_data_url) || (opt_ctrl_url && !opt_data_url)) {
319 ERR("Both control and data URLs must be specified.");
320 ret = CMD_ERROR;
321 goto error;
00e2e675
DG
322 }
323
b178f53e
JG
324 session_descriptor = create_session_descriptor();
325 if (!session_descriptor) {
326 ret = CMD_ERROR;
327 goto error;
ecc48a90 328 }
b178f53e
JG
329 ret_code = lttng_create_session_ext(session_descriptor);
330 if (ret_code != LTTNG_OK) {
331 ERR("%s", lttng_strerror(-ret_code));
ecc48a90
JD
332 ret = CMD_ERROR;
333 goto error;
334 }
335
b178f53e
JG
336 descriptor_status = lttng_session_descriptor_get_session_name(
337 session_descriptor, &created_session_name);
338 if (descriptor_status != LTTNG_SESSION_DESCRIPTOR_STATUS_OK) {
339 ERR("Failed to obtain created session name");
340 ret = CMD_ERROR;
341 goto error;
16f6f820 342 }
b178f53e
JG
343
344 ret = lttng_list_sessions(&sessions);
f3ed775e 345 if (ret < 0) {
b178f53e
JG
346 ERR("Failed to fetch properties of created session: %s",
347 lttng_strerror(ret));
348 ret = CMD_ERROR;
349 goto error;
350 }
351 for (i = 0; i < ret; i++) {
352 if (!strcmp(created_session_name, sessions[i].name)) {
353 created_session = &sessions[i];
60e835ca 354 break;
42224349 355 }
b178f53e
JG
356 }
357 if (!created_session) {
358 ERR("Failed to fetch properties of created session");
359 ret = CMD_ERROR;
f3ed775e
DG
360 goto error;
361 }
362
b178f53e
JG
363 if (opt_shm_path) {
364 char datetime_suffix[17] = {};
365
366 /*
367 * An auto-generated session name already includes the creation
368 * timestamp.
369 */
370 if (opt_session_name) {
371 uint64_t creation_time;
372 struct tm *timeinfo;
373 time_t creation_time_t;
374 size_t strftime_ret;
375
376 ret_code = lttng_session_get_creation_time(
377 created_session,
378 &creation_time);
379 if (ret_code != LTTNG_OK) {
380 ERR("%s", lttng_strerror(-ret_code));
381 ret = CMD_ERROR;
382 goto error;
383 }
384 creation_time_t = (time_t) creation_time;
385 timeinfo = localtime(&creation_time_t);
386 if (!timeinfo) {
387 PERROR("Failed to interpret session creation time");
388 ret = CMD_ERROR;
389 goto error;
390 }
391 strftime_ret = strftime(datetime_suffix,
392 sizeof(datetime_suffix),
393 "-%Y%m%d-%H%M%S", timeinfo);
394 if (strftime_ret == 0) {
395 ERR("Failed to format session creation time.");
396 ret = CMD_ERROR;
397 goto error;
398 }
a4b92340 399 }
4f50c803 400
d7ba1388 401 ret = snprintf(shm_path, sizeof(shm_path),
b178f53e
JG
402 "%s/%s%s", opt_shm_path, created_session_name,
403 datetime_suffix);
404 if (ret < 0 || ret >= sizeof(shm_path)) {
405 ERR("Failed to format the shared memory path.");
406 ret = CMD_ERROR;
d7ba1388
MD
407 goto error;
408 }
b178f53e
JG
409 ret = lttng_set_session_shm_path(created_session_name,
410 shm_path);
d7ba1388 411 if (ret < 0) {
b178f53e
JG
412 lttng_destroy_session(created_session_name);
413 ret = CMD_ERROR;
d7ba1388
MD
414 goto error;
415 }
416 }
417
b178f53e
JG
418 if (opt_snapshot) {
419 MSG("Snapshot session %s created.", created_session_name);
420 } else if (opt_live_timer) {
421 MSG("Live session %s created.", created_session_name);
422 } else {
423 MSG("Session %s created.", created_session_name);
424 }
425
426 if (*created_session->path && !opt_snapshot) {
427 MSG("Traces will be output to %s", created_session->path);
d73c5802
DG
428
429 if (opt_live_timer) {
b178f53e
JG
430 MSG("Live timer interval set to %u %s", opt_live_timer,
431 USEC_UNIT);
d73c5802 432 }
16f6f820 433 } else if (opt_snapshot) {
b178f53e
JG
434 struct lttng_snapshot_output_list *list;
435 struct lttng_snapshot_output *iter;
436 char snapshot_url[LTTNG_PATH_MAX] = {};
437
438 ret = lttng_snapshot_list_output(created_session_name, &list);
439 if (ret < 0) {
440 ERR("Failed to list snapshot outputs.");
441 ret = CMD_ERROR;
442 goto error;
16f6f820 443 }
b178f53e
JG
444
445 while ((iter = lttng_snapshot_output_list_get_next(list))) {
446 const char *url = NULL;
447
448 url = lttng_snapshot_output_get_ctrl_url(
449 iter);
450 ret = lttng_strncpy(snapshot_url, url,
451 sizeof(snapshot_url));
452 if (ret) {
453 snapshot_url[0] = '\0';
454 ERR("Failed to retrieve snapshot output destination");
455 }
456 break;
457 }
458 lttng_snapshot_output_list_destroy(list);
459
460 if (*snapshot_url) {
461 MSG("Default snapshot output set to %s",
462 snapshot_url);
463 }
464 MSG("Every channel enabled for this session will be set to mmap output and default to overwrite mode.");
a4b92340 465 }
d7ba1388 466 if (opt_shm_path) {
b178f53e 467 MSG("Shared memory path set to %s", shm_path);
d7ba1388 468 }
a4b92340 469
37d03ff7
JRJ
470 /* Mi output */
471 if (lttng_opt_mi) {
b178f53e 472 ret = mi_created_session(created_session_name);
37d03ff7
JRJ
473 if (ret) {
474 ret = CMD_ERROR;
475 goto error;
476 }
477 }
478
58a97671 479 /* Init lttng session config */
b178f53e 480 ret = config_init(created_session_name);
f3ed775e 481 if (ret < 0) {
27089920 482 ret = CMD_ERROR;
f3ed775e
DG
483 goto error;
484 }
485
f3ed775e 486 ret = CMD_SUCCESS;
f3ed775e 487error:
b178f53e
JG
488 lttng_session_descriptor_destroy(session_descriptor);
489 free(sessions);
f3ed775e
DG
490 return ret;
491}
492
92360082
JG
493/*
494 * spawn_sessiond
495 *
496 * Spawn a session daemon by forking and execv.
497 */
498static int spawn_sessiond(char *pathname)
499{
500 int ret = 0;
501 pid_t pid;
502
503 MSG("Spawning a session daemon");
92360082
JG
504 pid = fork();
505 if (pid == 0) {
506 /*
bbd44cae 507 * Spawn session daemon in daemon mode.
92360082 508 */
bbd44cae
PP
509 execlp(pathname, "lttng-sessiond",
510 "--daemonize", NULL);
92360082
JG
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) {
92360082 520 /*
bbd44cae
PP
521 * In daemon mode (--daemonize), sessiond only exits when
522 * it's ready to accept commands.
92360082 523 */
bbd44cae 524 for (;;) {
81527d36
JG
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 }
bbd44cae
PP
536
537 if (WIFSIGNALED(status)) {
538 ERR("Session daemon was killed by signal %d",
539 WTERMSIG(status));
540 ret = -1;
541 goto end;
542 } else if (WIFEXITED(status)) {
543 DBG("Session daemon terminated normally (exit status: %d)",
544 WEXITSTATUS(status));
545
546 if (WEXITSTATUS(status) != 0) {
547 ERR("Session daemon terminated with an error (exit status: %d)",
548 WEXITSTATUS(status));
549 ret = -1;
550 goto end;
551 }
552 break;
553 }
92360082 554 }
bbd44cae 555
92360082
JG
556 goto end;
557 } else {
558 PERROR("fork");
559 ret = -1;
560 goto end;
561 }
562
563end:
564 return ret;
565}
566
567/*
568 * launch_sessiond
569 *
570 * Check if the session daemon is available using
571 * the liblttngctl API for the check. If not, try to
572 * spawn a daemon.
573 */
574static int launch_sessiond(void)
575{
576 int ret;
577 char *pathname = NULL;
578
579 ret = lttng_session_daemon_alive();
580 if (ret) {
581 /* Sessiond is alive, not an error */
582 ret = 0;
583 goto end;
584 }
585
586 /* Try command line option path */
587 pathname = opt_sessiond_path;
588
589 /* Try LTTNG_SESSIOND_PATH env variable */
590 if (pathname == NULL) {
591 pathname = getenv(DEFAULT_SESSIOND_PATH_ENV);
592 }
593
594 /* Try with configured path */
595 if (pathname == NULL) {
596 if (CONFIG_SESSIOND_BIN[0] != '\0') {
597 pathname = CONFIG_SESSIOND_BIN;
598 }
599 }
600
601 /* Try the default path */
602 if (pathname == NULL) {
603 pathname = INSTALL_BIN_PATH "/lttng-sessiond";
604 }
605
606 DBG("Session daemon binary path: %s", pathname);
607
608 /* Check existence and permissions */
609 ret = access(pathname, F_OK | X_OK);
610 if (ret < 0) {
611 ERR("No such file or access denied: %s", pathname);
612 goto end;
613 }
614
615 ret = spawn_sessiond(pathname);
92360082 616end:
0f4fa0d2
JG
617 if (ret) {
618 ERR("Problem occurred while launching session daemon (%s)",
619 pathname);
620 }
92360082
JG
621 return ret;
622}
623
a8d119b5
JG
624int validate_url_option_combination(void)
625{
626 int ret = 0;
627 int used_count = 0;
628
629 used_count += !!opt_url;
630 used_count += !!opt_output_path;
631 used_count += (opt_data_url || opt_ctrl_url);
632 if (used_count > 1) {
633 ERR("Only one of the --set-url, --ctrl-url/data-url, or --output options may be used at once.");
634 ret = -1;
635 }
636
637 return ret;
638}
639
f3ed775e 640/*
74cc1d0f 641 * The 'create <options>' first level command
1c8d13c8
TD
642 *
643 * Returns one of the CMD_* result constants.
f3ed775e
DG
644 */
645int cmd_create(int argc, const char **argv)
646{
37d03ff7 647 int opt, ret = CMD_SUCCESS, command_ret = CMD_SUCCESS, success = 1;
ecc48a90 648 char *opt_arg = NULL;
68c7f6e5 649 const char *leftover = NULL;
f3ed775e
DG
650 static poptContext pc;
651
652 pc = poptGetContext(NULL, argc, argv, long_options, 0);
653 poptReadDefaultConfig(pc, 0);
654
655 while ((opt = poptGetNextOpt(pc)) != -1) {
656 switch (opt) {
657 case OPT_HELP:
4ba92f18 658 SHOW_HELP();
f3ed775e 659 goto end;
679b4943
SM
660 case OPT_LIST_OPTIONS:
661 list_cmd_options(stdout, long_options);
679b4943 662 goto end;
ecc48a90
JD
663 case OPT_LIVE_TIMER:
664 {
c7219617 665 uint64_t v;
ecc48a90
JD
666
667 errno = 0;
668 opt_arg = poptGetOptArg(pc);
d73c5802
DG
669 if (!opt_arg) {
670 /* Set up default values. */
671 opt_live_timer = (uint32_t) DEFAULT_LTTNG_LIVE_TIMER;
672 DBG("Session live timer interval set to default value %d",
673 opt_live_timer);
674 break;
675 }
676
c7219617
SM
677 if (utils_parse_time_suffix(opt_arg, &v) < 0) {
678 ERR("Wrong value for --live parameter: %s", opt_arg);
ecc48a90
JD
679 ret = CMD_ERROR;
680 goto end;
681 }
c7219617 682
ecc48a90
JD
683 if (v != (uint32_t) v) {
684 ERR("32-bit overflow in --live parameter: %s", opt_arg);
685 ret = CMD_ERROR;
686 goto end;
687 }
c7219617 688
0ed9e0be
JG
689 if (v == 0) {
690 ERR("Live timer interval must be greater than zero");
691 ret = CMD_ERROR;
692 goto end;
693 }
c7219617 694
ecc48a90
JD
695 opt_live_timer = (uint32_t) v;
696 DBG("Session live timer interval set to %d", opt_live_timer);
697 break;
698 }
f3ed775e 699 default:
f3ed775e
DG
700 ret = CMD_UNDEFINED;
701 goto end;
702 }
703 }
704
785d2d0d 705 if (opt_no_consumer) {
96fe6b8d 706 MSG("The option --no-consumer is obsolete. Use --no-output now.");
785d2d0d
DG
707 ret = CMD_WARNING;
708 goto end;
709 }
710
a8d119b5
JG
711 ret = validate_url_option_combination();
712 if (ret) {
713 ret = CMD_ERROR;
714 goto end;
715 }
716
92360082
JG
717 /* Spawn a session daemon if needed */
718 if (!opt_no_sessiond) {
719 ret = launch_sessiond();
720 if (ret) {
721 ret = CMD_ERROR;
722 goto end;
723 }
724 }
725
acc09215 726 /* MI initialization */
37d03ff7
JRJ
727 if (lttng_opt_mi) {
728 writer = mi_lttng_writer_create(fileno(stdout), lttng_opt_mi);
729 if (!writer) {
730 ret = -LTTNG_ERR_NOMEM;
731 goto end;
732 }
733
734 /* Open command element */
735 ret = mi_lttng_writer_command_open(writer,
736 mi_lttng_element_command_create);
737 if (ret) {
738 ret = CMD_ERROR;
739 goto end;
740 }
741
742 /* Open output element */
743 ret = mi_lttng_writer_open_element(writer,
744 mi_lttng_element_command_output);
745 if (ret) {
746 ret = CMD_ERROR;
747 goto end;
748 }
749 }
f3ed775e
DG
750 opt_session_name = (char*) poptGetArg(pc);
751
68c7f6e5
JD
752 leftover = poptGetArg(pc);
753 if (leftover) {
754 ERR("Unknown argument: %s", leftover);
755 ret = CMD_ERROR;
756 goto end;
757 }
758
37d03ff7
JRJ
759 command_ret = create_session();
760 if (command_ret) {
761 success = 0;
762 }
763
764 if (lttng_opt_mi) {
765 /* Close output element */
766 ret = mi_lttng_writer_close_element(writer);
767 if (ret) {
768 ret = CMD_ERROR;
769 goto end;
770 }
771
772 /* Success ? */
773 ret = mi_lttng_writer_write_element_bool(writer,
774 mi_lttng_element_command_success, success);
775 if (ret) {
776 ret = CMD_ERROR;
777 goto end;
778 }
779
780 /* Command element close */
781 ret = mi_lttng_writer_command_close(writer);
782 if (ret) {
783 ret = CMD_ERROR;
784 goto end;
785 }
786 }
f3ed775e
DG
787
788end:
37d03ff7
JRJ
789 /* Mi clean-up */
790 if (writer && mi_lttng_writer_destroy(writer)) {
791 /* Preserve original error code */
792 ret = ret ? ret : -LTTNG_ERR_MI_IO_FAIL;
793 }
794
acc09215 795 /* Overwrite ret if an error occurred in create_session() */
37d03ff7
JRJ
796 ret = command_ret ? command_ret : ret;
797
ca1c3607 798 poptFreeContext(pc);
f3ed775e
DG
799 return ret;
800}
This page took 0.106181 seconds and 5 git commands to generate.