}
}();
- if (!listing_failed && sessions.size() == 0 && spec.type == session_spec::type::NAME) {
+ if (!listing_failed && sessions.size() == 0 && spec.type_ == session_spec::type::NAME) {
ERR_FMT("Session `{}` not found", spec.value);
return CMD_ERROR;
}
} catch (const lttng::ctl::error& ctl_exception) {
switch (ctl_exception.code()) {
case LTTNG_ERR_NO_SESSION:
- if (spec.type != session_spec::type::NAME) {
+ if (spec.type_ != session_spec::type::NAME) {
/* Session destroyed during command, ignore and carry-on. */
sub_ret = CMD_SUCCESS;
break;
bool success;
static poptContext pc;
const char *leftover = nullptr;
- struct session_spec spec = {
- .type = session_spec::NAME,
- .value = nullptr,
- };
+ struct session_spec spec(session_spec::type::NAME);
session_list const sessions;
pc = poptGetContext(nullptr, argc, argv, long_options, 0);
list_cmd_options(stdout, long_options);
goto end;
case OPT_ALL:
- spec.type = session_spec::ALL;
+ spec.type_ = session_spec::type::ALL;
break;
case OPT_ENABLE_GLOB:
- spec.type = session_spec::GLOB_PATTERN;
+ spec.type_ = session_spec::type::GLOB_PATTERN;
break;
default:
command_ret = CMD_UNDEFINED;
}
}();
- if (!listing_failed && sessions.size() == 0 && spec.type == session_spec::type::NAME) {
+ if (!listing_failed && sessions.size() == 0 && spec.type_ == session_spec::type::NAME) {
ERR_FMT("Session `{}` not found", spec.value);
return CMD_ERROR;
}
sub_ret = CMD_SUCCESS;
break;
case LTTNG_ERR_NO_SESSION:
- if (spec.type != session_spec::type::NAME) {
+ if (spec.type_ != session_spec::type::NAME) {
/* Session destroyed during command, ignore and carry-on. */
sub_ret = CMD_SUCCESS;
break;
bool success = true;
static poptContext pc;
const char *leftover = nullptr;
- session_spec session_spec = {
- .type = session_spec::NAME,
- .value = nullptr,
- };
+ session_spec session_spec(session_spec::type::NAME);
pc = poptGetContext(nullptr, argc, argv, long_options, 0);
poptReadDefaultConfig(pc, 0);
list_cmd_options(stdout, long_options);
goto end;
case OPT_ENABLE_GLOB:
- session_spec.type = session_spec::GLOB_PATTERN;
+ session_spec.type_ = session_spec::type::GLOB_PATTERN;
break;
case OPT_ALL:
- session_spec.type = session_spec::ALL;
+ session_spec.type_ = session_spec::type::ALL;
break;
default:
command_ret = CMD_UNDEFINED;
}
}();
- if (!listing_failed && sessions.size() == 0 && spec.type == session_spec::type::NAME) {
+ if (!listing_failed && sessions.size() == 0 && spec.type_ == session_spec::type::NAME) {
ERR_FMT("Session `{}` not found", spec.value);
return CMD_ERROR;
}
sub_ret = CMD_SUCCESS;
break;
case LTTNG_ERR_NO_SESSION:
- if (spec.type != session_spec::type::NAME) {
+ if (spec.type_ != session_spec::type::NAME) {
/* Session destroyed during command, ignore and carry-on. */
sub_ret = CMD_SUCCESS;
break;
bool success = true;
static poptContext pc;
const char *leftover = nullptr;
- struct session_spec session_spec = {
- .type = session_spec::NAME,
- .value = nullptr,
- };
+ struct session_spec session_spec(session_spec::type::NAME);
pc = poptGetContext(nullptr, argc, argv, long_options, 0);
poptReadDefaultConfig(pc, 0);
list_cmd_options(stdout, long_options);
goto end;
case OPT_ENABLE_GLOB:
- session_spec.type = session_spec::GLOB_PATTERN;
+ session_spec.type_ = session_spec::type::GLOB_PATTERN;
break;
case OPT_ALL:
- session_spec.type = session_spec::ALL;
+ session_spec.type_ = session_spec::type::ALL;
break;
default:
command_ret = CMD_UNDEFINED;
session_list list_sessions(const struct session_spec& spec)
{
- switch (spec.type) {
- case session_spec::NAME:
+ switch (spec.type_) {
+ case session_spec::type::NAME:
if (spec.value == nullptr) {
const auto configured_name =
lttng::make_unique_wrapper<char, lttng::free>(get_session_name());
if (configured_name) {
- const struct session_spec new_spec = {
- .type = session_spec::NAME, .value = configured_name.get()
- };
+ const struct session_spec new_spec(session_spec::type::NAME,
+ configured_name.get());
return list_sessions(new_spec);
}
return strcmp(session.name, spec.value) == 0;
},
true);
- case session_spec::GLOB_PATTERN:
+ case session_spec::type::GLOB_PATTERN:
return get_sessions([&spec](const lttng_session& session) {
return fnmatch(spec.value, session.name, 0) == 0;
});
- case session_spec::ALL:
+ case session_spec::type::ALL:
return get_sessions([](const lttng_session&) { return true; });
}
struct cmd_struct;
struct session_spec {
- enum type {
+ enum class type {
NAME,
GLOB_PATTERN,
ALL,
};
- type type;
+ explicit session_spec(type spec_type, const char *name_or_pattern = nullptr) noexcept :
+ type_(spec_type), value(name_or_pattern)
+ {
+ }
+
+ /* Disambiguate type enum from the member for buggy g++ versions. */
+ type type_;
const char *value;
};