Force usage of assert() condition when NDEBUG is defined
[lttng-tools.git] / src / bin / lttng / commands / create.c
index a7d2d89bece3a4bdefa83f8712dd329a6afb39b0..b266c10a9397a8e250c0c156a5d7e2fef547db46 100644 (file)
@@ -1,23 +1,12 @@
 /*
- * Copyright (C) 2011 David Goulet <david.goulet@polymtl.ca>
- * Copyright (C) 2019 Jérémie Galarneau <jeremie.galarneau@efficios.com>
+ * Copyright (C) 2011 David Goulet <david.goulet@polymtl.ca>
+ * 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 <assert.h>
 #include <ctype.h>
 #include <popt.h>
 #include <stdio.h>
@@ -39,8 +28,7 @@
 #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 <lttng/lttng.h>
 
 static char *opt_output_path;
 static char *opt_session_name;
@@ -100,8 +88,8 @@ static int mi_created_session(const char *session_name)
        struct lttng_session *sessions;
 
        /* session_name should not be null */
-       assert(session_name);
-       assert(writer);
+       LTTNG_ASSERT(session_name);
+       LTTNG_ASSERT(writer);
 
        count = lttng_list_sessions(&sessions);
        if (count < 0) {
@@ -143,7 +131,6 @@ end:
 static
 struct lttng_session_descriptor *create_session_descriptor(void)
 {
-       int ret;
        ssize_t uri_count;
        enum output_type output_type;
        struct lttng_uri *uris = NULL;
@@ -155,6 +142,7 @@ struct lttng_session_descriptor *create_session_descriptor(void)
                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);
@@ -171,6 +159,8 @@ struct lttng_session_descriptor *create_session_descriptor(void)
                        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;
 
@@ -236,7 +226,6 @@ struct lttng_session_descriptor *create_session_descriptor(void)
                descriptor = lttng_session_descriptor_live_network_create(
                                opt_session_name, uri_str1, uri_str2,
                                opt_live_timer);
-
        } else {
                /* Regular session. */
                switch (output_type) {
@@ -261,6 +250,23 @@ struct lttng_session_descriptor *create_session_descriptor(void)
        }
        if (!descriptor) {
                ERR("Failed to initialize session creation command.");
+       } else {
+               /*
+                * Auto-launch the relay daemon when a live session
+                * is created using default URLs.
+                */
+               if (!opt_url && !opt_ctrl_url && !opt_data_url &&
+                               opt_live_timer && !check_relayd()) {
+                       int ret;
+                       const char *pathname = opt_relayd_path ? :
+                                       INSTALL_BIN_PATH "/lttng-relayd";
+
+                       ret = spawn_relayd(pathname, 0);
+                       if (ret < 0) {
+                               lttng_session_descriptor_destroy(descriptor);
+                               descriptor = NULL;
+                       }
+               }
        }
 end:
        free(uris);
@@ -495,7 +501,7 @@ error:
  *
  *  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;
@@ -574,7 +580,7 @@ end:
 static int launch_sessiond(void)
 {
        int ret;
-       char *pathname = NULL;
+       const char *pathname = NULL;
 
        ret = lttng_session_daemon_alive();
        if (ret) {
@@ -621,6 +627,7 @@ end:
        return ret;
 }
 
+static
 int validate_url_option_combination(void)
 {
        int ret = 0;
This page took 0.024693 seconds and 4 git commands to generate.