/*
- * Copyright (C) 2011 - David Goulet <david.goulet@polymtl.ca>
- * Copyright (C) 2019 - Jérémie Galarneau <jeremie.galarneau@efficios.com>
+ * Copyright (C) 2011 EfficiOS Inc.
+ * Copyright (C) 2019 Jérémie Galarneau <jeremie.galarneau@efficios.com>
*
- * 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/sessiond-comm/sessiond-comm.h>
#include <common/uri.h>
#include <common/utils.h>
-#include <lttng/snapshot.h>
-#include <lttng/session-descriptor.h>
+#include <common/path.h>
+#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;
enum output_type output_type;
struct lttng_uri *uris = NULL;
output_type = OUTPUT_NONE;
} else if (opt_output_path) {
char *expanded_output_path;
+ int ret;
output_type = OUTPUT_LOCAL;
expanded_output_path = utils_expand_path(opt_output_path);
goto end;
}
} else if (opt_url || opt_ctrl_url) {
+ int ret;
+
uri_str1 = opt_ctrl_url ? opt_ctrl_url : opt_url;
uri_str2 = opt_data_url;
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;
*
* Spawn a session daemon by forking and execv.
*/
-static int spawn_sessiond(char *pathname)
+static int spawn_sessiond(const char *pathname)
{
int ret = 0;
pid_t pid;
static int launch_sessiond(void)
{
int ret;
- char *pathname = NULL;
+ const char *pathname = NULL;
ret = lttng_session_daemon_alive();
if (ret) {
return ret;
}
+static
int validate_url_option_combination(void)
{
int ret = 0;
{
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;
uint64_t v;
errno = 0;
+ if (opt_arg) {
+ free(opt_arg);
+ opt_arg = NULL;
+ }
+
opt_arg = poptGetOptArg(pc);
if (!opt_arg) {
/* Set up default values. */
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;
}
/* Overwrite ret if an error occurred in create_session() */
ret = command_ret ? command_ret : ret;
+ free(opt_arg);
poptFreeContext(pc);
return ret;
}