SYNOPSIS
--------
[verse]
-*lttng* ['linkgenoptions:(GENERAL OPTIONS)'] *start* ['SESSION']
+*lttng* ['linkgenoptions:(GENERAL OPTIONS)'] *start* [option::--all | option::--glob 'SESSION' | 'SESSION' ]
DESCRIPTION
include::common-lttng-cmd-help-options.txt[]
+option:-a, option:--all::
+ Start all sessions.
+
+option:-g, option:--glob::
+ Interpret SESSION as a globbing pattern.
include::common-lttng-cmd-after-options.txt[]
----
====
+.Start all sessions.
+====
+See the option::--all option.
+
+[role="term"]
+----
+$ lttng start --all
+----
+====
+
+.Start all sessions with the suffix foo.
+====
+See the option::--glob option.
+
+[role="term"]
+----
+$ lttng start --glob '*foo'
+----
+====
+
include::common-footer.txt[]
#define _LGPL_SOURCE
#include "../command.hpp"
+#include "../utils.hpp"
+#include <common/exception.hpp>
#include <common/mi-lttng.hpp>
#include <common/sessiond-comm/sessiond-comm.hpp>
enum {
OPT_HELP = 1,
OPT_LIST_OPTIONS,
+ OPT_ENABLE_GLOB,
+ OPT_ALL,
};
static struct poptOption long_options[] = {
/* longName, shortName, argInfo, argPtr, value, descrip, argDesc */
{ "help", 'h', POPT_ARG_NONE, nullptr, OPT_HELP, nullptr, nullptr },
{ "list-options", 0, POPT_ARG_NONE, nullptr, OPT_LIST_OPTIONS, nullptr, nullptr },
+ { "glob", 'g', POPT_ARG_NONE, nullptr, OPT_ENABLE_GLOB, nullptr, nullptr },
+ { "all", 'a', POPT_ARG_NONE, nullptr, OPT_ALL, nullptr, nullptr },
{ nullptr, 0, 0, nullptr, 0, nullptr, nullptr }
};
-static int mi_print_session(char *session_name, int enabled)
+static int mi_print_session(const char *session_name, int enabled)
{
int ret;
*
* Start tracing for all trace of the session.
*/
-static int start_tracing(const char *arg_session_name)
+static int start_tracing(const char *session_name)
{
int ret;
- char *session_name;
-
- if (arg_session_name == nullptr) {
- session_name = get_session_name();
- } else {
- session_name = strdup(arg_session_name);
- if (session_name == nullptr) {
- PERROR("Failed to copy session name");
- }
- }
if (session_name == nullptr) {
ret = CMD_ERROR;
ERR("%s", lttng_strerror(ret));
break;
}
- goto free_name;
+ goto error;
}
ret = CMD_SUCCESS;
ret = mi_print_session(session_name, 1);
if (ret) {
ret = CMD_ERROR;
- goto free_name;
+ goto error;
}
}
-free_name:
- free(session_name);
error:
return ret;
}
+static int start_tracing(const struct session_spec& spec)
+{
+ int ret = CMD_SUCCESS;
+ bool had_warning = false;
+
+ try {
+ for (const auto& session : list_sessions(spec)) {
+ const auto sub_ret = start_tracing(session.name);
+
+ switch (sub_ret) {
+ case CMD_WARNING:
+ had_warning = true;
+ /* fall-through. */
+ case CMD_SUCCESS:
+ continue;
+ default:
+ ret = sub_ret;
+ break;
+ }
+ }
+ } catch (const std::exception& e) {
+ ERR_FMT("{}", e.what());
+ return CMD_FATAL;
+ }
+
+ if (ret == CMD_SUCCESS && had_warning) {
+ ret = CMD_WARNING;
+ }
+
+ return ret;
+}
+
/*
* cmd_start
*
{
int opt, ret = CMD_SUCCESS, command_ret = CMD_SUCCESS, success = 1;
static poptContext pc;
- const char *arg_session_name = nullptr;
const char *leftover = nullptr;
+ struct session_spec session_spec = {
+ .type = session_spec::NAME,
+ .value = nullptr,
+ };
pc = poptGetContext(nullptr, argc, argv, long_options, 0);
poptReadDefaultConfig(pc, 0);
case OPT_LIST_OPTIONS:
list_cmd_options(stdout, long_options);
goto end;
+ case OPT_ENABLE_GLOB:
+ session_spec.type = session_spec::GLOB_PATTERN;
+ break;
+ case OPT_ALL:
+ session_spec.type = session_spec::ALL;
+ break;
default:
ret = CMD_UNDEFINED;
goto end;
}
}
- arg_session_name = poptGetArg(pc);
+ session_spec.value = poptGetArg(pc);
leftover = poptGetArg(pc);
if (leftover) {
}
}
- command_ret = start_tracing(arg_session_name);
+ command_ret = start_tracing(session_spec);
if (command_ret) {
success = 0;
}