/*
- * Copyright (C) 2011 - David Goulet <david.goulet@polymtl.ca>
+ * Copyright (C) 2011 EfficiOS Inc.
*
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License, version 2 only,
- * as published by the Free Software Foundation.
+ * SPDX-License-Identifier: GPL-2.0-only
*
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License along
- * with this program; if not, write to the Free Software Foundation, Inc.,
- * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
#define _LGPL_SOURCE
#include <common/utils.h>
#include <common/mi-lttng.h>
+#include <lttng/domain-internal.h>
+
#include "../command.h"
#include "../utils.h"
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;
/* Validate channel name's length */
- if (strlen(channel_name) >= NAME_MAX) {
+ if (strlen(channel_name) >= sizeof(chan_opts.name)) {
ERR("Channel name is too long (max. %zu characters)",
sizeof(chan_opts.name) - 1);
error = 1;
}
} else {
MSG("%s channel %s enabled for session %s",
- get_domain_str(dom.type), channel_name, session_name);
+ lttng_domain_type_str(dom.type),
+ channel_name, session_name);
success = 1;
}
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();
ret = CMD_UNDEFINED;
goto end;
}
+
+ if (opt_arg) {
+ free(opt_arg);
+ opt_arg = NULL;
+ }
}
- ret = print_missing_or_multiple_domains(opt_kernel + opt_userspace);
+ ret = print_missing_or_multiple_domains(
+ opt_kernel + opt_userspace, false);
if (ret) {
ret = CMD_ERROR;
goto end;
}
}
- 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);
+ free(opt_arg);
return ret;
}