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;
- bool free_session_name = false;
struct lttng_session *sessions = NULL;
int count;
int found;
}
if (!opt_clear_all) {
- 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();
+ } else {
+ session_name = strdup(arg_session_name);
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);
}
free(sessions);
- if (free_session_name) {
- free(session_name);
- }
+ free(session_name);
/* 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;
-static char *opt_session_name;
static char *opt_url;
static char *opt_ctrl_url;
static char *opt_data_url;
}
static
-struct lttng_session_descriptor *create_session_descriptor(void)
+struct lttng_session_descriptor *create_session_descriptor(const char *session_name)
{
int ret;
ssize_t uri_count;
case OUTPUT_UNSPECIFIED:
case OUTPUT_LOCAL:
descriptor = lttng_session_descriptor_snapshot_local_create(
- opt_session_name,
+ session_name,
output_type == OUTPUT_LOCAL ?
local_output_path : NULL);
break;
case OUTPUT_NONE:
descriptor = lttng_session_descriptor_snapshot_create(
- opt_session_name);
+ session_name);
break;
case OUTPUT_NETWORK:
descriptor = lttng_session_descriptor_snapshot_network_create(
- opt_session_name, uri_str1, uri_str2);
+ session_name, uri_str1, uri_str2);
break;
default:
abort();
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. */
case OUTPUT_UNSPECIFIED:
case OUTPUT_LOCAL:
descriptor = lttng_session_descriptor_local_create(
- opt_session_name,
+ session_name,
output_type == OUTPUT_LOCAL ?
local_output_path : NULL);
break;
case OUTPUT_NONE:
descriptor = lttng_session_descriptor_create(
- opt_session_name);
+ session_name);
break;
case OUTPUT_NETWORK:
descriptor = lttng_session_descriptor_network_create(
- opt_session_name, uri_str1, uri_str2);
+ session_name, uri_str1, uri_str2);
break;
default:
abort();
*
* 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] = {};
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;
* 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) ||
- (strncmp(opt_session_name, DEFAULT_SESSION_NAME,
+ (strncmp(session_name, DEFAULT_SESSION_NAME,
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;
goto error;
}
- session_descriptor = create_session_descriptor();
+ session_descriptor = create_session_descriptor(session_name);
if (!session_descriptor) {
ret = CMD_ERROR;
goto error;
* An auto-generated session name already includes the creation
* timestamp.
*/
- if (opt_session_name) {
+ if (session_name) {
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;
+ const char *arg_session_name = NULL;
const char *leftover = NULL;
static poptContext pc;
goto end;
}
}
- opt_session_name = (char*) poptGetArg(pc);
+
+ /* Get the optional session name argument. */
+ arg_session_name = poptGetArg(pc);
leftover = poptGetArg(pc);
if (leftover) {
goto end;
}
- command_ret = create_session();
+ command_ret = create_session(arg_session_name);
if (command_ret) {
success = 0;
}
#include <common/sessiond-comm/sessiond-comm.h>
#include <common/utils.h>
-static char *opt_session_name;
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;
+ const char *arg_session_name = NULL;
const char *leftover = NULL;
struct lttng_session *sessions = NULL;
success = 0;
}
} else {
- 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();
+ } else {
+ session_name = strdup(arg_session_name);
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 */
ret = ret ? ret : -LTTNG_ERR_MI_IO_FAIL;
}
- if (opt_session_name == NULL) {
- free(session_name);
- }
-
+ free(session_name);
free(sessions);
/* Overwrite ret if an error occurred during destroy_session/all */
#include "../command.h"
-static char *opt_channels;
static int opt_kernel;
static char *opt_session_name;
static int opt_userspace;
/*
* 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;
}
/* Strip channel list */
- channel_name = strtok(opt_channels, ",");
+ channel_name = strtok(channel_list, ",");
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;
+ char *channel_list = NULL;
+ const char *arg_channel_list = NULL;
const char *leftover = NULL;
pc = poptGetContext(NULL, argc, argv, long_options, 0);
goto end;
}
- 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;
}
}
}
- command_ret = disable_channels(session_name);
+ command_ret = disable_channels(session_name, channel_list);
if (command_ret) {
success = 0;
}
free(session_name);
}
+ free(channel_list);
+
/* Overwrite ret if an error occurred in disable_channels */
ret = command_ret ? command_ret : ret;
#include "../command.h"
-static char *opt_event_list;
static int opt_kernel;
static char *opt_channel_name;
static char *opt_session_name;
*
* 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;
}
} 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);
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;
goto end;
}
- 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;
}
+ 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);
}
}
- command_ret = disable_events(session_name);
+ command_ret = disable_events(session_name, event_list);
if (command_ret) {
success = 0;
}
free(session_name);
}
+ free(event_list);
+
/* Mi clean-up */
if (writer && mi_lttng_writer_destroy(writer)) {
/* Preserve original error code */
static struct lttng_channel chan_opts;
-static char *opt_channels;
static int opt_kernel;
static char *opt_session_name;
static int opt_userspace;
/*
* 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;
}
/* Strip channel list (format: chan1,chan2,...) */
- channel_name = strtok(opt_channels, ",");
+ channel_name = strtok(channel_list, ",");
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;
+ char *channel_list = NULL;
char *opt_arg = NULL;
+ const char *arg_channel_list = NULL;
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;
session_name = opt_session_name;
}
- command_ret = enable_channel(session_name);
+ command_ret = enable_channel(session_name, channel_list);
if (command_ret) {
success = 0;
}
free(session_name);
}
+ free(channel_list);
+
/* 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
-static char *opt_event_list;
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.
*/
-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;
}
/* Strip event list */
- 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);
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;
}
}
- 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;
}
+ 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);
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;
free(session_name);
}
+ free(event_list);
+
/* 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;
- char *cmd_name;
+ const char *arg_cmd_name;
static poptContext pc;
const struct cmd_struct *cmd;
int found = 0;
}
/* Get command name */
- 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) {
}
/* Help about help? */
- if (strcmp(cmd_name, "help") == 0) {
+ if (strcmp(arg_cmd_name, "help") == 0) {
SHOW_HELP();
goto end;
}
cmd = &commands[0];
while (cmd->name != NULL) {
- if (strcmp(cmd->name, cmd_name) == 0) {
+ if (strcmp(cmd->name, arg_cmd_name) == 0) {
found = 1;
break;
}
}
if (!found) {
- ERR("Unknown command \"%s\"", cmd_name);
+ ERR("Unknown command \"%s\"", arg_cmd_name);
ret = CMD_ERROR;
goto end;
}
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;
}
/* 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) {
}
if (opt_kernel || opt_userspace || opt_jul || opt_log4j || opt_python) {
- handle = lttng_create_handle(session_name, &domain);
+ handle = lttng_create_handle(arg_session_name, &domain);
if (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);
}
}
/* MI: the ouptut of list_sessions is an unclosed session element */
- ret = list_sessions(session_name);
+ ret = list_sessions(arg_session_name);
if (ret) {
goto end;
}
- ret = list_rotate_settings(session_name);
+ ret = list_rotate_settings(arg_session_name);
if (ret) {
goto end;
}
/* Domain listing */
if (opt_domain) {
- ret = list_domains(session_name);
+ ret = list_domains(arg_session_name);
goto end;
}
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));
lttng_destroy_handle(handle);
}
- handle = lttng_create_handle(session_name, &domains[i]);
+ handle = lttng_create_handle(arg_session_name, &domains[i]);
if (handle == NULL) {
ret = CMD_FATAL;
goto end;
#include <lttng/rotation.h>
#include <lttng/location.h>
-static char *opt_session_name;
static int opt_no_wait;
static struct mi_writer *writer;
enum cmd_error_code cmd_ret = CMD_SUCCESS;
int popt_ret;
static poptContext pc;
+ const char *arg_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");
- goto error;
+ cmd_ret = CMD_ERROR;
+ goto end;
}
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();
- if (!session_name) {
- goto error;
- }
- free_session_name = true;
} else {
- 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) {
- goto error;
+ cmd_ret = CMD_ERROR;
+ goto end;
}
/* Open rotate command */
ret = mi_lttng_writer_command_open(writer,
mi_lttng_element_command_rotate);
if (ret) {
- goto error;
+ cmd_ret = CMD_ERROR;
+ goto end;
}
/* Open output element */
ret = mi_lttng_writer_open_element(writer,
mi_lttng_element_command_output);
if (ret) {
- goto error;
+ cmd_ret = CMD_ERROR;
+ goto end;
}
}
/* Close output element */
ret = mi_lttng_writer_close_element(writer);
if (ret) {
- goto error;
+ 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) {
- goto error;
+ cmd_ret = CMD_ERROR;
+ goto end;
}
/* Command element close */
ret = mi_lttng_writer_command_close(writer);
if (ret) {
- goto error;
+ cmd_ret = CMD_ERROR;
+ goto end;
}
}
/* Mi clean-up */
if (writer && mi_lttng_writer_destroy(writer)) {
- goto error;
+ cmd_ret = CMD_ERROR;
+ goto end;
}
end:
+ free(session_name);
poptFreeContext(pc);
- if (free_session_name) {
- free(session_name);
- }
return cmd_ret;
-error:
- cmd_ret = CMD_ERROR;
- goto end;
}
{
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;
}
if (!opt_save_all) {
- 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;
goto end_destroy;
}
- 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;
}
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,
opt_output_path);
- } 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 {
/* 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;
#include "../command.h"
-static char *opt_session_name;
-
#ifdef LTTNG_EMBED_HELP
static const char help_msg[] =
#include <lttng-set-session.1.h>
/*
* Print the necessary mi for a session and name.
*/
-static int mi_print(char *session_name)
+static int mi_print(const char *session_name)
{
int ret;
/*
* set_session
*/
-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;
- 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;
}
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) {
- ERR("Session '%s' not found", opt_session_name);
+ ERR("Session '%s' not found", session_name);
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;
}
- MSG("Session set to %s", opt_session_name);
+ MSG("Session set to %s", session_name);
if (lttng_opt_mi) {
- ret = mi_print(opt_session_name);
+ ret = mi_print(session_name);
if (ret) {
ret = CMD_ERROR;
goto error;
{
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);
}
}
- 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;
}
}
- command_ret = set_session();
+ command_ret = set_session(arg_session_name);
if (command_ret) {
success = 0;
}
#include "../command.h"
-static char *opt_session_name;
static struct mi_writer *writer;
#ifdef LTTNG_EMBED_HELP
*
* 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;
- if (opt_session_name == NULL) {
+ if (arg_session_name == NULL) {
session_name = get_session_name();
+ } else {
+ session_name = strdup(arg_session_name);
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);
}
free_name:
- if (opt_session_name == NULL) {
- free(session_name);
- }
+ free(session_name);
error:
return ret;
}
{
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);
}
}
- opt_session_name = (char*) poptGetArg(pc);
+ arg_session_name = poptGetArg(pc);
leftover = poptGetArg(pc);
if (leftover) {
}
}
- command_ret = start_tracing();
+ command_ret = start_tracing(arg_session_name);
if (command_ret) {
success = 0;
}
#include "../command.h"
-static char *opt_session_name;
static int opt_no_wait;
static struct mi_writer *writer;
/*
* 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;
- if (opt_session_name == NULL) {
+ if (arg_session_name == NULL) {
session_name = get_session_name();
+ } else {
+ session_name = strdup(arg_session_name);
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);
}
free_name:
- if (opt_session_name == NULL) {
- free(session_name);
- }
+ free(session_name);
error:
return ret;
{
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);
}
}
- opt_session_name = (char*) poptGetArg(pc);
+ arg_session_name = poptGetArg(pc);
leftover = poptGetArg(pc);
if (leftover) {
goto end;
}
- command_ret = stop_tracing();
+ command_ret = stop_tracing(arg_session_name);
if (command_ret) {
success = 0;
}
#include <common/spawn-viewer.h>
#include "../command.h"
-static char *opt_session_name;
static char *opt_viewer;
static char *opt_trace_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;
/* 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;
}
- } else {
- session_name = opt_session_name;
}
DBG("Viewing trace for session %s", session_name);
}
free(sessions);
free_error:
- if (opt_session_name == NULL) {
- free(session_name);
- }
+ free(session_name);
error:
return ret;
}
{
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);
}
}
- opt_session_name = (char*) poptGetArg(pc);
+ arg_session_name = poptGetArg(pc);
leftover = poptGetArg(pc);
if (leftover) {
goto end;
}
- ret = view_trace();
+ ret = view_trace(arg_session_name);
end:
poptFreeContext(pc);