*/
#define _LGPL_SOURCE
+#include "../command.hpp"
+
+#include <common/mi-lttng.hpp>
+
#include <popt.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <unistd.h>
-#include <common/mi-lttng.hpp>
-
-#include "../command.hpp"
-
-static char *opt_session_name;
-
#ifdef LTTNG_EMBED_HELP
static const char help_msg[] =
#include <lttng-set-session.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 }
};
/*
* 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;
}
/* Session name */
- 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;
}
/*
* 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) {
- ERR("Session name too long. Length must be lower or equal to %d",
- 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;
goto end;
}
}
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 = 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);
- if (opt_session_name == NULL) {
+ arg_session_name = poptGetArg(pc);
+ if (arg_session_name == nullptr) {
ERR("Missing session name");
ret = CMD_ERROR;
goto end;
}
/* Open command element */
- ret = mi_lttng_writer_command_open(writer,
- mi_lttng_element_command_set_session);
+ ret = mi_lttng_writer_command_open(writer, mi_lttng_element_command_set_session);
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;
}
}
- command_ret = set_session();
+ command_ret = set_session(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;