/*
- * Copyright (C) 2011 David Goulet <david.goulet@polymtl.ca>
+ * Copyright (C) 2011 EfficiOS Inc.
*
* SPDX-License-Identifier: GPL-2.0-only
*
*/
#define _LGPL_SOURCE
+#include "../command.hpp"
+
+#include <common/mi-lttng.hpp>
+#include <common/sessiond-comm/sessiond-comm.hpp>
+
#include <popt.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <unistd.h>
-#include <common/sessiond-comm/sessiond-comm.h>
-#include <common/mi-lttng.h>
-
-#include "../command.h"
-
-
-static char *opt_session_name;
static struct mi_writer *writer;
#ifdef LTTNG_EMBED_HELP
static const char help_msg[] =
#include <lttng-start.1.h>
-;
+ ;
#endif
enum {
static struct poptOption long_options[] = {
/* longName, shortName, argInfo, argPtr, value, descrip, argDesc */
- {"help", 'h', POPT_ARG_NONE, 0, OPT_HELP, 0, 0},
- {"list-options", 0, POPT_ARG_NONE, NULL, OPT_LIST_OPTIONS, NULL, NULL},
- {0, 0, 0, 0, 0, 0, 0}
+ { "help", 'h', POPT_ARG_NONE, nullptr, OPT_HELP, nullptr, nullptr },
+ { "list-options", 0, POPT_ARG_NONE, nullptr, OPT_LIST_OPTIONS, nullptr, nullptr },
+ { nullptr, 0, 0, nullptr, 0, nullptr, nullptr }
};
static int mi_print_session(char *session_name, int enabled)
}
/* Print session name element */
- ret = mi_lttng_writer_write_element_string(writer, config_element_name,
- session_name);
+ ret = mi_lttng_writer_write_element_string(writer, config_element_name, session_name);
if (ret) {
goto end;
}
- ret = mi_lttng_writer_write_element_bool(writer, config_element_enabled,
- enabled);
+ ret = mi_lttng_writer_write_element_bool(writer, config_element_enabled, enabled);
if (ret) {
goto end;
}
*
* 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 == nullptr) {
session_name = get_session_name();
- if (session_name == NULL) {
- ret = CMD_ERROR;
- goto error;
- }
} else {
- session_name = opt_session_name;
+ session_name = strdup(arg_session_name);
+ if (session_name == nullptr) {
+ PERROR("Failed to copy session name");
+ }
+ }
+
+ if (session_name == nullptr) {
+ 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 *leftover = NULL;
+ const char *arg_session_name = nullptr;
+ const char *leftover = nullptr;
- pc = poptGetContext(NULL, argc, argv, long_options, 0);
+ pc = poptGetContext(nullptr, argc, argv, long_options, 0);
poptReadDefaultConfig(pc, 0);
while ((opt = poptGetNextOpt(pc)) != -1) {
}
}
- opt_session_name = (char*) poptGetArg(pc);
+ arg_session_name = poptGetArg(pc);
leftover = poptGetArg(pc);
if (leftover) {
}
/* Open command element */
- ret = mi_lttng_writer_command_open(writer,
- mi_lttng_element_command_start);
+ ret = mi_lttng_writer_command_open(writer, mi_lttng_element_command_start);
if (ret) {
ret = CMD_ERROR;
goto end;
}
/* Open output element */
- ret = mi_lttng_writer_open_element(writer,
- mi_lttng_element_command_output);
+ ret = mi_lttng_writer_open_element(writer, mi_lttng_element_command_output);
if (ret) {
ret = CMD_ERROR;
goto end;
* Open sessions element
* For validation purpose
*/
- ret = mi_lttng_writer_open_element(writer,
- config_element_sessions);
+ ret = mi_lttng_writer_open_element(writer, config_element_sessions);
if (ret) {
ret = CMD_ERROR;
goto end;
}
}
- command_ret = start_tracing();
+ command_ret = start_tracing(arg_session_name);
if (command_ret) {
success = 0;
}
}
/* Success ? */
- ret = mi_lttng_writer_write_element_bool(writer,
- mi_lttng_element_command_success, success);
+ ret = mi_lttng_writer_write_element_bool(
+ writer, mi_lttng_element_command_success, success);
if (ret) {
ret = CMD_ERROR;
goto end;