The string returned by poptGetArg() is 'const' because it is owned by
the popt librairy and is free'd by it when poptFreeContext() is called.
Copy those strings when we need to alter them to maintain proper
ownership.
The latest release of popt (v1.19) introduced a breaking
change (changing the ownership of left-over command line arguments) that
can cause double free()-s.
This is ultimately due to this upstream commit in popt 1.19:
https://github.com/rpm-software-management/popt/commit/
7182e4618ad5a0186145fc2aa4a98c2229afdfa8
which is derived from a package patch:
https://src.fedoraproject.org/rpms/babeltrace/c/
d48452beff87b145c038f070e7182358db04336c?branch=rawhide
Change-Id: Id2535d1534c0e47cc0747968d6dd60a587f0b810
Signed-off-by: Michael Jeanson <mjeanson@efficios.com>
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
15 files changed:
int ret = CMD_SUCCESS , i, command_ret = CMD_SUCCESS, success = 1;
static poptContext pc;
char *session_name = NULL;
int ret = CMD_SUCCESS , i, command_ret = CMD_SUCCESS, success = 1;
static poptContext pc;
char *session_name = NULL;
+ const char *arg_session_name = NULL;
const char *leftover = NULL;
const char *leftover = NULL;
- bool free_session_name = false;
struct lttng_session *sessions = NULL;
int count;
int found;
struct lttng_session *sessions = NULL;
int count;
int found;
- session_name = (char *) poptGetArg(pc);
- if (!session_name) {
+ arg_session_name = poptGetArg(pc);
+ if (!arg_session_name) {
/* No session name specified, lookup default */
session_name = get_session_name();
/* No session name specified, lookup default */
session_name = get_session_name();
+ } else {
+ session_name = strdup(arg_session_name);
if (session_name == NULL) {
if (session_name == NULL) {
- command_ret = CMD_ERROR;
- success = 0;
- goto mi_closing;
+ PERROR("Failed to copy session name");
- free_session_name = true;
- } else {
- session_name = NULL;
+
+ if (session_name == NULL) {
+ command_ret = CMD_ERROR;
+ success = 0;
+ goto mi_closing;
+ }
}
leftover = poptGetArg(pc);
}
leftover = poptGetArg(pc);
- if (free_session_name) {
- free(session_name);
- }
/* Overwrite ret if an error occurred during clear_session/all */
ret = command_ret ? command_ret : ret;
/* Overwrite ret if an error occurred during clear_session/all */
ret = command_ret ? command_ret : ret;
#include <lttng/lttng.h>
static char *opt_output_path;
#include <lttng/lttng.h>
static char *opt_output_path;
-static char *opt_session_name;
static char *opt_url;
static char *opt_ctrl_url;
static char *opt_data_url;
static char *opt_url;
static char *opt_ctrl_url;
static char *opt_data_url;
-struct lttng_session_descriptor *create_session_descriptor(void)
+struct lttng_session_descriptor *create_session_descriptor(const char *session_name)
{
ssize_t uri_count;
enum output_type output_type;
{
ssize_t uri_count;
enum output_type output_type;
case OUTPUT_UNSPECIFIED:
case OUTPUT_LOCAL:
descriptor = lttng_session_descriptor_snapshot_local_create(
case OUTPUT_UNSPECIFIED:
case OUTPUT_LOCAL:
descriptor = lttng_session_descriptor_snapshot_local_create(
output_type == OUTPUT_LOCAL ?
local_output_path : NULL);
break;
case OUTPUT_NONE:
descriptor = lttng_session_descriptor_snapshot_create(
output_type == OUTPUT_LOCAL ?
local_output_path : NULL);
break;
case OUTPUT_NONE:
descriptor = lttng_session_descriptor_snapshot_create(
break;
case OUTPUT_NETWORK:
descriptor = lttng_session_descriptor_snapshot_network_create(
break;
case OUTPUT_NETWORK:
descriptor = lttng_session_descriptor_snapshot_network_create(
- opt_session_name, uri_str1, uri_str2);
+ session_name, uri_str1, uri_str2);
goto end;
}
descriptor = lttng_session_descriptor_live_network_create(
goto end;
}
descriptor = lttng_session_descriptor_live_network_create(
- opt_session_name, uri_str1, uri_str2,
+ session_name, uri_str1, uri_str2,
opt_live_timer);
} else {
/* Regular session. */
opt_live_timer);
} else {
/* Regular session. */
case OUTPUT_UNSPECIFIED:
case OUTPUT_LOCAL:
descriptor = lttng_session_descriptor_local_create(
case OUTPUT_UNSPECIFIED:
case OUTPUT_LOCAL:
descriptor = lttng_session_descriptor_local_create(
output_type == OUTPUT_LOCAL ?
local_output_path : NULL);
break;
case OUTPUT_NONE:
descriptor = lttng_session_descriptor_create(
output_type == OUTPUT_LOCAL ?
local_output_path : NULL);
break;
case OUTPUT_NONE:
descriptor = lttng_session_descriptor_create(
break;
case OUTPUT_NETWORK:
descriptor = lttng_session_descriptor_network_create(
break;
case OUTPUT_NETWORK:
descriptor = lttng_session_descriptor_network_create(
- opt_session_name, uri_str1, uri_str2);
+ session_name, uri_str1, uri_str2);
*
* Returns one of the CMD_* result constants.
*/
*
* Returns one of the CMD_* result constants.
*/
-static int create_session(void)
+static int create_session(const char *session_name)
{
int ret, i;
char shm_path[LTTNG_PATH_MAX] = {};
{
int ret, i;
char shm_path[LTTNG_PATH_MAX] = {};
const char *created_session_name;
/* Validate options. */
const char *created_session_name;
/* Validate options. */
- if (opt_session_name) {
- if (strlen(opt_session_name) > NAME_MAX) {
+ if (session_name) {
+ if (strlen(session_name) > NAME_MAX) {
ERR("Session name too long. Length must be lower or equal to %d",
NAME_MAX);
ret = CMD_ERROR;
ERR("Session name too long. Length must be lower or equal to %d",
NAME_MAX);
ret = CMD_ERROR;
* Both are reserved for the default session name. See bug #449 to
* understand why we need to check both here.
*/
* Both are reserved for the default session name. See bug #449 to
* understand why we need to check both here.
*/
- if ((strncmp(opt_session_name, DEFAULT_SESSION_NAME "-",
+ if ((strncmp(session_name, DEFAULT_SESSION_NAME "-",
strlen(DEFAULT_SESSION_NAME) + 1) == 0) ||
strlen(DEFAULT_SESSION_NAME) + 1) == 0) ||
- (strncmp(opt_session_name, DEFAULT_SESSION_NAME,
+ (strncmp(session_name, DEFAULT_SESSION_NAME,
strlen(DEFAULT_SESSION_NAME)) == 0 &&
strlen(DEFAULT_SESSION_NAME)) == 0 &&
- strlen(opt_session_name) == strlen(DEFAULT_SESSION_NAME))) {
+ strlen(session_name) == strlen(DEFAULT_SESSION_NAME))) {
ERR("%s is a reserved keyword for default session(s)",
DEFAULT_SESSION_NAME);
ret = CMD_ERROR;
ERR("%s is a reserved keyword for default session(s)",
DEFAULT_SESSION_NAME);
ret = CMD_ERROR;
- session_descriptor = create_session_descriptor();
+ session_descriptor = create_session_descriptor(session_name);
if (!session_descriptor) {
ret = CMD_ERROR;
goto error;
if (!session_descriptor) {
ret = CMD_ERROR;
goto error;
* An auto-generated session name already includes the creation
* timestamp.
*/
* An auto-generated session name already includes the creation
* timestamp.
*/
- if (opt_session_name) {
uint64_t creation_time;
struct tm *timeinfo;
time_t creation_time_t;
uint64_t creation_time;
struct tm *timeinfo;
time_t creation_time_t;
{
int opt, ret = CMD_SUCCESS, command_ret = CMD_SUCCESS, success = 1;
char *opt_arg = NULL;
{
int opt, ret = CMD_SUCCESS, command_ret = CMD_SUCCESS, success = 1;
char *opt_arg = NULL;
+ const char *arg_session_name = NULL;
const char *leftover = NULL;
static poptContext pc;
const char *leftover = NULL;
static poptContext pc;
- opt_session_name = (char*) poptGetArg(pc);
+
+ /* Get the optional session name argument. */
+ arg_session_name = poptGetArg(pc);
leftover = poptGetArg(pc);
if (leftover) {
leftover = poptGetArg(pc);
if (leftover) {
- command_ret = create_session();
+ command_ret = create_session(arg_session_name);
if (command_ret) {
success = 0;
}
if (command_ret) {
success = 0;
}
#include <common/sessiond-comm/sessiond-comm.hpp>
#include <common/utils.hpp>
#include <common/sessiond-comm/sessiond-comm.hpp>
#include <common/utils.hpp>
-static char *opt_session_name;
static int opt_destroy_all;
static int opt_no_wait;
static int opt_destroy_all;
static int opt_no_wait;
int ret = CMD_SUCCESS , i, command_ret = CMD_SUCCESS, success = 1;
static poptContext pc;
char *session_name = NULL;
int ret = CMD_SUCCESS , i, command_ret = CMD_SUCCESS, success = 1;
static poptContext pc;
char *session_name = NULL;
+ const char *arg_session_name = NULL;
const char *leftover = NULL;
struct lttng_session *sessions = NULL;
const char *leftover = NULL;
struct lttng_session *sessions = NULL;
- opt_session_name = (char *) poptGetArg(pc);
+ arg_session_name = poptGetArg(pc);
- if (!opt_session_name) {
+ if (!arg_session_name) {
/* No session name specified, lookup default */
session_name = get_session_name();
/* No session name specified, lookup default */
session_name = get_session_name();
+ } else {
+ session_name = strdup(arg_session_name);
if (session_name == NULL) {
if (session_name == NULL) {
- command_ret = CMD_ERROR;
- success = 0;
- goto mi_closing;
+ PERROR("Failed to copy session name");
- } else {
- session_name = opt_session_name;
+ }
+
+ if (session_name == NULL) {
+ command_ret = CMD_ERROR;
+ success = 0;
+ goto mi_closing;
}
/* Find the corresponding lttng_session struct */
}
/* Find the corresponding lttng_session struct */
ret = ret ? ret : -LTTNG_ERR_MI_IO_FAIL;
}
ret = ret ? ret : -LTTNG_ERR_MI_IO_FAIL;
}
- if (opt_session_name == NULL) {
- free(session_name);
- }
-
free(sessions);
/* Overwrite ret if an error occurred during destroy_session/all */
free(sessions);
/* Overwrite ret if an error occurred during destroy_session/all */
#include "../command.hpp"
#include "../command.hpp"
-static char *opt_channels;
static int opt_kernel;
static char *opt_session_name;
static int opt_userspace;
static int opt_kernel;
static char *opt_session_name;
static int opt_userspace;
/*
* Disabling channel using the lttng API.
*/
/*
* Disabling channel using the lttng API.
*/
-static int disable_channels(char *session_name)
+static int disable_channels(char *session_name, char *channel_list)
{
int ret = CMD_SUCCESS, warn = 0, success;
{
int ret = CMD_SUCCESS, warn = 0, success;
}
/* Strip channel list */
}
/* Strip channel list */
- channel_name = strtok(opt_channels, ",");
+ channel_name = strtok(channel_list, ",");
while (channel_name != NULL) {
DBG("Disabling channel %s", channel_name);
while (channel_name != NULL) {
DBG("Disabling channel %s", channel_name);
int opt, ret = CMD_SUCCESS, command_ret = CMD_SUCCESS, success = 1;
static poptContext pc;
char *session_name = NULL;
int opt, ret = CMD_SUCCESS, command_ret = CMD_SUCCESS, success = 1;
static poptContext pc;
char *session_name = NULL;
+ char *channel_list = NULL;
+ const char *arg_channel_list = NULL;
const char *leftover = NULL;
pc = poptGetContext(NULL, argc, argv, long_options, 0);
const char *leftover = NULL;
pc = poptGetContext(NULL, argc, argv, long_options, 0);
- opt_channels = (char*) poptGetArg(pc);
- if (opt_channels == NULL) {
- ERR("Missing channel name(s).\n");
+ arg_channel_list = poptGetArg(pc);
+ if (arg_channel_list == NULL) {
+ ERR("Missing channel name(s).");
+ ret = CMD_ERROR;
+ goto end;
+ }
+
+ channel_list = strdup(arg_channel_list);
+ if (channel_list == NULL) {
+ PERROR("Failed to copy channel name");
ret = CMD_ERROR;
goto end;
}
ret = CMD_ERROR;
goto end;
}
- command_ret = disable_channels(session_name);
+ command_ret = disable_channels(session_name, channel_list);
if (command_ret) {
success = 0;
}
if (command_ret) {
success = 0;
}
/* Overwrite ret if an error occurred in disable_channels */
ret = command_ret ? command_ret : ret;
/* Overwrite ret if an error occurred in disable_channels */
ret = command_ret ? command_ret : ret;
#include "../command.hpp"
#include "../command.hpp"
-static char *opt_event_list;
static int opt_kernel;
static char *opt_channel_name;
static char *opt_session_name;
static int opt_kernel;
static char *opt_channel_name;
static char *opt_session_name;
*
* Disabling event using the lttng API.
*/
*
* Disabling event using the lttng API.
*/
-static int disable_events(char *session_name)
+static int disable_events(char *session_name, char *event_list)
{
int ret = CMD_SUCCESS, warn = 0, command_ret = CMD_SUCCESS;
int enabled = 1, success = 1;
{
int ret = CMD_SUCCESS, warn = 0, command_ret = CMD_SUCCESS;
int enabled = 1, success = 1;
}
} else {
/* Strip event list */
}
} else {
/* Strip event list */
- event_name = strtok(opt_event_list, ",");
+ event_name = strtok(event_list, ",");
while (event_name != NULL) {
DBG("Disabling event %s", event_name);
while (event_name != NULL) {
DBG("Disabling event %s", event_name);
int opt, ret = CMD_SUCCESS, command_ret = CMD_SUCCESS, success = 1;
static poptContext pc;
char *session_name = NULL;
int opt, ret = CMD_SUCCESS, command_ret = CMD_SUCCESS, success = 1;
static poptContext pc;
char *session_name = NULL;
+ char *event_list = NULL;
+ const char *arg_event_list = NULL;
const char *leftover = NULL;
int event_type = -1;
const char *leftover = NULL;
int event_type = -1;
- opt_event_list = (char*) poptGetArg(pc);
- if (opt_event_list == NULL && opt_disable_all == 0) {
+ arg_event_list = poptGetArg(pc);
+ if (arg_event_list == NULL && opt_disable_all == 0) {
ERR("Missing event name(s).\n");
ret = CMD_ERROR;
goto end;
}
ERR("Missing event name(s).\n");
ret = CMD_ERROR;
goto end;
}
+ if (opt_disable_all == 0) {
+ event_list = strdup(arg_event_list);
+ if (event_list == NULL) {
+ PERROR("Failed to copy event name(s)");
+ ret = CMD_ERROR;
+ goto end;
+ }
+ }
+
leftover = poptGetArg(pc);
if (leftover) {
ERR("Unknown argument: %s", leftover);
leftover = poptGetArg(pc);
if (leftover) {
ERR("Unknown argument: %s", leftover);
- command_ret = disable_events(session_name);
+ command_ret = disable_events(session_name, event_list);
if (command_ret) {
success = 0;
}
if (command_ret) {
success = 0;
}
/* Mi clean-up */
if (writer && mi_lttng_writer_destroy(writer)) {
/* Preserve original error code */
/* Mi clean-up */
if (writer && mi_lttng_writer_destroy(writer)) {
/* Preserve original error code */
static struct lttng_channel chan_opts;
static struct lttng_channel chan_opts;
-static char *opt_channels;
static int opt_kernel;
static char *opt_session_name;
static int opt_userspace;
static int opt_kernel;
static char *opt_session_name;
static int opt_userspace;
/*
* Adding channel using the lttng API.
*/
/*
* Adding channel using the lttng API.
*/
-static int enable_channel(char *session_name)
+static int enable_channel(char *session_name, char *channel_list)
{
struct lttng_channel *channel = NULL;
int ret = CMD_SUCCESS, warn = 0, error = 0, success = 0;
{
struct lttng_channel *channel = NULL;
int ret = CMD_SUCCESS, warn = 0, error = 0, success = 0;
}
/* Strip channel list (format: chan1,chan2,...) */
}
/* Strip channel list (format: chan1,chan2,...) */
- channel_name = strtok(opt_channels, ",");
+ channel_name = strtok(channel_list, ",");
while (channel_name != NULL) {
void *extended_ptr;
while (channel_name != NULL) {
void *extended_ptr;
int opt, ret = CMD_SUCCESS, command_ret = CMD_SUCCESS, success = 1;
static poptContext pc;
char *session_name = NULL;
int opt, ret = CMD_SUCCESS, command_ret = CMD_SUCCESS, success = 1;
static poptContext pc;
char *session_name = NULL;
+ char *channel_list = NULL;
+ const char *arg_channel_list = NULL;
const char *leftover = NULL;
init_channel_config();
const char *leftover = NULL;
init_channel_config();
- opt_channels = (char*) poptGetArg(pc);
- if (opt_channels == NULL) {
- ERR("Missing channel name.\n");
+ arg_channel_list = poptGetArg(pc);
+ if (arg_channel_list == NULL) {
+ ERR("Missing channel name.");
+ ret = CMD_ERROR;
+ success = 0;
+ goto mi_closing;
+ }
+
+ channel_list = strdup(arg_channel_list);
+ if (channel_list == NULL) {
+ PERROR("Failed to copy channel name");
ret = CMD_ERROR;
success = 0;
goto mi_closing;
ret = CMD_ERROR;
success = 0;
goto mi_closing;
session_name = opt_session_name;
}
session_name = opt_session_name;
}
- command_ret = enable_channel(session_name);
+ command_ret = enable_channel(session_name, channel_list);
if (command_ret) {
success = 0;
}
if (command_ret) {
success = 0;
}
/* Overwrite ret if an error occurred when enable_channel */
ret = command_ret ? command_ret : ret;
poptFreeContext(pc);
/* Overwrite ret if an error occurred when enable_channel */
ret = command_ret ? command_ret : ret;
poptFreeContext(pc);
#define LTTNG_SYMBOL_NAME_LEN_SCANF_IS_A_BROKEN_API "255"
#endif
#define LTTNG_SYMBOL_NAME_LEN_SCANF_IS_A_BROKEN_API "255"
#endif
-static char *opt_event_list;
static int opt_event_type;
static const char *opt_loglevel;
static int opt_loglevel_type;
static int opt_event_type;
static const char *opt_loglevel;
static int opt_loglevel_type;
* Enabling event using the lttng API.
* Note: in case of error only the last error code will be return.
*/
* Enabling event using the lttng API.
* Note: in case of error only the last error code will be return.
*/
-static int enable_events(char *session_name)
+static int enable_events(char *session_name, char *event_list)
{
int ret = CMD_SUCCESS, command_ret = CMD_SUCCESS;
int error_holder = CMD_SUCCESS, warn = 0, error = 0, success = 1;
{
int ret = CMD_SUCCESS, command_ret = CMD_SUCCESS;
int error_holder = CMD_SUCCESS, warn = 0, error = 0, success = 1;
- event_name = strtok(opt_event_list, ",");
+ event_name = strtok(event_list, ",");
while (event_name != NULL) {
/* Copy name and type of the event */
strncpy(ev->name, event_name, LTTNG_SYMBOL_NAME_LEN);
while (event_name != NULL) {
/* Copy name and type of the event */
strncpy(ev->name, event_name, LTTNG_SYMBOL_NAME_LEN);
int opt, ret = CMD_SUCCESS, command_ret = CMD_SUCCESS, success = 1;
static poptContext pc;
char *session_name = NULL;
int opt, ret = CMD_SUCCESS, command_ret = CMD_SUCCESS, success = 1;
static poptContext pc;
char *session_name = NULL;
+ char *event_list = NULL;
+ const char *arg_event_list = NULL;
const char *leftover = NULL;
int event_type = -1;
const char *leftover = NULL;
int event_type = -1;
- opt_event_list = (char*) poptGetArg(pc);
- if (opt_event_list == NULL && opt_enable_all == 0) {
- ERR("Missing event name(s).\n");
+ arg_event_list = poptGetArg(pc);
+ if (arg_event_list == NULL && opt_enable_all == 0) {
+ ERR("Missing event name(s).");
ret = CMD_ERROR;
goto end;
}
ret = CMD_ERROR;
goto end;
}
+ if (opt_enable_all == 0) {
+ event_list = strdup(arg_event_list);
+ if (event_list == NULL) {
+ PERROR("Failed to copy event name(s)");
+ ret = CMD_ERROR;
+ goto end;
+ }
+ }
+
leftover = poptGetArg(pc);
if (leftover) {
ERR("Unknown argument: %s", leftover);
leftover = poptGetArg(pc);
if (leftover) {
ERR("Unknown argument: %s", leftover);
session_name = opt_session_name;
}
session_name = opt_session_name;
}
- command_ret = enable_events(session_name);
+ command_ret = enable_events(session_name, event_list);
if (command_ret) {
success = 0;
goto mi_closing;
if (command_ret) {
success = 0;
goto mi_closing;
/* Overwrite ret if an error occurred in enable_events */
ret = command_ret ? command_ret : ret;
/* Overwrite ret if an error occurred in enable_events */
ret = command_ret ? command_ret : ret;
int cmd_help(int argc, const char **argv, const struct cmd_struct commands[])
{
int opt, ret = CMD_SUCCESS;
int cmd_help(int argc, const char **argv, const struct cmd_struct commands[])
{
int opt, ret = CMD_SUCCESS;
+ const char *arg_cmd_name;
static poptContext pc;
const struct cmd_struct *cmd;
int found = 0;
static poptContext pc;
const struct cmd_struct *cmd;
int found = 0;
- cmd_name = (char *) poptGetArg(pc);
-
- if (cmd_name == NULL) {
+ arg_cmd_name = poptGetArg(pc);
+ if (arg_cmd_name == NULL) {
/* Fall back to lttng(1) */
ret = utils_show_help(1, "lttng", lttng_help_msg);
if (ret) {
/* Fall back to lttng(1) */
ret = utils_show_help(1, "lttng", lttng_help_msg);
if (ret) {
- if (strcmp(cmd_name, "help") == 0) {
+ if (strcmp(arg_cmd_name, "help") == 0) {
cmd = &commands[0];
while (cmd->name != NULL) {
cmd = &commands[0];
while (cmd->name != NULL) {
- if (strcmp(cmd->name, cmd_name) == 0) {
+ if (strcmp(cmd->name, arg_cmd_name) == 0) {
- ERR("Unknown command \"%s\"", cmd_name);
+ ERR("Unknown command \"%s\"", arg_cmd_name);
ret = CMD_ERROR;
goto end;
}
ret = CMD_ERROR;
goto end;
}
int cmd_list(int argc, const char **argv)
{
int opt, ret = CMD_SUCCESS;
int cmd_list(int argc, const char **argv)
{
int opt, ret = CMD_SUCCESS;
- const char *session_name, *leftover = NULL;
+ const char *arg_session_name, *leftover = NULL;
static poptContext pc;
struct lttng_domain domain;
struct lttng_domain *domains = NULL;
static poptContext pc;
struct lttng_domain domain;
struct lttng_domain *domains = NULL;
}
/* Get session name (trailing argument) */
}
/* Get session name (trailing argument) */
- session_name = poptGetArg(pc);
- DBG2("Session name: %s", session_name);
+ arg_session_name = poptGetArg(pc);
+ DBG2("Session name: %s", arg_session_name);
leftover = poptGetArg(pc);
if (leftover) {
leftover = poptGetArg(pc);
if (leftover) {
}
if (opt_kernel || opt_userspace || opt_jul || opt_log4j || opt_python) {
}
if (opt_kernel || opt_userspace || opt_jul || opt_log4j || opt_python) {
- the_handle = lttng_create_handle(session_name, &domain);
+ the_handle = lttng_create_handle(arg_session_name, &domain);
if (the_handle == NULL) {
ret = CMD_FATAL;
goto end;
}
}
if (the_handle == NULL) {
ret = CMD_FATAL;
goto end;
}
}
- if (session_name == NULL) {
+ if (arg_session_name == NULL) {
if (!opt_kernel && !opt_userspace && !opt_jul && !opt_log4j
&& !opt_python) {
ret = list_sessions(NULL);
if (!opt_kernel && !opt_userspace && !opt_jul && !opt_log4j
&& !opt_python) {
ret = list_sessions(NULL);
}
}
/* MI: the ouptut of list_sessions is an unclosed session element */
}
}
/* MI: the ouptut of list_sessions is an unclosed session element */
- ret = list_sessions(session_name);
+ ret = list_sessions(arg_session_name);
- ret = list_rotate_settings(session_name);
+ ret = list_rotate_settings(arg_session_name);
if (ret) {
goto end;
}
/* Domain listing */
if (opt_domain) {
if (ret) {
goto end;
}
/* Domain listing */
if (opt_domain) {
- ret = list_domains(session_name);
+ ret = list_domains(arg_session_name);
int i, nb_domain;
/* We want all domain(s) */
int i, nb_domain;
/* We want all domain(s) */
- nb_domain = lttng_list_domains(session_name, &domains);
+ nb_domain = lttng_list_domains(arg_session_name, &domains);
if (nb_domain < 0) {
ret = CMD_ERROR;
ERR("%s", lttng_strerror(nb_domain));
if (nb_domain < 0) {
ret = CMD_ERROR;
ERR("%s", lttng_strerror(nb_domain));
}
the_handle = lttng_create_handle(
}
the_handle = lttng_create_handle(
- session_name, &domains[i]);
+ arg_session_name, &domains[i]);
if (the_handle == NULL) {
ret = CMD_FATAL;
goto end;
if (the_handle == NULL) {
ret = CMD_FATAL;
goto end;
#include "../command.hpp"
#include <lttng/lttng.h>
#include "../command.hpp"
#include <lttng/lttng.h>
-static char *opt_session_name;
static int opt_no_wait;
static struct mi_writer *writer;
static int opt_no_wait;
static struct mi_writer *writer;
enum cmd_error_code cmd_ret = CMD_SUCCESS;
int popt_ret;
static poptContext pc;
enum cmd_error_code cmd_ret = CMD_SUCCESS;
int popt_ret;
static poptContext pc;
+ const char *arg_session_name = NULL;
char *session_name = NULL;
char *session_name = NULL;
- bool free_session_name = false;
pc = poptGetContext(NULL, argc, argv, long_options, 0);
popt_ret = poptReadDefaultConfig(pc, 0);
if (popt_ret) {
ERR("poptReadDefaultConfig");
pc = poptGetContext(NULL, argc, argv, long_options, 0);
popt_ret = poptReadDefaultConfig(pc, 0);
if (popt_ret) {
ERR("poptReadDefaultConfig");
+ cmd_ret = CMD_ERROR;
+ goto end;
}
while ((opt = poptGetNextOpt(pc)) != -1) {
}
while ((opt = poptGetNextOpt(pc)) != -1) {
- opt_session_name = (char*) poptGetArg(pc);
-
- if (!opt_session_name) {
+ arg_session_name = poptGetArg(pc);
+ if (arg_session_name == NULL) {
session_name = get_session_name();
session_name = get_session_name();
- if (!session_name) {
- goto error;
- }
- free_session_name = true;
- session_name = opt_session_name;
+ session_name = strdup(arg_session_name);
+ if (session_name == NULL) {
+ PERROR("Failed to copy session name");
+ }
+ }
+
+ if (session_name == NULL) {
+ cmd_ret = CMD_ERROR;
+ goto end;
}
/* Mi check */
if (lttng_opt_mi) {
writer = mi_lttng_writer_create(fileno(stdout), lttng_opt_mi);
if (!writer) {
}
/* Mi check */
if (lttng_opt_mi) {
writer = mi_lttng_writer_create(fileno(stdout), lttng_opt_mi);
if (!writer) {
+ cmd_ret = CMD_ERROR;
+ goto end;
}
/* Open rotate command */
ret = mi_lttng_writer_command_open(writer,
mi_lttng_element_command_rotate);
if (ret) {
}
/* Open rotate command */
ret = mi_lttng_writer_command_open(writer,
mi_lttng_element_command_rotate);
if (ret) {
+ cmd_ret = CMD_ERROR;
+ goto end;
}
/* Open output element */
ret = mi_lttng_writer_open_element(writer,
mi_lttng_element_command_output);
if (ret) {
}
/* Open output element */
ret = mi_lttng_writer_open_element(writer,
mi_lttng_element_command_output);
if (ret) {
+ cmd_ret = CMD_ERROR;
+ goto end;
/* Close output element */
ret = mi_lttng_writer_close_element(writer);
if (ret) {
/* Close output element */
ret = mi_lttng_writer_close_element(writer);
if (ret) {
+ cmd_ret = CMD_ERROR;
+ goto end;
}
/* Success ? */
ret = mi_lttng_writer_write_element_bool(writer,
mi_lttng_element_command_success,
cmd_ret == CMD_SUCCESS);
if (ret) {
}
/* Success ? */
ret = mi_lttng_writer_write_element_bool(writer,
mi_lttng_element_command_success,
cmd_ret == CMD_SUCCESS);
if (ret) {
+ cmd_ret = CMD_ERROR;
+ goto end;
}
/* Command element close */
ret = mi_lttng_writer_command_close(writer);
if (ret) {
}
/* Command element close */
ret = mi_lttng_writer_command_close(writer);
if (ret) {
+ cmd_ret = CMD_ERROR;
+ goto end;
}
}
/* Mi clean-up */
if (writer && mi_lttng_writer_destroy(writer)) {
}
}
/* Mi clean-up */
if (writer && mi_lttng_writer_destroy(writer)) {
+ cmd_ret = CMD_ERROR;
+ goto end;
- if (free_session_name) {
- free(session_name);
- }
-error:
- cmd_ret = CMD_ERROR;
- goto end;
{
int ret = CMD_SUCCESS, command_ret = CMD_SUCCESS, success;
int opt;
{
int ret = CMD_SUCCESS, command_ret = CMD_SUCCESS, success;
int opt;
- const char *session_name = NULL, *leftover = NULL;
+ const char *arg_session_name = NULL, *leftover = NULL;
poptContext pc;
struct lttng_save_session_attr *attr;
poptContext pc;
struct lttng_save_session_attr *attr;
- session_name = poptGetArg(pc);
- if (session_name) {
- DBG2("Session name: %s", session_name);
+ arg_session_name = poptGetArg(pc);
+ if (arg_session_name) {
+ DBG2("Session name: %s", arg_session_name);
} else {
/* default to opt_save_all */
opt_save_all = true;
} else {
/* default to opt_save_all */
opt_save_all = true;
- if (lttng_save_session_attr_set_session_name(attr, session_name)) {
+ if (lttng_save_session_attr_set_session_name(attr, arg_session_name)) {
ret = CMD_ERROR;
goto end_destroy;
}
ret = CMD_ERROR;
goto end_destroy;
}
success = 0;
} else {
/* Inform the user of what just happened on success. */
success = 0;
} else {
/* Inform the user of what just happened on success. */
- if (session_name && opt_output_path) {
- MSG("Session %s saved successfully in %s.", session_name,
+ if (arg_session_name && opt_output_path) {
+ MSG("Session %s saved successfully in %s.", arg_session_name,
- } else if (session_name && !opt_output_path) {
- MSG("Session %s saved successfully.", session_name);
- } else if (!session_name && opt_output_path) {
+ } else if (arg_session_name && !opt_output_path) {
+ MSG("Session %s saved successfully.", arg_session_name);
+ } else if (!arg_session_name && opt_output_path) {
MSG("All sessions have been saved successfully in %s.",
opt_output_path);
} else {
MSG("All sessions have been saved successfully in %s.",
opt_output_path);
} else {
/* Mi Printing and closing */
if (lttng_opt_mi) {
/* Mi print */
/* Mi Printing and closing */
if (lttng_opt_mi) {
/* Mi print */
- ret = mi_save_print(session_name);
+ ret = mi_save_print(arg_session_name);
if (ret) {
ret = CMD_ERROR;
goto end_destroy;
if (ret) {
ret = CMD_ERROR;
goto end_destroy;
#include "../command.hpp"
#include "../command.hpp"
-static char *opt_session_name;
-
#ifdef LTTNG_EMBED_HELP
static const char help_msg[] =
#include <lttng-set-session.1.h>
#ifdef LTTNG_EMBED_HELP
static const char help_msg[] =
#include <lttng-set-session.1.h>
/*
* Print the necessary mi for a session and name.
*/
/*
* Print the necessary mi for a session and name.
*/
-static int mi_print(char *session_name)
+static int mi_print(const char *session_name)
-static int set_session(void)
+static int set_session(const char *session_name)
{
int ret = CMD_SUCCESS;
int count, i;
unsigned int session_found = 0;
struct lttng_session *sessions;
{
int ret = CMD_SUCCESS;
int count, i;
unsigned int session_found = 0;
struct lttng_session *sessions;
- if (opt_session_name && strlen(opt_session_name) > NAME_MAX) {
+ if (session_name && strlen(session_name) > NAME_MAX) {
ERR("Session name too long. Length must be lower or equal to %d",
NAME_MAX);
ret = CMD_ERROR;
ERR("Session name too long. Length must be lower or equal to %d",
NAME_MAX);
ret = CMD_ERROR;
}
for (i = 0; i < count; i++) {
}
for (i = 0; i < count; i++) {
- if (strncmp(sessions[i].name, opt_session_name, NAME_MAX) == 0) {
+ if (strncmp(sessions[i].name, session_name, NAME_MAX) == 0) {
session_found = 1;
break;
}
}
if (!session_found) {
session_found = 1;
break;
}
}
if (!session_found) {
- ERR("Session '%s' not found", opt_session_name);
+ ERR("Session '%s' not found", session_name);
ret = CMD_ERROR;
goto error;
}
ret = CMD_ERROR;
goto error;
}
- ret = config_init(opt_session_name);
+ ret = config_init(session_name);
if (ret < 0) {
ERR("Unable to set session name");
ret = CMD_ERROR;
goto error;
}
if (ret < 0) {
ERR("Unable to set session name");
ret = CMD_ERROR;
goto error;
}
- MSG("Session set to %s", opt_session_name);
+ MSG("Session set to %s", session_name);
- ret = mi_print(opt_session_name);
+ ret = mi_print(session_name);
if (ret) {
ret = CMD_ERROR;
goto error;
if (ret) {
ret = CMD_ERROR;
goto error;
{
int opt, ret = CMD_SUCCESS, command_ret = CMD_SUCCESS, success = 1;
static poptContext pc;
{
int opt, ret = CMD_SUCCESS, command_ret = CMD_SUCCESS, success = 1;
static poptContext pc;
+ const char *arg_session_name = NULL;
pc = poptGetContext(NULL, argc, argv, long_options, 0);
poptReadDefaultConfig(pc, 0);
pc = poptGetContext(NULL, argc, argv, long_options, 0);
poptReadDefaultConfig(pc, 0);
- opt_session_name = (char *) poptGetArg(pc);
- if (opt_session_name == NULL) {
+ arg_session_name = poptGetArg(pc);
+ if (arg_session_name == NULL) {
ERR("Missing session name");
ret = CMD_ERROR;
goto end;
ERR("Missing session name");
ret = CMD_ERROR;
goto end;
- command_ret = set_session();
+ command_ret = set_session(arg_session_name);
if (command_ret) {
success = 0;
}
if (command_ret) {
success = 0;
}
#include "../command.hpp"
#include "../command.hpp"
-static char *opt_session_name;
static struct mi_writer *writer;
#ifdef LTTNG_EMBED_HELP
static struct mi_writer *writer;
#ifdef LTTNG_EMBED_HELP
*
* Start tracing for all trace of the session.
*/
*
* Start tracing for all trace of the session.
*/
-static int start_tracing(void)
+static int start_tracing(const char *arg_session_name)
{
int ret;
char *session_name;
{
int ret;
char *session_name;
- if (opt_session_name == NULL) {
+ if (arg_session_name == NULL) {
session_name = get_session_name();
session_name = get_session_name();
+ } else {
+ session_name = strdup(arg_session_name);
if (session_name == NULL) {
if (session_name == NULL) {
- ret = CMD_ERROR;
- goto error;
+ PERROR("Failed to copy session name");
- } else {
- session_name = opt_session_name;
+ }
+
+ if (session_name == NULL) {
+ ret = CMD_ERROR;
+ goto error;
}
DBG("Starting tracing for session %s", session_name);
}
DBG("Starting tracing for session %s", session_name);
- if (opt_session_name == NULL) {
- free(session_name);
- }
{
int opt, ret = CMD_SUCCESS, command_ret = CMD_SUCCESS, success = 1;
static poptContext pc;
{
int opt, ret = CMD_SUCCESS, command_ret = CMD_SUCCESS, success = 1;
static poptContext pc;
+ const char *arg_session_name = NULL;
const char *leftover = NULL;
pc = poptGetContext(NULL, argc, argv, long_options, 0);
const char *leftover = NULL;
pc = poptGetContext(NULL, argc, argv, long_options, 0);
- opt_session_name = (char*) poptGetArg(pc);
+ arg_session_name = poptGetArg(pc);
leftover = poptGetArg(pc);
if (leftover) {
leftover = poptGetArg(pc);
if (leftover) {
- command_ret = start_tracing();
+ command_ret = start_tracing(arg_session_name);
if (command_ret) {
success = 0;
}
if (command_ret) {
success = 0;
}
#include "../command.hpp"
#include "../command.hpp"
-static char *opt_session_name;
static int opt_no_wait;
static struct mi_writer *writer;
static int opt_no_wait;
static struct mi_writer *writer;
/*
* Start tracing for all trace of the session.
*/
/*
* Start tracing for all trace of the session.
*/
-static int stop_tracing(void)
+static int stop_tracing(const char *arg_session_name)
{
int ret;
char *session_name;
{
int ret;
char *session_name;
- if (opt_session_name == NULL) {
+ if (arg_session_name == NULL) {
session_name = get_session_name();
session_name = get_session_name();
+ } else {
+ session_name = strdup(arg_session_name);
if (session_name == NULL) {
if (session_name == NULL) {
- ret = CMD_ERROR;
- goto error;
+ PERROR("Failed to copy session name");
- } else {
- session_name = opt_session_name;
+ }
+
+ if (session_name == NULL) {
+ ret = CMD_ERROR;
+ goto error;
}
ret = lttng_stop_tracing_no_wait(session_name);
}
ret = lttng_stop_tracing_no_wait(session_name);
- if (opt_session_name == NULL) {
- free(session_name);
- }
{
int opt, ret = CMD_SUCCESS, command_ret = CMD_SUCCESS, success = 1;
static poptContext pc;
{
int opt, ret = CMD_SUCCESS, command_ret = CMD_SUCCESS, success = 1;
static poptContext pc;
+ const char *arg_session_name = NULL;
const char *leftover = NULL;
pc = poptGetContext(NULL, argc, argv, long_options, 0);
const char *leftover = NULL;
pc = poptGetContext(NULL, argc, argv, long_options, 0);
- opt_session_name = (char*) poptGetArg(pc);
+ arg_session_name = poptGetArg(pc);
leftover = poptGetArg(pc);
if (leftover) {
leftover = poptGetArg(pc);
if (leftover) {
- command_ret = stop_tracing();
+ command_ret = stop_tracing(arg_session_name);
if (command_ret) {
success = 0;
}
if (command_ret) {
success = 0;
}
#include <common/spawn-viewer.hpp>
#include "../command.hpp"
#include <common/spawn-viewer.hpp>
#include "../command.hpp"
-static char *opt_session_name;
static char *opt_viewer;
static char *opt_trace_path;
static char *opt_viewer;
static char *opt_trace_path;
/*
* Exec viewer if found and use session name path.
*/
/*
* Exec viewer if found and use session name path.
*/
-static int view_trace(void)
+static int view_trace(const char *arg_session_name)
{
int ret;
char *session_name, *trace_path = NULL;
{
int ret;
char *session_name, *trace_path = NULL;
/* User define trace path override the session name */
if (opt_trace_path) {
session_name = NULL;
/* User define trace path override the session name */
if (opt_trace_path) {
session_name = NULL;
- } else if(opt_session_name == NULL) {
- session_name = get_session_name();
+ } else {
+ if (arg_session_name == NULL) {
+ session_name = get_session_name();
+ } else {
+ session_name = strdup(arg_session_name);
+ if (session_name == NULL) {
+ PERROR("Failed to copy session name");
+ }
+ }
+
if (session_name == NULL) {
ret = CMD_ERROR;
goto error;
}
if (session_name == NULL) {
ret = CMD_ERROR;
goto error;
}
- } else {
- session_name = opt_session_name;
}
DBG("Viewing trace for session %s", session_name);
}
DBG("Viewing trace for session %s", session_name);
}
free(sessions);
free_error:
}
free(sessions);
free_error:
- if (opt_session_name == NULL) {
- free(session_name);
- }
{
int opt, ret = CMD_SUCCESS;
static poptContext pc;
{
int opt, ret = CMD_SUCCESS;
static poptContext pc;
+ const char *arg_session_name = NULL;
const char *leftover = NULL;
pc = poptGetContext(NULL, argc, argv, long_options, 0);
const char *leftover = NULL;
pc = poptGetContext(NULL, argc, argv, long_options, 0);
- opt_session_name = (char*) poptGetArg(pc);
+ arg_session_name = poptGetArg(pc);
leftover = poptGetArg(pc);
if (leftover) {
leftover = poptGetArg(pc);
if (leftover) {
+ ret = view_trace(arg_session_name);
end:
poptFreeContext(pc);
end:
poptFreeContext(pc);