#include <common/spawn-viewer.hpp>
#include "../command.hpp"
-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);